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