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    import com.liferay.portlet.journal.service.persistence.JournalArticlePersistence;
051    
052    import java.io.Serializable;
053    
054    import java.util.ArrayList;
055    import java.util.Collections;
056    import java.util.Date;
057    import java.util.List;
058    import java.util.Set;
059    
060    /**
061     * The persistence implementation for the journal article service.
062     *
063     * <p>
064     * Caching information and settings can be found in <code>portal.properties</code>
065     * </p>
066     *
067     * @author Brian Wing Shun Chan
068     * @see JournalArticlePersistence
069     * @see JournalArticleUtil
070     * @generated
071     */
072    public class JournalArticlePersistenceImpl extends BasePersistenceImpl<JournalArticle>
073            implements JournalArticlePersistence {
074            /*
075             * NOTE FOR DEVELOPERS:
076             *
077             * 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.
078             */
079            public static final String FINDER_CLASS_NAME_ENTITY = JournalArticleImpl.class.getName();
080            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
081                    ".List1";
082            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
083                    ".List2";
084            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
085                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
086                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
087                            "findAll", new String[0]);
088            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
089                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
090                            JournalArticleImpl.class,
091                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
092            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
093                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
094                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
095            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
096                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
097                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
098                            "findByUuid",
099                            new String[] {
100                                    String.class.getName(),
101                                    
102                            Integer.class.getName(), Integer.class.getName(),
103                                    OrderByComparator.class.getName()
104                            });
105            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
106                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
107                            JournalArticleImpl.class,
108                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
109                            new String[] { String.class.getName() },
110                            JournalArticleModelImpl.UUID_COLUMN_BITMASK |
111                            JournalArticleModelImpl.ARTICLEID_COLUMN_BITMASK |
112                            JournalArticleModelImpl.VERSION_COLUMN_BITMASK);
113            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
114                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
115                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
116                            new String[] { String.class.getName() });
117    
118            /**
119             * Returns all the journal articles where uuid = &#63;.
120             *
121             * @param uuid the uuid
122             * @return the matching journal articles
123             * @throws SystemException if a system exception occurred
124             */
125            @Override
126            public List<JournalArticle> findByUuid(String uuid)
127                    throws SystemException {
128                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
129            }
130    
131            /**
132             * Returns a range of all the journal articles where uuid = &#63;.
133             *
134             * <p>
135             * 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.
136             * </p>
137             *
138             * @param uuid the uuid
139             * @param start the lower bound of the range of journal articles
140             * @param end the upper bound of the range of journal articles (not inclusive)
141             * @return the range of matching journal articles
142             * @throws SystemException if a system exception occurred
143             */
144            @Override
145            public List<JournalArticle> findByUuid(String uuid, int start, int end)
146                    throws SystemException {
147                    return findByUuid(uuid, start, end, null);
148            }
149    
150            /**
151             * Returns an ordered range of all the journal articles where uuid = &#63;.
152             *
153             * <p>
154             * 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.
155             * </p>
156             *
157             * @param uuid the uuid
158             * @param start the lower bound of the range of journal articles
159             * @param end the upper bound of the range of journal articles (not inclusive)
160             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
161             * @return the ordered range of matching journal articles
162             * @throws SystemException if a system exception occurred
163             */
164            @Override
165            public List<JournalArticle> findByUuid(String uuid, int start, int end,
166                    OrderByComparator orderByComparator) throws SystemException {
167                    boolean pagination = true;
168                    FinderPath finderPath = null;
169                    Object[] finderArgs = null;
170    
171                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
172                                    (orderByComparator == null)) {
173                            pagination = false;
174                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
175                            finderArgs = new Object[] { uuid };
176                    }
177                    else {
178                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
179                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
180                    }
181    
182                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
183                                    finderArgs, this);
184    
185                    if ((list != null) && !list.isEmpty()) {
186                            for (JournalArticle journalArticle : list) {
187                                    if (!Validator.equals(uuid, journalArticle.getUuid())) {
188                                            list = null;
189    
190                                            break;
191                                    }
192                            }
193                    }
194    
195                    if (list == null) {
196                            StringBundler query = null;
197    
198                            if (orderByComparator != null) {
199                                    query = new StringBundler(3 +
200                                                    (orderByComparator.getOrderByFields().length * 3));
201                            }
202                            else {
203                                    query = new StringBundler(3);
204                            }
205    
206                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
207    
208                            boolean bindUuid = false;
209    
210                            if (uuid == null) {
211                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
212                            }
213                            else if (uuid.equals(StringPool.BLANK)) {
214                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
215                            }
216                            else {
217                                    bindUuid = true;
218    
219                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
220                            }
221    
222                            if (orderByComparator != null) {
223                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
224                                            orderByComparator);
225                            }
226                            else
227                             if (pagination) {
228                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
229                            }
230    
231                            String sql = query.toString();
232    
233                            Session session = null;
234    
235                            try {
236                                    session = openSession();
237    
238                                    Query q = session.createQuery(sql);
239    
240                                    QueryPos qPos = QueryPos.getInstance(q);
241    
242                                    if (bindUuid) {
243                                            qPos.add(uuid);
244                                    }
245    
246                                    if (!pagination) {
247                                            list = (List<JournalArticle>)QueryUtil.list(q,
248                                                            getDialect(), start, end, false);
249    
250                                            Collections.sort(list);
251    
252                                            list = new UnmodifiableList<JournalArticle>(list);
253                                    }
254                                    else {
255                                            list = (List<JournalArticle>)QueryUtil.list(q,
256                                                            getDialect(), start, end);
257                                    }
258    
259                                    cacheResult(list);
260    
261                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
262                            }
263                            catch (Exception e) {
264                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
265    
266                                    throw processException(e);
267                            }
268                            finally {
269                                    closeSession(session);
270                            }
271                    }
272    
273                    return list;
274            }
275    
276            /**
277             * Returns the first journal article in the ordered set where uuid = &#63;.
278             *
279             * @param uuid the uuid
280             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
281             * @return the first matching journal article
282             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
283             * @throws SystemException if a system exception occurred
284             */
285            @Override
286            public JournalArticle findByUuid_First(String uuid,
287                    OrderByComparator orderByComparator)
288                    throws NoSuchArticleException, SystemException {
289                    JournalArticle journalArticle = fetchByUuid_First(uuid,
290                                    orderByComparator);
291    
292                    if (journalArticle != null) {
293                            return journalArticle;
294                    }
295    
296                    StringBundler msg = new StringBundler(4);
297    
298                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
299    
300                    msg.append("uuid=");
301                    msg.append(uuid);
302    
303                    msg.append(StringPool.CLOSE_CURLY_BRACE);
304    
305                    throw new NoSuchArticleException(msg.toString());
306            }
307    
308            /**
309             * Returns the first journal article in the ordered set where uuid = &#63;.
310             *
311             * @param uuid the uuid
312             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
313             * @return the first matching journal article, or <code>null</code> if a matching journal article could not be found
314             * @throws SystemException if a system exception occurred
315             */
316            @Override
317            public JournalArticle fetchByUuid_First(String uuid,
318                    OrderByComparator orderByComparator) throws SystemException {
319                    List<JournalArticle> list = findByUuid(uuid, 0, 1, orderByComparator);
320    
321                    if (!list.isEmpty()) {
322                            return list.get(0);
323                    }
324    
325                    return null;
326            }
327    
328            /**
329             * Returns the last journal article in the ordered set where uuid = &#63;.
330             *
331             * @param uuid the uuid
332             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
333             * @return the last matching journal article
334             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
335             * @throws SystemException if a system exception occurred
336             */
337            @Override
338            public JournalArticle findByUuid_Last(String uuid,
339                    OrderByComparator orderByComparator)
340                    throws NoSuchArticleException, SystemException {
341                    JournalArticle journalArticle = fetchByUuid_Last(uuid, orderByComparator);
342    
343                    if (journalArticle != null) {
344                            return journalArticle;
345                    }
346    
347                    StringBundler msg = new StringBundler(4);
348    
349                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
350    
351                    msg.append("uuid=");
352                    msg.append(uuid);
353    
354                    msg.append(StringPool.CLOSE_CURLY_BRACE);
355    
356                    throw new NoSuchArticleException(msg.toString());
357            }
358    
359            /**
360             * Returns the last journal article in the ordered set where uuid = &#63;.
361             *
362             * @param uuid the uuid
363             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
364             * @return the last matching journal article, or <code>null</code> if a matching journal article could not be found
365             * @throws SystemException if a system exception occurred
366             */
367            @Override
368            public JournalArticle fetchByUuid_Last(String uuid,
369                    OrderByComparator orderByComparator) throws SystemException {
370                    int count = countByUuid(uuid);
371    
372                    if (count == 0) {
373                            return null;
374                    }
375    
376                    List<JournalArticle> list = findByUuid(uuid, count - 1, count,
377                                    orderByComparator);
378    
379                    if (!list.isEmpty()) {
380                            return list.get(0);
381                    }
382    
383                    return null;
384            }
385    
386            /**
387             * Returns the journal articles before and after the current journal article in the ordered set where uuid = &#63;.
388             *
389             * @param id the primary key of the current journal article
390             * @param uuid the uuid
391             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
392             * @return the previous, current, and next journal article
393             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
394             * @throws SystemException if a system exception occurred
395             */
396            @Override
397            public JournalArticle[] findByUuid_PrevAndNext(long id, String uuid,
398                    OrderByComparator orderByComparator)
399                    throws NoSuchArticleException, SystemException {
400                    JournalArticle journalArticle = findByPrimaryKey(id);
401    
402                    Session session = null;
403    
404                    try {
405                            session = openSession();
406    
407                            JournalArticle[] array = new JournalArticleImpl[3];
408    
409                            array[0] = getByUuid_PrevAndNext(session, journalArticle, uuid,
410                                            orderByComparator, true);
411    
412                            array[1] = journalArticle;
413    
414                            array[2] = getByUuid_PrevAndNext(session, journalArticle, uuid,
415                                            orderByComparator, false);
416    
417                            return array;
418                    }
419                    catch (Exception e) {
420                            throw processException(e);
421                    }
422                    finally {
423                            closeSession(session);
424                    }
425            }
426    
427            protected JournalArticle getByUuid_PrevAndNext(Session session,
428                    JournalArticle journalArticle, String uuid,
429                    OrderByComparator orderByComparator, boolean previous) {
430                    StringBundler query = null;
431    
432                    if (orderByComparator != null) {
433                            query = new StringBundler(6 +
434                                            (orderByComparator.getOrderByFields().length * 6));
435                    }
436                    else {
437                            query = new StringBundler(3);
438                    }
439    
440                    query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
441    
442                    boolean bindUuid = false;
443    
444                    if (uuid == null) {
445                            query.append(_FINDER_COLUMN_UUID_UUID_1);
446                    }
447                    else if (uuid.equals(StringPool.BLANK)) {
448                            query.append(_FINDER_COLUMN_UUID_UUID_3);
449                    }
450                    else {
451                            bindUuid = true;
452    
453                            query.append(_FINDER_COLUMN_UUID_UUID_2);
454                    }
455    
456                    if (orderByComparator != null) {
457                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
458    
459                            if (orderByConditionFields.length > 0) {
460                                    query.append(WHERE_AND);
461                            }
462    
463                            for (int i = 0; i < orderByConditionFields.length; i++) {
464                                    query.append(_ORDER_BY_ENTITY_ALIAS);
465                                    query.append(orderByConditionFields[i]);
466    
467                                    if ((i + 1) < orderByConditionFields.length) {
468                                            if (orderByComparator.isAscending() ^ previous) {
469                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
470                                            }
471                                            else {
472                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
473                                            }
474                                    }
475                                    else {
476                                            if (orderByComparator.isAscending() ^ previous) {
477                                                    query.append(WHERE_GREATER_THAN);
478                                            }
479                                            else {
480                                                    query.append(WHERE_LESSER_THAN);
481                                            }
482                                    }
483                            }
484    
485                            query.append(ORDER_BY_CLAUSE);
486    
487                            String[] orderByFields = orderByComparator.getOrderByFields();
488    
489                            for (int i = 0; i < orderByFields.length; i++) {
490                                    query.append(_ORDER_BY_ENTITY_ALIAS);
491                                    query.append(orderByFields[i]);
492    
493                                    if ((i + 1) < orderByFields.length) {
494                                            if (orderByComparator.isAscending() ^ previous) {
495                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
496                                            }
497                                            else {
498                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
499                                            }
500                                    }
501                                    else {
502                                            if (orderByComparator.isAscending() ^ previous) {
503                                                    query.append(ORDER_BY_ASC);
504                                            }
505                                            else {
506                                                    query.append(ORDER_BY_DESC);
507                                            }
508                                    }
509                            }
510                    }
511                    else {
512                            query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
513                    }
514    
515                    String sql = query.toString();
516    
517                    Query q = session.createQuery(sql);
518    
519                    q.setFirstResult(0);
520                    q.setMaxResults(2);
521    
522                    QueryPos qPos = QueryPos.getInstance(q);
523    
524                    if (bindUuid) {
525                            qPos.add(uuid);
526                    }
527    
528                    if (orderByComparator != null) {
529                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
530    
531                            for (Object value : values) {
532                                    qPos.add(value);
533                            }
534                    }
535    
536                    List<JournalArticle> list = q.list();
537    
538                    if (list.size() == 2) {
539                            return list.get(1);
540                    }
541                    else {
542                            return null;
543                    }
544            }
545    
546            /**
547             * Removes all the journal articles where uuid = &#63; from the database.
548             *
549             * @param uuid the uuid
550             * @throws SystemException if a system exception occurred
551             */
552            @Override
553            public void removeByUuid(String uuid) throws SystemException {
554                    for (JournalArticle journalArticle : findByUuid(uuid,
555                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
556                            remove(journalArticle);
557                    }
558            }
559    
560            /**
561             * Returns the number of journal articles where uuid = &#63;.
562             *
563             * @param uuid the uuid
564             * @return the number of matching journal articles
565             * @throws SystemException if a system exception occurred
566             */
567            @Override
568            public int countByUuid(String uuid) throws SystemException {
569                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
570    
571                    Object[] finderArgs = new Object[] { uuid };
572    
573                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
574                                    this);
575    
576                    if (count == null) {
577                            StringBundler query = new StringBundler(2);
578    
579                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
580    
581                            boolean bindUuid = false;
582    
583                            if (uuid == null) {
584                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
585                            }
586                            else if (uuid.equals(StringPool.BLANK)) {
587                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
588                            }
589                            else {
590                                    bindUuid = true;
591    
592                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
593                            }
594    
595                            String sql = query.toString();
596    
597                            Session session = null;
598    
599                            try {
600                                    session = openSession();
601    
602                                    Query q = session.createQuery(sql);
603    
604                                    QueryPos qPos = QueryPos.getInstance(q);
605    
606                                    if (bindUuid) {
607                                            qPos.add(uuid);
608                                    }
609    
610                                    count = (Long)q.uniqueResult();
611    
612                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
613                            }
614                            catch (Exception e) {
615                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
616    
617                                    throw processException(e);
618                            }
619                            finally {
620                                    closeSession(session);
621                            }
622                    }
623    
624                    return count.intValue();
625            }
626    
627            private static final String _FINDER_COLUMN_UUID_UUID_1 = "journalArticle.uuid IS NULL";
628            private static final String _FINDER_COLUMN_UUID_UUID_2 = "journalArticle.uuid = ?";
629            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(journalArticle.uuid IS NULL OR journalArticle.uuid = '')";
630            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
631                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
632                            JournalArticleImpl.class, FINDER_CLASS_NAME_ENTITY,
633                            "fetchByUUID_G",
634                            new String[] { String.class.getName(), Long.class.getName() },
635                            JournalArticleModelImpl.UUID_COLUMN_BITMASK |
636                            JournalArticleModelImpl.GROUPID_COLUMN_BITMASK);
637            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
638                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
639                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
640                            new String[] { String.class.getName(), Long.class.getName() });
641    
642            /**
643             * 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.
644             *
645             * @param uuid the uuid
646             * @param groupId the group ID
647             * @return the matching journal article
648             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
649             * @throws SystemException if a system exception occurred
650             */
651            @Override
652            public JournalArticle findByUUID_G(String uuid, long groupId)
653                    throws NoSuchArticleException, SystemException {
654                    JournalArticle journalArticle = fetchByUUID_G(uuid, groupId);
655    
656                    if (journalArticle == null) {
657                            StringBundler msg = new StringBundler(6);
658    
659                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
660    
661                            msg.append("uuid=");
662                            msg.append(uuid);
663    
664                            msg.append(", groupId=");
665                            msg.append(groupId);
666    
667                            msg.append(StringPool.CLOSE_CURLY_BRACE);
668    
669                            if (_log.isWarnEnabled()) {
670                                    _log.warn(msg.toString());
671                            }
672    
673                            throw new NoSuchArticleException(msg.toString());
674                    }
675    
676                    return journalArticle;
677            }
678    
679            /**
680             * 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.
681             *
682             * @param uuid the uuid
683             * @param groupId the group ID
684             * @return the matching journal article, or <code>null</code> if a matching journal article could not be found
685             * @throws SystemException if a system exception occurred
686             */
687            @Override
688            public JournalArticle fetchByUUID_G(String uuid, long groupId)
689                    throws SystemException {
690                    return fetchByUUID_G(uuid, groupId, true);
691            }
692    
693            /**
694             * 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.
695             *
696             * @param uuid the uuid
697             * @param groupId the group ID
698             * @param retrieveFromCache whether to use the finder cache
699             * @return the matching journal article, or <code>null</code> if a matching journal article could not be found
700             * @throws SystemException if a system exception occurred
701             */
702            @Override
703            public JournalArticle fetchByUUID_G(String uuid, long groupId,
704                    boolean retrieveFromCache) throws SystemException {
705                    Object[] finderArgs = new Object[] { uuid, groupId };
706    
707                    Object result = null;
708    
709                    if (retrieveFromCache) {
710                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
711                                            finderArgs, this);
712                    }
713    
714                    if (result instanceof JournalArticle) {
715                            JournalArticle journalArticle = (JournalArticle)result;
716    
717                            if (!Validator.equals(uuid, journalArticle.getUuid()) ||
718                                            (groupId != journalArticle.getGroupId())) {
719                                    result = null;
720                            }
721                    }
722    
723                    if (result == null) {
724                            StringBundler query = new StringBundler(4);
725    
726                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
727    
728                            boolean bindUuid = false;
729    
730                            if (uuid == null) {
731                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
732                            }
733                            else if (uuid.equals(StringPool.BLANK)) {
734                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
735                            }
736                            else {
737                                    bindUuid = true;
738    
739                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
740                            }
741    
742                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
743    
744                            String sql = query.toString();
745    
746                            Session session = null;
747    
748                            try {
749                                    session = openSession();
750    
751                                    Query q = session.createQuery(sql);
752    
753                                    QueryPos qPos = QueryPos.getInstance(q);
754    
755                                    if (bindUuid) {
756                                            qPos.add(uuid);
757                                    }
758    
759                                    qPos.add(groupId);
760    
761                                    List<JournalArticle> list = q.list();
762    
763                                    if (list.isEmpty()) {
764                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
765                                                    finderArgs, list);
766                                    }
767                                    else {
768                                            JournalArticle journalArticle = list.get(0);
769    
770                                            result = journalArticle;
771    
772                                            cacheResult(journalArticle);
773    
774                                            if ((journalArticle.getUuid() == null) ||
775                                                            !journalArticle.getUuid().equals(uuid) ||
776                                                            (journalArticle.getGroupId() != groupId)) {
777                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
778                                                            finderArgs, journalArticle);
779                                            }
780                                    }
781                            }
782                            catch (Exception e) {
783                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
784                                            finderArgs);
785    
786                                    throw processException(e);
787                            }
788                            finally {
789                                    closeSession(session);
790                            }
791                    }
792    
793                    if (result instanceof List<?>) {
794                            return null;
795                    }
796                    else {
797                            return (JournalArticle)result;
798                    }
799            }
800    
801            /**
802             * Removes the journal article where uuid = &#63; and groupId = &#63; from the database.
803             *
804             * @param uuid the uuid
805             * @param groupId the group ID
806             * @return the journal article that was removed
807             * @throws SystemException if a system exception occurred
808             */
809            @Override
810            public JournalArticle removeByUUID_G(String uuid, long groupId)
811                    throws NoSuchArticleException, SystemException {
812                    JournalArticle journalArticle = findByUUID_G(uuid, groupId);
813    
814                    return remove(journalArticle);
815            }
816    
817            /**
818             * Returns the number of journal articles where uuid = &#63; and groupId = &#63;.
819             *
820             * @param uuid the uuid
821             * @param groupId the group ID
822             * @return the number of matching journal articles
823             * @throws SystemException if a system exception occurred
824             */
825            @Override
826            public int countByUUID_G(String uuid, long groupId)
827                    throws SystemException {
828                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
829    
830                    Object[] finderArgs = new Object[] { uuid, groupId };
831    
832                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
833                                    this);
834    
835                    if (count == null) {
836                            StringBundler query = new StringBundler(3);
837    
838                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
839    
840                            boolean bindUuid = false;
841    
842                            if (uuid == null) {
843                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
844                            }
845                            else if (uuid.equals(StringPool.BLANK)) {
846                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
847                            }
848                            else {
849                                    bindUuid = true;
850    
851                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
852                            }
853    
854                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
855    
856                            String sql = query.toString();
857    
858                            Session session = null;
859    
860                            try {
861                                    session = openSession();
862    
863                                    Query q = session.createQuery(sql);
864    
865                                    QueryPos qPos = QueryPos.getInstance(q);
866    
867                                    if (bindUuid) {
868                                            qPos.add(uuid);
869                                    }
870    
871                                    qPos.add(groupId);
872    
873                                    count = (Long)q.uniqueResult();
874    
875                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
876                            }
877                            catch (Exception e) {
878                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
879    
880                                    throw processException(e);
881                            }
882                            finally {
883                                    closeSession(session);
884                            }
885                    }
886    
887                    return count.intValue();
888            }
889    
890            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "journalArticle.uuid IS NULL AND ";
891            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "journalArticle.uuid = ? AND ";
892            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(journalArticle.uuid IS NULL OR journalArticle.uuid = '') AND ";
893            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "journalArticle.groupId = ?";
894            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
895                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
896                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
897                            "findByUuid_C",
898                            new String[] {
899                                    String.class.getName(), Long.class.getName(),
900                                    
901                            Integer.class.getName(), Integer.class.getName(),
902                                    OrderByComparator.class.getName()
903                            });
904            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
905                    new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
906                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
907                            JournalArticleImpl.class,
908                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
909                            new String[] { String.class.getName(), Long.class.getName() },
910                            JournalArticleModelImpl.UUID_COLUMN_BITMASK |
911                            JournalArticleModelImpl.COMPANYID_COLUMN_BITMASK |
912                            JournalArticleModelImpl.ARTICLEID_COLUMN_BITMASK |
913                            JournalArticleModelImpl.VERSION_COLUMN_BITMASK);
914            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
915                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
916                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
917                            new String[] { String.class.getName(), Long.class.getName() });
918    
919            /**
920             * Returns all the journal articles where uuid = &#63; and companyId = &#63;.
921             *
922             * @param uuid the uuid
923             * @param companyId the company ID
924             * @return the matching journal articles
925             * @throws SystemException if a system exception occurred
926             */
927            @Override
928            public List<JournalArticle> findByUuid_C(String uuid, long companyId)
929                    throws SystemException {
930                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
931                            QueryUtil.ALL_POS, null);
932            }
933    
934            /**
935             * Returns a range of all the journal articles where uuid = &#63; and companyId = &#63;.
936             *
937             * <p>
938             * 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.
939             * </p>
940             *
941             * @param uuid the uuid
942             * @param companyId the company ID
943             * @param start the lower bound of the range of journal articles
944             * @param end the upper bound of the range of journal articles (not inclusive)
945             * @return the range of matching journal articles
946             * @throws SystemException if a system exception occurred
947             */
948            @Override
949            public List<JournalArticle> findByUuid_C(String uuid, long companyId,
950                    int start, int end) throws SystemException {
951                    return findByUuid_C(uuid, companyId, start, end, null);
952            }
953    
954            /**
955             * Returns an ordered range of all the journal articles where uuid = &#63; and companyId = &#63;.
956             *
957             * <p>
958             * 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.
959             * </p>
960             *
961             * @param uuid the uuid
962             * @param companyId the company ID
963             * @param start the lower bound of the range of journal articles
964             * @param end the upper bound of the range of journal articles (not inclusive)
965             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
966             * @return the ordered range of matching journal articles
967             * @throws SystemException if a system exception occurred
968             */
969            @Override
970            public List<JournalArticle> findByUuid_C(String uuid, long companyId,
971                    int start, int end, OrderByComparator orderByComparator)
972                    throws SystemException {
973                    boolean pagination = true;
974                    FinderPath finderPath = null;
975                    Object[] finderArgs = null;
976    
977                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
978                                    (orderByComparator == null)) {
979                            pagination = false;
980                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
981                            finderArgs = new Object[] { uuid, companyId };
982                    }
983                    else {
984                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
985                            finderArgs = new Object[] {
986                                            uuid, companyId,
987                                            
988                                            start, end, orderByComparator
989                                    };
990                    }
991    
992                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
993                                    finderArgs, this);
994    
995                    if ((list != null) && !list.isEmpty()) {
996                            for (JournalArticle journalArticle : list) {
997                                    if (!Validator.equals(uuid, journalArticle.getUuid()) ||
998                                                    (companyId != journalArticle.getCompanyId())) {
999                                            list = null;
1000    
1001                                            break;
1002                                    }
1003                            }
1004                    }
1005    
1006                    if (list == null) {
1007                            StringBundler query = null;
1008    
1009                            if (orderByComparator != null) {
1010                                    query = new StringBundler(4 +
1011                                                    (orderByComparator.getOrderByFields().length * 3));
1012                            }
1013                            else {
1014                                    query = new StringBundler(4);
1015                            }
1016    
1017                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
1018    
1019                            boolean bindUuid = false;
1020    
1021                            if (uuid == null) {
1022                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1023                            }
1024                            else if (uuid.equals(StringPool.BLANK)) {
1025                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1026                            }
1027                            else {
1028                                    bindUuid = true;
1029    
1030                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1031                            }
1032    
1033                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1034    
1035                            if (orderByComparator != null) {
1036                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1037                                            orderByComparator);
1038                            }
1039                            else
1040                             if (pagination) {
1041                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
1042                            }
1043    
1044                            String sql = query.toString();
1045    
1046                            Session session = null;
1047    
1048                            try {
1049                                    session = openSession();
1050    
1051                                    Query q = session.createQuery(sql);
1052    
1053                                    QueryPos qPos = QueryPos.getInstance(q);
1054    
1055                                    if (bindUuid) {
1056                                            qPos.add(uuid);
1057                                    }
1058    
1059                                    qPos.add(companyId);
1060    
1061                                    if (!pagination) {
1062                                            list = (List<JournalArticle>)QueryUtil.list(q,
1063                                                            getDialect(), start, end, false);
1064    
1065                                            Collections.sort(list);
1066    
1067                                            list = new UnmodifiableList<JournalArticle>(list);
1068                                    }
1069                                    else {
1070                                            list = (List<JournalArticle>)QueryUtil.list(q,
1071                                                            getDialect(), start, end);
1072                                    }
1073    
1074                                    cacheResult(list);
1075    
1076                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1077                            }
1078                            catch (Exception e) {
1079                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1080    
1081                                    throw processException(e);
1082                            }
1083                            finally {
1084                                    closeSession(session);
1085                            }
1086                    }
1087    
1088                    return list;
1089            }
1090    
1091            /**
1092             * Returns the first journal article in the ordered set where uuid = &#63; and companyId = &#63;.
1093             *
1094             * @param uuid the uuid
1095             * @param companyId the company ID
1096             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1097             * @return the first matching journal article
1098             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
1099             * @throws SystemException if a system exception occurred
1100             */
1101            @Override
1102            public JournalArticle findByUuid_C_First(String uuid, long companyId,
1103                    OrderByComparator orderByComparator)
1104                    throws NoSuchArticleException, SystemException {
1105                    JournalArticle journalArticle = fetchByUuid_C_First(uuid, companyId,
1106                                    orderByComparator);
1107    
1108                    if (journalArticle != null) {
1109                            return journalArticle;
1110                    }
1111    
1112                    StringBundler msg = new StringBundler(6);
1113    
1114                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1115    
1116                    msg.append("uuid=");
1117                    msg.append(uuid);
1118    
1119                    msg.append(", companyId=");
1120                    msg.append(companyId);
1121    
1122                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1123    
1124                    throw new NoSuchArticleException(msg.toString());
1125            }
1126    
1127            /**
1128             * Returns the first journal article in the ordered set where uuid = &#63; and companyId = &#63;.
1129             *
1130             * @param uuid the uuid
1131             * @param companyId the company ID
1132             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1133             * @return the first matching journal article, or <code>null</code> if a matching journal article could not be found
1134             * @throws SystemException if a system exception occurred
1135             */
1136            @Override
1137            public JournalArticle fetchByUuid_C_First(String uuid, long companyId,
1138                    OrderByComparator orderByComparator) throws SystemException {
1139                    List<JournalArticle> list = findByUuid_C(uuid, companyId, 0, 1,
1140                                    orderByComparator);
1141    
1142                    if (!list.isEmpty()) {
1143                            return list.get(0);
1144                    }
1145    
1146                    return null;
1147            }
1148    
1149            /**
1150             * Returns the last journal article in the ordered set where uuid = &#63; and companyId = &#63;.
1151             *
1152             * @param uuid the uuid
1153             * @param companyId the company ID
1154             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1155             * @return the last matching journal article
1156             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
1157             * @throws SystemException if a system exception occurred
1158             */
1159            @Override
1160            public JournalArticle findByUuid_C_Last(String uuid, long companyId,
1161                    OrderByComparator orderByComparator)
1162                    throws NoSuchArticleException, SystemException {
1163                    JournalArticle journalArticle = fetchByUuid_C_Last(uuid, companyId,
1164                                    orderByComparator);
1165    
1166                    if (journalArticle != null) {
1167                            return journalArticle;
1168                    }
1169    
1170                    StringBundler msg = new StringBundler(6);
1171    
1172                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1173    
1174                    msg.append("uuid=");
1175                    msg.append(uuid);
1176    
1177                    msg.append(", companyId=");
1178                    msg.append(companyId);
1179    
1180                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1181    
1182                    throw new NoSuchArticleException(msg.toString());
1183            }
1184    
1185            /**
1186             * Returns the last journal article in the ordered set where uuid = &#63; and companyId = &#63;.
1187             *
1188             * @param uuid the uuid
1189             * @param companyId the company ID
1190             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1191             * @return the last matching journal article, or <code>null</code> if a matching journal article could not be found
1192             * @throws SystemException if a system exception occurred
1193             */
1194            @Override
1195            public JournalArticle fetchByUuid_C_Last(String uuid, long companyId,
1196                    OrderByComparator orderByComparator) throws SystemException {
1197                    int count = countByUuid_C(uuid, companyId);
1198    
1199                    if (count == 0) {
1200                            return null;
1201                    }
1202    
1203                    List<JournalArticle> list = findByUuid_C(uuid, companyId, count - 1,
1204                                    count, orderByComparator);
1205    
1206                    if (!list.isEmpty()) {
1207                            return list.get(0);
1208                    }
1209    
1210                    return null;
1211            }
1212    
1213            /**
1214             * Returns the journal articles before and after the current journal article in the ordered set where uuid = &#63; and companyId = &#63;.
1215             *
1216             * @param id the primary key of the current journal article
1217             * @param uuid the uuid
1218             * @param companyId the company ID
1219             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1220             * @return the previous, current, and next journal article
1221             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
1222             * @throws SystemException if a system exception occurred
1223             */
1224            @Override
1225            public JournalArticle[] findByUuid_C_PrevAndNext(long id, String uuid,
1226                    long companyId, OrderByComparator orderByComparator)
1227                    throws NoSuchArticleException, SystemException {
1228                    JournalArticle journalArticle = findByPrimaryKey(id);
1229    
1230                    Session session = null;
1231    
1232                    try {
1233                            session = openSession();
1234    
1235                            JournalArticle[] array = new JournalArticleImpl[3];
1236    
1237                            array[0] = getByUuid_C_PrevAndNext(session, journalArticle, uuid,
1238                                            companyId, orderByComparator, true);
1239    
1240                            array[1] = journalArticle;
1241    
1242                            array[2] = getByUuid_C_PrevAndNext(session, journalArticle, uuid,
1243                                            companyId, orderByComparator, false);
1244    
1245                            return array;
1246                    }
1247                    catch (Exception e) {
1248                            throw processException(e);
1249                    }
1250                    finally {
1251                            closeSession(session);
1252                    }
1253            }
1254    
1255            protected JournalArticle getByUuid_C_PrevAndNext(Session session,
1256                    JournalArticle journalArticle, String uuid, long companyId,
1257                    OrderByComparator orderByComparator, boolean previous) {
1258                    StringBundler query = null;
1259    
1260                    if (orderByComparator != null) {
1261                            query = new StringBundler(6 +
1262                                            (orderByComparator.getOrderByFields().length * 6));
1263                    }
1264                    else {
1265                            query = new StringBundler(3);
1266                    }
1267    
1268                    query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
1269    
1270                    boolean bindUuid = false;
1271    
1272                    if (uuid == null) {
1273                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1274                    }
1275                    else if (uuid.equals(StringPool.BLANK)) {
1276                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1277                    }
1278                    else {
1279                            bindUuid = true;
1280    
1281                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1282                    }
1283    
1284                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1285    
1286                    if (orderByComparator != null) {
1287                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1288    
1289                            if (orderByConditionFields.length > 0) {
1290                                    query.append(WHERE_AND);
1291                            }
1292    
1293                            for (int i = 0; i < orderByConditionFields.length; i++) {
1294                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1295                                    query.append(orderByConditionFields[i]);
1296    
1297                                    if ((i + 1) < orderByConditionFields.length) {
1298                                            if (orderByComparator.isAscending() ^ previous) {
1299                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1300                                            }
1301                                            else {
1302                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1303                                            }
1304                                    }
1305                                    else {
1306                                            if (orderByComparator.isAscending() ^ previous) {
1307                                                    query.append(WHERE_GREATER_THAN);
1308                                            }
1309                                            else {
1310                                                    query.append(WHERE_LESSER_THAN);
1311                                            }
1312                                    }
1313                            }
1314    
1315                            query.append(ORDER_BY_CLAUSE);
1316    
1317                            String[] orderByFields = orderByComparator.getOrderByFields();
1318    
1319                            for (int i = 0; i < orderByFields.length; i++) {
1320                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1321                                    query.append(orderByFields[i]);
1322    
1323                                    if ((i + 1) < orderByFields.length) {
1324                                            if (orderByComparator.isAscending() ^ previous) {
1325                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1326                                            }
1327                                            else {
1328                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1329                                            }
1330                                    }
1331                                    else {
1332                                            if (orderByComparator.isAscending() ^ previous) {
1333                                                    query.append(ORDER_BY_ASC);
1334                                            }
1335                                            else {
1336                                                    query.append(ORDER_BY_DESC);
1337                                            }
1338                                    }
1339                            }
1340                    }
1341                    else {
1342                            query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
1343                    }
1344    
1345                    String sql = query.toString();
1346    
1347                    Query q = session.createQuery(sql);
1348    
1349                    q.setFirstResult(0);
1350                    q.setMaxResults(2);
1351    
1352                    QueryPos qPos = QueryPos.getInstance(q);
1353    
1354                    if (bindUuid) {
1355                            qPos.add(uuid);
1356                    }
1357    
1358                    qPos.add(companyId);
1359    
1360                    if (orderByComparator != null) {
1361                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
1362    
1363                            for (Object value : values) {
1364                                    qPos.add(value);
1365                            }
1366                    }
1367    
1368                    List<JournalArticle> list = q.list();
1369    
1370                    if (list.size() == 2) {
1371                            return list.get(1);
1372                    }
1373                    else {
1374                            return null;
1375                    }
1376            }
1377    
1378            /**
1379             * Removes all the journal articles where uuid = &#63; and companyId = &#63; from the database.
1380             *
1381             * @param uuid the uuid
1382             * @param companyId the company ID
1383             * @throws SystemException if a system exception occurred
1384             */
1385            @Override
1386            public void removeByUuid_C(String uuid, long companyId)
1387                    throws SystemException {
1388                    for (JournalArticle journalArticle : findByUuid_C(uuid, companyId,
1389                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1390                            remove(journalArticle);
1391                    }
1392            }
1393    
1394            /**
1395             * Returns the number of journal articles where uuid = &#63; and companyId = &#63;.
1396             *
1397             * @param uuid the uuid
1398             * @param companyId the company ID
1399             * @return the number of matching journal articles
1400             * @throws SystemException if a system exception occurred
1401             */
1402            @Override
1403            public int countByUuid_C(String uuid, long companyId)
1404                    throws SystemException {
1405                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1406    
1407                    Object[] finderArgs = new Object[] { uuid, companyId };
1408    
1409                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1410                                    this);
1411    
1412                    if (count == null) {
1413                            StringBundler query = new StringBundler(3);
1414    
1415                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
1416    
1417                            boolean bindUuid = false;
1418    
1419                            if (uuid == null) {
1420                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1421                            }
1422                            else if (uuid.equals(StringPool.BLANK)) {
1423                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1424                            }
1425                            else {
1426                                    bindUuid = true;
1427    
1428                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1429                            }
1430    
1431                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1432    
1433                            String sql = query.toString();
1434    
1435                            Session session = null;
1436    
1437                            try {
1438                                    session = openSession();
1439    
1440                                    Query q = session.createQuery(sql);
1441    
1442                                    QueryPos qPos = QueryPos.getInstance(q);
1443    
1444                                    if (bindUuid) {
1445                                            qPos.add(uuid);
1446                                    }
1447    
1448                                    qPos.add(companyId);
1449    
1450                                    count = (Long)q.uniqueResult();
1451    
1452                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1453                            }
1454                            catch (Exception e) {
1455                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1456    
1457                                    throw processException(e);
1458                            }
1459                            finally {
1460                                    closeSession(session);
1461                            }
1462                    }
1463    
1464                    return count.intValue();
1465            }
1466    
1467            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "journalArticle.uuid IS NULL AND ";
1468            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "journalArticle.uuid = ? AND ";
1469            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(journalArticle.uuid IS NULL OR journalArticle.uuid = '') AND ";
1470            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "journalArticle.companyId = ?";
1471            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_RESOURCEPRIMKEY =
1472                    new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
1473                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
1474                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1475                            "findByResourcePrimKey",
1476                            new String[] {
1477                                    Long.class.getName(),
1478                                    
1479                            Integer.class.getName(), Integer.class.getName(),
1480                                    OrderByComparator.class.getName()
1481                            });
1482            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEPRIMKEY =
1483                    new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
1484                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
1485                            JournalArticleImpl.class,
1486                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByResourcePrimKey",
1487                            new String[] { Long.class.getName() },
1488                            JournalArticleModelImpl.RESOURCEPRIMKEY_COLUMN_BITMASK |
1489                            JournalArticleModelImpl.ARTICLEID_COLUMN_BITMASK |
1490                            JournalArticleModelImpl.VERSION_COLUMN_BITMASK);
1491            public static final FinderPath FINDER_PATH_COUNT_BY_RESOURCEPRIMKEY = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
1492                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
1493                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
1494                            "countByResourcePrimKey", new String[] { Long.class.getName() });
1495    
1496            /**
1497             * Returns all the journal articles where resourcePrimKey = &#63;.
1498             *
1499             * @param resourcePrimKey the resource prim key
1500             * @return the matching journal articles
1501             * @throws SystemException if a system exception occurred
1502             */
1503            @Override
1504            public List<JournalArticle> findByResourcePrimKey(long resourcePrimKey)
1505                    throws SystemException {
1506                    return findByResourcePrimKey(resourcePrimKey, QueryUtil.ALL_POS,
1507                            QueryUtil.ALL_POS, null);
1508            }
1509    
1510            /**
1511             * Returns a range of all the journal articles where resourcePrimKey = &#63;.
1512             *
1513             * <p>
1514             * 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.
1515             * </p>
1516             *
1517             * @param resourcePrimKey the resource prim key
1518             * @param start the lower bound of the range of journal articles
1519             * @param end the upper bound of the range of journal articles (not inclusive)
1520             * @return the range of matching journal articles
1521             * @throws SystemException if a system exception occurred
1522             */
1523            @Override
1524            public List<JournalArticle> findByResourcePrimKey(long resourcePrimKey,
1525                    int start, int end) throws SystemException {
1526                    return findByResourcePrimKey(resourcePrimKey, start, end, null);
1527            }
1528    
1529            /**
1530             * Returns an ordered range of all the journal articles where resourcePrimKey = &#63;.
1531             *
1532             * <p>
1533             * 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.
1534             * </p>
1535             *
1536             * @param resourcePrimKey the resource prim key
1537             * @param start the lower bound of the range of journal articles
1538             * @param end the upper bound of the range of journal articles (not inclusive)
1539             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1540             * @return the ordered range of matching journal articles
1541             * @throws SystemException if a system exception occurred
1542             */
1543            @Override
1544            public List<JournalArticle> findByResourcePrimKey(long resourcePrimKey,
1545                    int start, int end, OrderByComparator orderByComparator)
1546                    throws SystemException {
1547                    boolean pagination = true;
1548                    FinderPath finderPath = null;
1549                    Object[] finderArgs = null;
1550    
1551                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1552                                    (orderByComparator == null)) {
1553                            pagination = false;
1554                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEPRIMKEY;
1555                            finderArgs = new Object[] { resourcePrimKey };
1556                    }
1557                    else {
1558                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_RESOURCEPRIMKEY;
1559                            finderArgs = new Object[] {
1560                                            resourcePrimKey,
1561                                            
1562                                            start, end, orderByComparator
1563                                    };
1564                    }
1565    
1566                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
1567                                    finderArgs, this);
1568    
1569                    if ((list != null) && !list.isEmpty()) {
1570                            for (JournalArticle journalArticle : list) {
1571                                    if ((resourcePrimKey != journalArticle.getResourcePrimKey())) {
1572                                            list = null;
1573    
1574                                            break;
1575                                    }
1576                            }
1577                    }
1578    
1579                    if (list == null) {
1580                            StringBundler query = null;
1581    
1582                            if (orderByComparator != null) {
1583                                    query = new StringBundler(3 +
1584                                                    (orderByComparator.getOrderByFields().length * 3));
1585                            }
1586                            else {
1587                                    query = new StringBundler(3);
1588                            }
1589    
1590                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
1591    
1592                            query.append(_FINDER_COLUMN_RESOURCEPRIMKEY_RESOURCEPRIMKEY_2);
1593    
1594                            if (orderByComparator != null) {
1595                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1596                                            orderByComparator);
1597                            }
1598                            else
1599                             if (pagination) {
1600                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
1601                            }
1602    
1603                            String sql = query.toString();
1604    
1605                            Session session = null;
1606    
1607                            try {
1608                                    session = openSession();
1609    
1610                                    Query q = session.createQuery(sql);
1611    
1612                                    QueryPos qPos = QueryPos.getInstance(q);
1613    
1614                                    qPos.add(resourcePrimKey);
1615    
1616                                    if (!pagination) {
1617                                            list = (List<JournalArticle>)QueryUtil.list(q,
1618                                                            getDialect(), start, end, false);
1619    
1620                                            Collections.sort(list);
1621    
1622                                            list = new UnmodifiableList<JournalArticle>(list);
1623                                    }
1624                                    else {
1625                                            list = (List<JournalArticle>)QueryUtil.list(q,
1626                                                            getDialect(), start, end);
1627                                    }
1628    
1629                                    cacheResult(list);
1630    
1631                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1632                            }
1633                            catch (Exception e) {
1634                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1635    
1636                                    throw processException(e);
1637                            }
1638                            finally {
1639                                    closeSession(session);
1640                            }
1641                    }
1642    
1643                    return list;
1644            }
1645    
1646            /**
1647             * Returns the first journal article in the ordered set where resourcePrimKey = &#63;.
1648             *
1649             * @param resourcePrimKey the resource prim key
1650             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1651             * @return the first matching journal article
1652             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
1653             * @throws SystemException if a system exception occurred
1654             */
1655            @Override
1656            public JournalArticle findByResourcePrimKey_First(long resourcePrimKey,
1657                    OrderByComparator orderByComparator)
1658                    throws NoSuchArticleException, SystemException {
1659                    JournalArticle journalArticle = fetchByResourcePrimKey_First(resourcePrimKey,
1660                                    orderByComparator);
1661    
1662                    if (journalArticle != null) {
1663                            return journalArticle;
1664                    }
1665    
1666                    StringBundler msg = new StringBundler(4);
1667    
1668                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1669    
1670                    msg.append("resourcePrimKey=");
1671                    msg.append(resourcePrimKey);
1672    
1673                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1674    
1675                    throw new NoSuchArticleException(msg.toString());
1676            }
1677    
1678            /**
1679             * Returns the first journal article in the ordered set where resourcePrimKey = &#63;.
1680             *
1681             * @param resourcePrimKey the resource prim key
1682             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1683             * @return the first matching journal article, or <code>null</code> if a matching journal article could not be found
1684             * @throws SystemException if a system exception occurred
1685             */
1686            @Override
1687            public JournalArticle fetchByResourcePrimKey_First(long resourcePrimKey,
1688                    OrderByComparator orderByComparator) throws SystemException {
1689                    List<JournalArticle> list = findByResourcePrimKey(resourcePrimKey, 0,
1690                                    1, orderByComparator);
1691    
1692                    if (!list.isEmpty()) {
1693                            return list.get(0);
1694                    }
1695    
1696                    return null;
1697            }
1698    
1699            /**
1700             * Returns the last journal article in the ordered set where resourcePrimKey = &#63;.
1701             *
1702             * @param resourcePrimKey the resource prim key
1703             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1704             * @return the last matching journal article
1705             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
1706             * @throws SystemException if a system exception occurred
1707             */
1708            @Override
1709            public JournalArticle findByResourcePrimKey_Last(long resourcePrimKey,
1710                    OrderByComparator orderByComparator)
1711                    throws NoSuchArticleException, SystemException {
1712                    JournalArticle journalArticle = fetchByResourcePrimKey_Last(resourcePrimKey,
1713                                    orderByComparator);
1714    
1715                    if (journalArticle != null) {
1716                            return journalArticle;
1717                    }
1718    
1719                    StringBundler msg = new StringBundler(4);
1720    
1721                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1722    
1723                    msg.append("resourcePrimKey=");
1724                    msg.append(resourcePrimKey);
1725    
1726                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1727    
1728                    throw new NoSuchArticleException(msg.toString());
1729            }
1730    
1731            /**
1732             * Returns the last journal article in the ordered set where resourcePrimKey = &#63;.
1733             *
1734             * @param resourcePrimKey the resource prim key
1735             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1736             * @return the last matching journal article, or <code>null</code> if a matching journal article could not be found
1737             * @throws SystemException if a system exception occurred
1738             */
1739            @Override
1740            public JournalArticle fetchByResourcePrimKey_Last(long resourcePrimKey,
1741                    OrderByComparator orderByComparator) throws SystemException {
1742                    int count = countByResourcePrimKey(resourcePrimKey);
1743    
1744                    if (count == 0) {
1745                            return null;
1746                    }
1747    
1748                    List<JournalArticle> list = findByResourcePrimKey(resourcePrimKey,
1749                                    count - 1, count, orderByComparator);
1750    
1751                    if (!list.isEmpty()) {
1752                            return list.get(0);
1753                    }
1754    
1755                    return null;
1756            }
1757    
1758            /**
1759             * Returns the journal articles before and after the current journal article in the ordered set where resourcePrimKey = &#63;.
1760             *
1761             * @param id the primary key of the current journal article
1762             * @param resourcePrimKey the resource prim key
1763             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1764             * @return the previous, current, and next journal article
1765             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
1766             * @throws SystemException if a system exception occurred
1767             */
1768            @Override
1769            public JournalArticle[] findByResourcePrimKey_PrevAndNext(long id,
1770                    long resourcePrimKey, OrderByComparator orderByComparator)
1771                    throws NoSuchArticleException, SystemException {
1772                    JournalArticle journalArticle = findByPrimaryKey(id);
1773    
1774                    Session session = null;
1775    
1776                    try {
1777                            session = openSession();
1778    
1779                            JournalArticle[] array = new JournalArticleImpl[3];
1780    
1781                            array[0] = getByResourcePrimKey_PrevAndNext(session,
1782                                            journalArticle, resourcePrimKey, orderByComparator, true);
1783    
1784                            array[1] = journalArticle;
1785    
1786                            array[2] = getByResourcePrimKey_PrevAndNext(session,
1787                                            journalArticle, resourcePrimKey, orderByComparator, false);
1788    
1789                            return array;
1790                    }
1791                    catch (Exception e) {
1792                            throw processException(e);
1793                    }
1794                    finally {
1795                            closeSession(session);
1796                    }
1797            }
1798    
1799            protected JournalArticle getByResourcePrimKey_PrevAndNext(Session session,
1800                    JournalArticle journalArticle, long resourcePrimKey,
1801                    OrderByComparator orderByComparator, boolean previous) {
1802                    StringBundler query = null;
1803    
1804                    if (orderByComparator != null) {
1805                            query = new StringBundler(6 +
1806                                            (orderByComparator.getOrderByFields().length * 6));
1807                    }
1808                    else {
1809                            query = new StringBundler(3);
1810                    }
1811    
1812                    query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
1813    
1814                    query.append(_FINDER_COLUMN_RESOURCEPRIMKEY_RESOURCEPRIMKEY_2);
1815    
1816                    if (orderByComparator != null) {
1817                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1818    
1819                            if (orderByConditionFields.length > 0) {
1820                                    query.append(WHERE_AND);
1821                            }
1822    
1823                            for (int i = 0; i < orderByConditionFields.length; i++) {
1824                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1825                                    query.append(orderByConditionFields[i]);
1826    
1827                                    if ((i + 1) < orderByConditionFields.length) {
1828                                            if (orderByComparator.isAscending() ^ previous) {
1829                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1830                                            }
1831                                            else {
1832                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1833                                            }
1834                                    }
1835                                    else {
1836                                            if (orderByComparator.isAscending() ^ previous) {
1837                                                    query.append(WHERE_GREATER_THAN);
1838                                            }
1839                                            else {
1840                                                    query.append(WHERE_LESSER_THAN);
1841                                            }
1842                                    }
1843                            }
1844    
1845                            query.append(ORDER_BY_CLAUSE);
1846    
1847                            String[] orderByFields = orderByComparator.getOrderByFields();
1848    
1849                            for (int i = 0; i < orderByFields.length; i++) {
1850                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1851                                    query.append(orderByFields[i]);
1852    
1853                                    if ((i + 1) < orderByFields.length) {
1854                                            if (orderByComparator.isAscending() ^ previous) {
1855                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1856                                            }
1857                                            else {
1858                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1859                                            }
1860                                    }
1861                                    else {
1862                                            if (orderByComparator.isAscending() ^ previous) {
1863                                                    query.append(ORDER_BY_ASC);
1864                                            }
1865                                            else {
1866                                                    query.append(ORDER_BY_DESC);
1867                                            }
1868                                    }
1869                            }
1870                    }
1871                    else {
1872                            query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
1873                    }
1874    
1875                    String sql = query.toString();
1876    
1877                    Query q = session.createQuery(sql);
1878    
1879                    q.setFirstResult(0);
1880                    q.setMaxResults(2);
1881    
1882                    QueryPos qPos = QueryPos.getInstance(q);
1883    
1884                    qPos.add(resourcePrimKey);
1885    
1886                    if (orderByComparator != null) {
1887                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
1888    
1889                            for (Object value : values) {
1890                                    qPos.add(value);
1891                            }
1892                    }
1893    
1894                    List<JournalArticle> list = q.list();
1895    
1896                    if (list.size() == 2) {
1897                            return list.get(1);
1898                    }
1899                    else {
1900                            return null;
1901                    }
1902            }
1903    
1904            /**
1905             * Removes all the journal articles where resourcePrimKey = &#63; from the database.
1906             *
1907             * @param resourcePrimKey the resource prim key
1908             * @throws SystemException if a system exception occurred
1909             */
1910            @Override
1911            public void removeByResourcePrimKey(long resourcePrimKey)
1912                    throws SystemException {
1913                    for (JournalArticle journalArticle : findByResourcePrimKey(
1914                                    resourcePrimKey, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1915                            remove(journalArticle);
1916                    }
1917            }
1918    
1919            /**
1920             * Returns the number of journal articles where resourcePrimKey = &#63;.
1921             *
1922             * @param resourcePrimKey the resource prim key
1923             * @return the number of matching journal articles
1924             * @throws SystemException if a system exception occurred
1925             */
1926            @Override
1927            public int countByResourcePrimKey(long resourcePrimKey)
1928                    throws SystemException {
1929                    FinderPath finderPath = FINDER_PATH_COUNT_BY_RESOURCEPRIMKEY;
1930    
1931                    Object[] finderArgs = new Object[] { resourcePrimKey };
1932    
1933                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1934                                    this);
1935    
1936                    if (count == null) {
1937                            StringBundler query = new StringBundler(2);
1938    
1939                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
1940    
1941                            query.append(_FINDER_COLUMN_RESOURCEPRIMKEY_RESOURCEPRIMKEY_2);
1942    
1943                            String sql = query.toString();
1944    
1945                            Session session = null;
1946    
1947                            try {
1948                                    session = openSession();
1949    
1950                                    Query q = session.createQuery(sql);
1951    
1952                                    QueryPos qPos = QueryPos.getInstance(q);
1953    
1954                                    qPos.add(resourcePrimKey);
1955    
1956                                    count = (Long)q.uniqueResult();
1957    
1958                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1959                            }
1960                            catch (Exception e) {
1961                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1962    
1963                                    throw processException(e);
1964                            }
1965                            finally {
1966                                    closeSession(session);
1967                            }
1968                    }
1969    
1970                    return count.intValue();
1971            }
1972    
1973            private static final String _FINDER_COLUMN_RESOURCEPRIMKEY_RESOURCEPRIMKEY_2 =
1974                    "journalArticle.resourcePrimKey = ?";
1975            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
1976                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
1977                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1978                            "findByGroupId",
1979                            new String[] {
1980                                    Long.class.getName(),
1981                                    
1982                            Integer.class.getName(), Integer.class.getName(),
1983                                    OrderByComparator.class.getName()
1984                            });
1985            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1986                    new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
1987                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
1988                            JournalArticleImpl.class,
1989                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1990                            new String[] { Long.class.getName() },
1991                            JournalArticleModelImpl.GROUPID_COLUMN_BITMASK |
1992                            JournalArticleModelImpl.ARTICLEID_COLUMN_BITMASK |
1993                            JournalArticleModelImpl.VERSION_COLUMN_BITMASK);
1994            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
1995                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
1996                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1997                            new String[] { Long.class.getName() });
1998    
1999            /**
2000             * Returns all the journal articles where groupId = &#63;.
2001             *
2002             * @param groupId the group ID
2003             * @return the matching journal articles
2004             * @throws SystemException if a system exception occurred
2005             */
2006            @Override
2007            public List<JournalArticle> findByGroupId(long groupId)
2008                    throws SystemException {
2009                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2010            }
2011    
2012            /**
2013             * Returns a range of all the journal articles where groupId = &#63;.
2014             *
2015             * <p>
2016             * 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.
2017             * </p>
2018             *
2019             * @param groupId the group ID
2020             * @param start the lower bound of the range of journal articles
2021             * @param end the upper bound of the range of journal articles (not inclusive)
2022             * @return the range of matching journal articles
2023             * @throws SystemException if a system exception occurred
2024             */
2025            @Override
2026            public List<JournalArticle> findByGroupId(long groupId, int start, int end)
2027                    throws SystemException {
2028                    return findByGroupId(groupId, start, end, null);
2029            }
2030    
2031            /**
2032             * Returns an ordered range of all the journal articles where groupId = &#63;.
2033             *
2034             * <p>
2035             * 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.
2036             * </p>
2037             *
2038             * @param groupId the group ID
2039             * @param start the lower bound of the range of journal articles
2040             * @param end the upper bound of the range of journal articles (not inclusive)
2041             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2042             * @return the ordered range of matching journal articles
2043             * @throws SystemException if a system exception occurred
2044             */
2045            @Override
2046            public List<JournalArticle> findByGroupId(long groupId, int start, int end,
2047                    OrderByComparator orderByComparator) throws SystemException {
2048                    boolean pagination = true;
2049                    FinderPath finderPath = null;
2050                    Object[] finderArgs = null;
2051    
2052                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2053                                    (orderByComparator == null)) {
2054                            pagination = false;
2055                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
2056                            finderArgs = new Object[] { groupId };
2057                    }
2058                    else {
2059                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
2060                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
2061                    }
2062    
2063                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
2064                                    finderArgs, this);
2065    
2066                    if ((list != null) && !list.isEmpty()) {
2067                            for (JournalArticle journalArticle : list) {
2068                                    if ((groupId != journalArticle.getGroupId())) {
2069                                            list = null;
2070    
2071                                            break;
2072                                    }
2073                            }
2074                    }
2075    
2076                    if (list == null) {
2077                            StringBundler query = null;
2078    
2079                            if (orderByComparator != null) {
2080                                    query = new StringBundler(3 +
2081                                                    (orderByComparator.getOrderByFields().length * 3));
2082                            }
2083                            else {
2084                                    query = new StringBundler(3);
2085                            }
2086    
2087                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
2088    
2089                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2090    
2091                            if (orderByComparator != null) {
2092                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2093                                            orderByComparator);
2094                            }
2095                            else
2096                             if (pagination) {
2097                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
2098                            }
2099    
2100                            String sql = query.toString();
2101    
2102                            Session session = null;
2103    
2104                            try {
2105                                    session = openSession();
2106    
2107                                    Query q = session.createQuery(sql);
2108    
2109                                    QueryPos qPos = QueryPos.getInstance(q);
2110    
2111                                    qPos.add(groupId);
2112    
2113                                    if (!pagination) {
2114                                            list = (List<JournalArticle>)QueryUtil.list(q,
2115                                                            getDialect(), start, end, false);
2116    
2117                                            Collections.sort(list);
2118    
2119                                            list = new UnmodifiableList<JournalArticle>(list);
2120                                    }
2121                                    else {
2122                                            list = (List<JournalArticle>)QueryUtil.list(q,
2123                                                            getDialect(), start, end);
2124                                    }
2125    
2126                                    cacheResult(list);
2127    
2128                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2129                            }
2130                            catch (Exception e) {
2131                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2132    
2133                                    throw processException(e);
2134                            }
2135                            finally {
2136                                    closeSession(session);
2137                            }
2138                    }
2139    
2140                    return list;
2141            }
2142    
2143            /**
2144             * Returns the first journal article in the ordered set where groupId = &#63;.
2145             *
2146             * @param groupId the group ID
2147             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2148             * @return the first matching journal article
2149             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
2150             * @throws SystemException if a system exception occurred
2151             */
2152            @Override
2153            public JournalArticle findByGroupId_First(long groupId,
2154                    OrderByComparator orderByComparator)
2155                    throws NoSuchArticleException, SystemException {
2156                    JournalArticle journalArticle = fetchByGroupId_First(groupId,
2157                                    orderByComparator);
2158    
2159                    if (journalArticle != null) {
2160                            return journalArticle;
2161                    }
2162    
2163                    StringBundler msg = new StringBundler(4);
2164    
2165                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2166    
2167                    msg.append("groupId=");
2168                    msg.append(groupId);
2169    
2170                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2171    
2172                    throw new NoSuchArticleException(msg.toString());
2173            }
2174    
2175            /**
2176             * Returns the first journal article in the ordered set where groupId = &#63;.
2177             *
2178             * @param groupId the group ID
2179             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2180             * @return the first matching journal article, or <code>null</code> if a matching journal article could not be found
2181             * @throws SystemException if a system exception occurred
2182             */
2183            @Override
2184            public JournalArticle fetchByGroupId_First(long groupId,
2185                    OrderByComparator orderByComparator) throws SystemException {
2186                    List<JournalArticle> list = findByGroupId(groupId, 0, 1,
2187                                    orderByComparator);
2188    
2189                    if (!list.isEmpty()) {
2190                            return list.get(0);
2191                    }
2192    
2193                    return null;
2194            }
2195    
2196            /**
2197             * Returns the last journal article in the ordered set where groupId = &#63;.
2198             *
2199             * @param groupId the group ID
2200             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2201             * @return the last matching journal article
2202             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
2203             * @throws SystemException if a system exception occurred
2204             */
2205            @Override
2206            public JournalArticle findByGroupId_Last(long groupId,
2207                    OrderByComparator orderByComparator)
2208                    throws NoSuchArticleException, SystemException {
2209                    JournalArticle journalArticle = fetchByGroupId_Last(groupId,
2210                                    orderByComparator);
2211    
2212                    if (journalArticle != null) {
2213                            return journalArticle;
2214                    }
2215    
2216                    StringBundler msg = new StringBundler(4);
2217    
2218                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2219    
2220                    msg.append("groupId=");
2221                    msg.append(groupId);
2222    
2223                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2224    
2225                    throw new NoSuchArticleException(msg.toString());
2226            }
2227    
2228            /**
2229             * Returns the last journal article in the ordered set where groupId = &#63;.
2230             *
2231             * @param groupId the group ID
2232             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2233             * @return the last matching journal article, or <code>null</code> if a matching journal article could not be found
2234             * @throws SystemException if a system exception occurred
2235             */
2236            @Override
2237            public JournalArticle fetchByGroupId_Last(long groupId,
2238                    OrderByComparator orderByComparator) throws SystemException {
2239                    int count = countByGroupId(groupId);
2240    
2241                    if (count == 0) {
2242                            return null;
2243                    }
2244    
2245                    List<JournalArticle> list = findByGroupId(groupId, count - 1, count,
2246                                    orderByComparator);
2247    
2248                    if (!list.isEmpty()) {
2249                            return list.get(0);
2250                    }
2251    
2252                    return null;
2253            }
2254    
2255            /**
2256             * Returns the journal articles before and after the current journal article in the ordered set where groupId = &#63;.
2257             *
2258             * @param id the primary key of the current journal article
2259             * @param groupId the group ID
2260             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2261             * @return the previous, current, and next journal article
2262             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
2263             * @throws SystemException if a system exception occurred
2264             */
2265            @Override
2266            public JournalArticle[] findByGroupId_PrevAndNext(long id, long groupId,
2267                    OrderByComparator orderByComparator)
2268                    throws NoSuchArticleException, SystemException {
2269                    JournalArticle journalArticle = findByPrimaryKey(id);
2270    
2271                    Session session = null;
2272    
2273                    try {
2274                            session = openSession();
2275    
2276                            JournalArticle[] array = new JournalArticleImpl[3];
2277    
2278                            array[0] = getByGroupId_PrevAndNext(session, journalArticle,
2279                                            groupId, orderByComparator, true);
2280    
2281                            array[1] = journalArticle;
2282    
2283                            array[2] = getByGroupId_PrevAndNext(session, journalArticle,
2284                                            groupId, orderByComparator, false);
2285    
2286                            return array;
2287                    }
2288                    catch (Exception e) {
2289                            throw processException(e);
2290                    }
2291                    finally {
2292                            closeSession(session);
2293                    }
2294            }
2295    
2296            protected JournalArticle getByGroupId_PrevAndNext(Session session,
2297                    JournalArticle journalArticle, long groupId,
2298                    OrderByComparator orderByComparator, boolean previous) {
2299                    StringBundler query = null;
2300    
2301                    if (orderByComparator != null) {
2302                            query = new StringBundler(6 +
2303                                            (orderByComparator.getOrderByFields().length * 6));
2304                    }
2305                    else {
2306                            query = new StringBundler(3);
2307                    }
2308    
2309                    query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
2310    
2311                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2312    
2313                    if (orderByComparator != null) {
2314                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2315    
2316                            if (orderByConditionFields.length > 0) {
2317                                    query.append(WHERE_AND);
2318                            }
2319    
2320                            for (int i = 0; i < orderByConditionFields.length; i++) {
2321                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2322                                    query.append(orderByConditionFields[i]);
2323    
2324                                    if ((i + 1) < orderByConditionFields.length) {
2325                                            if (orderByComparator.isAscending() ^ previous) {
2326                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2327                                            }
2328                                            else {
2329                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2330                                            }
2331                                    }
2332                                    else {
2333                                            if (orderByComparator.isAscending() ^ previous) {
2334                                                    query.append(WHERE_GREATER_THAN);
2335                                            }
2336                                            else {
2337                                                    query.append(WHERE_LESSER_THAN);
2338                                            }
2339                                    }
2340                            }
2341    
2342                            query.append(ORDER_BY_CLAUSE);
2343    
2344                            String[] orderByFields = orderByComparator.getOrderByFields();
2345    
2346                            for (int i = 0; i < orderByFields.length; i++) {
2347                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2348                                    query.append(orderByFields[i]);
2349    
2350                                    if ((i + 1) < orderByFields.length) {
2351                                            if (orderByComparator.isAscending() ^ previous) {
2352                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2353                                            }
2354                                            else {
2355                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2356                                            }
2357                                    }
2358                                    else {
2359                                            if (orderByComparator.isAscending() ^ previous) {
2360                                                    query.append(ORDER_BY_ASC);
2361                                            }
2362                                            else {
2363                                                    query.append(ORDER_BY_DESC);
2364                                            }
2365                                    }
2366                            }
2367                    }
2368                    else {
2369                            query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
2370                    }
2371    
2372                    String sql = query.toString();
2373    
2374                    Query q = session.createQuery(sql);
2375    
2376                    q.setFirstResult(0);
2377                    q.setMaxResults(2);
2378    
2379                    QueryPos qPos = QueryPos.getInstance(q);
2380    
2381                    qPos.add(groupId);
2382    
2383                    if (orderByComparator != null) {
2384                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
2385    
2386                            for (Object value : values) {
2387                                    qPos.add(value);
2388                            }
2389                    }
2390    
2391                    List<JournalArticle> list = q.list();
2392    
2393                    if (list.size() == 2) {
2394                            return list.get(1);
2395                    }
2396                    else {
2397                            return null;
2398                    }
2399            }
2400    
2401            /**
2402             * Returns all the journal articles that the user has permission to view where groupId = &#63;.
2403             *
2404             * @param groupId the group ID
2405             * @return the matching journal articles that the user has permission to view
2406             * @throws SystemException if a system exception occurred
2407             */
2408            @Override
2409            public List<JournalArticle> filterFindByGroupId(long groupId)
2410                    throws SystemException {
2411                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
2412                            QueryUtil.ALL_POS, null);
2413            }
2414    
2415            /**
2416             * Returns a range of all the journal articles that the user has permission to view where groupId = &#63;.
2417             *
2418             * <p>
2419             * 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.
2420             * </p>
2421             *
2422             * @param groupId the group ID
2423             * @param start the lower bound of the range of journal articles
2424             * @param end the upper bound of the range of journal articles (not inclusive)
2425             * @return the range of matching journal articles that the user has permission to view
2426             * @throws SystemException if a system exception occurred
2427             */
2428            @Override
2429            public List<JournalArticle> filterFindByGroupId(long groupId, int start,
2430                    int end) throws SystemException {
2431                    return filterFindByGroupId(groupId, start, end, null);
2432            }
2433    
2434            /**
2435             * Returns an ordered range of all the journal articles that the user has permissions to view where groupId = &#63;.
2436             *
2437             * <p>
2438             * 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.
2439             * </p>
2440             *
2441             * @param groupId the group ID
2442             * @param start the lower bound of the range of journal articles
2443             * @param end the upper bound of the range of journal articles (not inclusive)
2444             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2445             * @return the ordered range of matching journal articles that the user has permission to view
2446             * @throws SystemException if a system exception occurred
2447             */
2448            @Override
2449            public List<JournalArticle> filterFindByGroupId(long groupId, int start,
2450                    int end, OrderByComparator orderByComparator) throws SystemException {
2451                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2452                            return findByGroupId(groupId, start, end, orderByComparator);
2453                    }
2454    
2455                    StringBundler query = null;
2456    
2457                    if (orderByComparator != null) {
2458                            query = new StringBundler(3 +
2459                                            (orderByComparator.getOrderByFields().length * 3));
2460                    }
2461                    else {
2462                            query = new StringBundler(3);
2463                    }
2464    
2465                    if (getDB().isSupportsInlineDistinct()) {
2466                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_WHERE);
2467                    }
2468                    else {
2469                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1);
2470                    }
2471    
2472                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2473    
2474                    if (!getDB().isSupportsInlineDistinct()) {
2475                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_2);
2476                    }
2477    
2478                    if (orderByComparator != null) {
2479                            if (getDB().isSupportsInlineDistinct()) {
2480                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2481                                            orderByComparator, true);
2482                            }
2483                            else {
2484                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2485                                            orderByComparator, true);
2486                            }
2487                    }
2488                    else {
2489                            if (getDB().isSupportsInlineDistinct()) {
2490                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
2491                            }
2492                            else {
2493                                    query.append(JournalArticleModelImpl.ORDER_BY_SQL);
2494                            }
2495                    }
2496    
2497                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2498                                    JournalArticle.class.getName(),
2499                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2500    
2501                    Session session = null;
2502    
2503                    try {
2504                            session = openSession();
2505    
2506                            SQLQuery q = session.createSQLQuery(sql);
2507    
2508                            if (getDB().isSupportsInlineDistinct()) {
2509                                    q.addEntity(_FILTER_ENTITY_ALIAS, JournalArticleImpl.class);
2510                            }
2511                            else {
2512                                    q.addEntity(_FILTER_ENTITY_TABLE, JournalArticleImpl.class);
2513                            }
2514    
2515                            QueryPos qPos = QueryPos.getInstance(q);
2516    
2517                            qPos.add(groupId);
2518    
2519                            return (List<JournalArticle>)QueryUtil.list(q, getDialect(), start,
2520                                    end);
2521                    }
2522                    catch (Exception e) {
2523                            throw processException(e);
2524                    }
2525                    finally {
2526                            closeSession(session);
2527                    }
2528            }
2529    
2530            /**
2531             * 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;.
2532             *
2533             * @param id the primary key of the current journal article
2534             * @param groupId the group ID
2535             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2536             * @return the previous, current, and next journal article
2537             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
2538             * @throws SystemException if a system exception occurred
2539             */
2540            @Override
2541            public JournalArticle[] filterFindByGroupId_PrevAndNext(long id,
2542                    long groupId, OrderByComparator orderByComparator)
2543                    throws NoSuchArticleException, SystemException {
2544                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2545                            return findByGroupId_PrevAndNext(id, groupId, orderByComparator);
2546                    }
2547    
2548                    JournalArticle journalArticle = findByPrimaryKey(id);
2549    
2550                    Session session = null;
2551    
2552                    try {
2553                            session = openSession();
2554    
2555                            JournalArticle[] array = new JournalArticleImpl[3];
2556    
2557                            array[0] = filterGetByGroupId_PrevAndNext(session, journalArticle,
2558                                            groupId, orderByComparator, true);
2559    
2560                            array[1] = journalArticle;
2561    
2562                            array[2] = filterGetByGroupId_PrevAndNext(session, journalArticle,
2563                                            groupId, orderByComparator, false);
2564    
2565                            return array;
2566                    }
2567                    catch (Exception e) {
2568                            throw processException(e);
2569                    }
2570                    finally {
2571                            closeSession(session);
2572                    }
2573            }
2574    
2575            protected JournalArticle filterGetByGroupId_PrevAndNext(Session session,
2576                    JournalArticle journalArticle, long groupId,
2577                    OrderByComparator orderByComparator, boolean previous) {
2578                    StringBundler query = null;
2579    
2580                    if (orderByComparator != null) {
2581                            query = new StringBundler(6 +
2582                                            (orderByComparator.getOrderByFields().length * 6));
2583                    }
2584                    else {
2585                            query = new StringBundler(3);
2586                    }
2587    
2588                    if (getDB().isSupportsInlineDistinct()) {
2589                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_WHERE);
2590                    }
2591                    else {
2592                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1);
2593                    }
2594    
2595                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2596    
2597                    if (!getDB().isSupportsInlineDistinct()) {
2598                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_2);
2599                    }
2600    
2601                    if (orderByComparator != null) {
2602                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2603    
2604                            if (orderByConditionFields.length > 0) {
2605                                    query.append(WHERE_AND);
2606                            }
2607    
2608                            for (int i = 0; i < orderByConditionFields.length; i++) {
2609                                    if (getDB().isSupportsInlineDistinct()) {
2610                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2611                                    }
2612                                    else {
2613                                            query.append(_ORDER_BY_ENTITY_TABLE);
2614                                    }
2615    
2616                                    query.append(orderByConditionFields[i]);
2617    
2618                                    if ((i + 1) < orderByConditionFields.length) {
2619                                            if (orderByComparator.isAscending() ^ previous) {
2620                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2621                                            }
2622                                            else {
2623                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2624                                            }
2625                                    }
2626                                    else {
2627                                            if (orderByComparator.isAscending() ^ previous) {
2628                                                    query.append(WHERE_GREATER_THAN);
2629                                            }
2630                                            else {
2631                                                    query.append(WHERE_LESSER_THAN);
2632                                            }
2633                                    }
2634                            }
2635    
2636                            query.append(ORDER_BY_CLAUSE);
2637    
2638                            String[] orderByFields = orderByComparator.getOrderByFields();
2639    
2640                            for (int i = 0; i < orderByFields.length; i++) {
2641                                    if (getDB().isSupportsInlineDistinct()) {
2642                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2643                                    }
2644                                    else {
2645                                            query.append(_ORDER_BY_ENTITY_TABLE);
2646                                    }
2647    
2648                                    query.append(orderByFields[i]);
2649    
2650                                    if ((i + 1) < orderByFields.length) {
2651                                            if (orderByComparator.isAscending() ^ previous) {
2652                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2653                                            }
2654                                            else {
2655                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2656                                            }
2657                                    }
2658                                    else {
2659                                            if (orderByComparator.isAscending() ^ previous) {
2660                                                    query.append(ORDER_BY_ASC);
2661                                            }
2662                                            else {
2663                                                    query.append(ORDER_BY_DESC);
2664                                            }
2665                                    }
2666                            }
2667                    }
2668                    else {
2669                            if (getDB().isSupportsInlineDistinct()) {
2670                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
2671                            }
2672                            else {
2673                                    query.append(JournalArticleModelImpl.ORDER_BY_SQL);
2674                            }
2675                    }
2676    
2677                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2678                                    JournalArticle.class.getName(),
2679                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2680    
2681                    SQLQuery q = session.createSQLQuery(sql);
2682    
2683                    q.setFirstResult(0);
2684                    q.setMaxResults(2);
2685    
2686                    if (getDB().isSupportsInlineDistinct()) {
2687                            q.addEntity(_FILTER_ENTITY_ALIAS, JournalArticleImpl.class);
2688                    }
2689                    else {
2690                            q.addEntity(_FILTER_ENTITY_TABLE, JournalArticleImpl.class);
2691                    }
2692    
2693                    QueryPos qPos = QueryPos.getInstance(q);
2694    
2695                    qPos.add(groupId);
2696    
2697                    if (orderByComparator != null) {
2698                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
2699    
2700                            for (Object value : values) {
2701                                    qPos.add(value);
2702                            }
2703                    }
2704    
2705                    List<JournalArticle> list = q.list();
2706    
2707                    if (list.size() == 2) {
2708                            return list.get(1);
2709                    }
2710                    else {
2711                            return null;
2712                    }
2713            }
2714    
2715            /**
2716             * Removes all the journal articles where groupId = &#63; from the database.
2717             *
2718             * @param groupId the group ID
2719             * @throws SystemException if a system exception occurred
2720             */
2721            @Override
2722            public void removeByGroupId(long groupId) throws SystemException {
2723                    for (JournalArticle journalArticle : findByGroupId(groupId,
2724                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2725                            remove(journalArticle);
2726                    }
2727            }
2728    
2729            /**
2730             * Returns the number of journal articles where groupId = &#63;.
2731             *
2732             * @param groupId the group ID
2733             * @return the number of matching journal articles
2734             * @throws SystemException if a system exception occurred
2735             */
2736            @Override
2737            public int countByGroupId(long groupId) throws SystemException {
2738                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2739    
2740                    Object[] finderArgs = new Object[] { groupId };
2741    
2742                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2743                                    this);
2744    
2745                    if (count == null) {
2746                            StringBundler query = new StringBundler(2);
2747    
2748                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
2749    
2750                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2751    
2752                            String sql = query.toString();
2753    
2754                            Session session = null;
2755    
2756                            try {
2757                                    session = openSession();
2758    
2759                                    Query q = session.createQuery(sql);
2760    
2761                                    QueryPos qPos = QueryPos.getInstance(q);
2762    
2763                                    qPos.add(groupId);
2764    
2765                                    count = (Long)q.uniqueResult();
2766    
2767                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2768                            }
2769                            catch (Exception e) {
2770                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2771    
2772                                    throw processException(e);
2773                            }
2774                            finally {
2775                                    closeSession(session);
2776                            }
2777                    }
2778    
2779                    return count.intValue();
2780            }
2781    
2782            /**
2783             * Returns the number of journal articles that the user has permission to view where groupId = &#63;.
2784             *
2785             * @param groupId the group ID
2786             * @return the number of matching journal articles that the user has permission to view
2787             * @throws SystemException if a system exception occurred
2788             */
2789            @Override
2790            public int filterCountByGroupId(long groupId) throws SystemException {
2791                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2792                            return countByGroupId(groupId);
2793                    }
2794    
2795                    StringBundler query = new StringBundler(2);
2796    
2797                    query.append(_FILTER_SQL_COUNT_JOURNALARTICLE_WHERE);
2798    
2799                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2800    
2801                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2802                                    JournalArticle.class.getName(),
2803                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2804    
2805                    Session session = null;
2806    
2807                    try {
2808                            session = openSession();
2809    
2810                            SQLQuery q = session.createSQLQuery(sql);
2811    
2812                            q.addScalar(COUNT_COLUMN_NAME,
2813                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2814    
2815                            QueryPos qPos = QueryPos.getInstance(q);
2816    
2817                            qPos.add(groupId);
2818    
2819                            Long count = (Long)q.uniqueResult();
2820    
2821                            return count.intValue();
2822                    }
2823                    catch (Exception e) {
2824                            throw processException(e);
2825                    }
2826                    finally {
2827                            closeSession(session);
2828                    }
2829            }
2830    
2831            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "journalArticle.groupId = ?";
2832            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
2833                    new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
2834                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
2835                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
2836                            "findByCompanyId",
2837                            new String[] {
2838                                    Long.class.getName(),
2839                                    
2840                            Integer.class.getName(), Integer.class.getName(),
2841                                    OrderByComparator.class.getName()
2842                            });
2843            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
2844                    new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
2845                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
2846                            JournalArticleImpl.class,
2847                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
2848                            new String[] { Long.class.getName() },
2849                            JournalArticleModelImpl.COMPANYID_COLUMN_BITMASK |
2850                            JournalArticleModelImpl.ARTICLEID_COLUMN_BITMASK |
2851                            JournalArticleModelImpl.VERSION_COLUMN_BITMASK);
2852            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
2853                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
2854                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
2855                            new String[] { Long.class.getName() });
2856    
2857            /**
2858             * Returns all the journal articles where companyId = &#63;.
2859             *
2860             * @param companyId the company ID
2861             * @return the matching journal articles
2862             * @throws SystemException if a system exception occurred
2863             */
2864            @Override
2865            public List<JournalArticle> findByCompanyId(long companyId)
2866                    throws SystemException {
2867                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2868                            null);
2869            }
2870    
2871            /**
2872             * Returns a range of all the journal articles where companyId = &#63;.
2873             *
2874             * <p>
2875             * 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.
2876             * </p>
2877             *
2878             * @param companyId the company ID
2879             * @param start the lower bound of the range of journal articles
2880             * @param end the upper bound of the range of journal articles (not inclusive)
2881             * @return the range of matching journal articles
2882             * @throws SystemException if a system exception occurred
2883             */
2884            @Override
2885            public List<JournalArticle> findByCompanyId(long companyId, int start,
2886                    int end) throws SystemException {
2887                    return findByCompanyId(companyId, start, end, null);
2888            }
2889    
2890            /**
2891             * Returns an ordered range of all the journal articles where companyId = &#63;.
2892             *
2893             * <p>
2894             * 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.
2895             * </p>
2896             *
2897             * @param companyId the company ID
2898             * @param start the lower bound of the range of journal articles
2899             * @param end the upper bound of the range of journal articles (not inclusive)
2900             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2901             * @return the ordered range of matching journal articles
2902             * @throws SystemException if a system exception occurred
2903             */
2904            @Override
2905            public List<JournalArticle> findByCompanyId(long companyId, int start,
2906                    int end, OrderByComparator orderByComparator) throws SystemException {
2907                    boolean pagination = true;
2908                    FinderPath finderPath = null;
2909                    Object[] finderArgs = null;
2910    
2911                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2912                                    (orderByComparator == null)) {
2913                            pagination = false;
2914                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2915                            finderArgs = new Object[] { companyId };
2916                    }
2917                    else {
2918                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2919                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
2920                    }
2921    
2922                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
2923                                    finderArgs, this);
2924    
2925                    if ((list != null) && !list.isEmpty()) {
2926                            for (JournalArticle journalArticle : list) {
2927                                    if ((companyId != journalArticle.getCompanyId())) {
2928                                            list = null;
2929    
2930                                            break;
2931                                    }
2932                            }
2933                    }
2934    
2935                    if (list == null) {
2936                            StringBundler query = null;
2937    
2938                            if (orderByComparator != null) {
2939                                    query = new StringBundler(3 +
2940                                                    (orderByComparator.getOrderByFields().length * 3));
2941                            }
2942                            else {
2943                                    query = new StringBundler(3);
2944                            }
2945    
2946                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
2947    
2948                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2949    
2950                            if (orderByComparator != null) {
2951                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2952                                            orderByComparator);
2953                            }
2954                            else
2955                             if (pagination) {
2956                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
2957                            }
2958    
2959                            String sql = query.toString();
2960    
2961                            Session session = null;
2962    
2963                            try {
2964                                    session = openSession();
2965    
2966                                    Query q = session.createQuery(sql);
2967    
2968                                    QueryPos qPos = QueryPos.getInstance(q);
2969    
2970                                    qPos.add(companyId);
2971    
2972                                    if (!pagination) {
2973                                            list = (List<JournalArticle>)QueryUtil.list(q,
2974                                                            getDialect(), start, end, false);
2975    
2976                                            Collections.sort(list);
2977    
2978                                            list = new UnmodifiableList<JournalArticle>(list);
2979                                    }
2980                                    else {
2981                                            list = (List<JournalArticle>)QueryUtil.list(q,
2982                                                            getDialect(), start, end);
2983                                    }
2984    
2985                                    cacheResult(list);
2986    
2987                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2988                            }
2989                            catch (Exception e) {
2990                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2991    
2992                                    throw processException(e);
2993                            }
2994                            finally {
2995                                    closeSession(session);
2996                            }
2997                    }
2998    
2999                    return list;
3000            }
3001    
3002            /**
3003             * Returns the first journal article in the ordered set where companyId = &#63;.
3004             *
3005             * @param companyId the company ID
3006             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3007             * @return the first matching journal article
3008             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
3009             * @throws SystemException if a system exception occurred
3010             */
3011            @Override
3012            public JournalArticle findByCompanyId_First(long companyId,
3013                    OrderByComparator orderByComparator)
3014                    throws NoSuchArticleException, SystemException {
3015                    JournalArticle journalArticle = fetchByCompanyId_First(companyId,
3016                                    orderByComparator);
3017    
3018                    if (journalArticle != null) {
3019                            return journalArticle;
3020                    }
3021    
3022                    StringBundler msg = new StringBundler(4);
3023    
3024                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3025    
3026                    msg.append("companyId=");
3027                    msg.append(companyId);
3028    
3029                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3030    
3031                    throw new NoSuchArticleException(msg.toString());
3032            }
3033    
3034            /**
3035             * Returns the first journal article in the ordered set where companyId = &#63;.
3036             *
3037             * @param companyId the company ID
3038             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3039             * @return the first matching journal article, or <code>null</code> if a matching journal article could not be found
3040             * @throws SystemException if a system exception occurred
3041             */
3042            @Override
3043            public JournalArticle fetchByCompanyId_First(long companyId,
3044                    OrderByComparator orderByComparator) throws SystemException {
3045                    List<JournalArticle> list = findByCompanyId(companyId, 0, 1,
3046                                    orderByComparator);
3047    
3048                    if (!list.isEmpty()) {
3049                            return list.get(0);
3050                    }
3051    
3052                    return null;
3053            }
3054    
3055            /**
3056             * Returns the last journal article in the ordered set where companyId = &#63;.
3057             *
3058             * @param companyId the company ID
3059             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3060             * @return the last matching journal article
3061             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
3062             * @throws SystemException if a system exception occurred
3063             */
3064            @Override
3065            public JournalArticle findByCompanyId_Last(long companyId,
3066                    OrderByComparator orderByComparator)
3067                    throws NoSuchArticleException, SystemException {
3068                    JournalArticle journalArticle = fetchByCompanyId_Last(companyId,
3069                                    orderByComparator);
3070    
3071                    if (journalArticle != null) {
3072                            return journalArticle;
3073                    }
3074    
3075                    StringBundler msg = new StringBundler(4);
3076    
3077                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3078    
3079                    msg.append("companyId=");
3080                    msg.append(companyId);
3081    
3082                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3083    
3084                    throw new NoSuchArticleException(msg.toString());
3085            }
3086    
3087            /**
3088             * Returns the last journal article in the ordered set where companyId = &#63;.
3089             *
3090             * @param companyId the company ID
3091             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3092             * @return the last matching journal article, or <code>null</code> if a matching journal article could not be found
3093             * @throws SystemException if a system exception occurred
3094             */
3095            @Override
3096            public JournalArticle fetchByCompanyId_Last(long companyId,
3097                    OrderByComparator orderByComparator) throws SystemException {
3098                    int count = countByCompanyId(companyId);
3099    
3100                    if (count == 0) {
3101                            return null;
3102                    }
3103    
3104                    List<JournalArticle> list = findByCompanyId(companyId, count - 1,
3105                                    count, orderByComparator);
3106    
3107                    if (!list.isEmpty()) {
3108                            return list.get(0);
3109                    }
3110    
3111                    return null;
3112            }
3113    
3114            /**
3115             * Returns the journal articles before and after the current journal article in the ordered set where companyId = &#63;.
3116             *
3117             * @param id the primary key of the current journal article
3118             * @param companyId the company ID
3119             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3120             * @return the previous, current, and next journal article
3121             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
3122             * @throws SystemException if a system exception occurred
3123             */
3124            @Override
3125            public JournalArticle[] findByCompanyId_PrevAndNext(long id,
3126                    long companyId, OrderByComparator orderByComparator)
3127                    throws NoSuchArticleException, SystemException {
3128                    JournalArticle journalArticle = findByPrimaryKey(id);
3129    
3130                    Session session = null;
3131    
3132                    try {
3133                            session = openSession();
3134    
3135                            JournalArticle[] array = new JournalArticleImpl[3];
3136    
3137                            array[0] = getByCompanyId_PrevAndNext(session, journalArticle,
3138                                            companyId, orderByComparator, true);
3139    
3140                            array[1] = journalArticle;
3141    
3142                            array[2] = getByCompanyId_PrevAndNext(session, journalArticle,
3143                                            companyId, orderByComparator, false);
3144    
3145                            return array;
3146                    }
3147                    catch (Exception e) {
3148                            throw processException(e);
3149                    }
3150                    finally {
3151                            closeSession(session);
3152                    }
3153            }
3154    
3155            protected JournalArticle getByCompanyId_PrevAndNext(Session session,
3156                    JournalArticle journalArticle, long companyId,
3157                    OrderByComparator orderByComparator, boolean previous) {
3158                    StringBundler query = null;
3159    
3160                    if (orderByComparator != null) {
3161                            query = new StringBundler(6 +
3162                                            (orderByComparator.getOrderByFields().length * 6));
3163                    }
3164                    else {
3165                            query = new StringBundler(3);
3166                    }
3167    
3168                    query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
3169    
3170                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
3171    
3172                    if (orderByComparator != null) {
3173                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3174    
3175                            if (orderByConditionFields.length > 0) {
3176                                    query.append(WHERE_AND);
3177                            }
3178    
3179                            for (int i = 0; i < orderByConditionFields.length; i++) {
3180                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3181                                    query.append(orderByConditionFields[i]);
3182    
3183                                    if ((i + 1) < orderByConditionFields.length) {
3184                                            if (orderByComparator.isAscending() ^ previous) {
3185                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3186                                            }
3187                                            else {
3188                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3189                                            }
3190                                    }
3191                                    else {
3192                                            if (orderByComparator.isAscending() ^ previous) {
3193                                                    query.append(WHERE_GREATER_THAN);
3194                                            }
3195                                            else {
3196                                                    query.append(WHERE_LESSER_THAN);
3197                                            }
3198                                    }
3199                            }
3200    
3201                            query.append(ORDER_BY_CLAUSE);
3202    
3203                            String[] orderByFields = orderByComparator.getOrderByFields();
3204    
3205                            for (int i = 0; i < orderByFields.length; i++) {
3206                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3207                                    query.append(orderByFields[i]);
3208    
3209                                    if ((i + 1) < orderByFields.length) {
3210                                            if (orderByComparator.isAscending() ^ previous) {
3211                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3212                                            }
3213                                            else {
3214                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3215                                            }
3216                                    }
3217                                    else {
3218                                            if (orderByComparator.isAscending() ^ previous) {
3219                                                    query.append(ORDER_BY_ASC);
3220                                            }
3221                                            else {
3222                                                    query.append(ORDER_BY_DESC);
3223                                            }
3224                                    }
3225                            }
3226                    }
3227                    else {
3228                            query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
3229                    }
3230    
3231                    String sql = query.toString();
3232    
3233                    Query q = session.createQuery(sql);
3234    
3235                    q.setFirstResult(0);
3236                    q.setMaxResults(2);
3237    
3238                    QueryPos qPos = QueryPos.getInstance(q);
3239    
3240                    qPos.add(companyId);
3241    
3242                    if (orderByComparator != null) {
3243                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
3244    
3245                            for (Object value : values) {
3246                                    qPos.add(value);
3247                            }
3248                    }
3249    
3250                    List<JournalArticle> list = q.list();
3251    
3252                    if (list.size() == 2) {
3253                            return list.get(1);
3254                    }
3255                    else {
3256                            return null;
3257                    }
3258            }
3259    
3260            /**
3261             * Removes all the journal articles where companyId = &#63; from the database.
3262             *
3263             * @param companyId the company ID
3264             * @throws SystemException if a system exception occurred
3265             */
3266            @Override
3267            public void removeByCompanyId(long companyId) throws SystemException {
3268                    for (JournalArticle journalArticle : findByCompanyId(companyId,
3269                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3270                            remove(journalArticle);
3271                    }
3272            }
3273    
3274            /**
3275             * Returns the number of journal articles where companyId = &#63;.
3276             *
3277             * @param companyId the company ID
3278             * @return the number of matching journal articles
3279             * @throws SystemException if a system exception occurred
3280             */
3281            @Override
3282            public int countByCompanyId(long companyId) throws SystemException {
3283                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
3284    
3285                    Object[] finderArgs = new Object[] { companyId };
3286    
3287                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3288                                    this);
3289    
3290                    if (count == null) {
3291                            StringBundler query = new StringBundler(2);
3292    
3293                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
3294    
3295                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
3296    
3297                            String sql = query.toString();
3298    
3299                            Session session = null;
3300    
3301                            try {
3302                                    session = openSession();
3303    
3304                                    Query q = session.createQuery(sql);
3305    
3306                                    QueryPos qPos = QueryPos.getInstance(q);
3307    
3308                                    qPos.add(companyId);
3309    
3310                                    count = (Long)q.uniqueResult();
3311    
3312                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3313                            }
3314                            catch (Exception e) {
3315                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3316    
3317                                    throw processException(e);
3318                            }
3319                            finally {
3320                                    closeSession(session);
3321                            }
3322                    }
3323    
3324                    return count.intValue();
3325            }
3326    
3327            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "journalArticle.companyId = ?";
3328            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_STRUCTUREID =
3329                    new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
3330                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
3331                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
3332                            "findByStructureId",
3333                            new String[] {
3334                                    String.class.getName(),
3335                                    
3336                            Integer.class.getName(), Integer.class.getName(),
3337                                    OrderByComparator.class.getName()
3338                            });
3339            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREID =
3340                    new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
3341                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
3342                            JournalArticleImpl.class,
3343                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByStructureId",
3344                            new String[] { String.class.getName() },
3345                            JournalArticleModelImpl.STRUCTUREID_COLUMN_BITMASK |
3346                            JournalArticleModelImpl.ARTICLEID_COLUMN_BITMASK |
3347                            JournalArticleModelImpl.VERSION_COLUMN_BITMASK);
3348            public static final FinderPath FINDER_PATH_COUNT_BY_STRUCTUREID = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
3349                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
3350                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByStructureId",
3351                            new String[] { String.class.getName() });
3352            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_STRUCTUREID =
3353                    new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
3354                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
3355                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByStructureId",
3356                            new String[] { String.class.getName() });
3357    
3358            /**
3359             * Returns all the journal articles where structureId = &#63;.
3360             *
3361             * @param structureId the structure ID
3362             * @return the matching journal articles
3363             * @throws SystemException if a system exception occurred
3364             */
3365            @Override
3366            public List<JournalArticle> findByStructureId(String structureId)
3367                    throws SystemException {
3368                    return findByStructureId(structureId, QueryUtil.ALL_POS,
3369                            QueryUtil.ALL_POS, null);
3370            }
3371    
3372            /**
3373             * Returns a range of all the journal articles where structureId = &#63;.
3374             *
3375             * <p>
3376             * 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.
3377             * </p>
3378             *
3379             * @param structureId the structure ID
3380             * @param start the lower bound of the range of journal articles
3381             * @param end the upper bound of the range of journal articles (not inclusive)
3382             * @return the range of matching journal articles
3383             * @throws SystemException if a system exception occurred
3384             */
3385            @Override
3386            public List<JournalArticle> findByStructureId(String structureId,
3387                    int start, int end) throws SystemException {
3388                    return findByStructureId(structureId, start, end, null);
3389            }
3390    
3391            /**
3392             * Returns an ordered range of all the journal articles where structureId = &#63;.
3393             *
3394             * <p>
3395             * 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.
3396             * </p>
3397             *
3398             * @param structureId the structure ID
3399             * @param start the lower bound of the range of journal articles
3400             * @param end the upper bound of the range of journal articles (not inclusive)
3401             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3402             * @return the ordered range of matching journal articles
3403             * @throws SystemException if a system exception occurred
3404             */
3405            @Override
3406            public List<JournalArticle> findByStructureId(String structureId,
3407                    int start, int end, OrderByComparator orderByComparator)
3408                    throws SystemException {
3409                    boolean pagination = true;
3410                    FinderPath finderPath = null;
3411                    Object[] finderArgs = null;
3412    
3413                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3414                                    (orderByComparator == null)) {
3415                            pagination = false;
3416                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREID;
3417                            finderArgs = new Object[] { structureId };
3418                    }
3419                    else {
3420                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_STRUCTUREID;
3421                            finderArgs = new Object[] { structureId, start, end, orderByComparator };
3422                    }
3423    
3424                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
3425                                    finderArgs, this);
3426    
3427                    if ((list != null) && !list.isEmpty()) {
3428                            for (JournalArticle journalArticle : list) {
3429                                    if (!Validator.equals(structureId,
3430                                                            journalArticle.getStructureId())) {
3431                                            list = null;
3432    
3433                                            break;
3434                                    }
3435                            }
3436                    }
3437    
3438                    if (list == null) {
3439                            StringBundler query = null;
3440    
3441                            if (orderByComparator != null) {
3442                                    query = new StringBundler(3 +
3443                                                    (orderByComparator.getOrderByFields().length * 3));
3444                            }
3445                            else {
3446                                    query = new StringBundler(3);
3447                            }
3448    
3449                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
3450    
3451                            boolean bindStructureId = false;
3452    
3453                            if (structureId == null) {
3454                                    query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_1);
3455                            }
3456                            else if (structureId.equals(StringPool.BLANK)) {
3457                                    query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_3);
3458                            }
3459                            else {
3460                                    bindStructureId = true;
3461    
3462                                    query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_2);
3463                            }
3464    
3465                            if (orderByComparator != null) {
3466                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3467                                            orderByComparator);
3468                            }
3469                            else
3470                             if (pagination) {
3471                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
3472                            }
3473    
3474                            String sql = query.toString();
3475    
3476                            Session session = null;
3477    
3478                            try {
3479                                    session = openSession();
3480    
3481                                    Query q = session.createQuery(sql);
3482    
3483                                    QueryPos qPos = QueryPos.getInstance(q);
3484    
3485                                    if (bindStructureId) {
3486                                            qPos.add(structureId);
3487                                    }
3488    
3489                                    if (!pagination) {
3490                                            list = (List<JournalArticle>)QueryUtil.list(q,
3491                                                            getDialect(), start, end, false);
3492    
3493                                            Collections.sort(list);
3494    
3495                                            list = new UnmodifiableList<JournalArticle>(list);
3496                                    }
3497                                    else {
3498                                            list = (List<JournalArticle>)QueryUtil.list(q,
3499                                                            getDialect(), start, end);
3500                                    }
3501    
3502                                    cacheResult(list);
3503    
3504                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3505                            }
3506                            catch (Exception e) {
3507                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3508    
3509                                    throw processException(e);
3510                            }
3511                            finally {
3512                                    closeSession(session);
3513                            }
3514                    }
3515    
3516                    return list;
3517            }
3518    
3519            /**
3520             * Returns the first journal article in the ordered set where structureId = &#63;.
3521             *
3522             * @param structureId the structure ID
3523             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3524             * @return the first matching journal article
3525             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
3526             * @throws SystemException if a system exception occurred
3527             */
3528            @Override
3529            public JournalArticle findByStructureId_First(String structureId,
3530                    OrderByComparator orderByComparator)
3531                    throws NoSuchArticleException, SystemException {
3532                    JournalArticle journalArticle = fetchByStructureId_First(structureId,
3533                                    orderByComparator);
3534    
3535                    if (journalArticle != null) {
3536                            return journalArticle;
3537                    }
3538    
3539                    StringBundler msg = new StringBundler(4);
3540    
3541                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3542    
3543                    msg.append("structureId=");
3544                    msg.append(structureId);
3545    
3546                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3547    
3548                    throw new NoSuchArticleException(msg.toString());
3549            }
3550    
3551            /**
3552             * Returns the first journal article in the ordered set where structureId = &#63;.
3553             *
3554             * @param structureId the structure ID
3555             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3556             * @return the first matching journal article, or <code>null</code> if a matching journal article could not be found
3557             * @throws SystemException if a system exception occurred
3558             */
3559            @Override
3560            public JournalArticle fetchByStructureId_First(String structureId,
3561                    OrderByComparator orderByComparator) throws SystemException {
3562                    List<JournalArticle> list = findByStructureId(structureId, 0, 1,
3563                                    orderByComparator);
3564    
3565                    if (!list.isEmpty()) {
3566                            return list.get(0);
3567                    }
3568    
3569                    return null;
3570            }
3571    
3572            /**
3573             * Returns the last journal article in the ordered set where structureId = &#63;.
3574             *
3575             * @param structureId the structure ID
3576             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3577             * @return the last matching journal article
3578             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
3579             * @throws SystemException if a system exception occurred
3580             */
3581            @Override
3582            public JournalArticle findByStructureId_Last(String structureId,
3583                    OrderByComparator orderByComparator)
3584                    throws NoSuchArticleException, SystemException {
3585                    JournalArticle journalArticle = fetchByStructureId_Last(structureId,
3586                                    orderByComparator);
3587    
3588                    if (journalArticle != null) {
3589                            return journalArticle;
3590                    }
3591    
3592                    StringBundler msg = new StringBundler(4);
3593    
3594                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3595    
3596                    msg.append("structureId=");
3597                    msg.append(structureId);
3598    
3599                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3600    
3601                    throw new NoSuchArticleException(msg.toString());
3602            }
3603    
3604            /**
3605             * Returns the last journal article in the ordered set where structureId = &#63;.
3606             *
3607             * @param structureId the structure ID
3608             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3609             * @return the last matching journal article, or <code>null</code> if a matching journal article could not be found
3610             * @throws SystemException if a system exception occurred
3611             */
3612            @Override
3613            public JournalArticle fetchByStructureId_Last(String structureId,
3614                    OrderByComparator orderByComparator) throws SystemException {
3615                    int count = countByStructureId(structureId);
3616    
3617                    if (count == 0) {
3618                            return null;
3619                    }
3620    
3621                    List<JournalArticle> list = findByStructureId(structureId, count - 1,
3622                                    count, orderByComparator);
3623    
3624                    if (!list.isEmpty()) {
3625                            return list.get(0);
3626                    }
3627    
3628                    return null;
3629            }
3630    
3631            /**
3632             * Returns the journal articles before and after the current journal article in the ordered set where structureId = &#63;.
3633             *
3634             * @param id the primary key of the current journal article
3635             * @param structureId the structure ID
3636             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3637             * @return the previous, current, and next journal article
3638             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
3639             * @throws SystemException if a system exception occurred
3640             */
3641            @Override
3642            public JournalArticle[] findByStructureId_PrevAndNext(long id,
3643                    String structureId, OrderByComparator orderByComparator)
3644                    throws NoSuchArticleException, SystemException {
3645                    JournalArticle journalArticle = findByPrimaryKey(id);
3646    
3647                    Session session = null;
3648    
3649                    try {
3650                            session = openSession();
3651    
3652                            JournalArticle[] array = new JournalArticleImpl[3];
3653    
3654                            array[0] = getByStructureId_PrevAndNext(session, journalArticle,
3655                                            structureId, orderByComparator, true);
3656    
3657                            array[1] = journalArticle;
3658    
3659                            array[2] = getByStructureId_PrevAndNext(session, journalArticle,
3660                                            structureId, orderByComparator, false);
3661    
3662                            return array;
3663                    }
3664                    catch (Exception e) {
3665                            throw processException(e);
3666                    }
3667                    finally {
3668                            closeSession(session);
3669                    }
3670            }
3671    
3672            protected JournalArticle getByStructureId_PrevAndNext(Session session,
3673                    JournalArticle journalArticle, String structureId,
3674                    OrderByComparator orderByComparator, boolean previous) {
3675                    StringBundler query = null;
3676    
3677                    if (orderByComparator != null) {
3678                            query = new StringBundler(6 +
3679                                            (orderByComparator.getOrderByFields().length * 6));
3680                    }
3681                    else {
3682                            query = new StringBundler(3);
3683                    }
3684    
3685                    query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
3686    
3687                    boolean bindStructureId = false;
3688    
3689                    if (structureId == null) {
3690                            query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_1);
3691                    }
3692                    else if (structureId.equals(StringPool.BLANK)) {
3693                            query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_3);
3694                    }
3695                    else {
3696                            bindStructureId = true;
3697    
3698                            query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_2);
3699                    }
3700    
3701                    if (orderByComparator != null) {
3702                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3703    
3704                            if (orderByConditionFields.length > 0) {
3705                                    query.append(WHERE_AND);
3706                            }
3707    
3708                            for (int i = 0; i < orderByConditionFields.length; i++) {
3709                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3710                                    query.append(orderByConditionFields[i]);
3711    
3712                                    if ((i + 1) < orderByConditionFields.length) {
3713                                            if (orderByComparator.isAscending() ^ previous) {
3714                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3715                                            }
3716                                            else {
3717                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3718                                            }
3719                                    }
3720                                    else {
3721                                            if (orderByComparator.isAscending() ^ previous) {
3722                                                    query.append(WHERE_GREATER_THAN);
3723                                            }
3724                                            else {
3725                                                    query.append(WHERE_LESSER_THAN);
3726                                            }
3727                                    }
3728                            }
3729    
3730                            query.append(ORDER_BY_CLAUSE);
3731    
3732                            String[] orderByFields = orderByComparator.getOrderByFields();
3733    
3734                            for (int i = 0; i < orderByFields.length; i++) {
3735                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3736                                    query.append(orderByFields[i]);
3737    
3738                                    if ((i + 1) < orderByFields.length) {
3739                                            if (orderByComparator.isAscending() ^ previous) {
3740                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3741                                            }
3742                                            else {
3743                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3744                                            }
3745                                    }
3746                                    else {
3747                                            if (orderByComparator.isAscending() ^ previous) {
3748                                                    query.append(ORDER_BY_ASC);
3749                                            }
3750                                            else {
3751                                                    query.append(ORDER_BY_DESC);
3752                                            }
3753                                    }
3754                            }
3755                    }
3756                    else {
3757                            query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
3758                    }
3759    
3760                    String sql = query.toString();
3761    
3762                    Query q = session.createQuery(sql);
3763    
3764                    q.setFirstResult(0);
3765                    q.setMaxResults(2);
3766    
3767                    QueryPos qPos = QueryPos.getInstance(q);
3768    
3769                    if (bindStructureId) {
3770                            qPos.add(structureId);
3771                    }
3772    
3773                    if (orderByComparator != null) {
3774                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
3775    
3776                            for (Object value : values) {
3777                                    qPos.add(value);
3778                            }
3779                    }
3780    
3781                    List<JournalArticle> list = q.list();
3782    
3783                    if (list.size() == 2) {
3784                            return list.get(1);
3785                    }
3786                    else {
3787                            return null;
3788                    }
3789            }
3790    
3791            /**
3792             * Returns all the journal articles where structureId = any &#63;.
3793             *
3794             * <p>
3795             * 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.
3796             * </p>
3797             *
3798             * @param structureIds the structure IDs
3799             * @return the matching journal articles
3800             * @throws SystemException if a system exception occurred
3801             */
3802            @Override
3803            public List<JournalArticle> findByStructureId(String[] structureIds)
3804                    throws SystemException {
3805                    return findByStructureId(structureIds, QueryUtil.ALL_POS,
3806                            QueryUtil.ALL_POS, null);
3807            }
3808    
3809            /**
3810             * Returns a range of all the journal articles where structureId = any &#63;.
3811             *
3812             * <p>
3813             * 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.
3814             * </p>
3815             *
3816             * @param structureIds the structure IDs
3817             * @param start the lower bound of the range of journal articles
3818             * @param end the upper bound of the range of journal articles (not inclusive)
3819             * @return the range of matching journal articles
3820             * @throws SystemException if a system exception occurred
3821             */
3822            @Override
3823            public List<JournalArticle> findByStructureId(String[] structureIds,
3824                    int start, int end) throws SystemException {
3825                    return findByStructureId(structureIds, start, end, null);
3826            }
3827    
3828            /**
3829             * Returns an ordered range of all the journal articles where structureId = any &#63;.
3830             *
3831             * <p>
3832             * 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.
3833             * </p>
3834             *
3835             * @param structureIds the structure IDs
3836             * @param start the lower bound of the range of journal articles
3837             * @param end the upper bound of the range of journal articles (not inclusive)
3838             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3839             * @return the ordered range of matching journal articles
3840             * @throws SystemException if a system exception occurred
3841             */
3842            @Override
3843            public List<JournalArticle> findByStructureId(String[] structureIds,
3844                    int start, int end, OrderByComparator orderByComparator)
3845                    throws SystemException {
3846                    if ((structureIds != null) && (structureIds.length == 1)) {
3847                            return findByStructureId(structureIds[0], start, end,
3848                                    orderByComparator);
3849                    }
3850    
3851                    boolean pagination = true;
3852                    Object[] finderArgs = null;
3853    
3854                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3855                                    (orderByComparator == null)) {
3856                            pagination = false;
3857                            finderArgs = new Object[] { StringUtil.merge(structureIds) };
3858                    }
3859                    else {
3860                            finderArgs = new Object[] {
3861                                            StringUtil.merge(structureIds),
3862                                            
3863                                            start, end, orderByComparator
3864                                    };
3865                    }
3866    
3867                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_STRUCTUREID,
3868                                    finderArgs, this);
3869    
3870                    if ((list != null) && !list.isEmpty()) {
3871                            for (JournalArticle journalArticle : list) {
3872                                    if (!ArrayUtil.contains(structureIds,
3873                                                            journalArticle.getStructureId())) {
3874                                            list = null;
3875    
3876                                            break;
3877                                    }
3878                            }
3879                    }
3880    
3881                    if (list == null) {
3882                            StringBundler query = new StringBundler();
3883    
3884                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
3885    
3886                            boolean conjunctionable = false;
3887    
3888                            if ((structureIds == null) || (structureIds.length > 0)) {
3889                                    if (conjunctionable) {
3890                                            query.append(WHERE_AND);
3891                                    }
3892    
3893                                    query.append(StringPool.OPEN_PARENTHESIS);
3894    
3895                                    for (int i = 0; i < structureIds.length; i++) {
3896                                            String structureId = structureIds[i];
3897    
3898                                            if (structureId == null) {
3899                                                    query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_4);
3900                                            }
3901                                            else if (structureId.equals(StringPool.BLANK)) {
3902                                                    query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_6);
3903                                            }
3904                                            else {
3905                                                    query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_5);
3906                                            }
3907    
3908                                            if ((i + 1) < structureIds.length) {
3909                                                    query.append(WHERE_OR);
3910                                            }
3911                                    }
3912    
3913                                    query.append(StringPool.CLOSE_PARENTHESIS);
3914    
3915                                    conjunctionable = true;
3916                            }
3917    
3918                            if (orderByComparator != null) {
3919                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3920                                            orderByComparator);
3921                            }
3922                            else
3923                             if (pagination) {
3924                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
3925                            }
3926    
3927                            String sql = query.toString();
3928    
3929                            Session session = null;
3930    
3931                            try {
3932                                    session = openSession();
3933    
3934                                    Query q = session.createQuery(sql);
3935    
3936                                    QueryPos qPos = QueryPos.getInstance(q);
3937    
3938                                    if (structureIds != null) {
3939                                            qPos.add(structureIds);
3940                                    }
3941    
3942                                    if (!pagination) {
3943                                            list = (List<JournalArticle>)QueryUtil.list(q,
3944                                                            getDialect(), start, end, false);
3945    
3946                                            Collections.sort(list);
3947    
3948                                            list = new UnmodifiableList<JournalArticle>(list);
3949                                    }
3950                                    else {
3951                                            list = (List<JournalArticle>)QueryUtil.list(q,
3952                                                            getDialect(), start, end);
3953                                    }
3954    
3955                                    cacheResult(list);
3956    
3957                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_STRUCTUREID,
3958                                            finderArgs, list);
3959                            }
3960                            catch (Exception e) {
3961                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_STRUCTUREID,
3962                                            finderArgs);
3963    
3964                                    throw processException(e);
3965                            }
3966                            finally {
3967                                    closeSession(session);
3968                            }
3969                    }
3970    
3971                    return list;
3972            }
3973    
3974            /**
3975             * Removes all the journal articles where structureId = &#63; from the database.
3976             *
3977             * @param structureId the structure ID
3978             * @throws SystemException if a system exception occurred
3979             */
3980            @Override
3981            public void removeByStructureId(String structureId)
3982                    throws SystemException {
3983                    for (JournalArticle journalArticle : findByStructureId(structureId,
3984                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3985                            remove(journalArticle);
3986                    }
3987            }
3988    
3989            /**
3990             * Returns the number of journal articles where structureId = &#63;.
3991             *
3992             * @param structureId the structure ID
3993             * @return the number of matching journal articles
3994             * @throws SystemException if a system exception occurred
3995             */
3996            @Override
3997            public int countByStructureId(String structureId) throws SystemException {
3998                    FinderPath finderPath = FINDER_PATH_COUNT_BY_STRUCTUREID;
3999    
4000                    Object[] finderArgs = new Object[] { structureId };
4001    
4002                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4003                                    this);
4004    
4005                    if (count == null) {
4006                            StringBundler query = new StringBundler(2);
4007    
4008                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
4009    
4010                            boolean bindStructureId = false;
4011    
4012                            if (structureId == null) {
4013                                    query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_1);
4014                            }
4015                            else if (structureId.equals(StringPool.BLANK)) {
4016                                    query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_3);
4017                            }
4018                            else {
4019                                    bindStructureId = true;
4020    
4021                                    query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_2);
4022                            }
4023    
4024                            String sql = query.toString();
4025    
4026                            Session session = null;
4027    
4028                            try {
4029                                    session = openSession();
4030    
4031                                    Query q = session.createQuery(sql);
4032    
4033                                    QueryPos qPos = QueryPos.getInstance(q);
4034    
4035                                    if (bindStructureId) {
4036                                            qPos.add(structureId);
4037                                    }
4038    
4039                                    count = (Long)q.uniqueResult();
4040    
4041                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4042                            }
4043                            catch (Exception e) {
4044                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4045    
4046                                    throw processException(e);
4047                            }
4048                            finally {
4049                                    closeSession(session);
4050                            }
4051                    }
4052    
4053                    return count.intValue();
4054            }
4055    
4056            /**
4057             * Returns the number of journal articles where structureId = any &#63;.
4058             *
4059             * @param structureIds the structure IDs
4060             * @return the number of matching journal articles
4061             * @throws SystemException if a system exception occurred
4062             */
4063            @Override
4064            public int countByStructureId(String[] structureIds)
4065                    throws SystemException {
4066                    Object[] finderArgs = new Object[] { StringUtil.merge(structureIds) };
4067    
4068                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_STRUCTUREID,
4069                                    finderArgs, this);
4070    
4071                    if (count == null) {
4072                            StringBundler query = new StringBundler();
4073    
4074                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
4075    
4076                            boolean conjunctionable = false;
4077    
4078                            if ((structureIds == null) || (structureIds.length > 0)) {
4079                                    if (conjunctionable) {
4080                                            query.append(WHERE_AND);
4081                                    }
4082    
4083                                    query.append(StringPool.OPEN_PARENTHESIS);
4084    
4085                                    for (int i = 0; i < structureIds.length; i++) {
4086                                            String structureId = structureIds[i];
4087    
4088                                            if (structureId == null) {
4089                                                    query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_4);
4090                                            }
4091                                            else if (structureId.equals(StringPool.BLANK)) {
4092                                                    query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_6);
4093                                            }
4094                                            else {
4095                                                    query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_5);
4096                                            }
4097    
4098                                            if ((i + 1) < structureIds.length) {
4099                                                    query.append(WHERE_OR);
4100                                            }
4101                                    }
4102    
4103                                    query.append(StringPool.CLOSE_PARENTHESIS);
4104    
4105                                    conjunctionable = true;
4106                            }
4107    
4108                            String sql = query.toString();
4109    
4110                            Session session = null;
4111    
4112                            try {
4113                                    session = openSession();
4114    
4115                                    Query q = session.createQuery(sql);
4116    
4117                                    QueryPos qPos = QueryPos.getInstance(q);
4118    
4119                                    if (structureIds != null) {
4120                                            qPos.add(structureIds);
4121                                    }
4122    
4123                                    count = (Long)q.uniqueResult();
4124    
4125                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_STRUCTUREID,
4126                                            finderArgs, count);
4127                            }
4128                            catch (Exception e) {
4129                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_STRUCTUREID,
4130                                            finderArgs);
4131    
4132                                    throw processException(e);
4133                            }
4134                            finally {
4135                                    closeSession(session);
4136                            }
4137                    }
4138    
4139                    return count.intValue();
4140            }
4141    
4142            private static final String _FINDER_COLUMN_STRUCTUREID_STRUCTUREID_1 = "journalArticle.structureId IS NULL";
4143            private static final String _FINDER_COLUMN_STRUCTUREID_STRUCTUREID_2 = "journalArticle.structureId = ?";
4144            private static final String _FINDER_COLUMN_STRUCTUREID_STRUCTUREID_3 = "(journalArticle.structureId IS NULL OR journalArticle.structureId = '')";
4145            private static final String _FINDER_COLUMN_STRUCTUREID_STRUCTUREID_4 = "(" +
4146                    removeConjunction(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_1) + ")";
4147            private static final String _FINDER_COLUMN_STRUCTUREID_STRUCTUREID_5 = "(" +
4148                    removeConjunction(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_2) + ")";
4149            private static final String _FINDER_COLUMN_STRUCTUREID_STRUCTUREID_6 = "(" +
4150                    removeConjunction(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_3) + ")";
4151            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TEMPLATEID =
4152                    new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
4153                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
4154                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
4155                            "findByTemplateId",
4156                            new String[] {
4157                                    String.class.getName(),
4158                                    
4159                            Integer.class.getName(), Integer.class.getName(),
4160                                    OrderByComparator.class.getName()
4161                            });
4162            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TEMPLATEID =
4163                    new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
4164                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
4165                            JournalArticleImpl.class,
4166                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByTemplateId",
4167                            new String[] { String.class.getName() },
4168                            JournalArticleModelImpl.TEMPLATEID_COLUMN_BITMASK |
4169                            JournalArticleModelImpl.ARTICLEID_COLUMN_BITMASK |
4170                            JournalArticleModelImpl.VERSION_COLUMN_BITMASK);
4171            public static final FinderPath FINDER_PATH_COUNT_BY_TEMPLATEID = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
4172                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
4173                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByTemplateId",
4174                            new String[] { String.class.getName() });
4175    
4176            /**
4177             * Returns all the journal articles where templateId = &#63;.
4178             *
4179             * @param templateId the template ID
4180             * @return the matching journal articles
4181             * @throws SystemException if a system exception occurred
4182             */
4183            @Override
4184            public List<JournalArticle> findByTemplateId(String templateId)
4185                    throws SystemException {
4186                    return findByTemplateId(templateId, QueryUtil.ALL_POS,
4187                            QueryUtil.ALL_POS, null);
4188            }
4189    
4190            /**
4191             * Returns a range of all the journal articles where templateId = &#63;.
4192             *
4193             * <p>
4194             * 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.
4195             * </p>
4196             *
4197             * @param templateId the template ID
4198             * @param start the lower bound of the range of journal articles
4199             * @param end the upper bound of the range of journal articles (not inclusive)
4200             * @return the range of matching journal articles
4201             * @throws SystemException if a system exception occurred
4202             */
4203            @Override
4204            public List<JournalArticle> findByTemplateId(String templateId, int start,
4205                    int end) throws SystemException {
4206                    return findByTemplateId(templateId, start, end, null);
4207            }
4208    
4209            /**
4210             * Returns an ordered range of all the journal articles where templateId = &#63;.
4211             *
4212             * <p>
4213             * 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.
4214             * </p>
4215             *
4216             * @param templateId the template ID
4217             * @param start the lower bound of the range of journal articles
4218             * @param end the upper bound of the range of journal articles (not inclusive)
4219             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4220             * @return the ordered range of matching journal articles
4221             * @throws SystemException if a system exception occurred
4222             */
4223            @Override
4224            public List<JournalArticle> findByTemplateId(String templateId, int start,
4225                    int end, OrderByComparator orderByComparator) throws SystemException {
4226                    boolean pagination = true;
4227                    FinderPath finderPath = null;
4228                    Object[] finderArgs = null;
4229    
4230                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4231                                    (orderByComparator == null)) {
4232                            pagination = false;
4233                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TEMPLATEID;
4234                            finderArgs = new Object[] { templateId };
4235                    }
4236                    else {
4237                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TEMPLATEID;
4238                            finderArgs = new Object[] { templateId, start, end, orderByComparator };
4239                    }
4240    
4241                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
4242                                    finderArgs, this);
4243    
4244                    if ((list != null) && !list.isEmpty()) {
4245                            for (JournalArticle journalArticle : list) {
4246                                    if (!Validator.equals(templateId, journalArticle.getTemplateId())) {
4247                                            list = null;
4248    
4249                                            break;
4250                                    }
4251                            }
4252                    }
4253    
4254                    if (list == null) {
4255                            StringBundler query = null;
4256    
4257                            if (orderByComparator != null) {
4258                                    query = new StringBundler(3 +
4259                                                    (orderByComparator.getOrderByFields().length * 3));
4260                            }
4261                            else {
4262                                    query = new StringBundler(3);
4263                            }
4264    
4265                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
4266    
4267                            boolean bindTemplateId = false;
4268    
4269                            if (templateId == null) {
4270                                    query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_1);
4271                            }
4272                            else if (templateId.equals(StringPool.BLANK)) {
4273                                    query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_3);
4274                            }
4275                            else {
4276                                    bindTemplateId = true;
4277    
4278                                    query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_2);
4279                            }
4280    
4281                            if (orderByComparator != null) {
4282                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4283                                            orderByComparator);
4284                            }
4285                            else
4286                             if (pagination) {
4287                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
4288                            }
4289    
4290                            String sql = query.toString();
4291    
4292                            Session session = null;
4293    
4294                            try {
4295                                    session = openSession();
4296    
4297                                    Query q = session.createQuery(sql);
4298    
4299                                    QueryPos qPos = QueryPos.getInstance(q);
4300    
4301                                    if (bindTemplateId) {
4302                                            qPos.add(templateId);
4303                                    }
4304    
4305                                    if (!pagination) {
4306                                            list = (List<JournalArticle>)QueryUtil.list(q,
4307                                                            getDialect(), start, end, false);
4308    
4309                                            Collections.sort(list);
4310    
4311                                            list = new UnmodifiableList<JournalArticle>(list);
4312                                    }
4313                                    else {
4314                                            list = (List<JournalArticle>)QueryUtil.list(q,
4315                                                            getDialect(), start, end);
4316                                    }
4317    
4318                                    cacheResult(list);
4319    
4320                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4321                            }
4322                            catch (Exception e) {
4323                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4324    
4325                                    throw processException(e);
4326                            }
4327                            finally {
4328                                    closeSession(session);
4329                            }
4330                    }
4331    
4332                    return list;
4333            }
4334    
4335            /**
4336             * Returns the first journal article in the ordered set where templateId = &#63;.
4337             *
4338             * @param templateId the template ID
4339             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4340             * @return the first matching journal article
4341             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
4342             * @throws SystemException if a system exception occurred
4343             */
4344            @Override
4345            public JournalArticle findByTemplateId_First(String templateId,
4346                    OrderByComparator orderByComparator)
4347                    throws NoSuchArticleException, SystemException {
4348                    JournalArticle journalArticle = fetchByTemplateId_First(templateId,
4349                                    orderByComparator);
4350    
4351                    if (journalArticle != null) {
4352                            return journalArticle;
4353                    }
4354    
4355                    StringBundler msg = new StringBundler(4);
4356    
4357                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4358    
4359                    msg.append("templateId=");
4360                    msg.append(templateId);
4361    
4362                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4363    
4364                    throw new NoSuchArticleException(msg.toString());
4365            }
4366    
4367            /**
4368             * Returns the first journal article in the ordered set where templateId = &#63;.
4369             *
4370             * @param templateId the template ID
4371             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4372             * @return the first matching journal article, or <code>null</code> if a matching journal article could not be found
4373             * @throws SystemException if a system exception occurred
4374             */
4375            @Override
4376            public JournalArticle fetchByTemplateId_First(String templateId,
4377                    OrderByComparator orderByComparator) throws SystemException {
4378                    List<JournalArticle> list = findByTemplateId(templateId, 0, 1,
4379                                    orderByComparator);
4380    
4381                    if (!list.isEmpty()) {
4382                            return list.get(0);
4383                    }
4384    
4385                    return null;
4386            }
4387    
4388            /**
4389             * Returns the last journal article in the ordered set where templateId = &#63;.
4390             *
4391             * @param templateId the template ID
4392             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4393             * @return the last matching journal article
4394             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
4395             * @throws SystemException if a system exception occurred
4396             */
4397            @Override
4398            public JournalArticle findByTemplateId_Last(String templateId,
4399                    OrderByComparator orderByComparator)
4400                    throws NoSuchArticleException, SystemException {
4401                    JournalArticle journalArticle = fetchByTemplateId_Last(templateId,
4402                                    orderByComparator);
4403    
4404                    if (journalArticle != null) {
4405                            return journalArticle;
4406                    }
4407    
4408                    StringBundler msg = new StringBundler(4);
4409    
4410                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4411    
4412                    msg.append("templateId=");
4413                    msg.append(templateId);
4414    
4415                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4416    
4417                    throw new NoSuchArticleException(msg.toString());
4418            }
4419    
4420            /**
4421             * Returns the last journal article in the ordered set where templateId = &#63;.
4422             *
4423             * @param templateId the template ID
4424             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4425             * @return the last matching journal article, or <code>null</code> if a matching journal article could not be found
4426             * @throws SystemException if a system exception occurred
4427             */
4428            @Override
4429            public JournalArticle fetchByTemplateId_Last(String templateId,
4430                    OrderByComparator orderByComparator) throws SystemException {
4431                    int count = countByTemplateId(templateId);
4432    
4433                    if (count == 0) {
4434                            return null;
4435                    }
4436    
4437                    List<JournalArticle> list = findByTemplateId(templateId, count - 1,
4438                                    count, orderByComparator);
4439    
4440                    if (!list.isEmpty()) {
4441                            return list.get(0);
4442                    }
4443    
4444                    return null;
4445            }
4446    
4447            /**
4448             * Returns the journal articles before and after the current journal article in the ordered set where templateId = &#63;.
4449             *
4450             * @param id the primary key of the current journal article
4451             * @param templateId the template ID
4452             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4453             * @return the previous, current, and next journal article
4454             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
4455             * @throws SystemException if a system exception occurred
4456             */
4457            @Override
4458            public JournalArticle[] findByTemplateId_PrevAndNext(long id,
4459                    String templateId, OrderByComparator orderByComparator)
4460                    throws NoSuchArticleException, SystemException {
4461                    JournalArticle journalArticle = findByPrimaryKey(id);
4462    
4463                    Session session = null;
4464    
4465                    try {
4466                            session = openSession();
4467    
4468                            JournalArticle[] array = new JournalArticleImpl[3];
4469    
4470                            array[0] = getByTemplateId_PrevAndNext(session, journalArticle,
4471                                            templateId, orderByComparator, true);
4472    
4473                            array[1] = journalArticle;
4474    
4475                            array[2] = getByTemplateId_PrevAndNext(session, journalArticle,
4476                                            templateId, orderByComparator, false);
4477    
4478                            return array;
4479                    }
4480                    catch (Exception e) {
4481                            throw processException(e);
4482                    }
4483                    finally {
4484                            closeSession(session);
4485                    }
4486            }
4487    
4488            protected JournalArticle getByTemplateId_PrevAndNext(Session session,
4489                    JournalArticle journalArticle, String templateId,
4490                    OrderByComparator orderByComparator, boolean previous) {
4491                    StringBundler query = null;
4492    
4493                    if (orderByComparator != null) {
4494                            query = new StringBundler(6 +
4495                                            (orderByComparator.getOrderByFields().length * 6));
4496                    }
4497                    else {
4498                            query = new StringBundler(3);
4499                    }
4500    
4501                    query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
4502    
4503                    boolean bindTemplateId = false;
4504    
4505                    if (templateId == null) {
4506                            query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_1);
4507                    }
4508                    else if (templateId.equals(StringPool.BLANK)) {
4509                            query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_3);
4510                    }
4511                    else {
4512                            bindTemplateId = true;
4513    
4514                            query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_2);
4515                    }
4516    
4517                    if (orderByComparator != null) {
4518                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4519    
4520                            if (orderByConditionFields.length > 0) {
4521                                    query.append(WHERE_AND);
4522                            }
4523    
4524                            for (int i = 0; i < orderByConditionFields.length; i++) {
4525                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4526                                    query.append(orderByConditionFields[i]);
4527    
4528                                    if ((i + 1) < orderByConditionFields.length) {
4529                                            if (orderByComparator.isAscending() ^ previous) {
4530                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4531                                            }
4532                                            else {
4533                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4534                                            }
4535                                    }
4536                                    else {
4537                                            if (orderByComparator.isAscending() ^ previous) {
4538                                                    query.append(WHERE_GREATER_THAN);
4539                                            }
4540                                            else {
4541                                                    query.append(WHERE_LESSER_THAN);
4542                                            }
4543                                    }
4544                            }
4545    
4546                            query.append(ORDER_BY_CLAUSE);
4547    
4548                            String[] orderByFields = orderByComparator.getOrderByFields();
4549    
4550                            for (int i = 0; i < orderByFields.length; i++) {
4551                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4552                                    query.append(orderByFields[i]);
4553    
4554                                    if ((i + 1) < orderByFields.length) {
4555                                            if (orderByComparator.isAscending() ^ previous) {
4556                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4557                                            }
4558                                            else {
4559                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4560                                            }
4561                                    }
4562                                    else {
4563                                            if (orderByComparator.isAscending() ^ previous) {
4564                                                    query.append(ORDER_BY_ASC);
4565                                            }
4566                                            else {
4567                                                    query.append(ORDER_BY_DESC);
4568                                            }
4569                                    }
4570                            }
4571                    }
4572                    else {
4573                            query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
4574                    }
4575    
4576                    String sql = query.toString();
4577    
4578                    Query q = session.createQuery(sql);
4579    
4580                    q.setFirstResult(0);
4581                    q.setMaxResults(2);
4582    
4583                    QueryPos qPos = QueryPos.getInstance(q);
4584    
4585                    if (bindTemplateId) {
4586                            qPos.add(templateId);
4587                    }
4588    
4589                    if (orderByComparator != null) {
4590                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
4591    
4592                            for (Object value : values) {
4593                                    qPos.add(value);
4594                            }
4595                    }
4596    
4597                    List<JournalArticle> list = q.list();
4598    
4599                    if (list.size() == 2) {
4600                            return list.get(1);
4601                    }
4602                    else {
4603                            return null;
4604                    }
4605            }
4606    
4607            /**
4608             * Removes all the journal articles where templateId = &#63; from the database.
4609             *
4610             * @param templateId the template ID
4611             * @throws SystemException if a system exception occurred
4612             */
4613            @Override
4614            public void removeByTemplateId(String templateId) throws SystemException {
4615                    for (JournalArticle journalArticle : findByTemplateId(templateId,
4616                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4617                            remove(journalArticle);
4618                    }
4619            }
4620    
4621            /**
4622             * Returns the number of journal articles where templateId = &#63;.
4623             *
4624             * @param templateId the template ID
4625             * @return the number of matching journal articles
4626             * @throws SystemException if a system exception occurred
4627             */
4628            @Override
4629            public int countByTemplateId(String templateId) throws SystemException {
4630                    FinderPath finderPath = FINDER_PATH_COUNT_BY_TEMPLATEID;
4631    
4632                    Object[] finderArgs = new Object[] { templateId };
4633    
4634                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4635                                    this);
4636    
4637                    if (count == null) {
4638                            StringBundler query = new StringBundler(2);
4639    
4640                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
4641    
4642                            boolean bindTemplateId = false;
4643    
4644                            if (templateId == null) {
4645                                    query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_1);
4646                            }
4647                            else if (templateId.equals(StringPool.BLANK)) {
4648                                    query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_3);
4649                            }
4650                            else {
4651                                    bindTemplateId = true;
4652    
4653                                    query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_2);
4654                            }
4655    
4656                            String sql = query.toString();
4657    
4658                            Session session = null;
4659    
4660                            try {
4661                                    session = openSession();
4662    
4663                                    Query q = session.createQuery(sql);
4664    
4665                                    QueryPos qPos = QueryPos.getInstance(q);
4666    
4667                                    if (bindTemplateId) {
4668                                            qPos.add(templateId);
4669                                    }
4670    
4671                                    count = (Long)q.uniqueResult();
4672    
4673                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4674                            }
4675                            catch (Exception e) {
4676                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4677    
4678                                    throw processException(e);
4679                            }
4680                            finally {
4681                                    closeSession(session);
4682                            }
4683                    }
4684    
4685                    return count.intValue();
4686            }
4687    
4688            private static final String _FINDER_COLUMN_TEMPLATEID_TEMPLATEID_1 = "journalArticle.templateId IS NULL";
4689            private static final String _FINDER_COLUMN_TEMPLATEID_TEMPLATEID_2 = "journalArticle.templateId = ?";
4690            private static final String _FINDER_COLUMN_TEMPLATEID_TEMPLATEID_3 = "(journalArticle.templateId IS NULL OR journalArticle.templateId = '')";
4691            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_LAYOUTUUID =
4692                    new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
4693                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
4694                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
4695                            "findByLayoutUuid",
4696                            new String[] {
4697                                    String.class.getName(),
4698                                    
4699                            Integer.class.getName(), Integer.class.getName(),
4700                                    OrderByComparator.class.getName()
4701                            });
4702            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTUUID =
4703                    new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
4704                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
4705                            JournalArticleImpl.class,
4706                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByLayoutUuid",
4707                            new String[] { String.class.getName() },
4708                            JournalArticleModelImpl.LAYOUTUUID_COLUMN_BITMASK |
4709                            JournalArticleModelImpl.ARTICLEID_COLUMN_BITMASK |
4710                            JournalArticleModelImpl.VERSION_COLUMN_BITMASK);
4711            public static final FinderPath FINDER_PATH_COUNT_BY_LAYOUTUUID = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
4712                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
4713                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByLayoutUuid",
4714                            new String[] { String.class.getName() });
4715    
4716            /**
4717             * Returns all the journal articles where layoutUuid = &#63;.
4718             *
4719             * @param layoutUuid the layout uuid
4720             * @return the matching journal articles
4721             * @throws SystemException if a system exception occurred
4722             */
4723            @Override
4724            public List<JournalArticle> findByLayoutUuid(String layoutUuid)
4725                    throws SystemException {
4726                    return findByLayoutUuid(layoutUuid, QueryUtil.ALL_POS,
4727                            QueryUtil.ALL_POS, null);
4728            }
4729    
4730            /**
4731             * Returns a range of all the journal articles where layoutUuid = &#63;.
4732             *
4733             * <p>
4734             * 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.
4735             * </p>
4736             *
4737             * @param layoutUuid the layout uuid
4738             * @param start the lower bound of the range of journal articles
4739             * @param end the upper bound of the range of journal articles (not inclusive)
4740             * @return the range of matching journal articles
4741             * @throws SystemException if a system exception occurred
4742             */
4743            @Override
4744            public List<JournalArticle> findByLayoutUuid(String layoutUuid, int start,
4745                    int end) throws SystemException {
4746                    return findByLayoutUuid(layoutUuid, start, end, null);
4747            }
4748    
4749            /**
4750             * Returns an ordered range of all the journal articles where layoutUuid = &#63;.
4751             *
4752             * <p>
4753             * 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.
4754             * </p>
4755             *
4756             * @param layoutUuid the layout uuid
4757             * @param start the lower bound of the range of journal articles
4758             * @param end the upper bound of the range of journal articles (not inclusive)
4759             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4760             * @return the ordered range of matching journal articles
4761             * @throws SystemException if a system exception occurred
4762             */
4763            @Override
4764            public List<JournalArticle> findByLayoutUuid(String layoutUuid, int start,
4765                    int end, OrderByComparator orderByComparator) throws SystemException {
4766                    boolean pagination = true;
4767                    FinderPath finderPath = null;
4768                    Object[] finderArgs = null;
4769    
4770                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4771                                    (orderByComparator == null)) {
4772                            pagination = false;
4773                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTUUID;
4774                            finderArgs = new Object[] { layoutUuid };
4775                    }
4776                    else {
4777                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_LAYOUTUUID;
4778                            finderArgs = new Object[] { layoutUuid, start, end, orderByComparator };
4779                    }
4780    
4781                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
4782                                    finderArgs, this);
4783    
4784                    if ((list != null) && !list.isEmpty()) {
4785                            for (JournalArticle journalArticle : list) {
4786                                    if (!Validator.equals(layoutUuid, journalArticle.getLayoutUuid())) {
4787                                            list = null;
4788    
4789                                            break;
4790                                    }
4791                            }
4792                    }
4793    
4794                    if (list == null) {
4795                            StringBundler query = null;
4796    
4797                            if (orderByComparator != null) {
4798                                    query = new StringBundler(3 +
4799                                                    (orderByComparator.getOrderByFields().length * 3));
4800                            }
4801                            else {
4802                                    query = new StringBundler(3);
4803                            }
4804    
4805                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
4806    
4807                            boolean bindLayoutUuid = false;
4808    
4809                            if (layoutUuid == null) {
4810                                    query.append(_FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_1);
4811                            }
4812                            else if (layoutUuid.equals(StringPool.BLANK)) {
4813                                    query.append(_FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_3);
4814                            }
4815                            else {
4816                                    bindLayoutUuid = true;
4817    
4818                                    query.append(_FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_2);
4819                            }
4820    
4821                            if (orderByComparator != null) {
4822                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4823                                            orderByComparator);
4824                            }
4825                            else
4826                             if (pagination) {
4827                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
4828                            }
4829    
4830                            String sql = query.toString();
4831    
4832                            Session session = null;
4833    
4834                            try {
4835                                    session = openSession();
4836    
4837                                    Query q = session.createQuery(sql);
4838    
4839                                    QueryPos qPos = QueryPos.getInstance(q);
4840    
4841                                    if (bindLayoutUuid) {
4842                                            qPos.add(layoutUuid);
4843                                    }
4844    
4845                                    if (!pagination) {
4846                                            list = (List<JournalArticle>)QueryUtil.list(q,
4847                                                            getDialect(), start, end, false);
4848    
4849                                            Collections.sort(list);
4850    
4851                                            list = new UnmodifiableList<JournalArticle>(list);
4852                                    }
4853                                    else {
4854                                            list = (List<JournalArticle>)QueryUtil.list(q,
4855                                                            getDialect(), start, end);
4856                                    }
4857    
4858                                    cacheResult(list);
4859    
4860                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4861                            }
4862                            catch (Exception e) {
4863                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4864    
4865                                    throw processException(e);
4866                            }
4867                            finally {
4868                                    closeSession(session);
4869                            }
4870                    }
4871    
4872                    return list;
4873            }
4874    
4875            /**
4876             * Returns the first journal article in the ordered set where layoutUuid = &#63;.
4877             *
4878             * @param layoutUuid the layout uuid
4879             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4880             * @return the first matching journal article
4881             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
4882             * @throws SystemException if a system exception occurred
4883             */
4884            @Override
4885            public JournalArticle findByLayoutUuid_First(String layoutUuid,
4886                    OrderByComparator orderByComparator)
4887                    throws NoSuchArticleException, SystemException {
4888                    JournalArticle journalArticle = fetchByLayoutUuid_First(layoutUuid,
4889                                    orderByComparator);
4890    
4891                    if (journalArticle != null) {
4892                            return journalArticle;
4893                    }
4894    
4895                    StringBundler msg = new StringBundler(4);
4896    
4897                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4898    
4899                    msg.append("layoutUuid=");
4900                    msg.append(layoutUuid);
4901    
4902                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4903    
4904                    throw new NoSuchArticleException(msg.toString());
4905            }
4906    
4907            /**
4908             * Returns the first journal article in the ordered set where layoutUuid = &#63;.
4909             *
4910             * @param layoutUuid the layout uuid
4911             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4912             * @return the first matching journal article, or <code>null</code> if a matching journal article could not be found
4913             * @throws SystemException if a system exception occurred
4914             */
4915            @Override
4916            public JournalArticle fetchByLayoutUuid_First(String layoutUuid,
4917                    OrderByComparator orderByComparator) throws SystemException {
4918                    List<JournalArticle> list = findByLayoutUuid(layoutUuid, 0, 1,
4919                                    orderByComparator);
4920    
4921                    if (!list.isEmpty()) {
4922                            return list.get(0);
4923                    }
4924    
4925                    return null;
4926            }
4927    
4928            /**
4929             * Returns the last journal article in the ordered set where layoutUuid = &#63;.
4930             *
4931             * @param layoutUuid the layout uuid
4932             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4933             * @return the last matching journal article
4934             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
4935             * @throws SystemException if a system exception occurred
4936             */
4937            @Override
4938            public JournalArticle findByLayoutUuid_Last(String layoutUuid,
4939                    OrderByComparator orderByComparator)
4940                    throws NoSuchArticleException, SystemException {
4941                    JournalArticle journalArticle = fetchByLayoutUuid_Last(layoutUuid,
4942                                    orderByComparator);
4943    
4944                    if (journalArticle != null) {
4945                            return journalArticle;
4946                    }
4947    
4948                    StringBundler msg = new StringBundler(4);
4949    
4950                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4951    
4952                    msg.append("layoutUuid=");
4953                    msg.append(layoutUuid);
4954    
4955                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4956    
4957                    throw new NoSuchArticleException(msg.toString());
4958            }
4959    
4960            /**
4961             * Returns the last journal article in the ordered set where layoutUuid = &#63;.
4962             *
4963             * @param layoutUuid the layout uuid
4964             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4965             * @return the last matching journal article, or <code>null</code> if a matching journal article could not be found
4966             * @throws SystemException if a system exception occurred
4967             */
4968            @Override
4969            public JournalArticle fetchByLayoutUuid_Last(String layoutUuid,
4970                    OrderByComparator orderByComparator) throws SystemException {
4971                    int count = countByLayoutUuid(layoutUuid);
4972    
4973                    if (count == 0) {
4974                            return null;
4975                    }
4976    
4977                    List<JournalArticle> list = findByLayoutUuid(layoutUuid, count - 1,
4978                                    count, orderByComparator);
4979    
4980                    if (!list.isEmpty()) {
4981                            return list.get(0);
4982                    }
4983    
4984                    return null;
4985            }
4986    
4987            /**
4988             * Returns the journal articles before and after the current journal article in the ordered set where layoutUuid = &#63;.
4989             *
4990             * @param id the primary key of the current journal article
4991             * @param layoutUuid the layout uuid
4992             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4993             * @return the previous, current, and next journal article
4994             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
4995             * @throws SystemException if a system exception occurred
4996             */
4997            @Override
4998            public JournalArticle[] findByLayoutUuid_PrevAndNext(long id,
4999                    String layoutUuid, OrderByComparator orderByComparator)
5000                    throws NoSuchArticleException, SystemException {
5001                    JournalArticle journalArticle = findByPrimaryKey(id);
5002    
5003                    Session session = null;
5004    
5005                    try {
5006                            session = openSession();
5007    
5008                            JournalArticle[] array = new JournalArticleImpl[3];
5009    
5010                            array[0] = getByLayoutUuid_PrevAndNext(session, journalArticle,
5011                                            layoutUuid, orderByComparator, true);
5012    
5013                            array[1] = journalArticle;
5014    
5015                            array[2] = getByLayoutUuid_PrevAndNext(session, journalArticle,
5016                                            layoutUuid, orderByComparator, false);
5017    
5018                            return array;
5019                    }
5020                    catch (Exception e) {
5021                            throw processException(e);
5022                    }
5023                    finally {
5024                            closeSession(session);
5025                    }
5026            }
5027    
5028            protected JournalArticle getByLayoutUuid_PrevAndNext(Session session,
5029                    JournalArticle journalArticle, String layoutUuid,
5030                    OrderByComparator orderByComparator, boolean previous) {
5031                    StringBundler query = null;
5032    
5033                    if (orderByComparator != null) {
5034                            query = new StringBundler(6 +
5035                                            (orderByComparator.getOrderByFields().length * 6));
5036                    }
5037                    else {
5038                            query = new StringBundler(3);
5039                    }
5040    
5041                    query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
5042    
5043                    boolean bindLayoutUuid = false;
5044    
5045                    if (layoutUuid == null) {
5046                            query.append(_FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_1);
5047                    }
5048                    else if (layoutUuid.equals(StringPool.BLANK)) {
5049                            query.append(_FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_3);
5050                    }
5051                    else {
5052                            bindLayoutUuid = true;
5053    
5054                            query.append(_FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_2);
5055                    }
5056    
5057                    if (orderByComparator != null) {
5058                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5059    
5060                            if (orderByConditionFields.length > 0) {
5061                                    query.append(WHERE_AND);
5062                            }
5063    
5064                            for (int i = 0; i < orderByConditionFields.length; i++) {
5065                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5066                                    query.append(orderByConditionFields[i]);
5067    
5068                                    if ((i + 1) < orderByConditionFields.length) {
5069                                            if (orderByComparator.isAscending() ^ previous) {
5070                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5071                                            }
5072                                            else {
5073                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5074                                            }
5075                                    }
5076                                    else {
5077                                            if (orderByComparator.isAscending() ^ previous) {
5078                                                    query.append(WHERE_GREATER_THAN);
5079                                            }
5080                                            else {
5081                                                    query.append(WHERE_LESSER_THAN);
5082                                            }
5083                                    }
5084                            }
5085    
5086                            query.append(ORDER_BY_CLAUSE);
5087    
5088                            String[] orderByFields = orderByComparator.getOrderByFields();
5089    
5090                            for (int i = 0; i < orderByFields.length; i++) {
5091                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5092                                    query.append(orderByFields[i]);
5093    
5094                                    if ((i + 1) < orderByFields.length) {
5095                                            if (orderByComparator.isAscending() ^ previous) {
5096                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5097                                            }
5098                                            else {
5099                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5100                                            }
5101                                    }
5102                                    else {
5103                                            if (orderByComparator.isAscending() ^ previous) {
5104                                                    query.append(ORDER_BY_ASC);
5105                                            }
5106                                            else {
5107                                                    query.append(ORDER_BY_DESC);
5108                                            }
5109                                    }
5110                            }
5111                    }
5112                    else {
5113                            query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
5114                    }
5115    
5116                    String sql = query.toString();
5117    
5118                    Query q = session.createQuery(sql);
5119    
5120                    q.setFirstResult(0);
5121                    q.setMaxResults(2);
5122    
5123                    QueryPos qPos = QueryPos.getInstance(q);
5124    
5125                    if (bindLayoutUuid) {
5126                            qPos.add(layoutUuid);
5127                    }
5128    
5129                    if (orderByComparator != null) {
5130                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
5131    
5132                            for (Object value : values) {
5133                                    qPos.add(value);
5134                            }
5135                    }
5136    
5137                    List<JournalArticle> list = q.list();
5138    
5139                    if (list.size() == 2) {
5140                            return list.get(1);
5141                    }
5142                    else {
5143                            return null;
5144                    }
5145            }
5146    
5147            /**
5148             * Removes all the journal articles where layoutUuid = &#63; from the database.
5149             *
5150             * @param layoutUuid the layout uuid
5151             * @throws SystemException if a system exception occurred
5152             */
5153            @Override
5154            public void removeByLayoutUuid(String layoutUuid) throws SystemException {
5155                    for (JournalArticle journalArticle : findByLayoutUuid(layoutUuid,
5156                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5157                            remove(journalArticle);
5158                    }
5159            }
5160    
5161            /**
5162             * Returns the number of journal articles where layoutUuid = &#63;.
5163             *
5164             * @param layoutUuid the layout uuid
5165             * @return the number of matching journal articles
5166             * @throws SystemException if a system exception occurred
5167             */
5168            @Override
5169            public int countByLayoutUuid(String layoutUuid) throws SystemException {
5170                    FinderPath finderPath = FINDER_PATH_COUNT_BY_LAYOUTUUID;
5171    
5172                    Object[] finderArgs = new Object[] { layoutUuid };
5173    
5174                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5175                                    this);
5176    
5177                    if (count == null) {
5178                            StringBundler query = new StringBundler(2);
5179    
5180                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
5181    
5182                            boolean bindLayoutUuid = false;
5183    
5184                            if (layoutUuid == null) {
5185                                    query.append(_FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_1);
5186                            }
5187                            else if (layoutUuid.equals(StringPool.BLANK)) {
5188                                    query.append(_FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_3);
5189                            }
5190                            else {
5191                                    bindLayoutUuid = true;
5192    
5193                                    query.append(_FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_2);
5194                            }
5195    
5196                            String sql = query.toString();
5197    
5198                            Session session = null;
5199    
5200                            try {
5201                                    session = openSession();
5202    
5203                                    Query q = session.createQuery(sql);
5204    
5205                                    QueryPos qPos = QueryPos.getInstance(q);
5206    
5207                                    if (bindLayoutUuid) {
5208                                            qPos.add(layoutUuid);
5209                                    }
5210    
5211                                    count = (Long)q.uniqueResult();
5212    
5213                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5214                            }
5215                            catch (Exception e) {
5216                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5217    
5218                                    throw processException(e);
5219                            }
5220                            finally {
5221                                    closeSession(session);
5222                            }
5223                    }
5224    
5225                    return count.intValue();
5226            }
5227    
5228            private static final String _FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_1 = "journalArticle.layoutUuid IS NULL";
5229            private static final String _FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_2 = "journalArticle.layoutUuid = ?";
5230            private static final String _FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_3 = "(journalArticle.layoutUuid IS NULL OR journalArticle.layoutUuid = '')";
5231            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_SMALLIMAGEID =
5232                    new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
5233                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
5234                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
5235                            "findBySmallImageId",
5236                            new String[] {
5237                                    Long.class.getName(),
5238                                    
5239                            Integer.class.getName(), Integer.class.getName(),
5240                                    OrderByComparator.class.getName()
5241                            });
5242            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SMALLIMAGEID =
5243                    new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
5244                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
5245                            JournalArticleImpl.class,
5246                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findBySmallImageId",
5247                            new String[] { Long.class.getName() },
5248                            JournalArticleModelImpl.SMALLIMAGEID_COLUMN_BITMASK |
5249                            JournalArticleModelImpl.ARTICLEID_COLUMN_BITMASK |
5250                            JournalArticleModelImpl.VERSION_COLUMN_BITMASK);
5251            public static final FinderPath FINDER_PATH_COUNT_BY_SMALLIMAGEID = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
5252                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
5253                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countBySmallImageId",
5254                            new String[] { Long.class.getName() });
5255    
5256            /**
5257             * Returns all the journal articles where smallImageId = &#63;.
5258             *
5259             * @param smallImageId the small image ID
5260             * @return the matching journal articles
5261             * @throws SystemException if a system exception occurred
5262             */
5263            @Override
5264            public List<JournalArticle> findBySmallImageId(long smallImageId)
5265                    throws SystemException {
5266                    return findBySmallImageId(smallImageId, QueryUtil.ALL_POS,
5267                            QueryUtil.ALL_POS, null);
5268            }
5269    
5270            /**
5271             * Returns a range of all the journal articles where smallImageId = &#63;.
5272             *
5273             * <p>
5274             * 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.
5275             * </p>
5276             *
5277             * @param smallImageId the small image ID
5278             * @param start the lower bound of the range of journal articles
5279             * @param end the upper bound of the range of journal articles (not inclusive)
5280             * @return the range of matching journal articles
5281             * @throws SystemException if a system exception occurred
5282             */
5283            @Override
5284            public List<JournalArticle> findBySmallImageId(long smallImageId,
5285                    int start, int end) throws SystemException {
5286                    return findBySmallImageId(smallImageId, start, end, null);
5287            }
5288    
5289            /**
5290             * Returns an ordered range of all the journal articles where smallImageId = &#63;.
5291             *
5292             * <p>
5293             * 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.
5294             * </p>
5295             *
5296             * @param smallImageId the small image ID
5297             * @param start the lower bound of the range of journal articles
5298             * @param end the upper bound of the range of journal articles (not inclusive)
5299             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5300             * @return the ordered range of matching journal articles
5301             * @throws SystemException if a system exception occurred
5302             */
5303            @Override
5304            public List<JournalArticle> findBySmallImageId(long smallImageId,
5305                    int start, int end, OrderByComparator orderByComparator)
5306                    throws SystemException {
5307                    boolean pagination = true;
5308                    FinderPath finderPath = null;
5309                    Object[] finderArgs = null;
5310    
5311                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5312                                    (orderByComparator == null)) {
5313                            pagination = false;
5314                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SMALLIMAGEID;
5315                            finderArgs = new Object[] { smallImageId };
5316                    }
5317                    else {
5318                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_SMALLIMAGEID;
5319                            finderArgs = new Object[] {
5320                                            smallImageId,
5321                                            
5322                                            start, end, orderByComparator
5323                                    };
5324                    }
5325    
5326                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
5327                                    finderArgs, this);
5328    
5329                    if ((list != null) && !list.isEmpty()) {
5330                            for (JournalArticle journalArticle : list) {
5331                                    if ((smallImageId != journalArticle.getSmallImageId())) {
5332                                            list = null;
5333    
5334                                            break;
5335                                    }
5336                            }
5337                    }
5338    
5339                    if (list == null) {
5340                            StringBundler query = null;
5341    
5342                            if (orderByComparator != null) {
5343                                    query = new StringBundler(3 +
5344                                                    (orderByComparator.getOrderByFields().length * 3));
5345                            }
5346                            else {
5347                                    query = new StringBundler(3);
5348                            }
5349    
5350                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
5351    
5352                            query.append(_FINDER_COLUMN_SMALLIMAGEID_SMALLIMAGEID_2);
5353    
5354                            if (orderByComparator != null) {
5355                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5356                                            orderByComparator);
5357                            }
5358                            else
5359                             if (pagination) {
5360                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
5361                            }
5362    
5363                            String sql = query.toString();
5364    
5365                            Session session = null;
5366    
5367                            try {
5368                                    session = openSession();
5369    
5370                                    Query q = session.createQuery(sql);
5371    
5372                                    QueryPos qPos = QueryPos.getInstance(q);
5373    
5374                                    qPos.add(smallImageId);
5375    
5376                                    if (!pagination) {
5377                                            list = (List<JournalArticle>)QueryUtil.list(q,
5378                                                            getDialect(), start, end, false);
5379    
5380                                            Collections.sort(list);
5381    
5382                                            list = new UnmodifiableList<JournalArticle>(list);
5383                                    }
5384                                    else {
5385                                            list = (List<JournalArticle>)QueryUtil.list(q,
5386                                                            getDialect(), start, end);
5387                                    }
5388    
5389                                    cacheResult(list);
5390    
5391                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5392                            }
5393                            catch (Exception e) {
5394                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5395    
5396                                    throw processException(e);
5397                            }
5398                            finally {
5399                                    closeSession(session);
5400                            }
5401                    }
5402    
5403                    return list;
5404            }
5405    
5406            /**
5407             * Returns the first journal article in the ordered set where smallImageId = &#63;.
5408             *
5409             * @param smallImageId the small image ID
5410             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5411             * @return the first matching journal article
5412             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
5413             * @throws SystemException if a system exception occurred
5414             */
5415            @Override
5416            public JournalArticle findBySmallImageId_First(long smallImageId,
5417                    OrderByComparator orderByComparator)
5418                    throws NoSuchArticleException, SystemException {
5419                    JournalArticle journalArticle = fetchBySmallImageId_First(smallImageId,
5420                                    orderByComparator);
5421    
5422                    if (journalArticle != null) {
5423                            return journalArticle;
5424                    }
5425    
5426                    StringBundler msg = new StringBundler(4);
5427    
5428                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5429    
5430                    msg.append("smallImageId=");
5431                    msg.append(smallImageId);
5432    
5433                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5434    
5435                    throw new NoSuchArticleException(msg.toString());
5436            }
5437    
5438            /**
5439             * Returns the first journal article in the ordered set where smallImageId = &#63;.
5440             *
5441             * @param smallImageId the small image ID
5442             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5443             * @return the first matching journal article, or <code>null</code> if a matching journal article could not be found
5444             * @throws SystemException if a system exception occurred
5445             */
5446            @Override
5447            public JournalArticle fetchBySmallImageId_First(long smallImageId,
5448                    OrderByComparator orderByComparator) throws SystemException {
5449                    List<JournalArticle> list = findBySmallImageId(smallImageId, 0, 1,
5450                                    orderByComparator);
5451    
5452                    if (!list.isEmpty()) {
5453                            return list.get(0);
5454                    }
5455    
5456                    return null;
5457            }
5458    
5459            /**
5460             * Returns the last journal article in the ordered set where smallImageId = &#63;.
5461             *
5462             * @param smallImageId the small image ID
5463             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5464             * @return the last matching journal article
5465             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
5466             * @throws SystemException if a system exception occurred
5467             */
5468            @Override
5469            public JournalArticle findBySmallImageId_Last(long smallImageId,
5470                    OrderByComparator orderByComparator)
5471                    throws NoSuchArticleException, SystemException {
5472                    JournalArticle journalArticle = fetchBySmallImageId_Last(smallImageId,
5473                                    orderByComparator);
5474    
5475                    if (journalArticle != null) {
5476                            return journalArticle;
5477                    }
5478    
5479                    StringBundler msg = new StringBundler(4);
5480    
5481                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5482    
5483                    msg.append("smallImageId=");
5484                    msg.append(smallImageId);
5485    
5486                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5487    
5488                    throw new NoSuchArticleException(msg.toString());
5489            }
5490    
5491            /**
5492             * Returns the last journal article in the ordered set where smallImageId = &#63;.
5493             *
5494             * @param smallImageId the small image ID
5495             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5496             * @return the last matching journal article, or <code>null</code> if a matching journal article could not be found
5497             * @throws SystemException if a system exception occurred
5498             */
5499            @Override
5500            public JournalArticle fetchBySmallImageId_Last(long smallImageId,
5501                    OrderByComparator orderByComparator) throws SystemException {
5502                    int count = countBySmallImageId(smallImageId);
5503    
5504                    if (count == 0) {
5505                            return null;
5506                    }
5507    
5508                    List<JournalArticle> list = findBySmallImageId(smallImageId, count - 1,
5509                                    count, orderByComparator);
5510    
5511                    if (!list.isEmpty()) {
5512                            return list.get(0);
5513                    }
5514    
5515                    return null;
5516            }
5517    
5518            /**
5519             * Returns the journal articles before and after the current journal article in the ordered set where smallImageId = &#63;.
5520             *
5521             * @param id the primary key of the current journal article
5522             * @param smallImageId the small image ID
5523             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5524             * @return the previous, current, and next journal article
5525             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
5526             * @throws SystemException if a system exception occurred
5527             */
5528            @Override
5529            public JournalArticle[] findBySmallImageId_PrevAndNext(long id,
5530                    long smallImageId, OrderByComparator orderByComparator)
5531                    throws NoSuchArticleException, SystemException {
5532                    JournalArticle journalArticle = findByPrimaryKey(id);
5533    
5534                    Session session = null;
5535    
5536                    try {
5537                            session = openSession();
5538    
5539                            JournalArticle[] array = new JournalArticleImpl[3];
5540    
5541                            array[0] = getBySmallImageId_PrevAndNext(session, journalArticle,
5542                                            smallImageId, orderByComparator, true);
5543    
5544                            array[1] = journalArticle;
5545    
5546                            array[2] = getBySmallImageId_PrevAndNext(session, journalArticle,
5547                                            smallImageId, orderByComparator, false);
5548    
5549                            return array;
5550                    }
5551                    catch (Exception e) {
5552                            throw processException(e);
5553                    }
5554                    finally {
5555                            closeSession(session);
5556                    }
5557            }
5558    
5559            protected JournalArticle getBySmallImageId_PrevAndNext(Session session,
5560                    JournalArticle journalArticle, long smallImageId,
5561                    OrderByComparator orderByComparator, boolean previous) {
5562                    StringBundler query = null;
5563    
5564                    if (orderByComparator != null) {
5565                            query = new StringBundler(6 +
5566                                            (orderByComparator.getOrderByFields().length * 6));
5567                    }
5568                    else {
5569                            query = new StringBundler(3);
5570                    }
5571    
5572                    query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
5573    
5574                    query.append(_FINDER_COLUMN_SMALLIMAGEID_SMALLIMAGEID_2);
5575    
5576                    if (orderByComparator != null) {
5577                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5578    
5579                            if (orderByConditionFields.length > 0) {
5580                                    query.append(WHERE_AND);
5581                            }
5582    
5583                            for (int i = 0; i < orderByConditionFields.length; i++) {
5584                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5585                                    query.append(orderByConditionFields[i]);
5586    
5587                                    if ((i + 1) < orderByConditionFields.length) {
5588                                            if (orderByComparator.isAscending() ^ previous) {
5589                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5590                                            }
5591                                            else {
5592                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5593                                            }
5594                                    }
5595                                    else {
5596                                            if (orderByComparator.isAscending() ^ previous) {
5597                                                    query.append(WHERE_GREATER_THAN);
5598                                            }
5599                                            else {
5600                                                    query.append(WHERE_LESSER_THAN);
5601                                            }
5602                                    }
5603                            }
5604    
5605                            query.append(ORDER_BY_CLAUSE);
5606    
5607                            String[] orderByFields = orderByComparator.getOrderByFields();
5608    
5609                            for (int i = 0; i < orderByFields.length; i++) {
5610                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5611                                    query.append(orderByFields[i]);
5612    
5613                                    if ((i + 1) < orderByFields.length) {
5614                                            if (orderByComparator.isAscending() ^ previous) {
5615                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5616                                            }
5617                                            else {
5618                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5619                                            }
5620                                    }
5621                                    else {
5622                                            if (orderByComparator.isAscending() ^ previous) {
5623                                                    query.append(ORDER_BY_ASC);
5624                                            }
5625                                            else {
5626                                                    query.append(ORDER_BY_DESC);
5627                                            }
5628                                    }
5629                            }
5630                    }
5631                    else {
5632                            query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
5633                    }
5634    
5635                    String sql = query.toString();
5636    
5637                    Query q = session.createQuery(sql);
5638    
5639                    q.setFirstResult(0);
5640                    q.setMaxResults(2);
5641    
5642                    QueryPos qPos = QueryPos.getInstance(q);
5643    
5644                    qPos.add(smallImageId);
5645    
5646                    if (orderByComparator != null) {
5647                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
5648    
5649                            for (Object value : values) {
5650                                    qPos.add(value);
5651                            }
5652                    }
5653    
5654                    List<JournalArticle> list = q.list();
5655    
5656                    if (list.size() == 2) {
5657                            return list.get(1);
5658                    }
5659                    else {
5660                            return null;
5661                    }
5662            }
5663    
5664            /**
5665             * Removes all the journal articles where smallImageId = &#63; from the database.
5666             *
5667             * @param smallImageId the small image ID
5668             * @throws SystemException if a system exception occurred
5669             */
5670            @Override
5671            public void removeBySmallImageId(long smallImageId)
5672                    throws SystemException {
5673                    for (JournalArticle journalArticle : findBySmallImageId(smallImageId,
5674                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5675                            remove(journalArticle);
5676                    }
5677            }
5678    
5679            /**
5680             * Returns the number of journal articles where smallImageId = &#63;.
5681             *
5682             * @param smallImageId the small image ID
5683             * @return the number of matching journal articles
5684             * @throws SystemException if a system exception occurred
5685             */
5686            @Override
5687            public int countBySmallImageId(long smallImageId) throws SystemException {
5688                    FinderPath finderPath = FINDER_PATH_COUNT_BY_SMALLIMAGEID;
5689    
5690                    Object[] finderArgs = new Object[] { smallImageId };
5691    
5692                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5693                                    this);
5694    
5695                    if (count == null) {
5696                            StringBundler query = new StringBundler(2);
5697    
5698                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
5699    
5700                            query.append(_FINDER_COLUMN_SMALLIMAGEID_SMALLIMAGEID_2);
5701    
5702                            String sql = query.toString();
5703    
5704                            Session session = null;
5705    
5706                            try {
5707                                    session = openSession();
5708    
5709                                    Query q = session.createQuery(sql);
5710    
5711                                    QueryPos qPos = QueryPos.getInstance(q);
5712    
5713                                    qPos.add(smallImageId);
5714    
5715                                    count = (Long)q.uniqueResult();
5716    
5717                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5718                            }
5719                            catch (Exception e) {
5720                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5721    
5722                                    throw processException(e);
5723                            }
5724                            finally {
5725                                    closeSession(session);
5726                            }
5727                    }
5728    
5729                    return count.intValue();
5730            }
5731    
5732            private static final String _FINDER_COLUMN_SMALLIMAGEID_SMALLIMAGEID_2 = "journalArticle.smallImageId = ?";
5733            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_R_I = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
5734                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
5735                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
5736                            "findByR_I",
5737                            new String[] {
5738                                    Long.class.getName(), Boolean.class.getName(),
5739                                    
5740                            Integer.class.getName(), Integer.class.getName(),
5741                                    OrderByComparator.class.getName()
5742                            });
5743            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_I = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
5744                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
5745                            JournalArticleImpl.class,
5746                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByR_I",
5747                            new String[] { Long.class.getName(), Boolean.class.getName() },
5748                            JournalArticleModelImpl.RESOURCEPRIMKEY_COLUMN_BITMASK |
5749                            JournalArticleModelImpl.INDEXABLE_COLUMN_BITMASK |
5750                            JournalArticleModelImpl.ARTICLEID_COLUMN_BITMASK |
5751                            JournalArticleModelImpl.VERSION_COLUMN_BITMASK);
5752            public static final FinderPath FINDER_PATH_COUNT_BY_R_I = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
5753                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
5754                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByR_I",
5755                            new String[] { Long.class.getName(), Boolean.class.getName() });
5756    
5757            /**
5758             * Returns all the journal articles where resourcePrimKey = &#63; and indexable = &#63;.
5759             *
5760             * @param resourcePrimKey the resource prim key
5761             * @param indexable the indexable
5762             * @return the matching journal articles
5763             * @throws SystemException if a system exception occurred
5764             */
5765            @Override
5766            public List<JournalArticle> findByR_I(long resourcePrimKey,
5767                    boolean indexable) throws SystemException {
5768                    return findByR_I(resourcePrimKey, indexable, QueryUtil.ALL_POS,
5769                            QueryUtil.ALL_POS, null);
5770            }
5771    
5772            /**
5773             * Returns a range of all the journal articles where resourcePrimKey = &#63; and indexable = &#63;.
5774             *
5775             * <p>
5776             * 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.
5777             * </p>
5778             *
5779             * @param resourcePrimKey the resource prim key
5780             * @param indexable the indexable
5781             * @param start the lower bound of the range of journal articles
5782             * @param end the upper bound of the range of journal articles (not inclusive)
5783             * @return the range of matching journal articles
5784             * @throws SystemException if a system exception occurred
5785             */
5786            @Override
5787            public List<JournalArticle> findByR_I(long resourcePrimKey,
5788                    boolean indexable, int start, int end) throws SystemException {
5789                    return findByR_I(resourcePrimKey, indexable, start, end, null);
5790            }
5791    
5792            /**
5793             * Returns an ordered range of all the journal articles where resourcePrimKey = &#63; and indexable = &#63;.
5794             *
5795             * <p>
5796             * 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.
5797             * </p>
5798             *
5799             * @param resourcePrimKey the resource prim key
5800             * @param indexable the indexable
5801             * @param start the lower bound of the range of journal articles
5802             * @param end the upper bound of the range of journal articles (not inclusive)
5803             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5804             * @return the ordered range of matching journal articles
5805             * @throws SystemException if a system exception occurred
5806             */
5807            @Override
5808            public List<JournalArticle> findByR_I(long resourcePrimKey,
5809                    boolean indexable, int start, int end,
5810                    OrderByComparator orderByComparator) throws SystemException {
5811                    boolean pagination = true;
5812                    FinderPath finderPath = null;
5813                    Object[] finderArgs = null;
5814    
5815                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5816                                    (orderByComparator == null)) {
5817                            pagination = false;
5818                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_I;
5819                            finderArgs = new Object[] { resourcePrimKey, indexable };
5820                    }
5821                    else {
5822                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_R_I;
5823                            finderArgs = new Object[] {
5824                                            resourcePrimKey, indexable,
5825                                            
5826                                            start, end, orderByComparator
5827                                    };
5828                    }
5829    
5830                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
5831                                    finderArgs, this);
5832    
5833                    if ((list != null) && !list.isEmpty()) {
5834                            for (JournalArticle journalArticle : list) {
5835                                    if ((resourcePrimKey != journalArticle.getResourcePrimKey()) ||
5836                                                    (indexable != journalArticle.getIndexable())) {
5837                                            list = null;
5838    
5839                                            break;
5840                                    }
5841                            }
5842                    }
5843    
5844                    if (list == null) {
5845                            StringBundler query = null;
5846    
5847                            if (orderByComparator != null) {
5848                                    query = new StringBundler(4 +
5849                                                    (orderByComparator.getOrderByFields().length * 3));
5850                            }
5851                            else {
5852                                    query = new StringBundler(4);
5853                            }
5854    
5855                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
5856    
5857                            query.append(_FINDER_COLUMN_R_I_RESOURCEPRIMKEY_2);
5858    
5859                            query.append(_FINDER_COLUMN_R_I_INDEXABLE_2);
5860    
5861                            if (orderByComparator != null) {
5862                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5863                                            orderByComparator);
5864                            }
5865                            else
5866                             if (pagination) {
5867                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
5868                            }
5869    
5870                            String sql = query.toString();
5871    
5872                            Session session = null;
5873    
5874                            try {
5875                                    session = openSession();
5876    
5877                                    Query q = session.createQuery(sql);
5878    
5879                                    QueryPos qPos = QueryPos.getInstance(q);
5880    
5881                                    qPos.add(resourcePrimKey);
5882    
5883                                    qPos.add(indexable);
5884    
5885                                    if (!pagination) {
5886                                            list = (List<JournalArticle>)QueryUtil.list(q,
5887                                                            getDialect(), start, end, false);
5888    
5889                                            Collections.sort(list);
5890    
5891                                            list = new UnmodifiableList<JournalArticle>(list);
5892                                    }
5893                                    else {
5894                                            list = (List<JournalArticle>)QueryUtil.list(q,
5895                                                            getDialect(), start, end);
5896                                    }
5897    
5898                                    cacheResult(list);
5899    
5900                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5901                            }
5902                            catch (Exception e) {
5903                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5904    
5905                                    throw processException(e);
5906                            }
5907                            finally {
5908                                    closeSession(session);
5909                            }
5910                    }
5911    
5912                    return list;
5913            }
5914    
5915            /**
5916             * Returns the first journal article in the ordered set where resourcePrimKey = &#63; and indexable = &#63;.
5917             *
5918             * @param resourcePrimKey the resource prim key
5919             * @param indexable the indexable
5920             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5921             * @return the first matching journal article
5922             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
5923             * @throws SystemException if a system exception occurred
5924             */
5925            @Override
5926            public JournalArticle findByR_I_First(long resourcePrimKey,
5927                    boolean indexable, OrderByComparator orderByComparator)
5928                    throws NoSuchArticleException, SystemException {
5929                    JournalArticle journalArticle = fetchByR_I_First(resourcePrimKey,
5930                                    indexable, orderByComparator);
5931    
5932                    if (journalArticle != null) {
5933                            return journalArticle;
5934                    }
5935    
5936                    StringBundler msg = new StringBundler(6);
5937    
5938                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5939    
5940                    msg.append("resourcePrimKey=");
5941                    msg.append(resourcePrimKey);
5942    
5943                    msg.append(", indexable=");
5944                    msg.append(indexable);
5945    
5946                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5947    
5948                    throw new NoSuchArticleException(msg.toString());
5949            }
5950    
5951            /**
5952             * Returns the first journal article in the ordered set where resourcePrimKey = &#63; and indexable = &#63;.
5953             *
5954             * @param resourcePrimKey the resource prim key
5955             * @param indexable the indexable
5956             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5957             * @return the first matching journal article, or <code>null</code> if a matching journal article could not be found
5958             * @throws SystemException if a system exception occurred
5959             */
5960            @Override
5961            public JournalArticle fetchByR_I_First(long resourcePrimKey,
5962                    boolean indexable, OrderByComparator orderByComparator)
5963                    throws SystemException {
5964                    List<JournalArticle> list = findByR_I(resourcePrimKey, indexable, 0, 1,
5965                                    orderByComparator);
5966    
5967                    if (!list.isEmpty()) {
5968                            return list.get(0);
5969                    }
5970    
5971                    return null;
5972            }
5973    
5974            /**
5975             * Returns the last journal article in the ordered set where resourcePrimKey = &#63; and indexable = &#63;.
5976             *
5977             * @param resourcePrimKey the resource prim key
5978             * @param indexable the indexable
5979             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5980             * @return the last matching journal article
5981             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
5982             * @throws SystemException if a system exception occurred
5983             */
5984            @Override
5985            public JournalArticle findByR_I_Last(long resourcePrimKey,
5986                    boolean indexable, OrderByComparator orderByComparator)
5987                    throws NoSuchArticleException, SystemException {
5988                    JournalArticle journalArticle = fetchByR_I_Last(resourcePrimKey,
5989                                    indexable, orderByComparator);
5990    
5991                    if (journalArticle != null) {
5992                            return journalArticle;
5993                    }
5994    
5995                    StringBundler msg = new StringBundler(6);
5996    
5997                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5998    
5999                    msg.append("resourcePrimKey=");
6000                    msg.append(resourcePrimKey);
6001    
6002                    msg.append(", indexable=");
6003                    msg.append(indexable);
6004    
6005                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6006    
6007                    throw new NoSuchArticleException(msg.toString());
6008            }
6009    
6010            /**
6011             * Returns the last journal article in the ordered set where resourcePrimKey = &#63; and indexable = &#63;.
6012             *
6013             * @param resourcePrimKey the resource prim key
6014             * @param indexable the indexable
6015             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6016             * @return the last matching journal article, or <code>null</code> if a matching journal article could not be found
6017             * @throws SystemException if a system exception occurred
6018             */
6019            @Override
6020            public JournalArticle fetchByR_I_Last(long resourcePrimKey,
6021                    boolean indexable, OrderByComparator orderByComparator)
6022                    throws SystemException {
6023                    int count = countByR_I(resourcePrimKey, indexable);
6024    
6025                    if (count == 0) {
6026                            return null;
6027                    }
6028    
6029                    List<JournalArticle> list = findByR_I(resourcePrimKey, indexable,
6030                                    count - 1, count, orderByComparator);
6031    
6032                    if (!list.isEmpty()) {
6033                            return list.get(0);
6034                    }
6035    
6036                    return null;
6037            }
6038    
6039            /**
6040             * Returns the journal articles before and after the current journal article in the ordered set where resourcePrimKey = &#63; and indexable = &#63;.
6041             *
6042             * @param id the primary key of the current journal article
6043             * @param resourcePrimKey the resource prim key
6044             * @param indexable the indexable
6045             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6046             * @return the previous, current, and next journal article
6047             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
6048             * @throws SystemException if a system exception occurred
6049             */
6050            @Override
6051            public JournalArticle[] findByR_I_PrevAndNext(long id,
6052                    long resourcePrimKey, boolean indexable,
6053                    OrderByComparator orderByComparator)
6054                    throws NoSuchArticleException, SystemException {
6055                    JournalArticle journalArticle = findByPrimaryKey(id);
6056    
6057                    Session session = null;
6058    
6059                    try {
6060                            session = openSession();
6061    
6062                            JournalArticle[] array = new JournalArticleImpl[3];
6063    
6064                            array[0] = getByR_I_PrevAndNext(session, journalArticle,
6065                                            resourcePrimKey, indexable, orderByComparator, true);
6066    
6067                            array[1] = journalArticle;
6068    
6069                            array[2] = getByR_I_PrevAndNext(session, journalArticle,
6070                                            resourcePrimKey, indexable, orderByComparator, false);
6071    
6072                            return array;
6073                    }
6074                    catch (Exception e) {
6075                            throw processException(e);
6076                    }
6077                    finally {
6078                            closeSession(session);
6079                    }
6080            }
6081    
6082            protected JournalArticle getByR_I_PrevAndNext(Session session,
6083                    JournalArticle journalArticle, long resourcePrimKey, boolean indexable,
6084                    OrderByComparator orderByComparator, boolean previous) {
6085                    StringBundler query = null;
6086    
6087                    if (orderByComparator != null) {
6088                            query = new StringBundler(6 +
6089                                            (orderByComparator.getOrderByFields().length * 6));
6090                    }
6091                    else {
6092                            query = new StringBundler(3);
6093                    }
6094    
6095                    query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
6096    
6097                    query.append(_FINDER_COLUMN_R_I_RESOURCEPRIMKEY_2);
6098    
6099                    query.append(_FINDER_COLUMN_R_I_INDEXABLE_2);
6100    
6101                    if (orderByComparator != null) {
6102                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6103    
6104                            if (orderByConditionFields.length > 0) {
6105                                    query.append(WHERE_AND);
6106                            }
6107    
6108                            for (int i = 0; i < orderByConditionFields.length; i++) {
6109                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6110                                    query.append(orderByConditionFields[i]);
6111    
6112                                    if ((i + 1) < orderByConditionFields.length) {
6113                                            if (orderByComparator.isAscending() ^ previous) {
6114                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6115                                            }
6116                                            else {
6117                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6118                                            }
6119                                    }
6120                                    else {
6121                                            if (orderByComparator.isAscending() ^ previous) {
6122                                                    query.append(WHERE_GREATER_THAN);
6123                                            }
6124                                            else {
6125                                                    query.append(WHERE_LESSER_THAN);
6126                                            }
6127                                    }
6128                            }
6129    
6130                            query.append(ORDER_BY_CLAUSE);
6131    
6132                            String[] orderByFields = orderByComparator.getOrderByFields();
6133    
6134                            for (int i = 0; i < orderByFields.length; i++) {
6135                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6136                                    query.append(orderByFields[i]);
6137    
6138                                    if ((i + 1) < orderByFields.length) {
6139                                            if (orderByComparator.isAscending() ^ previous) {
6140                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6141                                            }
6142                                            else {
6143                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6144                                            }
6145                                    }
6146                                    else {
6147                                            if (orderByComparator.isAscending() ^ previous) {
6148                                                    query.append(ORDER_BY_ASC);
6149                                            }
6150                                            else {
6151                                                    query.append(ORDER_BY_DESC);
6152                                            }
6153                                    }
6154                            }
6155                    }
6156                    else {
6157                            query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
6158                    }
6159    
6160                    String sql = query.toString();
6161    
6162                    Query q = session.createQuery(sql);
6163    
6164                    q.setFirstResult(0);
6165                    q.setMaxResults(2);
6166    
6167                    QueryPos qPos = QueryPos.getInstance(q);
6168    
6169                    qPos.add(resourcePrimKey);
6170    
6171                    qPos.add(indexable);
6172    
6173                    if (orderByComparator != null) {
6174                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
6175    
6176                            for (Object value : values) {
6177                                    qPos.add(value);
6178                            }
6179                    }
6180    
6181                    List<JournalArticle> list = q.list();
6182    
6183                    if (list.size() == 2) {
6184                            return list.get(1);
6185                    }
6186                    else {
6187                            return null;
6188                    }
6189            }
6190    
6191            /**
6192             * Removes all the journal articles where resourcePrimKey = &#63; and indexable = &#63; from the database.
6193             *
6194             * @param resourcePrimKey the resource prim key
6195             * @param indexable the indexable
6196             * @throws SystemException if a system exception occurred
6197             */
6198            @Override
6199            public void removeByR_I(long resourcePrimKey, boolean indexable)
6200                    throws SystemException {
6201                    for (JournalArticle journalArticle : findByR_I(resourcePrimKey,
6202                                    indexable, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6203                            remove(journalArticle);
6204                    }
6205            }
6206    
6207            /**
6208             * Returns the number of journal articles where resourcePrimKey = &#63; and indexable = &#63;.
6209             *
6210             * @param resourcePrimKey the resource prim key
6211             * @param indexable the indexable
6212             * @return the number of matching journal articles
6213             * @throws SystemException if a system exception occurred
6214             */
6215            @Override
6216            public int countByR_I(long resourcePrimKey, boolean indexable)
6217                    throws SystemException {
6218                    FinderPath finderPath = FINDER_PATH_COUNT_BY_R_I;
6219    
6220                    Object[] finderArgs = new Object[] { resourcePrimKey, indexable };
6221    
6222                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6223                                    this);
6224    
6225                    if (count == null) {
6226                            StringBundler query = new StringBundler(3);
6227    
6228                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
6229    
6230                            query.append(_FINDER_COLUMN_R_I_RESOURCEPRIMKEY_2);
6231    
6232                            query.append(_FINDER_COLUMN_R_I_INDEXABLE_2);
6233    
6234                            String sql = query.toString();
6235    
6236                            Session session = null;
6237    
6238                            try {
6239                                    session = openSession();
6240    
6241                                    Query q = session.createQuery(sql);
6242    
6243                                    QueryPos qPos = QueryPos.getInstance(q);
6244    
6245                                    qPos.add(resourcePrimKey);
6246    
6247                                    qPos.add(indexable);
6248    
6249                                    count = (Long)q.uniqueResult();
6250    
6251                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
6252                            }
6253                            catch (Exception e) {
6254                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6255    
6256                                    throw processException(e);
6257                            }
6258                            finally {
6259                                    closeSession(session);
6260                            }
6261                    }
6262    
6263                    return count.intValue();
6264            }
6265    
6266            private static final String _FINDER_COLUMN_R_I_RESOURCEPRIMKEY_2 = "journalArticle.resourcePrimKey = ? AND ";
6267            private static final String _FINDER_COLUMN_R_I_INDEXABLE_2 = "journalArticle.indexable = ?";
6268            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_R_ST = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
6269                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
6270                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
6271                            "findByR_ST",
6272                            new String[] {
6273                                    Long.class.getName(), Integer.class.getName(),
6274                                    
6275                            Integer.class.getName(), Integer.class.getName(),
6276                                    OrderByComparator.class.getName()
6277                            });
6278            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_ST = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
6279                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
6280                            JournalArticleImpl.class,
6281                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByR_ST",
6282                            new String[] { Long.class.getName(), Integer.class.getName() },
6283                            JournalArticleModelImpl.RESOURCEPRIMKEY_COLUMN_BITMASK |
6284                            JournalArticleModelImpl.STATUS_COLUMN_BITMASK |
6285                            JournalArticleModelImpl.ARTICLEID_COLUMN_BITMASK |
6286                            JournalArticleModelImpl.VERSION_COLUMN_BITMASK);
6287            public static final FinderPath FINDER_PATH_COUNT_BY_R_ST = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
6288                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
6289                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByR_ST",
6290                            new String[] { Long.class.getName(), Integer.class.getName() });
6291            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_R_ST = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
6292                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
6293                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByR_ST",
6294                            new String[] { Long.class.getName(), Integer.class.getName() });
6295    
6296            /**
6297             * Returns all the journal articles where resourcePrimKey = &#63; and status = &#63;.
6298             *
6299             * @param resourcePrimKey the resource prim key
6300             * @param status the status
6301             * @return the matching journal articles
6302             * @throws SystemException if a system exception occurred
6303             */
6304            @Override
6305            public List<JournalArticle> findByR_ST(long resourcePrimKey, int status)
6306                    throws SystemException {
6307                    return findByR_ST(resourcePrimKey, status, QueryUtil.ALL_POS,
6308                            QueryUtil.ALL_POS, null);
6309            }
6310    
6311            /**
6312             * Returns a range of all the journal articles where resourcePrimKey = &#63; and status = &#63;.
6313             *
6314             * <p>
6315             * 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.
6316             * </p>
6317             *
6318             * @param resourcePrimKey the resource prim key
6319             * @param status the status
6320             * @param start the lower bound of the range of journal articles
6321             * @param end the upper bound of the range of journal articles (not inclusive)
6322             * @return the range of matching journal articles
6323             * @throws SystemException if a system exception occurred
6324             */
6325            @Override
6326            public List<JournalArticle> findByR_ST(long resourcePrimKey, int status,
6327                    int start, int end) throws SystemException {
6328                    return findByR_ST(resourcePrimKey, status, start, end, null);
6329            }
6330    
6331            /**
6332             * Returns an ordered range of all the journal articles where resourcePrimKey = &#63; and status = &#63;.
6333             *
6334             * <p>
6335             * 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.
6336             * </p>
6337             *
6338             * @param resourcePrimKey the resource prim key
6339             * @param status the status
6340             * @param start the lower bound of the range of journal articles
6341             * @param end the upper bound of the range of journal articles (not inclusive)
6342             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6343             * @return the ordered range of matching journal articles
6344             * @throws SystemException if a system exception occurred
6345             */
6346            @Override
6347            public List<JournalArticle> findByR_ST(long resourcePrimKey, int status,
6348                    int start, int end, OrderByComparator orderByComparator)
6349                    throws SystemException {
6350                    boolean pagination = true;
6351                    FinderPath finderPath = null;
6352                    Object[] finderArgs = null;
6353    
6354                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6355                                    (orderByComparator == null)) {
6356                            pagination = false;
6357                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_ST;
6358                            finderArgs = new Object[] { resourcePrimKey, status };
6359                    }
6360                    else {
6361                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_R_ST;
6362                            finderArgs = new Object[] {
6363                                            resourcePrimKey, status,
6364                                            
6365                                            start, end, orderByComparator
6366                                    };
6367                    }
6368    
6369                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
6370                                    finderArgs, this);
6371    
6372                    if ((list != null) && !list.isEmpty()) {
6373                            for (JournalArticle journalArticle : list) {
6374                                    if ((resourcePrimKey != journalArticle.getResourcePrimKey()) ||
6375                                                    (status != journalArticle.getStatus())) {
6376                                            list = null;
6377    
6378                                            break;
6379                                    }
6380                            }
6381                    }
6382    
6383                    if (list == null) {
6384                            StringBundler query = null;
6385    
6386                            if (orderByComparator != null) {
6387                                    query = new StringBundler(4 +
6388                                                    (orderByComparator.getOrderByFields().length * 3));
6389                            }
6390                            else {
6391                                    query = new StringBundler(4);
6392                            }
6393    
6394                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
6395    
6396                            query.append(_FINDER_COLUMN_R_ST_RESOURCEPRIMKEY_2);
6397    
6398                            query.append(_FINDER_COLUMN_R_ST_STATUS_2);
6399    
6400                            if (orderByComparator != null) {
6401                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6402                                            orderByComparator);
6403                            }
6404                            else
6405                             if (pagination) {
6406                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
6407                            }
6408    
6409                            String sql = query.toString();
6410    
6411                            Session session = null;
6412    
6413                            try {
6414                                    session = openSession();
6415    
6416                                    Query q = session.createQuery(sql);
6417    
6418                                    QueryPos qPos = QueryPos.getInstance(q);
6419    
6420                                    qPos.add(resourcePrimKey);
6421    
6422                                    qPos.add(status);
6423    
6424                                    if (!pagination) {
6425                                            list = (List<JournalArticle>)QueryUtil.list(q,
6426                                                            getDialect(), start, end, false);
6427    
6428                                            Collections.sort(list);
6429    
6430                                            list = new UnmodifiableList<JournalArticle>(list);
6431                                    }
6432                                    else {
6433                                            list = (List<JournalArticle>)QueryUtil.list(q,
6434                                                            getDialect(), start, end);
6435                                    }
6436    
6437                                    cacheResult(list);
6438    
6439                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
6440                            }
6441                            catch (Exception e) {
6442                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6443    
6444                                    throw processException(e);
6445                            }
6446                            finally {
6447                                    closeSession(session);
6448                            }
6449                    }
6450    
6451                    return list;
6452            }
6453    
6454            /**
6455             * Returns the first journal article in the ordered set where resourcePrimKey = &#63; and status = &#63;.
6456             *
6457             * @param resourcePrimKey the resource prim key
6458             * @param status the status
6459             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6460             * @return the first matching journal article
6461             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
6462             * @throws SystemException if a system exception occurred
6463             */
6464            @Override
6465            public JournalArticle findByR_ST_First(long resourcePrimKey, int status,
6466                    OrderByComparator orderByComparator)
6467                    throws NoSuchArticleException, SystemException {
6468                    JournalArticle journalArticle = fetchByR_ST_First(resourcePrimKey,
6469                                    status, orderByComparator);
6470    
6471                    if (journalArticle != null) {
6472                            return journalArticle;
6473                    }
6474    
6475                    StringBundler msg = new StringBundler(6);
6476    
6477                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6478    
6479                    msg.append("resourcePrimKey=");
6480                    msg.append(resourcePrimKey);
6481    
6482                    msg.append(", status=");
6483                    msg.append(status);
6484    
6485                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6486    
6487                    throw new NoSuchArticleException(msg.toString());
6488            }
6489    
6490            /**
6491             * Returns the first journal article in the ordered set where resourcePrimKey = &#63; and status = &#63;.
6492             *
6493             * @param resourcePrimKey the resource prim key
6494             * @param status the status
6495             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6496             * @return the first matching journal article, or <code>null</code> if a matching journal article could not be found
6497             * @throws SystemException if a system exception occurred
6498             */
6499            @Override
6500            public JournalArticle fetchByR_ST_First(long resourcePrimKey, int status,
6501                    OrderByComparator orderByComparator) throws SystemException {
6502                    List<JournalArticle> list = findByR_ST(resourcePrimKey, status, 0, 1,
6503                                    orderByComparator);
6504    
6505                    if (!list.isEmpty()) {
6506                            return list.get(0);
6507                    }
6508    
6509                    return null;
6510            }
6511    
6512            /**
6513             * Returns the last journal article in the ordered set where resourcePrimKey = &#63; and status = &#63;.
6514             *
6515             * @param resourcePrimKey the resource prim key
6516             * @param status the status
6517             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6518             * @return the last matching journal article
6519             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
6520             * @throws SystemException if a system exception occurred
6521             */
6522            @Override
6523            public JournalArticle findByR_ST_Last(long resourcePrimKey, int status,
6524                    OrderByComparator orderByComparator)
6525                    throws NoSuchArticleException, SystemException {
6526                    JournalArticle journalArticle = fetchByR_ST_Last(resourcePrimKey,
6527                                    status, orderByComparator);
6528    
6529                    if (journalArticle != null) {
6530                            return journalArticle;
6531                    }
6532    
6533                    StringBundler msg = new StringBundler(6);
6534    
6535                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6536    
6537                    msg.append("resourcePrimKey=");
6538                    msg.append(resourcePrimKey);
6539    
6540                    msg.append(", status=");
6541                    msg.append(status);
6542    
6543                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6544    
6545                    throw new NoSuchArticleException(msg.toString());
6546            }
6547    
6548            /**
6549             * Returns the last journal article in the ordered set where resourcePrimKey = &#63; and status = &#63;.
6550             *
6551             * @param resourcePrimKey the resource prim key
6552             * @param status the status
6553             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6554             * @return the last matching journal article, or <code>null</code> if a matching journal article could not be found
6555             * @throws SystemException if a system exception occurred
6556             */
6557            @Override
6558            public JournalArticle fetchByR_ST_Last(long resourcePrimKey, int status,
6559                    OrderByComparator orderByComparator) throws SystemException {
6560                    int count = countByR_ST(resourcePrimKey, status);
6561    
6562                    if (count == 0) {
6563                            return null;
6564                    }
6565    
6566                    List<JournalArticle> list = findByR_ST(resourcePrimKey, status,
6567                                    count - 1, count, orderByComparator);
6568    
6569                    if (!list.isEmpty()) {
6570                            return list.get(0);
6571                    }
6572    
6573                    return null;
6574            }
6575    
6576            /**
6577             * Returns the journal articles before and after the current journal article in the ordered set where resourcePrimKey = &#63; and status = &#63;.
6578             *
6579             * @param id the primary key of the current journal article
6580             * @param resourcePrimKey the resource prim key
6581             * @param status the status
6582             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6583             * @return the previous, current, and next journal article
6584             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
6585             * @throws SystemException if a system exception occurred
6586             */
6587            @Override
6588            public JournalArticle[] findByR_ST_PrevAndNext(long id,
6589                    long resourcePrimKey, int status, OrderByComparator orderByComparator)
6590                    throws NoSuchArticleException, SystemException {
6591                    JournalArticle journalArticle = findByPrimaryKey(id);
6592    
6593                    Session session = null;
6594    
6595                    try {
6596                            session = openSession();
6597    
6598                            JournalArticle[] array = new JournalArticleImpl[3];
6599    
6600                            array[0] = getByR_ST_PrevAndNext(session, journalArticle,
6601                                            resourcePrimKey, status, orderByComparator, true);
6602    
6603                            array[1] = journalArticle;
6604    
6605                            array[2] = getByR_ST_PrevAndNext(session, journalArticle,
6606                                            resourcePrimKey, status, orderByComparator, false);
6607    
6608                            return array;
6609                    }
6610                    catch (Exception e) {
6611                            throw processException(e);
6612                    }
6613                    finally {
6614                            closeSession(session);
6615                    }
6616            }
6617    
6618            protected JournalArticle getByR_ST_PrevAndNext(Session session,
6619                    JournalArticle journalArticle, long resourcePrimKey, int status,
6620                    OrderByComparator orderByComparator, boolean previous) {
6621                    StringBundler query = null;
6622    
6623                    if (orderByComparator != null) {
6624                            query = new StringBundler(6 +
6625                                            (orderByComparator.getOrderByFields().length * 6));
6626                    }
6627                    else {
6628                            query = new StringBundler(3);
6629                    }
6630    
6631                    query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
6632    
6633                    query.append(_FINDER_COLUMN_R_ST_RESOURCEPRIMKEY_2);
6634    
6635                    query.append(_FINDER_COLUMN_R_ST_STATUS_2);
6636    
6637                    if (orderByComparator != null) {
6638                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6639    
6640                            if (orderByConditionFields.length > 0) {
6641                                    query.append(WHERE_AND);
6642                            }
6643    
6644                            for (int i = 0; i < orderByConditionFields.length; i++) {
6645                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6646                                    query.append(orderByConditionFields[i]);
6647    
6648                                    if ((i + 1) < orderByConditionFields.length) {
6649                                            if (orderByComparator.isAscending() ^ previous) {
6650                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6651                                            }
6652                                            else {
6653                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6654                                            }
6655                                    }
6656                                    else {
6657                                            if (orderByComparator.isAscending() ^ previous) {
6658                                                    query.append(WHERE_GREATER_THAN);
6659                                            }
6660                                            else {
6661                                                    query.append(WHERE_LESSER_THAN);
6662                                            }
6663                                    }
6664                            }
6665    
6666                            query.append(ORDER_BY_CLAUSE);
6667    
6668                            String[] orderByFields = orderByComparator.getOrderByFields();
6669    
6670                            for (int i = 0; i < orderByFields.length; i++) {
6671                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6672                                    query.append(orderByFields[i]);
6673    
6674                                    if ((i + 1) < orderByFields.length) {
6675                                            if (orderByComparator.isAscending() ^ previous) {
6676                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6677                                            }
6678                                            else {
6679                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6680                                            }
6681                                    }
6682                                    else {
6683                                            if (orderByComparator.isAscending() ^ previous) {
6684                                                    query.append(ORDER_BY_ASC);
6685                                            }
6686                                            else {
6687                                                    query.append(ORDER_BY_DESC);
6688                                            }
6689                                    }
6690                            }
6691                    }
6692                    else {
6693                            query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
6694                    }
6695    
6696                    String sql = query.toString();
6697    
6698                    Query q = session.createQuery(sql);
6699    
6700                    q.setFirstResult(0);
6701                    q.setMaxResults(2);
6702    
6703                    QueryPos qPos = QueryPos.getInstance(q);
6704    
6705                    qPos.add(resourcePrimKey);
6706    
6707                    qPos.add(status);
6708    
6709                    if (orderByComparator != null) {
6710                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
6711    
6712                            for (Object value : values) {
6713                                    qPos.add(value);
6714                            }
6715                    }
6716    
6717                    List<JournalArticle> list = q.list();
6718    
6719                    if (list.size() == 2) {
6720                            return list.get(1);
6721                    }
6722                    else {
6723                            return null;
6724                    }
6725            }
6726    
6727            /**
6728             * Returns all the journal articles where resourcePrimKey = &#63; and status = any &#63;.
6729             *
6730             * <p>
6731             * 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.
6732             * </p>
6733             *
6734             * @param resourcePrimKey the resource prim key
6735             * @param statuses the statuses
6736             * @return the matching journal articles
6737             * @throws SystemException if a system exception occurred
6738             */
6739            @Override
6740            public List<JournalArticle> findByR_ST(long resourcePrimKey, int[] statuses)
6741                    throws SystemException {
6742                    return findByR_ST(resourcePrimKey, statuses, QueryUtil.ALL_POS,
6743                            QueryUtil.ALL_POS, null);
6744            }
6745    
6746            /**
6747             * Returns a range of all the journal articles where resourcePrimKey = &#63; and status = any &#63;.
6748             *
6749             * <p>
6750             * 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.
6751             * </p>
6752             *
6753             * @param resourcePrimKey the resource prim key
6754             * @param statuses the statuses
6755             * @param start the lower bound of the range of journal articles
6756             * @param end the upper bound of the range of journal articles (not inclusive)
6757             * @return the range of matching journal articles
6758             * @throws SystemException if a system exception occurred
6759             */
6760            @Override
6761            public List<JournalArticle> findByR_ST(long resourcePrimKey,
6762                    int[] statuses, int start, int end) throws SystemException {
6763                    return findByR_ST(resourcePrimKey, statuses, start, end, null);
6764            }
6765    
6766            /**
6767             * Returns an ordered range of all the journal articles where resourcePrimKey = &#63; and status = any &#63;.
6768             *
6769             * <p>
6770             * 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.
6771             * </p>
6772             *
6773             * @param resourcePrimKey the resource prim key
6774             * @param statuses the statuses
6775             * @param start the lower bound of the range of journal articles
6776             * @param end the upper bound of the range of journal articles (not inclusive)
6777             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6778             * @return the ordered range of matching journal articles
6779             * @throws SystemException if a system exception occurred
6780             */
6781            @Override
6782            public List<JournalArticle> findByR_ST(long resourcePrimKey,
6783                    int[] statuses, int start, int end, OrderByComparator orderByComparator)
6784                    throws SystemException {
6785                    if ((statuses != null) && (statuses.length == 1)) {
6786                            return findByR_ST(resourcePrimKey, statuses[0], start, end,
6787                                    orderByComparator);
6788                    }
6789    
6790                    boolean pagination = true;
6791                    Object[] finderArgs = null;
6792    
6793                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6794                                    (orderByComparator == null)) {
6795                            pagination = false;
6796                            finderArgs = new Object[] {
6797                                            resourcePrimKey, StringUtil.merge(statuses)
6798                                    };
6799                    }
6800                    else {
6801                            finderArgs = new Object[] {
6802                                            resourcePrimKey, StringUtil.merge(statuses),
6803                                            
6804                                            start, end, orderByComparator
6805                                    };
6806                    }
6807    
6808                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_R_ST,
6809                                    finderArgs, this);
6810    
6811                    if ((list != null) && !list.isEmpty()) {
6812                            for (JournalArticle journalArticle : list) {
6813                                    if ((resourcePrimKey != journalArticle.getResourcePrimKey()) ||
6814                                                    !ArrayUtil.contains(statuses, journalArticle.getStatus())) {
6815                                            list = null;
6816    
6817                                            break;
6818                                    }
6819                            }
6820                    }
6821    
6822                    if (list == null) {
6823                            StringBundler query = new StringBundler();
6824    
6825                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
6826    
6827                            boolean conjunctionable = false;
6828    
6829                            if (conjunctionable) {
6830                                    query.append(WHERE_AND);
6831                            }
6832    
6833                            query.append(_FINDER_COLUMN_R_ST_RESOURCEPRIMKEY_5);
6834    
6835                            conjunctionable = true;
6836    
6837                            if ((statuses == null) || (statuses.length > 0)) {
6838                                    if (conjunctionable) {
6839                                            query.append(WHERE_AND);
6840                                    }
6841    
6842                                    query.append(StringPool.OPEN_PARENTHESIS);
6843    
6844                                    for (int i = 0; i < statuses.length; i++) {
6845                                            query.append(_FINDER_COLUMN_R_ST_STATUS_5);
6846    
6847                                            if ((i + 1) < statuses.length) {
6848                                                    query.append(WHERE_OR);
6849                                            }
6850                                    }
6851    
6852                                    query.append(StringPool.CLOSE_PARENTHESIS);
6853    
6854                                    conjunctionable = true;
6855                            }
6856    
6857                            if (orderByComparator != null) {
6858                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6859                                            orderByComparator);
6860                            }
6861                            else
6862                             if (pagination) {
6863                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
6864                            }
6865    
6866                            String sql = query.toString();
6867    
6868                            Session session = null;
6869    
6870                            try {
6871                                    session = openSession();
6872    
6873                                    Query q = session.createQuery(sql);
6874    
6875                                    QueryPos qPos = QueryPos.getInstance(q);
6876    
6877                                    qPos.add(resourcePrimKey);
6878    
6879                                    if (statuses != null) {
6880                                            qPos.add(statuses);
6881                                    }
6882    
6883                                    if (!pagination) {
6884                                            list = (List<JournalArticle>)QueryUtil.list(q,
6885                                                            getDialect(), start, end, false);
6886    
6887                                            Collections.sort(list);
6888    
6889                                            list = new UnmodifiableList<JournalArticle>(list);
6890                                    }
6891                                    else {
6892                                            list = (List<JournalArticle>)QueryUtil.list(q,
6893                                                            getDialect(), start, end);
6894                                    }
6895    
6896                                    cacheResult(list);
6897    
6898                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_R_ST,
6899                                            finderArgs, list);
6900                            }
6901                            catch (Exception e) {
6902                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_R_ST,
6903                                            finderArgs);
6904    
6905                                    throw processException(e);
6906                            }
6907                            finally {
6908                                    closeSession(session);
6909                            }
6910                    }
6911    
6912                    return list;
6913            }
6914    
6915            /**
6916             * Removes all the journal articles where resourcePrimKey = &#63; and status = &#63; from the database.
6917             *
6918             * @param resourcePrimKey the resource prim key
6919             * @param status the status
6920             * @throws SystemException if a system exception occurred
6921             */
6922            @Override
6923            public void removeByR_ST(long resourcePrimKey, int status)
6924                    throws SystemException {
6925                    for (JournalArticle journalArticle : findByR_ST(resourcePrimKey,
6926                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6927                            remove(journalArticle);
6928                    }
6929            }
6930    
6931            /**
6932             * Returns the number of journal articles where resourcePrimKey = &#63; and status = &#63;.
6933             *
6934             * @param resourcePrimKey the resource prim key
6935             * @param status the status
6936             * @return the number of matching journal articles
6937             * @throws SystemException if a system exception occurred
6938             */
6939            @Override
6940            public int countByR_ST(long resourcePrimKey, int status)
6941                    throws SystemException {
6942                    FinderPath finderPath = FINDER_PATH_COUNT_BY_R_ST;
6943    
6944                    Object[] finderArgs = new Object[] { resourcePrimKey, status };
6945    
6946                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6947                                    this);
6948    
6949                    if (count == null) {
6950                            StringBundler query = new StringBundler(3);
6951    
6952                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
6953    
6954                            query.append(_FINDER_COLUMN_R_ST_RESOURCEPRIMKEY_2);
6955    
6956                            query.append(_FINDER_COLUMN_R_ST_STATUS_2);
6957    
6958                            String sql = query.toString();
6959    
6960                            Session session = null;
6961    
6962                            try {
6963                                    session = openSession();
6964    
6965                                    Query q = session.createQuery(sql);
6966    
6967                                    QueryPos qPos = QueryPos.getInstance(q);
6968    
6969                                    qPos.add(resourcePrimKey);
6970    
6971                                    qPos.add(status);
6972    
6973                                    count = (Long)q.uniqueResult();
6974    
6975                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
6976                            }
6977                            catch (Exception e) {
6978                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6979    
6980                                    throw processException(e);
6981                            }
6982                            finally {
6983                                    closeSession(session);
6984                            }
6985                    }
6986    
6987                    return count.intValue();
6988            }
6989    
6990            /**
6991             * Returns the number of journal articles where resourcePrimKey = &#63; and status = any &#63;.
6992             *
6993             * @param resourcePrimKey the resource prim key
6994             * @param statuses the statuses
6995             * @return the number of matching journal articles
6996             * @throws SystemException if a system exception occurred
6997             */
6998            @Override
6999            public int countByR_ST(long resourcePrimKey, int[] statuses)
7000                    throws SystemException {
7001                    Object[] finderArgs = new Object[] {
7002                                    resourcePrimKey, StringUtil.merge(statuses)
7003                            };
7004    
7005                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_R_ST,
7006                                    finderArgs, this);
7007    
7008                    if (count == null) {
7009                            StringBundler query = new StringBundler();
7010    
7011                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
7012    
7013                            boolean conjunctionable = false;
7014    
7015                            if (conjunctionable) {
7016                                    query.append(WHERE_AND);
7017                            }
7018    
7019                            query.append(_FINDER_COLUMN_R_ST_RESOURCEPRIMKEY_5);
7020    
7021                            conjunctionable = true;
7022    
7023                            if ((statuses == null) || (statuses.length > 0)) {
7024                                    if (conjunctionable) {
7025                                            query.append(WHERE_AND);
7026                                    }
7027    
7028                                    query.append(StringPool.OPEN_PARENTHESIS);
7029    
7030                                    for (int i = 0; i < statuses.length; i++) {
7031                                            query.append(_FINDER_COLUMN_R_ST_STATUS_5);
7032    
7033                                            if ((i + 1) < statuses.length) {
7034                                                    query.append(WHERE_OR);
7035                                            }
7036                                    }
7037    
7038                                    query.append(StringPool.CLOSE_PARENTHESIS);
7039    
7040                                    conjunctionable = true;
7041                            }
7042    
7043                            String sql = query.toString();
7044    
7045                            Session session = null;
7046    
7047                            try {
7048                                    session = openSession();
7049    
7050                                    Query q = session.createQuery(sql);
7051    
7052                                    QueryPos qPos = QueryPos.getInstance(q);
7053    
7054                                    qPos.add(resourcePrimKey);
7055    
7056                                    if (statuses != null) {
7057                                            qPos.add(statuses);
7058                                    }
7059    
7060                                    count = (Long)q.uniqueResult();
7061    
7062                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_R_ST,
7063                                            finderArgs, count);
7064                            }
7065                            catch (Exception e) {
7066                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_R_ST,
7067                                            finderArgs);
7068    
7069                                    throw processException(e);
7070                            }
7071                            finally {
7072                                    closeSession(session);
7073                            }
7074                    }
7075    
7076                    return count.intValue();
7077            }
7078    
7079            private static final String _FINDER_COLUMN_R_ST_RESOURCEPRIMKEY_2 = "journalArticle.resourcePrimKey = ? AND ";
7080            private static final String _FINDER_COLUMN_R_ST_RESOURCEPRIMKEY_5 = "(" +
7081                    removeConjunction(_FINDER_COLUMN_R_ST_RESOURCEPRIMKEY_2) + ")";
7082            private static final String _FINDER_COLUMN_R_ST_STATUS_2 = "journalArticle.status = ?";
7083            private static final String _FINDER_COLUMN_R_ST_STATUS_5 = "(" +
7084                    removeConjunction(_FINDER_COLUMN_R_ST_STATUS_2) + ")";
7085            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
7086                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
7087                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
7088                            "findByG_U",
7089                            new String[] {
7090                                    Long.class.getName(), Long.class.getName(),
7091                                    
7092                            Integer.class.getName(), Integer.class.getName(),
7093                                    OrderByComparator.class.getName()
7094                            });
7095            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
7096                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
7097                            JournalArticleImpl.class,
7098                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U",
7099                            new String[] { Long.class.getName(), Long.class.getName() },
7100                            JournalArticleModelImpl.GROUPID_COLUMN_BITMASK |
7101                            JournalArticleModelImpl.USERID_COLUMN_BITMASK |
7102                            JournalArticleModelImpl.ARTICLEID_COLUMN_BITMASK |
7103                            JournalArticleModelImpl.VERSION_COLUMN_BITMASK);
7104            public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
7105                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
7106                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U",
7107                            new String[] { Long.class.getName(), Long.class.getName() });
7108    
7109            /**
7110             * Returns all the journal articles where groupId = &#63; and userId = &#63;.
7111             *
7112             * @param groupId the group ID
7113             * @param userId the user ID
7114             * @return the matching journal articles
7115             * @throws SystemException if a system exception occurred
7116             */
7117            @Override
7118            public List<JournalArticle> findByG_U(long groupId, long userId)
7119                    throws SystemException {
7120                    return findByG_U(groupId, userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
7121                            null);
7122            }
7123    
7124            /**
7125             * Returns a range of all the journal articles where groupId = &#63; and userId = &#63;.
7126             *
7127             * <p>
7128             * 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.
7129             * </p>
7130             *
7131             * @param groupId the group ID
7132             * @param userId the user ID
7133             * @param start the lower bound of the range of journal articles
7134             * @param end the upper bound of the range of journal articles (not inclusive)
7135             * @return the range of matching journal articles
7136             * @throws SystemException if a system exception occurred
7137             */
7138            @Override
7139            public List<JournalArticle> findByG_U(long groupId, long userId, int start,
7140                    int end) throws SystemException {
7141                    return findByG_U(groupId, userId, start, end, null);
7142            }
7143    
7144            /**
7145             * Returns an ordered range of all the journal articles where groupId = &#63; and userId = &#63;.
7146             *
7147             * <p>
7148             * 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.
7149             * </p>
7150             *
7151             * @param groupId the group ID
7152             * @param userId the user ID
7153             * @param start the lower bound of the range of journal articles
7154             * @param end the upper bound of the range of journal articles (not inclusive)
7155             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7156             * @return the ordered range of matching journal articles
7157             * @throws SystemException if a system exception occurred
7158             */
7159            @Override
7160            public List<JournalArticle> findByG_U(long groupId, long userId, int start,
7161                    int end, OrderByComparator orderByComparator) throws SystemException {
7162                    boolean pagination = true;
7163                    FinderPath finderPath = null;
7164                    Object[] finderArgs = null;
7165    
7166                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7167                                    (orderByComparator == null)) {
7168                            pagination = false;
7169                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U;
7170                            finderArgs = new Object[] { groupId, userId };
7171                    }
7172                    else {
7173                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U;
7174                            finderArgs = new Object[] {
7175                                            groupId, userId,
7176                                            
7177                                            start, end, orderByComparator
7178                                    };
7179                    }
7180    
7181                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
7182                                    finderArgs, this);
7183    
7184                    if ((list != null) && !list.isEmpty()) {
7185                            for (JournalArticle journalArticle : list) {
7186                                    if ((groupId != journalArticle.getGroupId()) ||
7187                                                    (userId != journalArticle.getUserId())) {
7188                                            list = null;
7189    
7190                                            break;
7191                                    }
7192                            }
7193                    }
7194    
7195                    if (list == null) {
7196                            StringBundler query = null;
7197    
7198                            if (orderByComparator != null) {
7199                                    query = new StringBundler(4 +
7200                                                    (orderByComparator.getOrderByFields().length * 3));
7201                            }
7202                            else {
7203                                    query = new StringBundler(4);
7204                            }
7205    
7206                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
7207    
7208                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
7209    
7210                            query.append(_FINDER_COLUMN_G_U_USERID_2);
7211    
7212                            if (orderByComparator != null) {
7213                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7214                                            orderByComparator);
7215                            }
7216                            else
7217                             if (pagination) {
7218                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
7219                            }
7220    
7221                            String sql = query.toString();
7222    
7223                            Session session = null;
7224    
7225                            try {
7226                                    session = openSession();
7227    
7228                                    Query q = session.createQuery(sql);
7229    
7230                                    QueryPos qPos = QueryPos.getInstance(q);
7231    
7232                                    qPos.add(groupId);
7233    
7234                                    qPos.add(userId);
7235    
7236                                    if (!pagination) {
7237                                            list = (List<JournalArticle>)QueryUtil.list(q,
7238                                                            getDialect(), start, end, false);
7239    
7240                                            Collections.sort(list);
7241    
7242                                            list = new UnmodifiableList<JournalArticle>(list);
7243                                    }
7244                                    else {
7245                                            list = (List<JournalArticle>)QueryUtil.list(q,
7246                                                            getDialect(), start, end);
7247                                    }
7248    
7249                                    cacheResult(list);
7250    
7251                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
7252                            }
7253                            catch (Exception e) {
7254                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7255    
7256                                    throw processException(e);
7257                            }
7258                            finally {
7259                                    closeSession(session);
7260                            }
7261                    }
7262    
7263                    return list;
7264            }
7265    
7266            /**
7267             * Returns the first journal article in the ordered set where groupId = &#63; and userId = &#63;.
7268             *
7269             * @param groupId the group ID
7270             * @param userId the user ID
7271             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7272             * @return the first matching journal article
7273             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
7274             * @throws SystemException if a system exception occurred
7275             */
7276            @Override
7277            public JournalArticle findByG_U_First(long groupId, long userId,
7278                    OrderByComparator orderByComparator)
7279                    throws NoSuchArticleException, SystemException {
7280                    JournalArticle journalArticle = fetchByG_U_First(groupId, userId,
7281                                    orderByComparator);
7282    
7283                    if (journalArticle != null) {
7284                            return journalArticle;
7285                    }
7286    
7287                    StringBundler msg = new StringBundler(6);
7288    
7289                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7290    
7291                    msg.append("groupId=");
7292                    msg.append(groupId);
7293    
7294                    msg.append(", userId=");
7295                    msg.append(userId);
7296    
7297                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7298    
7299                    throw new NoSuchArticleException(msg.toString());
7300            }
7301    
7302            /**
7303             * Returns the first journal article in the ordered set where groupId = &#63; and userId = &#63;.
7304             *
7305             * @param groupId the group ID
7306             * @param userId the user ID
7307             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7308             * @return the first matching journal article, or <code>null</code> if a matching journal article could not be found
7309             * @throws SystemException if a system exception occurred
7310             */
7311            @Override
7312            public JournalArticle fetchByG_U_First(long groupId, long userId,
7313                    OrderByComparator orderByComparator) throws SystemException {
7314                    List<JournalArticle> list = findByG_U(groupId, userId, 0, 1,
7315                                    orderByComparator);
7316    
7317                    if (!list.isEmpty()) {
7318                            return list.get(0);
7319                    }
7320    
7321                    return null;
7322            }
7323    
7324            /**
7325             * Returns the last journal article in the ordered set where groupId = &#63; and userId = &#63;.
7326             *
7327             * @param groupId the group ID
7328             * @param userId the user ID
7329             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7330             * @return the last matching journal article
7331             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
7332             * @throws SystemException if a system exception occurred
7333             */
7334            @Override
7335            public JournalArticle findByG_U_Last(long groupId, long userId,
7336                    OrderByComparator orderByComparator)
7337                    throws NoSuchArticleException, SystemException {
7338                    JournalArticle journalArticle = fetchByG_U_Last(groupId, userId,
7339                                    orderByComparator);
7340    
7341                    if (journalArticle != null) {
7342                            return journalArticle;
7343                    }
7344    
7345                    StringBundler msg = new StringBundler(6);
7346    
7347                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7348    
7349                    msg.append("groupId=");
7350                    msg.append(groupId);
7351    
7352                    msg.append(", userId=");
7353                    msg.append(userId);
7354    
7355                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7356    
7357                    throw new NoSuchArticleException(msg.toString());
7358            }
7359    
7360            /**
7361             * Returns the last journal article in the ordered set where groupId = &#63; and userId = &#63;.
7362             *
7363             * @param groupId the group ID
7364             * @param userId the user ID
7365             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7366             * @return the last matching journal article, or <code>null</code> if a matching journal article could not be found
7367             * @throws SystemException if a system exception occurred
7368             */
7369            @Override
7370            public JournalArticle fetchByG_U_Last(long groupId, long userId,
7371                    OrderByComparator orderByComparator) throws SystemException {
7372                    int count = countByG_U(groupId, userId);
7373    
7374                    if (count == 0) {
7375                            return null;
7376                    }
7377    
7378                    List<JournalArticle> list = findByG_U(groupId, userId, count - 1,
7379                                    count, orderByComparator);
7380    
7381                    if (!list.isEmpty()) {
7382                            return list.get(0);
7383                    }
7384    
7385                    return null;
7386            }
7387    
7388            /**
7389             * Returns the journal articles before and after the current journal article in the ordered set where groupId = &#63; and userId = &#63;.
7390             *
7391             * @param id the primary key of the current journal article
7392             * @param groupId the group ID
7393             * @param userId the user ID
7394             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7395             * @return the previous, current, and next journal article
7396             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
7397             * @throws SystemException if a system exception occurred
7398             */
7399            @Override
7400            public JournalArticle[] findByG_U_PrevAndNext(long id, long groupId,
7401                    long userId, OrderByComparator orderByComparator)
7402                    throws NoSuchArticleException, SystemException {
7403                    JournalArticle journalArticle = findByPrimaryKey(id);
7404    
7405                    Session session = null;
7406    
7407                    try {
7408                            session = openSession();
7409    
7410                            JournalArticle[] array = new JournalArticleImpl[3];
7411    
7412                            array[0] = getByG_U_PrevAndNext(session, journalArticle, groupId,
7413                                            userId, orderByComparator, true);
7414    
7415                            array[1] = journalArticle;
7416    
7417                            array[2] = getByG_U_PrevAndNext(session, journalArticle, groupId,
7418                                            userId, orderByComparator, false);
7419    
7420                            return array;
7421                    }
7422                    catch (Exception e) {
7423                            throw processException(e);
7424                    }
7425                    finally {
7426                            closeSession(session);
7427                    }
7428            }
7429    
7430            protected JournalArticle getByG_U_PrevAndNext(Session session,
7431                    JournalArticle journalArticle, long groupId, long userId,
7432                    OrderByComparator orderByComparator, boolean previous) {
7433                    StringBundler query = null;
7434    
7435                    if (orderByComparator != null) {
7436                            query = new StringBundler(6 +
7437                                            (orderByComparator.getOrderByFields().length * 6));
7438                    }
7439                    else {
7440                            query = new StringBundler(3);
7441                    }
7442    
7443                    query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
7444    
7445                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
7446    
7447                    query.append(_FINDER_COLUMN_G_U_USERID_2);
7448    
7449                    if (orderByComparator != null) {
7450                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7451    
7452                            if (orderByConditionFields.length > 0) {
7453                                    query.append(WHERE_AND);
7454                            }
7455    
7456                            for (int i = 0; i < orderByConditionFields.length; i++) {
7457                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7458                                    query.append(orderByConditionFields[i]);
7459    
7460                                    if ((i + 1) < orderByConditionFields.length) {
7461                                            if (orderByComparator.isAscending() ^ previous) {
7462                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7463                                            }
7464                                            else {
7465                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7466                                            }
7467                                    }
7468                                    else {
7469                                            if (orderByComparator.isAscending() ^ previous) {
7470                                                    query.append(WHERE_GREATER_THAN);
7471                                            }
7472                                            else {
7473                                                    query.append(WHERE_LESSER_THAN);
7474                                            }
7475                                    }
7476                            }
7477    
7478                            query.append(ORDER_BY_CLAUSE);
7479    
7480                            String[] orderByFields = orderByComparator.getOrderByFields();
7481    
7482                            for (int i = 0; i < orderByFields.length; i++) {
7483                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7484                                    query.append(orderByFields[i]);
7485    
7486                                    if ((i + 1) < orderByFields.length) {
7487                                            if (orderByComparator.isAscending() ^ previous) {
7488                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7489                                            }
7490                                            else {
7491                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7492                                            }
7493                                    }
7494                                    else {
7495                                            if (orderByComparator.isAscending() ^ previous) {
7496                                                    query.append(ORDER_BY_ASC);
7497                                            }
7498                                            else {
7499                                                    query.append(ORDER_BY_DESC);
7500                                            }
7501                                    }
7502                            }
7503                    }
7504                    else {
7505                            query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
7506                    }
7507    
7508                    String sql = query.toString();
7509    
7510                    Query q = session.createQuery(sql);
7511    
7512                    q.setFirstResult(0);
7513                    q.setMaxResults(2);
7514    
7515                    QueryPos qPos = QueryPos.getInstance(q);
7516    
7517                    qPos.add(groupId);
7518    
7519                    qPos.add(userId);
7520    
7521                    if (orderByComparator != null) {
7522                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
7523    
7524                            for (Object value : values) {
7525                                    qPos.add(value);
7526                            }
7527                    }
7528    
7529                    List<JournalArticle> list = q.list();
7530    
7531                    if (list.size() == 2) {
7532                            return list.get(1);
7533                    }
7534                    else {
7535                            return null;
7536                    }
7537            }
7538    
7539            /**
7540             * Returns all the journal articles that the user has permission to view where groupId = &#63; and userId = &#63;.
7541             *
7542             * @param groupId the group ID
7543             * @param userId the user ID
7544             * @return the matching journal articles that the user has permission to view
7545             * @throws SystemException if a system exception occurred
7546             */
7547            @Override
7548            public List<JournalArticle> filterFindByG_U(long groupId, long userId)
7549                    throws SystemException {
7550                    return filterFindByG_U(groupId, userId, QueryUtil.ALL_POS,
7551                            QueryUtil.ALL_POS, null);
7552            }
7553    
7554            /**
7555             * Returns a range of all the journal articles that the user has permission to view where groupId = &#63; and userId = &#63;.
7556             *
7557             * <p>
7558             * 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.
7559             * </p>
7560             *
7561             * @param groupId the group ID
7562             * @param userId the user ID
7563             * @param start the lower bound of the range of journal articles
7564             * @param end the upper bound of the range of journal articles (not inclusive)
7565             * @return the range of matching journal articles that the user has permission to view
7566             * @throws SystemException if a system exception occurred
7567             */
7568            @Override
7569            public List<JournalArticle> filterFindByG_U(long groupId, long userId,
7570                    int start, int end) throws SystemException {
7571                    return filterFindByG_U(groupId, userId, start, end, null);
7572            }
7573    
7574            /**
7575             * Returns an ordered range of all the journal articles that the user has permissions to view where groupId = &#63; and userId = &#63;.
7576             *
7577             * <p>
7578             * 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.
7579             * </p>
7580             *
7581             * @param groupId the group ID
7582             * @param userId the user ID
7583             * @param start the lower bound of the range of journal articles
7584             * @param end the upper bound of the range of journal articles (not inclusive)
7585             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7586             * @return the ordered range of matching journal articles that the user has permission to view
7587             * @throws SystemException if a system exception occurred
7588             */
7589            @Override
7590            public List<JournalArticle> filterFindByG_U(long groupId, long userId,
7591                    int start, int end, OrderByComparator orderByComparator)
7592                    throws SystemException {
7593                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7594                            return findByG_U(groupId, userId, start, end, orderByComparator);
7595                    }
7596    
7597                    StringBundler query = null;
7598    
7599                    if (orderByComparator != null) {
7600                            query = new StringBundler(4 +
7601                                            (orderByComparator.getOrderByFields().length * 3));
7602                    }
7603                    else {
7604                            query = new StringBundler(4);
7605                    }
7606    
7607                    if (getDB().isSupportsInlineDistinct()) {
7608                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_WHERE);
7609                    }
7610                    else {
7611                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1);
7612                    }
7613    
7614                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
7615    
7616                    query.append(_FINDER_COLUMN_G_U_USERID_2);
7617    
7618                    if (!getDB().isSupportsInlineDistinct()) {
7619                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_2);
7620                    }
7621    
7622                    if (orderByComparator != null) {
7623                            if (getDB().isSupportsInlineDistinct()) {
7624                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7625                                            orderByComparator, true);
7626                            }
7627                            else {
7628                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
7629                                            orderByComparator, true);
7630                            }
7631                    }
7632                    else {
7633                            if (getDB().isSupportsInlineDistinct()) {
7634                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
7635                            }
7636                            else {
7637                                    query.append(JournalArticleModelImpl.ORDER_BY_SQL);
7638                            }
7639                    }
7640    
7641                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7642                                    JournalArticle.class.getName(),
7643                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7644    
7645                    Session session = null;
7646    
7647                    try {
7648                            session = openSession();
7649    
7650                            SQLQuery q = session.createSQLQuery(sql);
7651    
7652                            if (getDB().isSupportsInlineDistinct()) {
7653                                    q.addEntity(_FILTER_ENTITY_ALIAS, JournalArticleImpl.class);
7654                            }
7655                            else {
7656                                    q.addEntity(_FILTER_ENTITY_TABLE, JournalArticleImpl.class);
7657                            }
7658    
7659                            QueryPos qPos = QueryPos.getInstance(q);
7660    
7661                            qPos.add(groupId);
7662    
7663                            qPos.add(userId);
7664    
7665                            return (List<JournalArticle>)QueryUtil.list(q, getDialect(), start,
7666                                    end);
7667                    }
7668                    catch (Exception e) {
7669                            throw processException(e);
7670                    }
7671                    finally {
7672                            closeSession(session);
7673                    }
7674            }
7675    
7676            /**
7677             * 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;.
7678             *
7679             * @param id the primary key of the current journal article
7680             * @param groupId the group ID
7681             * @param userId the user ID
7682             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7683             * @return the previous, current, and next journal article
7684             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
7685             * @throws SystemException if a system exception occurred
7686             */
7687            @Override
7688            public JournalArticle[] filterFindByG_U_PrevAndNext(long id, long groupId,
7689                    long userId, OrderByComparator orderByComparator)
7690                    throws NoSuchArticleException, SystemException {
7691                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7692                            return findByG_U_PrevAndNext(id, groupId, userId, orderByComparator);
7693                    }
7694    
7695                    JournalArticle journalArticle = findByPrimaryKey(id);
7696    
7697                    Session session = null;
7698    
7699                    try {
7700                            session = openSession();
7701    
7702                            JournalArticle[] array = new JournalArticleImpl[3];
7703    
7704                            array[0] = filterGetByG_U_PrevAndNext(session, journalArticle,
7705                                            groupId, userId, orderByComparator, true);
7706    
7707                            array[1] = journalArticle;
7708    
7709                            array[2] = filterGetByG_U_PrevAndNext(session, journalArticle,
7710                                            groupId, userId, orderByComparator, false);
7711    
7712                            return array;
7713                    }
7714                    catch (Exception e) {
7715                            throw processException(e);
7716                    }
7717                    finally {
7718                            closeSession(session);
7719                    }
7720            }
7721    
7722            protected JournalArticle filterGetByG_U_PrevAndNext(Session session,
7723                    JournalArticle journalArticle, long groupId, long userId,
7724                    OrderByComparator orderByComparator, boolean previous) {
7725                    StringBundler query = null;
7726    
7727                    if (orderByComparator != null) {
7728                            query = new StringBundler(6 +
7729                                            (orderByComparator.getOrderByFields().length * 6));
7730                    }
7731                    else {
7732                            query = new StringBundler(3);
7733                    }
7734    
7735                    if (getDB().isSupportsInlineDistinct()) {
7736                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_WHERE);
7737                    }
7738                    else {
7739                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1);
7740                    }
7741    
7742                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
7743    
7744                    query.append(_FINDER_COLUMN_G_U_USERID_2);
7745    
7746                    if (!getDB().isSupportsInlineDistinct()) {
7747                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_2);
7748                    }
7749    
7750                    if (orderByComparator != null) {
7751                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7752    
7753                            if (orderByConditionFields.length > 0) {
7754                                    query.append(WHERE_AND);
7755                            }
7756    
7757                            for (int i = 0; i < orderByConditionFields.length; i++) {
7758                                    if (getDB().isSupportsInlineDistinct()) {
7759                                            query.append(_ORDER_BY_ENTITY_ALIAS);
7760                                    }
7761                                    else {
7762                                            query.append(_ORDER_BY_ENTITY_TABLE);
7763                                    }
7764    
7765                                    query.append(orderByConditionFields[i]);
7766    
7767                                    if ((i + 1) < orderByConditionFields.length) {
7768                                            if (orderByComparator.isAscending() ^ previous) {
7769                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7770                                            }
7771                                            else {
7772                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7773                                            }
7774                                    }
7775                                    else {
7776                                            if (orderByComparator.isAscending() ^ previous) {
7777                                                    query.append(WHERE_GREATER_THAN);
7778                                            }
7779                                            else {
7780                                                    query.append(WHERE_LESSER_THAN);
7781                                            }
7782                                    }
7783                            }
7784    
7785                            query.append(ORDER_BY_CLAUSE);
7786    
7787                            String[] orderByFields = orderByComparator.getOrderByFields();
7788    
7789                            for (int i = 0; i < orderByFields.length; i++) {
7790                                    if (getDB().isSupportsInlineDistinct()) {
7791                                            query.append(_ORDER_BY_ENTITY_ALIAS);
7792                                    }
7793                                    else {
7794                                            query.append(_ORDER_BY_ENTITY_TABLE);
7795                                    }
7796    
7797                                    query.append(orderByFields[i]);
7798    
7799                                    if ((i + 1) < orderByFields.length) {
7800                                            if (orderByComparator.isAscending() ^ previous) {
7801                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7802                                            }
7803                                            else {
7804                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7805                                            }
7806                                    }
7807                                    else {
7808                                            if (orderByComparator.isAscending() ^ previous) {
7809                                                    query.append(ORDER_BY_ASC);
7810                                            }
7811                                            else {
7812                                                    query.append(ORDER_BY_DESC);
7813                                            }
7814                                    }
7815                            }
7816                    }
7817                    else {
7818                            if (getDB().isSupportsInlineDistinct()) {
7819                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
7820                            }
7821                            else {
7822                                    query.append(JournalArticleModelImpl.ORDER_BY_SQL);
7823                            }
7824                    }
7825    
7826                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7827                                    JournalArticle.class.getName(),
7828                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7829    
7830                    SQLQuery q = session.createSQLQuery(sql);
7831    
7832                    q.setFirstResult(0);
7833                    q.setMaxResults(2);
7834    
7835                    if (getDB().isSupportsInlineDistinct()) {
7836                            q.addEntity(_FILTER_ENTITY_ALIAS, JournalArticleImpl.class);
7837                    }
7838                    else {
7839                            q.addEntity(_FILTER_ENTITY_TABLE, JournalArticleImpl.class);
7840                    }
7841    
7842                    QueryPos qPos = QueryPos.getInstance(q);
7843    
7844                    qPos.add(groupId);
7845    
7846                    qPos.add(userId);
7847    
7848                    if (orderByComparator != null) {
7849                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
7850    
7851                            for (Object value : values) {
7852                                    qPos.add(value);
7853                            }
7854                    }
7855    
7856                    List<JournalArticle> list = q.list();
7857    
7858                    if (list.size() == 2) {
7859                            return list.get(1);
7860                    }
7861                    else {
7862                            return null;
7863                    }
7864            }
7865    
7866            /**
7867             * Removes all the journal articles where groupId = &#63; and userId = &#63; from the database.
7868             *
7869             * @param groupId the group ID
7870             * @param userId the user ID
7871             * @throws SystemException if a system exception occurred
7872             */
7873            @Override
7874            public void removeByG_U(long groupId, long userId)
7875                    throws SystemException {
7876                    for (JournalArticle journalArticle : findByG_U(groupId, userId,
7877                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
7878                            remove(journalArticle);
7879                    }
7880            }
7881    
7882            /**
7883             * Returns the number of journal articles where groupId = &#63; and userId = &#63;.
7884             *
7885             * @param groupId the group ID
7886             * @param userId the user ID
7887             * @return the number of matching journal articles
7888             * @throws SystemException if a system exception occurred
7889             */
7890            @Override
7891            public int countByG_U(long groupId, long userId) throws SystemException {
7892                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U;
7893    
7894                    Object[] finderArgs = new Object[] { groupId, userId };
7895    
7896                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
7897                                    this);
7898    
7899                    if (count == null) {
7900                            StringBundler query = new StringBundler(3);
7901    
7902                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
7903    
7904                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
7905    
7906                            query.append(_FINDER_COLUMN_G_U_USERID_2);
7907    
7908                            String sql = query.toString();
7909    
7910                            Session session = null;
7911    
7912                            try {
7913                                    session = openSession();
7914    
7915                                    Query q = session.createQuery(sql);
7916    
7917                                    QueryPos qPos = QueryPos.getInstance(q);
7918    
7919                                    qPos.add(groupId);
7920    
7921                                    qPos.add(userId);
7922    
7923                                    count = (Long)q.uniqueResult();
7924    
7925                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
7926                            }
7927                            catch (Exception e) {
7928                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7929    
7930                                    throw processException(e);
7931                            }
7932                            finally {
7933                                    closeSession(session);
7934                            }
7935                    }
7936    
7937                    return count.intValue();
7938            }
7939    
7940            /**
7941             * Returns the number of journal articles that the user has permission to view where groupId = &#63; and userId = &#63;.
7942             *
7943             * @param groupId the group ID
7944             * @param userId the user ID
7945             * @return the number of matching journal articles that the user has permission to view
7946             * @throws SystemException if a system exception occurred
7947             */
7948            @Override
7949            public int filterCountByG_U(long groupId, long userId)
7950                    throws SystemException {
7951                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7952                            return countByG_U(groupId, userId);
7953                    }
7954    
7955                    StringBundler query = new StringBundler(3);
7956    
7957                    query.append(_FILTER_SQL_COUNT_JOURNALARTICLE_WHERE);
7958    
7959                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
7960    
7961                    query.append(_FINDER_COLUMN_G_U_USERID_2);
7962    
7963                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7964                                    JournalArticle.class.getName(),
7965                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7966    
7967                    Session session = null;
7968    
7969                    try {
7970                            session = openSession();
7971    
7972                            SQLQuery q = session.createSQLQuery(sql);
7973    
7974                            q.addScalar(COUNT_COLUMN_NAME,
7975                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
7976    
7977                            QueryPos qPos = QueryPos.getInstance(q);
7978    
7979                            qPos.add(groupId);
7980    
7981                            qPos.add(userId);
7982    
7983                            Long count = (Long)q.uniqueResult();
7984    
7985                            return count.intValue();
7986                    }
7987                    catch (Exception e) {
7988                            throw processException(e);
7989                    }
7990                    finally {
7991                            closeSession(session);
7992                    }
7993            }
7994    
7995            private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "journalArticle.groupId = ? AND ";
7996            private static final String _FINDER_COLUMN_G_U_USERID_2 = "journalArticle.userId = ?";
7997            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_F = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
7998                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
7999                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
8000                            "findByG_F",
8001                            new String[] {
8002                                    Long.class.getName(), Long.class.getName(),
8003                                    
8004                            Integer.class.getName(), Integer.class.getName(),
8005                                    OrderByComparator.class.getName()
8006                            });
8007            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
8008                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
8009                            JournalArticleImpl.class,
8010                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_F",
8011                            new String[] { Long.class.getName(), Long.class.getName() },
8012                            JournalArticleModelImpl.GROUPID_COLUMN_BITMASK |
8013                            JournalArticleModelImpl.FOLDERID_COLUMN_BITMASK |
8014                            JournalArticleModelImpl.ARTICLEID_COLUMN_BITMASK |
8015                            JournalArticleModelImpl.VERSION_COLUMN_BITMASK);
8016            public static final FinderPath FINDER_PATH_COUNT_BY_G_F = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
8017                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
8018                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_F",
8019                            new String[] { Long.class.getName(), Long.class.getName() });
8020            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_F = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
8021                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
8022                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_F",
8023                            new String[] { Long.class.getName(), Long.class.getName() });
8024    
8025            /**
8026             * Returns all the journal articles where groupId = &#63; and folderId = &#63;.
8027             *
8028             * @param groupId the group ID
8029             * @param folderId the folder ID
8030             * @return the matching journal articles
8031             * @throws SystemException if a system exception occurred
8032             */
8033            @Override
8034            public List<JournalArticle> findByG_F(long groupId, long folderId)
8035                    throws SystemException {
8036                    return findByG_F(groupId, folderId, QueryUtil.ALL_POS,
8037                            QueryUtil.ALL_POS, null);
8038            }
8039    
8040            /**
8041             * Returns a range of all the journal articles where groupId = &#63; and folderId = &#63;.
8042             *
8043             * <p>
8044             * 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.
8045             * </p>
8046             *
8047             * @param groupId the group ID
8048             * @param folderId the folder ID
8049             * @param start the lower bound of the range of journal articles
8050             * @param end the upper bound of the range of journal articles (not inclusive)
8051             * @return the range of matching journal articles
8052             * @throws SystemException if a system exception occurred
8053             */
8054            @Override
8055            public List<JournalArticle> findByG_F(long groupId, long folderId,
8056                    int start, int end) throws SystemException {
8057                    return findByG_F(groupId, folderId, start, end, null);
8058            }
8059    
8060            /**
8061             * Returns an ordered range of all the journal articles where groupId = &#63; and folderId = &#63;.
8062             *
8063             * <p>
8064             * 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.
8065             * </p>
8066             *
8067             * @param groupId the group ID
8068             * @param folderId the folder ID
8069             * @param start the lower bound of the range of journal articles
8070             * @param end the upper bound of the range of journal articles (not inclusive)
8071             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8072             * @return the ordered range of matching journal articles
8073             * @throws SystemException if a system exception occurred
8074             */
8075            @Override
8076            public List<JournalArticle> findByG_F(long groupId, long folderId,
8077                    int start, int end, OrderByComparator orderByComparator)
8078                    throws SystemException {
8079                    boolean pagination = true;
8080                    FinderPath finderPath = null;
8081                    Object[] finderArgs = null;
8082    
8083                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8084                                    (orderByComparator == null)) {
8085                            pagination = false;
8086                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F;
8087                            finderArgs = new Object[] { groupId, folderId };
8088                    }
8089                    else {
8090                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_F;
8091                            finderArgs = new Object[] {
8092                                            groupId, folderId,
8093                                            
8094                                            start, end, orderByComparator
8095                                    };
8096                    }
8097    
8098                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
8099                                    finderArgs, this);
8100    
8101                    if ((list != null) && !list.isEmpty()) {
8102                            for (JournalArticle journalArticle : list) {
8103                                    if ((groupId != journalArticle.getGroupId()) ||
8104                                                    (folderId != journalArticle.getFolderId())) {
8105                                            list = null;
8106    
8107                                            break;
8108                                    }
8109                            }
8110                    }
8111    
8112                    if (list == null) {
8113                            StringBundler query = null;
8114    
8115                            if (orderByComparator != null) {
8116                                    query = new StringBundler(4 +
8117                                                    (orderByComparator.getOrderByFields().length * 3));
8118                            }
8119                            else {
8120                                    query = new StringBundler(4);
8121                            }
8122    
8123                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
8124    
8125                            query.append(_FINDER_COLUMN_G_F_GROUPID_2);
8126    
8127                            query.append(_FINDER_COLUMN_G_F_FOLDERID_2);
8128    
8129                            if (orderByComparator != null) {
8130                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8131                                            orderByComparator);
8132                            }
8133                            else
8134                             if (pagination) {
8135                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
8136                            }
8137    
8138                            String sql = query.toString();
8139    
8140                            Session session = null;
8141    
8142                            try {
8143                                    session = openSession();
8144    
8145                                    Query q = session.createQuery(sql);
8146    
8147                                    QueryPos qPos = QueryPos.getInstance(q);
8148    
8149                                    qPos.add(groupId);
8150    
8151                                    qPos.add(folderId);
8152    
8153                                    if (!pagination) {
8154                                            list = (List<JournalArticle>)QueryUtil.list(q,
8155                                                            getDialect(), start, end, false);
8156    
8157                                            Collections.sort(list);
8158    
8159                                            list = new UnmodifiableList<JournalArticle>(list);
8160                                    }
8161                                    else {
8162                                            list = (List<JournalArticle>)QueryUtil.list(q,
8163                                                            getDialect(), start, end);
8164                                    }
8165    
8166                                    cacheResult(list);
8167    
8168                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
8169                            }
8170                            catch (Exception e) {
8171                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8172    
8173                                    throw processException(e);
8174                            }
8175                            finally {
8176                                    closeSession(session);
8177                            }
8178                    }
8179    
8180                    return list;
8181            }
8182    
8183            /**
8184             * Returns the first journal article in the ordered set where groupId = &#63; and folderId = &#63;.
8185             *
8186             * @param groupId the group ID
8187             * @param folderId the folder ID
8188             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8189             * @return the first matching journal article
8190             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
8191             * @throws SystemException if a system exception occurred
8192             */
8193            @Override
8194            public JournalArticle findByG_F_First(long groupId, long folderId,
8195                    OrderByComparator orderByComparator)
8196                    throws NoSuchArticleException, SystemException {
8197                    JournalArticle journalArticle = fetchByG_F_First(groupId, folderId,
8198                                    orderByComparator);
8199    
8200                    if (journalArticle != null) {
8201                            return journalArticle;
8202                    }
8203    
8204                    StringBundler msg = new StringBundler(6);
8205    
8206                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8207    
8208                    msg.append("groupId=");
8209                    msg.append(groupId);
8210    
8211                    msg.append(", folderId=");
8212                    msg.append(folderId);
8213    
8214                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8215    
8216                    throw new NoSuchArticleException(msg.toString());
8217            }
8218    
8219            /**
8220             * Returns the first journal article in the ordered set where groupId = &#63; and folderId = &#63;.
8221             *
8222             * @param groupId the group ID
8223             * @param folderId the folder ID
8224             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8225             * @return the first matching journal article, or <code>null</code> if a matching journal article could not be found
8226             * @throws SystemException if a system exception occurred
8227             */
8228            @Override
8229            public JournalArticle fetchByG_F_First(long groupId, long folderId,
8230                    OrderByComparator orderByComparator) throws SystemException {
8231                    List<JournalArticle> list = findByG_F(groupId, folderId, 0, 1,
8232                                    orderByComparator);
8233    
8234                    if (!list.isEmpty()) {
8235                            return list.get(0);
8236                    }
8237    
8238                    return null;
8239            }
8240    
8241            /**
8242             * Returns the last journal article in the ordered set where groupId = &#63; and folderId = &#63;.
8243             *
8244             * @param groupId the group ID
8245             * @param folderId the folder ID
8246             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8247             * @return the last matching journal article
8248             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
8249             * @throws SystemException if a system exception occurred
8250             */
8251            @Override
8252            public JournalArticle findByG_F_Last(long groupId, long folderId,
8253                    OrderByComparator orderByComparator)
8254                    throws NoSuchArticleException, SystemException {
8255                    JournalArticle journalArticle = fetchByG_F_Last(groupId, folderId,
8256                                    orderByComparator);
8257    
8258                    if (journalArticle != null) {
8259                            return journalArticle;
8260                    }
8261    
8262                    StringBundler msg = new StringBundler(6);
8263    
8264                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8265    
8266                    msg.append("groupId=");
8267                    msg.append(groupId);
8268    
8269                    msg.append(", folderId=");
8270                    msg.append(folderId);
8271    
8272                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8273    
8274                    throw new NoSuchArticleException(msg.toString());
8275            }
8276    
8277            /**
8278             * Returns the last journal article in the ordered set where groupId = &#63; and folderId = &#63;.
8279             *
8280             * @param groupId the group ID
8281             * @param folderId the folder ID
8282             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8283             * @return the last matching journal article, or <code>null</code> if a matching journal article could not be found
8284             * @throws SystemException if a system exception occurred
8285             */
8286            @Override
8287            public JournalArticle fetchByG_F_Last(long groupId, long folderId,
8288                    OrderByComparator orderByComparator) throws SystemException {
8289                    int count = countByG_F(groupId, folderId);
8290    
8291                    if (count == 0) {
8292                            return null;
8293                    }
8294    
8295                    List<JournalArticle> list = findByG_F(groupId, folderId, count - 1,
8296                                    count, orderByComparator);
8297    
8298                    if (!list.isEmpty()) {
8299                            return list.get(0);
8300                    }
8301    
8302                    return null;
8303            }
8304    
8305            /**
8306             * Returns the journal articles before and after the current journal article in the ordered set where groupId = &#63; and folderId = &#63;.
8307             *
8308             * @param id the primary key of the current journal article
8309             * @param groupId the group ID
8310             * @param folderId the folder ID
8311             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8312             * @return the previous, current, and next journal article
8313             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
8314             * @throws SystemException if a system exception occurred
8315             */
8316            @Override
8317            public JournalArticle[] findByG_F_PrevAndNext(long id, long groupId,
8318                    long folderId, OrderByComparator orderByComparator)
8319                    throws NoSuchArticleException, SystemException {
8320                    JournalArticle journalArticle = findByPrimaryKey(id);
8321    
8322                    Session session = null;
8323    
8324                    try {
8325                            session = openSession();
8326    
8327                            JournalArticle[] array = new JournalArticleImpl[3];
8328    
8329                            array[0] = getByG_F_PrevAndNext(session, journalArticle, groupId,
8330                                            folderId, orderByComparator, true);
8331    
8332                            array[1] = journalArticle;
8333    
8334                            array[2] = getByG_F_PrevAndNext(session, journalArticle, groupId,
8335                                            folderId, orderByComparator, false);
8336    
8337                            return array;
8338                    }
8339                    catch (Exception e) {
8340                            throw processException(e);
8341                    }
8342                    finally {
8343                            closeSession(session);
8344                    }
8345            }
8346    
8347            protected JournalArticle getByG_F_PrevAndNext(Session session,
8348                    JournalArticle journalArticle, long groupId, long folderId,
8349                    OrderByComparator orderByComparator, boolean previous) {
8350                    StringBundler query = null;
8351    
8352                    if (orderByComparator != null) {
8353                            query = new StringBundler(6 +
8354                                            (orderByComparator.getOrderByFields().length * 6));
8355                    }
8356                    else {
8357                            query = new StringBundler(3);
8358                    }
8359    
8360                    query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
8361    
8362                    query.append(_FINDER_COLUMN_G_F_GROUPID_2);
8363    
8364                    query.append(_FINDER_COLUMN_G_F_FOLDERID_2);
8365    
8366                    if (orderByComparator != null) {
8367                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8368    
8369                            if (orderByConditionFields.length > 0) {
8370                                    query.append(WHERE_AND);
8371                            }
8372    
8373                            for (int i = 0; i < orderByConditionFields.length; i++) {
8374                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8375                                    query.append(orderByConditionFields[i]);
8376    
8377                                    if ((i + 1) < orderByConditionFields.length) {
8378                                            if (orderByComparator.isAscending() ^ previous) {
8379                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8380                                            }
8381                                            else {
8382                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8383                                            }
8384                                    }
8385                                    else {
8386                                            if (orderByComparator.isAscending() ^ previous) {
8387                                                    query.append(WHERE_GREATER_THAN);
8388                                            }
8389                                            else {
8390                                                    query.append(WHERE_LESSER_THAN);
8391                                            }
8392                                    }
8393                            }
8394    
8395                            query.append(ORDER_BY_CLAUSE);
8396    
8397                            String[] orderByFields = orderByComparator.getOrderByFields();
8398    
8399                            for (int i = 0; i < orderByFields.length; i++) {
8400                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8401                                    query.append(orderByFields[i]);
8402    
8403                                    if ((i + 1) < orderByFields.length) {
8404                                            if (orderByComparator.isAscending() ^ previous) {
8405                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8406                                            }
8407                                            else {
8408                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8409                                            }
8410                                    }
8411                                    else {
8412                                            if (orderByComparator.isAscending() ^ previous) {
8413                                                    query.append(ORDER_BY_ASC);
8414                                            }
8415                                            else {
8416                                                    query.append(ORDER_BY_DESC);
8417                                            }
8418                                    }
8419                            }
8420                    }
8421                    else {
8422                            query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
8423                    }
8424    
8425                    String sql = query.toString();
8426    
8427                    Query q = session.createQuery(sql);
8428    
8429                    q.setFirstResult(0);
8430                    q.setMaxResults(2);
8431    
8432                    QueryPos qPos = QueryPos.getInstance(q);
8433    
8434                    qPos.add(groupId);
8435    
8436                    qPos.add(folderId);
8437    
8438                    if (orderByComparator != null) {
8439                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
8440    
8441                            for (Object value : values) {
8442                                    qPos.add(value);
8443                            }
8444                    }
8445    
8446                    List<JournalArticle> list = q.list();
8447    
8448                    if (list.size() == 2) {
8449                            return list.get(1);
8450                    }
8451                    else {
8452                            return null;
8453                    }
8454            }
8455    
8456            /**
8457             * Returns all the journal articles that the user has permission to view where groupId = &#63; and folderId = &#63;.
8458             *
8459             * @param groupId the group ID
8460             * @param folderId the folder ID
8461             * @return the matching journal articles that the user has permission to view
8462             * @throws SystemException if a system exception occurred
8463             */
8464            @Override
8465            public List<JournalArticle> filterFindByG_F(long groupId, long folderId)
8466                    throws SystemException {
8467                    return filterFindByG_F(groupId, folderId, QueryUtil.ALL_POS,
8468                            QueryUtil.ALL_POS, null);
8469            }
8470    
8471            /**
8472             * Returns a range of all the journal articles that the user has permission to view where groupId = &#63; and folderId = &#63;.
8473             *
8474             * <p>
8475             * 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.
8476             * </p>
8477             *
8478             * @param groupId the group ID
8479             * @param folderId the folder ID
8480             * @param start the lower bound of the range of journal articles
8481             * @param end the upper bound of the range of journal articles (not inclusive)
8482             * @return the range of matching journal articles that the user has permission to view
8483             * @throws SystemException if a system exception occurred
8484             */
8485            @Override
8486            public List<JournalArticle> filterFindByG_F(long groupId, long folderId,
8487                    int start, int end) throws SystemException {
8488                    return filterFindByG_F(groupId, folderId, start, end, null);
8489            }
8490    
8491            /**
8492             * Returns an ordered range of all the journal articles that the user has permissions to view where groupId = &#63; and folderId = &#63;.
8493             *
8494             * <p>
8495             * 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.
8496             * </p>
8497             *
8498             * @param groupId the group ID
8499             * @param folderId the folder ID
8500             * @param start the lower bound of the range of journal articles
8501             * @param end the upper bound of the range of journal articles (not inclusive)
8502             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8503             * @return the ordered range of matching journal articles that the user has permission to view
8504             * @throws SystemException if a system exception occurred
8505             */
8506            @Override
8507            public List<JournalArticle> filterFindByG_F(long groupId, long folderId,
8508                    int start, int end, OrderByComparator orderByComparator)
8509                    throws SystemException {
8510                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8511                            return findByG_F(groupId, folderId, start, end, orderByComparator);
8512                    }
8513    
8514                    StringBundler query = null;
8515    
8516                    if (orderByComparator != null) {
8517                            query = new StringBundler(4 +
8518                                            (orderByComparator.getOrderByFields().length * 3));
8519                    }
8520                    else {
8521                            query = new StringBundler(4);
8522                    }
8523    
8524                    if (getDB().isSupportsInlineDistinct()) {
8525                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_WHERE);
8526                    }
8527                    else {
8528                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1);
8529                    }
8530    
8531                    query.append(_FINDER_COLUMN_G_F_GROUPID_2);
8532    
8533                    query.append(_FINDER_COLUMN_G_F_FOLDERID_2);
8534    
8535                    if (!getDB().isSupportsInlineDistinct()) {
8536                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_2);
8537                    }
8538    
8539                    if (orderByComparator != null) {
8540                            if (getDB().isSupportsInlineDistinct()) {
8541                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8542                                            orderByComparator, true);
8543                            }
8544                            else {
8545                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
8546                                            orderByComparator, true);
8547                            }
8548                    }
8549                    else {
8550                            if (getDB().isSupportsInlineDistinct()) {
8551                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
8552                            }
8553                            else {
8554                                    query.append(JournalArticleModelImpl.ORDER_BY_SQL);
8555                            }
8556                    }
8557    
8558                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8559                                    JournalArticle.class.getName(),
8560                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8561    
8562                    Session session = null;
8563    
8564                    try {
8565                            session = openSession();
8566    
8567                            SQLQuery q = session.createSQLQuery(sql);
8568    
8569                            if (getDB().isSupportsInlineDistinct()) {
8570                                    q.addEntity(_FILTER_ENTITY_ALIAS, JournalArticleImpl.class);
8571                            }
8572                            else {
8573                                    q.addEntity(_FILTER_ENTITY_TABLE, JournalArticleImpl.class);
8574                            }
8575    
8576                            QueryPos qPos = QueryPos.getInstance(q);
8577    
8578                            qPos.add(groupId);
8579    
8580                            qPos.add(folderId);
8581    
8582                            return (List<JournalArticle>)QueryUtil.list(q, getDialect(), start,
8583                                    end);
8584                    }
8585                    catch (Exception e) {
8586                            throw processException(e);
8587                    }
8588                    finally {
8589                            closeSession(session);
8590                    }
8591            }
8592    
8593            /**
8594             * 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;.
8595             *
8596             * @param id the primary key of the current journal article
8597             * @param groupId the group ID
8598             * @param folderId the folder ID
8599             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8600             * @return the previous, current, and next journal article
8601             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
8602             * @throws SystemException if a system exception occurred
8603             */
8604            @Override
8605            public JournalArticle[] filterFindByG_F_PrevAndNext(long id, long groupId,
8606                    long folderId, OrderByComparator orderByComparator)
8607                    throws NoSuchArticleException, SystemException {
8608                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8609                            return findByG_F_PrevAndNext(id, groupId, folderId,
8610                                    orderByComparator);
8611                    }
8612    
8613                    JournalArticle journalArticle = findByPrimaryKey(id);
8614    
8615                    Session session = null;
8616    
8617                    try {
8618                            session = openSession();
8619    
8620                            JournalArticle[] array = new JournalArticleImpl[3];
8621    
8622                            array[0] = filterGetByG_F_PrevAndNext(session, journalArticle,
8623                                            groupId, folderId, orderByComparator, true);
8624    
8625                            array[1] = journalArticle;
8626    
8627                            array[2] = filterGetByG_F_PrevAndNext(session, journalArticle,
8628                                            groupId, folderId, orderByComparator, false);
8629    
8630                            return array;
8631                    }
8632                    catch (Exception e) {
8633                            throw processException(e);
8634                    }
8635                    finally {
8636                            closeSession(session);
8637                    }
8638            }
8639    
8640            protected JournalArticle filterGetByG_F_PrevAndNext(Session session,
8641                    JournalArticle journalArticle, long groupId, long folderId,
8642                    OrderByComparator orderByComparator, boolean previous) {
8643                    StringBundler query = null;
8644    
8645                    if (orderByComparator != null) {
8646                            query = new StringBundler(6 +
8647                                            (orderByComparator.getOrderByFields().length * 6));
8648                    }
8649                    else {
8650                            query = new StringBundler(3);
8651                    }
8652    
8653                    if (getDB().isSupportsInlineDistinct()) {
8654                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_WHERE);
8655                    }
8656                    else {
8657                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1);
8658                    }
8659    
8660                    query.append(_FINDER_COLUMN_G_F_GROUPID_2);
8661    
8662                    query.append(_FINDER_COLUMN_G_F_FOLDERID_2);
8663    
8664                    if (!getDB().isSupportsInlineDistinct()) {
8665                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_2);
8666                    }
8667    
8668                    if (orderByComparator != null) {
8669                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8670    
8671                            if (orderByConditionFields.length > 0) {
8672                                    query.append(WHERE_AND);
8673                            }
8674    
8675                            for (int i = 0; i < orderByConditionFields.length; i++) {
8676                                    if (getDB().isSupportsInlineDistinct()) {
8677                                            query.append(_ORDER_BY_ENTITY_ALIAS);
8678                                    }
8679                                    else {
8680                                            query.append(_ORDER_BY_ENTITY_TABLE);
8681                                    }
8682    
8683                                    query.append(orderByConditionFields[i]);
8684    
8685                                    if ((i + 1) < orderByConditionFields.length) {
8686                                            if (orderByComparator.isAscending() ^ previous) {
8687                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8688                                            }
8689                                            else {
8690                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8691                                            }
8692                                    }
8693                                    else {
8694                                            if (orderByComparator.isAscending() ^ previous) {
8695                                                    query.append(WHERE_GREATER_THAN);
8696                                            }
8697                                            else {
8698                                                    query.append(WHERE_LESSER_THAN);
8699                                            }
8700                                    }
8701                            }
8702    
8703                            query.append(ORDER_BY_CLAUSE);
8704    
8705                            String[] orderByFields = orderByComparator.getOrderByFields();
8706    
8707                            for (int i = 0; i < orderByFields.length; i++) {
8708                                    if (getDB().isSupportsInlineDistinct()) {
8709                                            query.append(_ORDER_BY_ENTITY_ALIAS);
8710                                    }
8711                                    else {
8712                                            query.append(_ORDER_BY_ENTITY_TABLE);
8713                                    }
8714    
8715                                    query.append(orderByFields[i]);
8716    
8717                                    if ((i + 1) < orderByFields.length) {
8718                                            if (orderByComparator.isAscending() ^ previous) {
8719                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8720                                            }
8721                                            else {
8722                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8723                                            }
8724                                    }
8725                                    else {
8726                                            if (orderByComparator.isAscending() ^ previous) {
8727                                                    query.append(ORDER_BY_ASC);
8728                                            }
8729                                            else {
8730                                                    query.append(ORDER_BY_DESC);
8731                                            }
8732                                    }
8733                            }
8734                    }
8735                    else {
8736                            if (getDB().isSupportsInlineDistinct()) {
8737                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
8738                            }
8739                            else {
8740                                    query.append(JournalArticleModelImpl.ORDER_BY_SQL);
8741                            }
8742                    }
8743    
8744                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8745                                    JournalArticle.class.getName(),
8746                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8747    
8748                    SQLQuery q = session.createSQLQuery(sql);
8749    
8750                    q.setFirstResult(0);
8751                    q.setMaxResults(2);
8752    
8753                    if (getDB().isSupportsInlineDistinct()) {
8754                            q.addEntity(_FILTER_ENTITY_ALIAS, JournalArticleImpl.class);
8755                    }
8756                    else {
8757                            q.addEntity(_FILTER_ENTITY_TABLE, JournalArticleImpl.class);
8758                    }
8759    
8760                    QueryPos qPos = QueryPos.getInstance(q);
8761    
8762                    qPos.add(groupId);
8763    
8764                    qPos.add(folderId);
8765    
8766                    if (orderByComparator != null) {
8767                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
8768    
8769                            for (Object value : values) {
8770                                    qPos.add(value);
8771                            }
8772                    }
8773    
8774                    List<JournalArticle> list = q.list();
8775    
8776                    if (list.size() == 2) {
8777                            return list.get(1);
8778                    }
8779                    else {
8780                            return null;
8781                    }
8782            }
8783    
8784            /**
8785             * Returns all the journal articles that the user has permission to view where groupId = &#63; and folderId = any &#63;.
8786             *
8787             * @param groupId the group ID
8788             * @param folderIds the folder IDs
8789             * @return the matching journal articles that the user has permission to view
8790             * @throws SystemException if a system exception occurred
8791             */
8792            @Override
8793            public List<JournalArticle> filterFindByG_F(long groupId, long[] folderIds)
8794                    throws SystemException {
8795                    return filterFindByG_F(groupId, folderIds, QueryUtil.ALL_POS,
8796                            QueryUtil.ALL_POS, null);
8797            }
8798    
8799            /**
8800             * Returns a range of all the journal articles that the user has permission to view where groupId = &#63; and folderId = any &#63;.
8801             *
8802             * <p>
8803             * 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.
8804             * </p>
8805             *
8806             * @param groupId the group ID
8807             * @param folderIds the folder IDs
8808             * @param start the lower bound of the range of journal articles
8809             * @param end the upper bound of the range of journal articles (not inclusive)
8810             * @return the range of matching journal articles that the user has permission to view
8811             * @throws SystemException if a system exception occurred
8812             */
8813            @Override
8814            public List<JournalArticle> filterFindByG_F(long groupId, long[] folderIds,
8815                    int start, int end) throws SystemException {
8816                    return filterFindByG_F(groupId, folderIds, start, end, null);
8817            }
8818    
8819            /**
8820             * Returns an ordered range of all the journal articles that the user has permission to view where groupId = &#63; and folderId = any &#63;.
8821             *
8822             * <p>
8823             * 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.
8824             * </p>
8825             *
8826             * @param groupId the group ID
8827             * @param folderIds the folder IDs
8828             * @param start the lower bound of the range of journal articles
8829             * @param end the upper bound of the range of journal articles (not inclusive)
8830             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8831             * @return the ordered range of matching journal articles that the user has permission to view
8832             * @throws SystemException if a system exception occurred
8833             */
8834            @Override
8835            public List<JournalArticle> filterFindByG_F(long groupId, long[] folderIds,
8836                    int start, int end, OrderByComparator orderByComparator)
8837                    throws SystemException {
8838                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8839                            return findByG_F(groupId, folderIds, start, end, orderByComparator);
8840                    }
8841    
8842                    StringBundler query = new StringBundler();
8843    
8844                    if (getDB().isSupportsInlineDistinct()) {
8845                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_WHERE);
8846                    }
8847                    else {
8848                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1);
8849                    }
8850    
8851                    boolean conjunctionable = false;
8852    
8853                    if (conjunctionable) {
8854                            query.append(WHERE_AND);
8855                    }
8856    
8857                    query.append(_FINDER_COLUMN_G_F_GROUPID_5);
8858    
8859                    conjunctionable = true;
8860    
8861                    if ((folderIds == null) || (folderIds.length > 0)) {
8862                            if (conjunctionable) {
8863                                    query.append(WHERE_AND);
8864                            }
8865    
8866                            query.append(StringPool.OPEN_PARENTHESIS);
8867    
8868                            for (int i = 0; i < folderIds.length; i++) {
8869                                    query.append(_FINDER_COLUMN_G_F_FOLDERID_5);
8870    
8871                                    if ((i + 1) < folderIds.length) {
8872                                            query.append(WHERE_OR);
8873                                    }
8874                            }
8875    
8876                            query.append(StringPool.CLOSE_PARENTHESIS);
8877    
8878                            conjunctionable = true;
8879                    }
8880    
8881                    if (!getDB().isSupportsInlineDistinct()) {
8882                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_2);
8883                    }
8884    
8885                    if (orderByComparator != null) {
8886                            if (getDB().isSupportsInlineDistinct()) {
8887                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8888                                            orderByComparator, true);
8889                            }
8890                            else {
8891                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
8892                                            orderByComparator, true);
8893                            }
8894                    }
8895                    else {
8896                            if (getDB().isSupportsInlineDistinct()) {
8897                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
8898                            }
8899                            else {
8900                                    query.append(JournalArticleModelImpl.ORDER_BY_SQL);
8901                            }
8902                    }
8903    
8904                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8905                                    JournalArticle.class.getName(),
8906                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8907    
8908                    Session session = null;
8909    
8910                    try {
8911                            session = openSession();
8912    
8913                            SQLQuery q = session.createSQLQuery(sql);
8914    
8915                            if (getDB().isSupportsInlineDistinct()) {
8916                                    q.addEntity(_FILTER_ENTITY_ALIAS, JournalArticleImpl.class);
8917                            }
8918                            else {
8919                                    q.addEntity(_FILTER_ENTITY_TABLE, JournalArticleImpl.class);
8920                            }
8921    
8922                            QueryPos qPos = QueryPos.getInstance(q);
8923    
8924                            qPos.add(groupId);
8925    
8926                            if (folderIds != null) {
8927                                    qPos.add(folderIds);
8928                            }
8929    
8930                            return (List<JournalArticle>)QueryUtil.list(q, getDialect(), start,
8931                                    end);
8932                    }
8933                    catch (Exception e) {
8934                            throw processException(e);
8935                    }
8936                    finally {
8937                            closeSession(session);
8938                    }
8939            }
8940    
8941            /**
8942             * Returns all the journal articles where groupId = &#63; and folderId = any &#63;.
8943             *
8944             * <p>
8945             * 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.
8946             * </p>
8947             *
8948             * @param groupId the group ID
8949             * @param folderIds the folder IDs
8950             * @return the matching journal articles
8951             * @throws SystemException if a system exception occurred
8952             */
8953            @Override
8954            public List<JournalArticle> findByG_F(long groupId, long[] folderIds)
8955                    throws SystemException {
8956                    return findByG_F(groupId, folderIds, QueryUtil.ALL_POS,
8957                            QueryUtil.ALL_POS, null);
8958            }
8959    
8960            /**
8961             * Returns a range of all the journal articles where groupId = &#63; and folderId = any &#63;.
8962             *
8963             * <p>
8964             * 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.
8965             * </p>
8966             *
8967             * @param groupId the group ID
8968             * @param folderIds the folder IDs
8969             * @param start the lower bound of the range of journal articles
8970             * @param end the upper bound of the range of journal articles (not inclusive)
8971             * @return the range of matching journal articles
8972             * @throws SystemException if a system exception occurred
8973             */
8974            @Override
8975            public List<JournalArticle> findByG_F(long groupId, long[] folderIds,
8976                    int start, int end) throws SystemException {
8977                    return findByG_F(groupId, folderIds, start, end, null);
8978            }
8979    
8980            /**
8981             * Returns an ordered range of all the journal articles where groupId = &#63; and folderId = any &#63;.
8982             *
8983             * <p>
8984             * 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.
8985             * </p>
8986             *
8987             * @param groupId the group ID
8988             * @param folderIds the folder IDs
8989             * @param start the lower bound of the range of journal articles
8990             * @param end the upper bound of the range of journal articles (not inclusive)
8991             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8992             * @return the ordered range of matching journal articles
8993             * @throws SystemException if a system exception occurred
8994             */
8995            @Override
8996            public List<JournalArticle> findByG_F(long groupId, long[] folderIds,
8997                    int start, int end, OrderByComparator orderByComparator)
8998                    throws SystemException {
8999                    if ((folderIds != null) && (folderIds.length == 1)) {
9000                            return findByG_F(groupId, folderIds[0], start, end,
9001                                    orderByComparator);
9002                    }
9003    
9004                    boolean pagination = true;
9005                    Object[] finderArgs = null;
9006    
9007                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9008                                    (orderByComparator == null)) {
9009                            pagination = false;
9010                            finderArgs = new Object[] { groupId, StringUtil.merge(folderIds) };
9011                    }
9012                    else {
9013                            finderArgs = new Object[] {
9014                                            groupId, StringUtil.merge(folderIds),
9015                                            
9016                                            start, end, orderByComparator
9017                                    };
9018                    }
9019    
9020                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_F,
9021                                    finderArgs, this);
9022    
9023                    if ((list != null) && !list.isEmpty()) {
9024                            for (JournalArticle journalArticle : list) {
9025                                    if ((groupId != journalArticle.getGroupId()) ||
9026                                                    !ArrayUtil.contains(folderIds,
9027                                                            journalArticle.getFolderId())) {
9028                                            list = null;
9029    
9030                                            break;
9031                                    }
9032                            }
9033                    }
9034    
9035                    if (list == null) {
9036                            StringBundler query = new StringBundler();
9037    
9038                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
9039    
9040                            boolean conjunctionable = false;
9041    
9042                            if (conjunctionable) {
9043                                    query.append(WHERE_AND);
9044                            }
9045    
9046                            query.append(_FINDER_COLUMN_G_F_GROUPID_5);
9047    
9048                            conjunctionable = true;
9049    
9050                            if ((folderIds == null) || (folderIds.length > 0)) {
9051                                    if (conjunctionable) {
9052                                            query.append(WHERE_AND);
9053                                    }
9054    
9055                                    query.append(StringPool.OPEN_PARENTHESIS);
9056    
9057                                    for (int i = 0; i < folderIds.length; i++) {
9058                                            query.append(_FINDER_COLUMN_G_F_FOLDERID_5);
9059    
9060                                            if ((i + 1) < folderIds.length) {
9061                                                    query.append(WHERE_OR);
9062                                            }
9063                                    }
9064    
9065                                    query.append(StringPool.CLOSE_PARENTHESIS);
9066    
9067                                    conjunctionable = true;
9068                            }
9069    
9070                            if (orderByComparator != null) {
9071                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9072                                            orderByComparator);
9073                            }
9074                            else
9075                             if (pagination) {
9076                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
9077                            }
9078    
9079                            String sql = query.toString();
9080    
9081                            Session session = null;
9082    
9083                            try {
9084                                    session = openSession();
9085    
9086                                    Query q = session.createQuery(sql);
9087    
9088                                    QueryPos qPos = QueryPos.getInstance(q);
9089    
9090                                    qPos.add(groupId);
9091    
9092                                    if (folderIds != null) {
9093                                            qPos.add(folderIds);
9094                                    }
9095    
9096                                    if (!pagination) {
9097                                            list = (List<JournalArticle>)QueryUtil.list(q,
9098                                                            getDialect(), start, end, false);
9099    
9100                                            Collections.sort(list);
9101    
9102                                            list = new UnmodifiableList<JournalArticle>(list);
9103                                    }
9104                                    else {
9105                                            list = (List<JournalArticle>)QueryUtil.list(q,
9106                                                            getDialect(), start, end);
9107                                    }
9108    
9109                                    cacheResult(list);
9110    
9111                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_F,
9112                                            finderArgs, list);
9113                            }
9114                            catch (Exception e) {
9115                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_F,
9116                                            finderArgs);
9117    
9118                                    throw processException(e);
9119                            }
9120                            finally {
9121                                    closeSession(session);
9122                            }
9123                    }
9124    
9125                    return list;
9126            }
9127    
9128            /**
9129             * Removes all the journal articles where groupId = &#63; and folderId = &#63; from the database.
9130             *
9131             * @param groupId the group ID
9132             * @param folderId the folder ID
9133             * @throws SystemException if a system exception occurred
9134             */
9135            @Override
9136            public void removeByG_F(long groupId, long folderId)
9137                    throws SystemException {
9138                    for (JournalArticle journalArticle : findByG_F(groupId, folderId,
9139                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
9140                            remove(journalArticle);
9141                    }
9142            }
9143    
9144            /**
9145             * Returns the number of journal articles where groupId = &#63; and folderId = &#63;.
9146             *
9147             * @param groupId the group ID
9148             * @param folderId the folder ID
9149             * @return the number of matching journal articles
9150             * @throws SystemException if a system exception occurred
9151             */
9152            @Override
9153            public int countByG_F(long groupId, long folderId)
9154                    throws SystemException {
9155                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_F;
9156    
9157                    Object[] finderArgs = new Object[] { groupId, folderId };
9158    
9159                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
9160                                    this);
9161    
9162                    if (count == null) {
9163                            StringBundler query = new StringBundler(3);
9164    
9165                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
9166    
9167                            query.append(_FINDER_COLUMN_G_F_GROUPID_2);
9168    
9169                            query.append(_FINDER_COLUMN_G_F_FOLDERID_2);
9170    
9171                            String sql = query.toString();
9172    
9173                            Session session = null;
9174    
9175                            try {
9176                                    session = openSession();
9177    
9178                                    Query q = session.createQuery(sql);
9179    
9180                                    QueryPos qPos = QueryPos.getInstance(q);
9181    
9182                                    qPos.add(groupId);
9183    
9184                                    qPos.add(folderId);
9185    
9186                                    count = (Long)q.uniqueResult();
9187    
9188                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
9189                            }
9190                            catch (Exception e) {
9191                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9192    
9193                                    throw processException(e);
9194                            }
9195                            finally {
9196                                    closeSession(session);
9197                            }
9198                    }
9199    
9200                    return count.intValue();
9201            }
9202    
9203            /**
9204             * Returns the number of journal articles where groupId = &#63; and folderId = any &#63;.
9205             *
9206             * @param groupId the group ID
9207             * @param folderIds the folder IDs
9208             * @return the number of matching journal articles
9209             * @throws SystemException if a system exception occurred
9210             */
9211            @Override
9212            public int countByG_F(long groupId, long[] folderIds)
9213                    throws SystemException {
9214                    Object[] finderArgs = new Object[] { groupId, StringUtil.merge(folderIds) };
9215    
9216                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_F,
9217                                    finderArgs, this);
9218    
9219                    if (count == null) {
9220                            StringBundler query = new StringBundler();
9221    
9222                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
9223    
9224                            boolean conjunctionable = false;
9225    
9226                            if (conjunctionable) {
9227                                    query.append(WHERE_AND);
9228                            }
9229    
9230                            query.append(_FINDER_COLUMN_G_F_GROUPID_5);
9231    
9232                            conjunctionable = true;
9233    
9234                            if ((folderIds == null) || (folderIds.length > 0)) {
9235                                    if (conjunctionable) {
9236                                            query.append(WHERE_AND);
9237                                    }
9238    
9239                                    query.append(StringPool.OPEN_PARENTHESIS);
9240    
9241                                    for (int i = 0; i < folderIds.length; i++) {
9242                                            query.append(_FINDER_COLUMN_G_F_FOLDERID_5);
9243    
9244                                            if ((i + 1) < folderIds.length) {
9245                                                    query.append(WHERE_OR);
9246                                            }
9247                                    }
9248    
9249                                    query.append(StringPool.CLOSE_PARENTHESIS);
9250    
9251                                    conjunctionable = true;
9252                            }
9253    
9254                            String sql = query.toString();
9255    
9256                            Session session = null;
9257    
9258                            try {
9259                                    session = openSession();
9260    
9261                                    Query q = session.createQuery(sql);
9262    
9263                                    QueryPos qPos = QueryPos.getInstance(q);
9264    
9265                                    qPos.add(groupId);
9266    
9267                                    if (folderIds != null) {
9268                                            qPos.add(folderIds);
9269                                    }
9270    
9271                                    count = (Long)q.uniqueResult();
9272    
9273                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_F,
9274                                            finderArgs, count);
9275                            }
9276                            catch (Exception e) {
9277                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_F,
9278                                            finderArgs);
9279    
9280                                    throw processException(e);
9281                            }
9282                            finally {
9283                                    closeSession(session);
9284                            }
9285                    }
9286    
9287                    return count.intValue();
9288            }
9289    
9290            /**
9291             * Returns the number of journal articles that the user has permission to view where groupId = &#63; and folderId = &#63;.
9292             *
9293             * @param groupId the group ID
9294             * @param folderId the folder ID
9295             * @return the number of matching journal articles that the user has permission to view
9296             * @throws SystemException if a system exception occurred
9297             */
9298            @Override
9299            public int filterCountByG_F(long groupId, long folderId)
9300                    throws SystemException {
9301                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9302                            return countByG_F(groupId, folderId);
9303                    }
9304    
9305                    StringBundler query = new StringBundler(3);
9306    
9307                    query.append(_FILTER_SQL_COUNT_JOURNALARTICLE_WHERE);
9308    
9309                    query.append(_FINDER_COLUMN_G_F_GROUPID_2);
9310    
9311                    query.append(_FINDER_COLUMN_G_F_FOLDERID_2);
9312    
9313                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9314                                    JournalArticle.class.getName(),
9315                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9316    
9317                    Session session = null;
9318    
9319                    try {
9320                            session = openSession();
9321    
9322                            SQLQuery q = session.createSQLQuery(sql);
9323    
9324                            q.addScalar(COUNT_COLUMN_NAME,
9325                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
9326    
9327                            QueryPos qPos = QueryPos.getInstance(q);
9328    
9329                            qPos.add(groupId);
9330    
9331                            qPos.add(folderId);
9332    
9333                            Long count = (Long)q.uniqueResult();
9334    
9335                            return count.intValue();
9336                    }
9337                    catch (Exception e) {
9338                            throw processException(e);
9339                    }
9340                    finally {
9341                            closeSession(session);
9342                    }
9343            }
9344    
9345            /**
9346             * Returns the number of journal articles that the user has permission to view where groupId = &#63; and folderId = any &#63;.
9347             *
9348             * @param groupId the group ID
9349             * @param folderIds the folder IDs
9350             * @return the number of matching journal articles that the user has permission to view
9351             * @throws SystemException if a system exception occurred
9352             */
9353            @Override
9354            public int filterCountByG_F(long groupId, long[] folderIds)
9355                    throws SystemException {
9356                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9357                            return countByG_F(groupId, folderIds);
9358                    }
9359    
9360                    StringBundler query = new StringBundler();
9361    
9362                    query.append(_FILTER_SQL_COUNT_JOURNALARTICLE_WHERE);
9363    
9364                    boolean conjunctionable = false;
9365    
9366                    if (conjunctionable) {
9367                            query.append(WHERE_AND);
9368                    }
9369    
9370                    query.append(_FINDER_COLUMN_G_F_GROUPID_5);
9371    
9372                    conjunctionable = true;
9373    
9374                    if ((folderIds == null) || (folderIds.length > 0)) {
9375                            if (conjunctionable) {
9376                                    query.append(WHERE_AND);
9377                            }
9378    
9379                            query.append(StringPool.OPEN_PARENTHESIS);
9380    
9381                            for (int i = 0; i < folderIds.length; i++) {
9382                                    query.append(_FINDER_COLUMN_G_F_FOLDERID_5);
9383    
9384                                    if ((i + 1) < folderIds.length) {
9385                                            query.append(WHERE_OR);
9386                                    }
9387                            }
9388    
9389                            query.append(StringPool.CLOSE_PARENTHESIS);
9390    
9391                            conjunctionable = true;
9392                    }
9393    
9394                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9395                                    JournalArticle.class.getName(),
9396                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9397    
9398                    Session session = null;
9399    
9400                    try {
9401                            session = openSession();
9402    
9403                            SQLQuery q = session.createSQLQuery(sql);
9404    
9405                            q.addScalar(COUNT_COLUMN_NAME,
9406                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
9407    
9408                            QueryPos qPos = QueryPos.getInstance(q);
9409    
9410                            qPos.add(groupId);
9411    
9412                            if (folderIds != null) {
9413                                    qPos.add(folderIds);
9414                            }
9415    
9416                            Long count = (Long)q.uniqueResult();
9417    
9418                            return count.intValue();
9419                    }
9420                    catch (Exception e) {
9421                            throw processException(e);
9422                    }
9423                    finally {
9424                            closeSession(session);
9425                    }
9426            }
9427    
9428            private static final String _FINDER_COLUMN_G_F_GROUPID_2 = "journalArticle.groupId = ? AND ";
9429            private static final String _FINDER_COLUMN_G_F_GROUPID_5 = "(" +
9430                    removeConjunction(_FINDER_COLUMN_G_F_GROUPID_2) + ")";
9431            private static final String _FINDER_COLUMN_G_F_FOLDERID_2 = "journalArticle.folderId = ?";
9432            private static final String _FINDER_COLUMN_G_F_FOLDERID_5 = "(" +
9433                    removeConjunction(_FINDER_COLUMN_G_F_FOLDERID_2) + ")";
9434            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_A = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
9435                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
9436                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
9437                            "findByG_A",
9438                            new String[] {
9439                                    Long.class.getName(), String.class.getName(),
9440                                    
9441                            Integer.class.getName(), Integer.class.getName(),
9442                                    OrderByComparator.class.getName()
9443                            });
9444            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_A = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
9445                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
9446                            JournalArticleImpl.class,
9447                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_A",
9448                            new String[] { Long.class.getName(), String.class.getName() },
9449                            JournalArticleModelImpl.GROUPID_COLUMN_BITMASK |
9450                            JournalArticleModelImpl.ARTICLEID_COLUMN_BITMASK |
9451                            JournalArticleModelImpl.VERSION_COLUMN_BITMASK);
9452            public static final FinderPath FINDER_PATH_COUNT_BY_G_A = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
9453                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
9454                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_A",
9455                            new String[] { Long.class.getName(), String.class.getName() });
9456    
9457            /**
9458             * Returns all the journal articles where groupId = &#63; and articleId = &#63;.
9459             *
9460             * @param groupId the group ID
9461             * @param articleId the article ID
9462             * @return the matching journal articles
9463             * @throws SystemException if a system exception occurred
9464             */
9465            @Override
9466            public List<JournalArticle> findByG_A(long groupId, String articleId)
9467                    throws SystemException {
9468                    return findByG_A(groupId, articleId, QueryUtil.ALL_POS,
9469                            QueryUtil.ALL_POS, null);
9470            }
9471    
9472            /**
9473             * Returns a range of all the journal articles where groupId = &#63; and articleId = &#63;.
9474             *
9475             * <p>
9476             * 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.
9477             * </p>
9478             *
9479             * @param groupId the group ID
9480             * @param articleId the article ID
9481             * @param start the lower bound of the range of journal articles
9482             * @param end the upper bound of the range of journal articles (not inclusive)
9483             * @return the range of matching journal articles
9484             * @throws SystemException if a system exception occurred
9485             */
9486            @Override
9487            public List<JournalArticle> findByG_A(long groupId, String articleId,
9488                    int start, int end) throws SystemException {
9489                    return findByG_A(groupId, articleId, start, end, null);
9490            }
9491    
9492            /**
9493             * Returns an ordered range of all the journal articles where groupId = &#63; and articleId = &#63;.
9494             *
9495             * <p>
9496             * 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.
9497             * </p>
9498             *
9499             * @param groupId the group ID
9500             * @param articleId the article ID
9501             * @param start the lower bound of the range of journal articles
9502             * @param end the upper bound of the range of journal articles (not inclusive)
9503             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9504             * @return the ordered range of matching journal articles
9505             * @throws SystemException if a system exception occurred
9506             */
9507            @Override
9508            public List<JournalArticle> findByG_A(long groupId, String articleId,
9509                    int start, int end, OrderByComparator orderByComparator)
9510                    throws SystemException {
9511                    boolean pagination = true;
9512                    FinderPath finderPath = null;
9513                    Object[] finderArgs = null;
9514    
9515                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9516                                    (orderByComparator == null)) {
9517                            pagination = false;
9518                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_A;
9519                            finderArgs = new Object[] { groupId, articleId };
9520                    }
9521                    else {
9522                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_A;
9523                            finderArgs = new Object[] {
9524                                            groupId, articleId,
9525                                            
9526                                            start, end, orderByComparator
9527                                    };
9528                    }
9529    
9530                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
9531                                    finderArgs, this);
9532    
9533                    if ((list != null) && !list.isEmpty()) {
9534                            for (JournalArticle journalArticle : list) {
9535                                    if ((groupId != journalArticle.getGroupId()) ||
9536                                                    !Validator.equals(articleId,
9537                                                            journalArticle.getArticleId())) {
9538                                            list = null;
9539    
9540                                            break;
9541                                    }
9542                            }
9543                    }
9544    
9545                    if (list == null) {
9546                            StringBundler query = null;
9547    
9548                            if (orderByComparator != null) {
9549                                    query = new StringBundler(4 +
9550                                                    (orderByComparator.getOrderByFields().length * 3));
9551                            }
9552                            else {
9553                                    query = new StringBundler(4);
9554                            }
9555    
9556                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
9557    
9558                            query.append(_FINDER_COLUMN_G_A_GROUPID_2);
9559    
9560                            boolean bindArticleId = false;
9561    
9562                            if