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_WITH_PAGINATION_FIND_BY_C_NOTS = new FinderPath(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
4001                            JournalFolderModelImpl.FINDER_CACHE_ENABLED,
4002                            JournalFolderImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
4003                            "findByC_NotS",
4004                            new String[] {
4005                                    Long.class.getName(), Integer.class.getName(),
4006                                    
4007                            Integer.class.getName(), Integer.class.getName(),
4008                                    OrderByComparator.class.getName()
4009                            });
4010            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_NOTS = new FinderPath(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
4011                            JournalFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
4012                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByC_NotS",
4013                            new String[] { Long.class.getName(), Integer.class.getName() });
4014    
4015            /**
4016             * Returns all the journal folders where companyId = &#63; and status &ne; &#63;.
4017             *
4018             * @param companyId the company ID
4019             * @param status the status
4020             * @return the matching journal folders
4021             * @throws SystemException if a system exception occurred
4022             */
4023            @Override
4024            public List<JournalFolder> findByC_NotS(long companyId, int status)
4025                    throws SystemException {
4026                    return findByC_NotS(companyId, status, QueryUtil.ALL_POS,
4027                            QueryUtil.ALL_POS, null);
4028            }
4029    
4030            /**
4031             * Returns a range of all the journal folders where companyId = &#63; and status &ne; &#63;.
4032             *
4033             * <p>
4034             * 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.
4035             * </p>
4036             *
4037             * @param companyId the company ID
4038             * @param status the status
4039             * @param start the lower bound of the range of journal folders
4040             * @param end the upper bound of the range of journal folders (not inclusive)
4041             * @return the range of matching journal folders
4042             * @throws SystemException if a system exception occurred
4043             */
4044            @Override
4045            public List<JournalFolder> findByC_NotS(long companyId, int status,
4046                    int start, int end) throws SystemException {
4047                    return findByC_NotS(companyId, status, start, end, null);
4048            }
4049    
4050            /**
4051             * Returns an ordered range of all the journal folders where companyId = &#63; and status &ne; &#63;.
4052             *
4053             * <p>
4054             * 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.
4055             * </p>
4056             *
4057             * @param companyId the company ID
4058             * @param status the status
4059             * @param start the lower bound of the range of journal folders
4060             * @param end the upper bound of the range of journal folders (not inclusive)
4061             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4062             * @return the ordered range of matching journal folders
4063             * @throws SystemException if a system exception occurred
4064             */
4065            @Override
4066            public List<JournalFolder> findByC_NotS(long companyId, int status,
4067                    int start, int end, OrderByComparator orderByComparator)
4068                    throws SystemException {
4069                    boolean pagination = true;
4070                    FinderPath finderPath = null;
4071                    Object[] finderArgs = null;
4072    
4073                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_NOTS;
4074                    finderArgs = new Object[] {
4075                                    companyId, status,
4076                                    
4077                                    start, end, orderByComparator
4078                            };
4079    
4080                    List<JournalFolder> list = (List<JournalFolder>)FinderCacheUtil.getResult(finderPath,
4081                                    finderArgs, this);
4082    
4083                    if ((list != null) && !list.isEmpty()) {
4084                            for (JournalFolder journalFolder : list) {
4085                                    if ((companyId != journalFolder.getCompanyId()) ||
4086                                                    (status != journalFolder.getStatus())) {
4087                                            list = null;
4088    
4089                                            break;
4090                                    }
4091                            }
4092                    }
4093    
4094                    if (list == null) {
4095                            StringBundler query = null;
4096    
4097                            if (orderByComparator != null) {
4098                                    query = new StringBundler(4 +
4099                                                    (orderByComparator.getOrderByFields().length * 3));
4100                            }
4101                            else {
4102                                    query = new StringBundler(4);
4103                            }
4104    
4105                            query.append(_SQL_SELECT_JOURNALFOLDER_WHERE);
4106    
4107                            query.append(_FINDER_COLUMN_C_NOTS_COMPANYID_2);
4108    
4109                            query.append(_FINDER_COLUMN_C_NOTS_STATUS_2);
4110    
4111                            if (orderByComparator != null) {
4112                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4113                                            orderByComparator);
4114                            }
4115                            else
4116                             if (pagination) {
4117                                    query.append(JournalFolderModelImpl.ORDER_BY_JPQL);
4118                            }
4119    
4120                            String sql = query.toString();
4121    
4122                            Session session = null;
4123    
4124                            try {
4125                                    session = openSession();
4126    
4127                                    Query q = session.createQuery(sql);
4128    
4129                                    QueryPos qPos = QueryPos.getInstance(q);
4130    
4131                                    qPos.add(companyId);
4132    
4133                                    qPos.add(status);
4134    
4135                                    if (!pagination) {
4136                                            list = (List<JournalFolder>)QueryUtil.list(q, getDialect(),
4137                                                            start, end, false);
4138    
4139                                            Collections.sort(list);
4140    
4141                                            list = new UnmodifiableList<JournalFolder>(list);
4142                                    }
4143                                    else {
4144                                            list = (List<JournalFolder>)QueryUtil.list(q, getDialect(),
4145                                                            start, end);
4146                                    }
4147    
4148                                    cacheResult(list);
4149    
4150                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4151                            }
4152                            catch (Exception e) {
4153                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4154    
4155                                    throw processException(e);
4156                            }
4157                            finally {
4158                                    closeSession(session);
4159                            }
4160                    }
4161    
4162                    return list;
4163            }
4164    
4165            /**
4166             * Returns the first journal folder in the ordered set where companyId = &#63; and status &ne; &#63;.
4167             *
4168             * @param companyId the company ID
4169             * @param status the status
4170             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4171             * @return the first matching journal folder
4172             * @throws com.liferay.portlet.journal.NoSuchFolderException if a matching journal folder could not be found
4173             * @throws SystemException if a system exception occurred
4174             */
4175            @Override
4176            public JournalFolder findByC_NotS_First(long companyId, int status,
4177                    OrderByComparator orderByComparator)
4178                    throws NoSuchFolderException, SystemException {
4179                    JournalFolder journalFolder = fetchByC_NotS_First(companyId, status,
4180                                    orderByComparator);
4181    
4182                    if (journalFolder != null) {
4183                            return journalFolder;
4184                    }
4185    
4186                    StringBundler msg = new StringBundler(6);
4187    
4188                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4189    
4190                    msg.append("companyId=");
4191                    msg.append(companyId);
4192    
4193                    msg.append(", status=");
4194                    msg.append(status);
4195    
4196                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4197    
4198                    throw new NoSuchFolderException(msg.toString());
4199            }
4200    
4201            /**
4202             * Returns the first journal folder in the ordered set where companyId = &#63; and status &ne; &#63;.
4203             *
4204             * @param companyId the company ID
4205             * @param status the status
4206             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4207             * @return the first matching journal folder, or <code>null</code> if a matching journal folder could not be found
4208             * @throws SystemException if a system exception occurred
4209             */
4210            @Override
4211            public JournalFolder fetchByC_NotS_First(long companyId, int status,
4212                    OrderByComparator orderByComparator) throws SystemException {
4213                    List<JournalFolder> list = findByC_NotS(companyId, status, 0, 1,
4214                                    orderByComparator);
4215    
4216                    if (!list.isEmpty()) {
4217                            return list.get(0);
4218                    }
4219    
4220                    return null;
4221            }
4222    
4223            /**
4224             * Returns the last journal folder in the ordered set where companyId = &#63; and status &ne; &#63;.
4225             *
4226             * @param companyId the company ID
4227             * @param status the status
4228             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4229             * @return the last matching journal folder
4230             * @throws com.liferay.portlet.journal.NoSuchFolderException if a matching journal folder could not be found
4231             * @throws SystemException if a system exception occurred
4232             */
4233            @Override
4234            public JournalFolder findByC_NotS_Last(long companyId, int status,
4235                    OrderByComparator orderByComparator)
4236                    throws NoSuchFolderException, SystemException {
4237                    JournalFolder journalFolder = fetchByC_NotS_Last(companyId, status,
4238                                    orderByComparator);
4239    
4240                    if (journalFolder != null) {
4241                            return journalFolder;
4242                    }
4243    
4244                    StringBundler msg = new StringBundler(6);
4245    
4246                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4247    
4248                    msg.append("companyId=");
4249                    msg.append(companyId);
4250    
4251                    msg.append(", status=");
4252                    msg.append(status);
4253    
4254                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4255    
4256                    throw new NoSuchFolderException(msg.toString());
4257            }
4258    
4259            /**
4260             * Returns the last journal folder in the ordered set where companyId = &#63; and status &ne; &#63;.
4261             *
4262             * @param companyId the company ID
4263             * @param status the status
4264             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4265             * @return the last matching journal folder, or <code>null</code> if a matching journal folder could not be found
4266             * @throws SystemException if a system exception occurred
4267             */
4268            @Override
4269            public JournalFolder fetchByC_NotS_Last(long companyId, int status,
4270                    OrderByComparator orderByComparator) throws SystemException {
4271                    int count = countByC_NotS(companyId, status);
4272    
4273                    if (count == 0) {
4274                            return null;
4275                    }
4276    
4277                    List<JournalFolder> list = findByC_NotS(companyId, status, count - 1,
4278                                    count, orderByComparator);
4279    
4280                    if (!list.isEmpty()) {
4281                            return list.get(0);
4282                    }
4283    
4284                    return null;
4285            }
4286    
4287            /**
4288             * Returns the journal folders before and after the current journal folder in the ordered set where companyId = &#63; and status &ne; &#63;.
4289             *
4290             * @param folderId the primary key of the current journal folder
4291             * @param companyId the company ID
4292             * @param status the status
4293             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4294             * @return the previous, current, and next journal folder
4295             * @throws com.liferay.portlet.journal.NoSuchFolderException if a journal folder with the primary key could not be found
4296             * @throws SystemException if a system exception occurred
4297             */
4298            @Override
4299            public JournalFolder[] findByC_NotS_PrevAndNext(long folderId,
4300                    long companyId, int status, OrderByComparator orderByComparator)
4301                    throws NoSuchFolderException, SystemException {
4302                    JournalFolder journalFolder = findByPrimaryKey(folderId);
4303    
4304                    Session session = null;
4305    
4306                    try {
4307                            session = openSession();
4308    
4309                            JournalFolder[] array = new JournalFolderImpl[3];
4310    
4311                            array[0] = getByC_NotS_PrevAndNext(session, journalFolder,
4312                                            companyId, status, orderByComparator, true);
4313    
4314                            array[1] = journalFolder;
4315    
4316                            array[2] = getByC_NotS_PrevAndNext(session, journalFolder,
4317                                            companyId, status, orderByComparator, false);
4318    
4319                            return array;
4320                    }
4321                    catch (Exception e) {
4322                            throw processException(e);
4323                    }
4324                    finally {
4325                            closeSession(session);
4326                    }
4327            }
4328    
4329            protected JournalFolder getByC_NotS_PrevAndNext(Session session,
4330                    JournalFolder journalFolder, long companyId, int status,
4331                    OrderByComparator orderByComparator, boolean previous) {
4332                    StringBundler query = null;
4333    
4334                    if (orderByComparator != null) {
4335                            query = new StringBundler(6 +
4336                                            (orderByComparator.getOrderByFields().length * 6));
4337                    }
4338                    else {
4339                            query = new StringBundler(3);
4340                    }
4341    
4342                    query.append(_SQL_SELECT_JOURNALFOLDER_WHERE);
4343    
4344                    query.append(_FINDER_COLUMN_C_NOTS_COMPANYID_2);
4345    
4346                    query.append(_FINDER_COLUMN_C_NOTS_STATUS_2);
4347    
4348                    if (orderByComparator != null) {
4349                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4350    
4351                            if (orderByConditionFields.length > 0) {
4352                                    query.append(WHERE_AND);
4353                            }
4354    
4355                            for (int i = 0; i < orderByConditionFields.length; i++) {
4356                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4357                                    query.append(orderByConditionFields[i]);
4358    
4359                                    if ((i + 1) < orderByConditionFields.length) {
4360                                            if (orderByComparator.isAscending() ^ previous) {
4361                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4362                                            }
4363                                            else {
4364                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4365                                            }
4366                                    }
4367                                    else {
4368                                            if (orderByComparator.isAscending() ^ previous) {
4369                                                    query.append(WHERE_GREATER_THAN);
4370                                            }
4371                                            else {
4372                                                    query.append(WHERE_LESSER_THAN);
4373                                            }
4374                                    }
4375                            }
4376    
4377                            query.append(ORDER_BY_CLAUSE);
4378    
4379                            String[] orderByFields = orderByComparator.getOrderByFields();
4380    
4381                            for (int i = 0; i < orderByFields.length; i++) {
4382                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4383                                    query.append(orderByFields[i]);
4384    
4385                                    if ((i + 1) < orderByFields.length) {
4386                                            if (orderByComparator.isAscending() ^ previous) {
4387                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4388                                            }
4389                                            else {
4390                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4391                                            }
4392                                    }
4393                                    else {
4394                                            if (orderByComparator.isAscending() ^ previous) {
4395                                                    query.append(ORDER_BY_ASC);
4396                                            }
4397                                            else {
4398                                                    query.append(ORDER_BY_DESC);
4399                                            }
4400                                    }
4401                            }
4402                    }
4403                    else {
4404                            query.append(JournalFolderModelImpl.ORDER_BY_JPQL);
4405                    }
4406    
4407                    String sql = query.toString();
4408    
4409                    Query q = session.createQuery(sql);
4410    
4411                    q.setFirstResult(0);
4412                    q.setMaxResults(2);
4413    
4414                    QueryPos qPos = QueryPos.getInstance(q);
4415    
4416                    qPos.add(companyId);
4417    
4418                    qPos.add(status);
4419    
4420                    if (orderByComparator != null) {
4421                            Object[] values = orderByComparator.getOrderByConditionValues(journalFolder);
4422    
4423                            for (Object value : values) {
4424                                    qPos.add(value);
4425                            }
4426                    }
4427    
4428                    List<JournalFolder> list = q.list();
4429    
4430                    if (list.size() == 2) {
4431                            return list.get(1);
4432                    }
4433                    else {
4434                            return null;
4435                    }
4436            }
4437    
4438            /**
4439             * Removes all the journal folders where companyId = &#63; and status &ne; &#63; from the database.
4440             *
4441             * @param companyId the company ID
4442             * @param status the status
4443             * @throws SystemException if a system exception occurred
4444             */
4445            @Override
4446            public void removeByC_NotS(long companyId, int status)
4447                    throws SystemException {
4448                    for (JournalFolder journalFolder : findByC_NotS(companyId, status,
4449                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4450                            remove(journalFolder);
4451                    }
4452            }
4453    
4454            /**
4455             * Returns the number of journal folders where companyId = &#63; and status &ne; &#63;.
4456             *
4457             * @param companyId the company ID
4458             * @param status the status
4459             * @return the number of matching journal folders
4460             * @throws SystemException if a system exception occurred
4461             */
4462            @Override
4463            public int countByC_NotS(long companyId, int status)
4464                    throws SystemException {
4465                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_NOTS;
4466    
4467                    Object[] finderArgs = new Object[] { companyId, status };
4468    
4469                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4470                                    this);
4471    
4472                    if (count == null) {
4473                            StringBundler query = new StringBundler(3);
4474    
4475                            query.append(_SQL_COUNT_JOURNALFOLDER_WHERE);
4476    
4477                            query.append(_FINDER_COLUMN_C_NOTS_COMPANYID_2);
4478    
4479                            query.append(_FINDER_COLUMN_C_NOTS_STATUS_2);
4480    
4481                            String sql = query.toString();
4482    
4483                            Session session = null;
4484    
4485                            try {
4486                                    session = openSession();
4487    
4488                                    Query q = session.createQuery(sql);
4489    
4490                                    QueryPos qPos = QueryPos.getInstance(q);
4491    
4492                                    qPos.add(companyId);
4493    
4494                                    qPos.add(status);
4495    
4496                                    count = (Long)q.uniqueResult();
4497    
4498                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4499                            }
4500                            catch (Exception e) {
4501                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4502    
4503                                    throw processException(e);
4504                            }
4505                            finally {
4506                                    closeSession(session);
4507                            }
4508                    }
4509    
4510                    return count.intValue();
4511            }
4512    
4513            private static final String _FINDER_COLUMN_C_NOTS_COMPANYID_2 = "journalFolder.companyId = ? AND ";
4514            private static final String _FINDER_COLUMN_C_NOTS_STATUS_2 = "journalFolder.status != ?";
4515            public static final FinderPath FINDER_PATH_FETCH_BY_G_P_N = new FinderPath(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
4516                            JournalFolderModelImpl.FINDER_CACHE_ENABLED,
4517                            JournalFolderImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByG_P_N",
4518                            new String[] {
4519                                    Long.class.getName(), Long.class.getName(),
4520                                    String.class.getName()
4521                            },
4522                            JournalFolderModelImpl.GROUPID_COLUMN_BITMASK |
4523                            JournalFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
4524                            JournalFolderModelImpl.NAME_COLUMN_BITMASK);
4525            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_N = new FinderPath(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
4526                            JournalFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
4527                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_N",
4528                            new String[] {
4529                                    Long.class.getName(), Long.class.getName(),
4530                                    String.class.getName()
4531                            });
4532    
4533            /**
4534             * 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.
4535             *
4536             * @param groupId the group ID
4537             * @param parentFolderId the parent folder ID
4538             * @param name the name
4539             * @return the matching journal folder
4540             * @throws com.liferay.portlet.journal.NoSuchFolderException if a matching journal folder could not be found
4541             * @throws SystemException if a system exception occurred
4542             */
4543            @Override
4544            public JournalFolder findByG_P_N(long groupId, long parentFolderId,
4545                    String name) throws NoSuchFolderException, SystemException {
4546                    JournalFolder journalFolder = fetchByG_P_N(groupId, parentFolderId, name);
4547    
4548                    if (journalFolder == null) {
4549                            StringBundler msg = new StringBundler(8);
4550    
4551                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4552    
4553                            msg.append("groupId=");
4554                            msg.append(groupId);
4555    
4556                            msg.append(", parentFolderId=");
4557                            msg.append(parentFolderId);
4558    
4559                            msg.append(", name=");
4560                            msg.append(name);
4561    
4562                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4563    
4564                            if (_log.isWarnEnabled()) {
4565                                    _log.warn(msg.toString());
4566                            }
4567    
4568                            throw new NoSuchFolderException(msg.toString());
4569                    }
4570    
4571                    return journalFolder;
4572            }
4573    
4574            /**
4575             * 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.
4576             *
4577             * @param groupId the group ID
4578             * @param parentFolderId the parent folder ID
4579             * @param name the name
4580             * @return the matching journal folder, or <code>null</code> if a matching journal folder could not be found
4581             * @throws SystemException if a system exception occurred
4582             */
4583            @Override
4584            public JournalFolder fetchByG_P_N(long groupId, long parentFolderId,
4585                    String name) throws SystemException {
4586                    return fetchByG_P_N(groupId, parentFolderId, name, true);
4587            }
4588    
4589            /**
4590             * 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.
4591             *
4592             * @param groupId the group ID
4593             * @param parentFolderId the parent folder ID
4594             * @param name the name
4595             * @param retrieveFromCache whether to use the finder cache
4596             * @return the matching journal folder, or <code>null</code> if a matching journal folder could not be found
4597             * @throws SystemException if a system exception occurred
4598             */
4599            @Override
4600            public JournalFolder fetchByG_P_N(long groupId, long parentFolderId,
4601                    String name, boolean retrieveFromCache) throws SystemException {
4602                    Object[] finderArgs = new Object[] { groupId, parentFolderId, name };
4603    
4604                    Object result = null;
4605    
4606                    if (retrieveFromCache) {
4607                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_P_N,
4608                                            finderArgs, this);
4609                    }
4610    
4611                    if (result instanceof JournalFolder) {
4612                            JournalFolder journalFolder = (JournalFolder)result;
4613    
4614                            if ((groupId != journalFolder.getGroupId()) ||
4615                                            (parentFolderId != journalFolder.getParentFolderId()) ||
4616                                            !Validator.equals(name, journalFolder.getName())) {
4617                                    result = null;
4618                            }
4619                    }
4620    
4621                    if (result == null) {
4622                            StringBundler query = new StringBundler(5);
4623    
4624                            query.append(_SQL_SELECT_JOURNALFOLDER_WHERE);
4625    
4626                            query.append(_FINDER_COLUMN_G_P_N_GROUPID_2);
4627    
4628                            query.append(_FINDER_COLUMN_G_P_N_PARENTFOLDERID_2);
4629    
4630                            boolean bindName = false;
4631    
4632                            if (name == null) {
4633                                    query.append(_FINDER_COLUMN_G_P_N_NAME_1);
4634                            }
4635                            else if (name.equals(StringPool.BLANK)) {
4636                                    query.append(_FINDER_COLUMN_G_P_N_NAME_3);
4637                            }
4638                            else {
4639                                    bindName = true;
4640    
4641                                    query.append(_FINDER_COLUMN_G_P_N_NAME_2);
4642                            }
4643    
4644                            String sql = query.toString();
4645    
4646                            Session session = null;
4647    
4648                            try {
4649                                    session = openSession();
4650    
4651                                    Query q = session.createQuery(sql);
4652    
4653                                    QueryPos qPos = QueryPos.getInstance(q);
4654    
4655                                    qPos.add(groupId);
4656    
4657                                    qPos.add(parentFolderId);
4658    
4659                                    if (bindName) {
4660                                            qPos.add(name);
4661                                    }
4662    
4663                                    List<JournalFolder> list = q.list();
4664    
4665                                    if (list.isEmpty()) {
4666                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N,
4667                                                    finderArgs, list);
4668                                    }
4669                                    else {
4670                                            JournalFolder journalFolder = list.get(0);
4671    
4672                                            result = journalFolder;
4673    
4674                                            cacheResult(journalFolder);
4675    
4676                                            if ((journalFolder.getGroupId() != groupId) ||
4677                                                            (journalFolder.getParentFolderId() != parentFolderId) ||
4678                                                            (journalFolder.getName() == null) ||
4679                                                            !journalFolder.getName().equals(name)) {
4680                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N,
4681                                                            finderArgs, journalFolder);
4682                                            }
4683                                    }
4684                            }
4685                            catch (Exception e) {
4686                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_N,
4687                                            finderArgs);
4688    
4689                                    throw processException(e);
4690                            }
4691                            finally {
4692                                    closeSession(session);
4693                            }
4694                    }
4695    
4696                    if (result instanceof List<?>) {
4697                            return null;
4698                    }
4699                    else {
4700                            return (JournalFolder)result;
4701                    }
4702            }
4703    
4704            /**
4705             * Removes the journal folder where groupId = &#63; and parentFolderId = &#63; and name = &#63; from the database.
4706             *
4707             * @param groupId the group ID
4708             * @param parentFolderId the parent folder ID
4709             * @param name the name
4710             * @return the journal folder that was removed
4711             * @throws SystemException if a system exception occurred
4712             */
4713            @Override
4714            public JournalFolder removeByG_P_N(long groupId, long parentFolderId,
4715                    String name) throws NoSuchFolderException, SystemException {
4716                    JournalFolder journalFolder = findByG_P_N(groupId, parentFolderId, name);
4717    
4718                    return remove(journalFolder);
4719            }
4720    
4721            /**
4722             * Returns the number of journal folders where groupId = &#63; and parentFolderId = &#63; and name = &#63;.
4723             *
4724             * @param groupId the group ID
4725             * @param parentFolderId the parent folder ID
4726             * @param name the name
4727             * @return the number of matching journal folders
4728             * @throws SystemException if a system exception occurred
4729             */
4730            @Override
4731            public int countByG_P_N(long groupId, long parentFolderId, String name)
4732                    throws SystemException {
4733                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_N;
4734    
4735                    Object[] finderArgs = new Object[] { groupId, parentFolderId, name };
4736    
4737                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4738                                    this);
4739    
4740                    if (count == null) {
4741                            StringBundler query = new StringBundler(4);
4742    
4743                            query.append(_SQL_COUNT_JOURNALFOLDER_WHERE);
4744    
4745                            query.append(_FINDER_COLUMN_G_P_N_GROUPID_2);
4746    
4747                            query.append(_FINDER_COLUMN_G_P_N_PARENTFOLDERID_2);
4748    
4749                            boolean bindName = false;
4750    
4751                            if (name == null) {
4752                                    query.append(_FINDER_COLUMN_G_P_N_NAME_1);
4753                            }
4754                            else if (name.equals(StringPool.BLANK)) {
4755                                    query.append(_FINDER_COLUMN_G_P_N_NAME_3);
4756                            }
4757                            else {
4758                                    bindName = true;
4759    
4760                                    query.append(_FINDER_COLUMN_G_P_N_NAME_2);
4761                            }
4762    
4763                            String sql = query.toString();
4764    
4765                            Session session = null;
4766    
4767                            try {
4768                                    session = openSession();
4769    
4770                                    Query q = session.createQuery(sql);
4771    
4772                                    QueryPos qPos = QueryPos.getInstance(q);
4773    
4774                                    qPos.add(groupId);
4775    
4776                                    qPos.add(parentFolderId);
4777    
4778                                    if (bindName) {
4779                                            qPos.add(name);
4780                                    }
4781    
4782                                    count = (Long)q.uniqueResult();
4783    
4784                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4785                            }
4786                            catch (Exception e) {
4787                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4788    
4789                                    throw processException(e);
4790                            }
4791                            finally {
4792                                    closeSession(session);
4793                            }
4794                    }
4795    
4796                    return count.intValue();
4797            }
4798    
4799            private static final String _FINDER_COLUMN_G_P_N_GROUPID_2 = "journalFolder.groupId = ? AND ";
4800            private static final String _FINDER_COLUMN_G_P_N_PARENTFOLDERID_2 = "journalFolder.parentFolderId = ? AND ";
4801            private static final String _FINDER_COLUMN_G_P_N_NAME_1 = "journalFolder.name IS NULL";
4802            private static final String _FINDER_COLUMN_G_P_N_NAME_2 = "journalFolder.name = ?";
4803            private static final String _FINDER_COLUMN_G_P_N_NAME_3 = "(journalFolder.name IS NULL OR journalFolder.name = '')";
4804            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_S = new FinderPath(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
4805                            JournalFolderModelImpl.FINDER_CACHE_ENABLED,
4806                            JournalFolderImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
4807                            "findByG_P_S",
4808                            new String[] {
4809                                    Long.class.getName(), Long.class.getName(),
4810                                    Integer.class.getName(),
4811                                    
4812                            Integer.class.getName(), Integer.class.getName(),
4813                                    OrderByComparator.class.getName()
4814                            });
4815            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_S = new FinderPath(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
4816                            JournalFolderModelImpl.FINDER_CACHE_ENABLED,
4817                            JournalFolderImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
4818                            "findByG_P_S",
4819                            new String[] {
4820                                    Long.class.getName(), Long.class.getName(),
4821                                    Integer.class.getName()
4822                            },
4823                            JournalFolderModelImpl.GROUPID_COLUMN_BITMASK |
4824                            JournalFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
4825                            JournalFolderModelImpl.STATUS_COLUMN_BITMASK |
4826                            JournalFolderModelImpl.NAME_COLUMN_BITMASK);
4827            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_S = new FinderPath(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
4828                            JournalFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
4829                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_S",
4830                            new String[] {
4831                                    Long.class.getName(), Long.class.getName(),
4832                                    Integer.class.getName()
4833                            });
4834    
4835            /**
4836             * Returns all the journal folders where groupId = &#63; and parentFolderId = &#63; and status = &#63;.
4837             *
4838             * @param groupId the group ID
4839             * @param parentFolderId the parent folder ID
4840             * @param status the status
4841             * @return the matching journal folders
4842             * @throws SystemException if a system exception occurred
4843             */
4844            @Override
4845            public List<JournalFolder> findByG_P_S(long groupId, long parentFolderId,
4846                    int status) throws SystemException {
4847                    return findByG_P_S(groupId, parentFolderId, status, QueryUtil.ALL_POS,
4848                            QueryUtil.ALL_POS, null);
4849            }
4850    
4851            /**
4852             * Returns a range of all the journal folders where groupId = &#63; and parentFolderId = &#63; and status = &#63;.
4853             *
4854             * <p>
4855             * 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.
4856             * </p>
4857             *
4858             * @param groupId the group ID
4859             * @param parentFolderId the parent folder ID
4860             * @param status the status
4861             * @param start the lower bound of the range of journal folders
4862             * @param end the upper bound of the range of journal folders (not inclusive)
4863             * @return the range of matching journal folders
4864             * @throws SystemException if a system exception occurred
4865             */
4866            @Override
4867            public List<JournalFolder> findByG_P_S(long groupId, long parentFolderId,
4868                    int status, int start, int end) throws SystemException {
4869                    return findByG_P_S(groupId, parentFolderId, status, start, end, null);
4870            }
4871    
4872            /**
4873             * Returns an ordered range of all the journal folders where groupId = &#63; and parentFolderId = &#63; and status = &#63;.
4874             *
4875             * <p>
4876             * 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.
4877             * </p>
4878             *
4879             * @param groupId the group ID
4880             * @param parentFolderId the parent folder ID
4881             * @param status the status
4882             * @param start the lower bound of the range of journal folders
4883             * @param end the upper bound of the range of journal folders (not inclusive)
4884             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4885             * @return the ordered range of matching journal folders
4886             * @throws SystemException if a system exception occurred
4887             */
4888            @Override
4889            public List<JournalFolder> findByG_P_S(long groupId, long parentFolderId,
4890                    int status, int start, int end, OrderByComparator orderByComparator)
4891                    throws SystemException {
4892                    boolean pagination = true;
4893                    FinderPath finderPath = null;
4894                    Object[] finderArgs = null;
4895    
4896                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4897                                    (orderByComparator == null)) {
4898                            pagination = false;
4899                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_S;
4900                            finderArgs = new Object[] { groupId, parentFolderId, status };
4901                    }
4902                    else {
4903                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_S;
4904                            finderArgs = new Object[] {
4905                                            groupId, parentFolderId, status,
4906                                            
4907                                            start, end, orderByComparator
4908                                    };
4909                    }
4910    
4911                    List<JournalFolder> list = (List<JournalFolder>)FinderCacheUtil.getResult(finderPath,
4912                                    finderArgs, this);
4913    
4914                    if ((list != null) && !list.isEmpty()) {
4915                            for (JournalFolder journalFolder : list) {
4916                                    if ((groupId != journalFolder.getGroupId()) ||
4917                                                    (parentFolderId != journalFolder.getParentFolderId()) ||
4918                                                    (status != journalFolder.getStatus())) {
4919                                            list = null;
4920    
4921                                            break;
4922                                    }
4923                            }
4924                    }
4925    
4926                    if (list == null) {
4927                            StringBundler query = null;
4928    
4929                            if (orderByComparator != null) {
4930                                    query = new StringBundler(5 +
4931                                                    (orderByComparator.getOrderByFields().length * 3));
4932                            }
4933                            else {
4934                                    query = new StringBundler(5);
4935                            }
4936    
4937                            query.append(_SQL_SELECT_JOURNALFOLDER_WHERE);
4938    
4939                            query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
4940    
4941                            query.append(_FINDER_COLUMN_G_P_S_PARENTFOLDERID_2);
4942    
4943                            query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
4944    
4945                            if (orderByComparator != null) {
4946                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4947                                            orderByComparator);
4948                            }
4949                            else
4950                             if (pagination) {
4951                                    query.append(JournalFolderModelImpl.ORDER_BY_JPQL);
4952                            }
4953    
4954                            String sql = query.toString();
4955    
4956                            Session session = null;
4957    
4958                            try {
4959                                    session = openSession();
4960    
4961                                    Query q = session.createQuery(sql);
4962    
4963                                    QueryPos qPos = QueryPos.getInstance(q);
4964    
4965                                    qPos.add(groupId);
4966    
4967                                    qPos.add(parentFolderId);
4968    
4969                                    qPos.add(status);
4970    
4971                                    if (!pagination) {
4972                                            list = (List<JournalFolder>)QueryUtil.list(q, getDialect(),
4973                                                            start, end, false);
4974    
4975                                            Collections.sort(list);
4976    
4977                                            list = new UnmodifiableList<JournalFolder>(list);
4978                                    }
4979                                    else {
4980                                            list = (List<JournalFolder>)QueryUtil.list(q, getDialect(),
4981                                                            start, end);
4982                                    }
4983    
4984                                    cacheResult(list);
4985    
4986                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4987                            }
4988                            catch (Exception e) {
4989                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4990    
4991                                    throw processException(e);
4992                            }
4993                            finally {
4994                                    closeSession(session);
4995                            }
4996                    }
4997    
4998                    return list;
4999            }
5000    
5001            /**
5002             * Returns the first journal folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and status = &#63;.
5003             *
5004             * @param groupId the group ID
5005             * @param parentFolderId the parent folder ID
5006             * @param status the status
5007             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5008             * @return the first matching journal folder
5009             * @throws com.liferay.portlet.journal.NoSuchFolderException if a matching journal folder could not be found
5010             * @throws SystemException if a system exception occurred
5011             */
5012            @Override
5013            public JournalFolder findByG_P_S_First(long groupId, long parentFolderId,
5014                    int status, OrderByComparator orderByComparator)
5015                    throws NoSuchFolderException, SystemException {
5016                    JournalFolder journalFolder = fetchByG_P_S_First(groupId,
5017                                    parentFolderId, status, orderByComparator);
5018    
5019                    if (journalFolder != null) {
5020                            return journalFolder;
5021                    }
5022    
5023                    StringBundler msg = new StringBundler(8);
5024    
5025                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5026    
5027                    msg.append("groupId=");
5028                    msg.append(groupId);
5029    
5030                    msg.append(", parentFolderId=");
5031                    msg.append(parentFolderId);
5032    
5033                    msg.append(", status=");
5034                    msg.append(status);
5035    
5036                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5037    
5038                    throw new NoSuchFolderException(msg.toString());
5039            }
5040    
5041            /**
5042             * Returns the first journal folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and status = &#63;.
5043             *
5044             * @param groupId the group ID
5045             * @param parentFolderId the parent folder ID
5046             * @param status the status
5047             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5048             * @return the first matching journal folder, or <code>null</code> if a matching journal folder could not be found
5049             * @throws SystemException if a system exception occurred
5050             */
5051            @Override
5052            public JournalFolder fetchByG_P_S_First(long groupId, long parentFolderId,
5053                    int status, OrderByComparator orderByComparator)
5054                    throws SystemException {
5055                    List<JournalFolder> list = findByG_P_S(groupId, parentFolderId, status,
5056                                    0, 1, orderByComparator);
5057    
5058                    if (!list.isEmpty()) {
5059                            return list.get(0);
5060                    }
5061    
5062                    return null;
5063            }
5064    
5065            /**
5066             * Returns the last journal folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and status = &#63;.
5067             *
5068             * @param groupId the group ID
5069             * @param parentFolderId the parent folder ID
5070             * @param status the status
5071             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5072             * @return the last matching journal folder
5073             * @throws com.liferay.portlet.journal.NoSuchFolderException if a matching journal folder could not be found
5074             * @throws SystemException if a system exception occurred
5075             */
5076            @Override
5077            public JournalFolder findByG_P_S_Last(long groupId, long parentFolderId,
5078                    int status, OrderByComparator orderByComparator)
5079                    throws NoSuchFolderException, SystemException {
5080                    JournalFolder journalFolder = fetchByG_P_S_Last(groupId,
5081                                    parentFolderId, status, orderByComparator);
5082    
5083                    if (journalFolder != null) {
5084                            return journalFolder;
5085                    }
5086    
5087                    StringBundler msg = new StringBundler(8);
5088    
5089                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5090    
5091                    msg.append("groupId=");
5092                    msg.append(groupId);
5093    
5094                    msg.append(", parentFolderId=");
5095                    msg.append(parentFolderId);
5096    
5097                    msg.append(", status=");
5098                    msg.append(status);
5099    
5100                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5101    
5102                    throw new NoSuchFolderException(msg.toString());
5103            }
5104    
5105            /**
5106             * Returns the last journal folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and status = &#63;.
5107             *
5108             * @param groupId the group ID
5109             * @param parentFolderId the parent folder ID
5110             * @param status the status
5111             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5112             * @return the last matching journal folder, or <code>null</code> if a matching journal folder could not be found
5113             * @throws SystemException if a system exception occurred
5114             */
5115            @Override
5116            public JournalFolder fetchByG_P_S_Last(long groupId, long parentFolderId,
5117                    int status, OrderByComparator orderByComparator)
5118                    throws SystemException {
5119                    int count = countByG_P_S(groupId, parentFolderId, status);
5120    
5121                    if (count == 0) {
5122                            return null;
5123                    }
5124    
5125                    List<JournalFolder> list = findByG_P_S(groupId, parentFolderId, status,
5126                                    count - 1, count, orderByComparator);
5127    
5128                    if (!list.isEmpty()) {
5129                            return list.get(0);
5130                    }
5131    
5132                    return null;
5133            }
5134    
5135            /**
5136             * Returns the journal folders before and after the current journal folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and status = &#63;.
5137             *
5138             * @param folderId the primary key of the current journal folder
5139             * @param groupId the group ID
5140             * @param parentFolderId the parent folder ID
5141             * @param status the status
5142             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5143             * @return the previous, current, and next journal folder
5144             * @throws com.liferay.portlet.journal.NoSuchFolderException if a journal folder with the primary key could not be found
5145             * @throws SystemException if a system exception occurred
5146             */
5147            @Override
5148            public JournalFolder[] findByG_P_S_PrevAndNext(long folderId, long groupId,
5149                    long parentFolderId, int status, OrderByComparator orderByComparator)
5150                    throws NoSuchFolderException, SystemException {
5151                    JournalFolder journalFolder = findByPrimaryKey(folderId);
5152    
5153                    Session session = null;
5154    
5155                    try {
5156                            session = openSession();
5157    
5158                            JournalFolder[] array = new JournalFolderImpl[3];
5159    
5160                            array[0] = getByG_P_S_PrevAndNext(session, journalFolder, groupId,
5161                                            parentFolderId, status, orderByComparator, true);
5162    
5163                            array[1] = journalFolder;
5164    
5165                            array[2] = getByG_P_S_PrevAndNext(session, journalFolder, groupId,
5166                                            parentFolderId, status, orderByComparator, false);
5167    
5168                            return array;
5169                    }
5170                    catch (Exception e) {
5171                            throw processException(e);
5172                    }
5173                    finally {
5174                            closeSession(session);
5175                    }
5176            }
5177    
5178            protected JournalFolder getByG_P_S_PrevAndNext(Session session,
5179                    JournalFolder journalFolder, long groupId, long parentFolderId,
5180                    int status, OrderByComparator orderByComparator, boolean previous) {
5181                    StringBundler query = null;
5182    
5183                    if (orderByComparator != null) {
5184                            query = new StringBundler(6 +
5185                                            (orderByComparator.getOrderByFields().length * 6));
5186                    }
5187                    else {
5188                            query = new StringBundler(3);
5189                    }
5190    
5191                    query.append(_SQL_SELECT_JOURNALFOLDER_WHERE);
5192    
5193                    query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
5194    
5195                    query.append(_FINDER_COLUMN_G_P_S_PARENTFOLDERID_2);
5196    
5197                    query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
5198    
5199                    if (orderByComparator != null) {
5200                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5201    
5202                            if (orderByConditionFields.length > 0) {
5203                                    query.append(WHERE_AND);
5204                            }
5205    
5206                            for (int i = 0; i < orderByConditionFields.length; i++) {
5207                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5208                                    query.append(orderByConditionFields[i]);
5209    
5210                                    if ((i + 1) < orderByConditionFields.length) {
5211                                            if (orderByComparator.isAscending() ^ previous) {
5212                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5213                                            }
5214                                            else {
5215                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5216                                            }
5217                                    }
5218                                    else {
5219                                            if (orderByComparator.isAscending() ^ previous) {
5220                                                    query.append(WHERE_GREATER_THAN);
5221                                            }
5222                                            else {
5223                                                    query.append(WHERE_LESSER_THAN);
5224                                            }
5225                                    }
5226                            }
5227    
5228                            query.append(ORDER_BY_CLAUSE);
5229    
5230                            String[] orderByFields = orderByComparator.getOrderByFields();
5231    
5232                            for (int i = 0; i < orderByFields.length; i++) {
5233                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5234                                    query.append(orderByFields[i]);
5235    
5236                                    if ((i + 1) < orderByFields.length) {
5237                                            if (orderByComparator.isAscending() ^ previous) {
5238                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5239                                            }
5240                                            else {
5241                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5242                                            }
5243                                    }
5244                                    else {
5245                                            if (orderByComparator.isAscending() ^ previous) {
5246                                                    query.append(ORDER_BY_ASC);
5247                                            }
5248                                            else {
5249                                                    query.append(ORDER_BY_DESC);
5250                                            }
5251                                    }
5252                            }
5253                    }
5254                    else {
5255                            query.append(JournalFolderModelImpl.ORDER_BY_JPQL);
5256                    }
5257    
5258                    String sql = query.toString();
5259    
5260                    Query q = session.createQuery(sql);
5261    
5262                    q.setFirstResult(0);
5263                    q.setMaxResults(2);
5264    
5265                    QueryPos qPos = QueryPos.getInstance(q);
5266    
5267                    qPos.add(groupId);
5268    
5269                    qPos.add(parentFolderId);
5270    
5271                    qPos.add(status);
5272    
5273                    if (orderByComparator != null) {
5274                            Object[] values = orderByComparator.getOrderByConditionValues(journalFolder);
5275    
5276                            for (Object value : values) {
5277                                    qPos.add(value);
5278                            }
5279                    }
5280    
5281                    List<JournalFolder> list = q.list();
5282    
5283                    if (list.size() == 2) {
5284                            return list.get(1);
5285                    }
5286                    else {
5287                            return null;
5288                    }
5289            }
5290    
5291            /**
5292             * Returns all the journal folders that the user has permission to view where groupId = &#63; and parentFolderId = &#63; and status = &#63;.
5293             *
5294             * @param groupId the group ID
5295             * @param parentFolderId the parent folder ID
5296             * @param status the status
5297             * @return the matching journal folders that the user has permission to view
5298             * @throws SystemException if a system exception occurred
5299             */
5300            @Override
5301            public List<JournalFolder> filterFindByG_P_S(long groupId,
5302                    long parentFolderId, int status) throws SystemException {
5303                    return filterFindByG_P_S(groupId, parentFolderId, status,
5304                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5305            }
5306    
5307            /**
5308             * Returns a range of all the journal folders that the user has permission to view where groupId = &#63; and parentFolderId = &#63; and status = &#63;.
5309             *
5310             * <p>
5311             * 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.
5312             * </p>
5313             *
5314             * @param groupId the group ID
5315             * @param parentFolderId the parent folder ID
5316             * @param status the status
5317             * @param start the lower bound of the range of journal folders
5318             * @param end the upper bound of the range of journal folders (not inclusive)
5319             * @return the range of matching journal folders that the user has permission to view
5320             * @throws SystemException if a system exception occurred
5321             */
5322            @Override
5323            public List<JournalFolder> filterFindByG_P_S(long groupId,
5324                    long parentFolderId, int status, int start, int end)
5325                    throws SystemException {
5326                    return filterFindByG_P_S(groupId, parentFolderId, status, start, end,
5327                            null);
5328            }
5329    
5330            /**
5331             * 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;.
5332             *
5333             * <p>
5334             * 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.
5335             * </p>
5336             *
5337             * @param groupId the group ID
5338             * @param parentFolderId the parent folder ID
5339             * @param status the status
5340             * @param start the lower bound of the range of journal folders
5341             * @param end the upper bound of the range of journal folders (not inclusive)
5342             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5343             * @return the ordered range of matching journal folders that the user has permission to view
5344             * @throws SystemException if a system exception occurred
5345             */
5346            @Override
5347            public List<JournalFolder> filterFindByG_P_S(long groupId,
5348                    long parentFolderId, int status, int start, int end,
5349                    OrderByComparator orderByComparator) throws SystemException {
5350                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5351                            return findByG_P_S(groupId, parentFolderId, status, start, end,
5352                                    orderByComparator);
5353                    }
5354    
5355                    StringBundler query = null;
5356    
5357                    if (orderByComparator != null) {
5358                            query = new StringBundler(5 +
5359                                            (orderByComparator.getOrderByFields().length * 3));
5360                    }
5361                    else {
5362                            query = new StringBundler(5);
5363                    }
5364    
5365                    if (getDB().isSupportsInlineDistinct()) {
5366                            query.append(_FILTER_SQL_SELECT_JOURNALFOLDER_WHERE);
5367                    }
5368                    else {
5369                            query.append(_FILTER_SQL_SELECT_JOURNALFOLDER_NO_INLINE_DISTINCT_WHERE_1);
5370                    }
5371    
5372                    query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
5373    
5374                    query.append(_FINDER_COLUMN_G_P_S_PARENTFOLDERID_2);
5375    
5376                    query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
5377    
5378                    if (!getDB().isSupportsInlineDistinct()) {
5379                            query.append(_FILTER_SQL_SELECT_JOURNALFOLDER_NO_INLINE_DISTINCT_WHERE_2);
5380                    }
5381    
5382                    if (orderByComparator != null) {
5383                            if (getDB().isSupportsInlineDistinct()) {
5384                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5385                                            orderByComparator, true);
5386                            }
5387                            else {
5388                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5389                                            orderByComparator, true);
5390                            }
5391                    }
5392                    else {
5393                            if (getDB().isSupportsInlineDistinct()) {
5394                                    query.append(JournalFolderModelImpl.ORDER_BY_JPQL);
5395                            }
5396                            else {
5397                                    query.append(JournalFolderModelImpl.ORDER_BY_SQL);
5398                            }
5399                    }
5400    
5401                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5402                                    JournalFolder.class.getName(),
5403                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5404    
5405                    Session session = null;
5406    
5407                    try {
5408                            session = openSession();
5409    
5410                            SQLQuery q = session.createSQLQuery(sql);
5411    
5412                            if (getDB().isSupportsInlineDistinct()) {
5413                                    q.addEntity(_FILTER_ENTITY_ALIAS, JournalFolderImpl.class);
5414                            }
5415                            else {
5416                                    q.addEntity(_FILTER_ENTITY_TABLE, JournalFolderImpl.class);
5417                            }
5418    
5419                            QueryPos qPos = QueryPos.getInstance(q);
5420    
5421                            qPos.add(groupId);
5422    
5423                            qPos.add(parentFolderId);
5424    
5425                            qPos.add(status);
5426    
5427                            return (List<JournalFolder>)QueryUtil.list(q, getDialect(), start,
5428                                    end);
5429                    }
5430                    catch (Exception e) {
5431                            throw processException(e);
5432                    }
5433                    finally {
5434                            closeSession(session);
5435                    }
5436            }
5437    
5438            /**
5439             * 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;.
5440             *
5441             * @param folderId the primary key of the current journal folder
5442             * @param groupId the group ID
5443             * @param parentFolderId the parent folder ID
5444             * @param status the status
5445             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5446             * @return the previous, current, and next journal folder
5447             * @throws com.liferay.portlet.journal.NoSuchFolderException if a journal folder with the primary key could not be found
5448             * @throws SystemException if a system exception occurred
5449             */
5450            @Override
5451            public JournalFolder[] filterFindByG_P_S_PrevAndNext(long folderId,
5452                    long groupId, long parentFolderId, int status,
5453                    OrderByComparator orderByComparator)
5454                    throws NoSuchFolderException, SystemException {
5455                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5456                            return findByG_P_S_PrevAndNext(folderId, groupId, parentFolderId,
5457                                    status, orderByComparator);
5458                    }
5459    
5460                    JournalFolder journalFolder = findByPrimaryKey(folderId);
5461    
5462                    Session session = null;
5463    
5464                    try {
5465                            session = openSession();
5466    
5467                            JournalFolder[] array = new JournalFolderImpl[3];
5468    
5469                            array[0] = filterGetByG_P_S_PrevAndNext(session, journalFolder,
5470                                            groupId, parentFolderId, status, orderByComparator, true);
5471    
5472                            array[1] = journalFolder;
5473    
5474                            array[2] = filterGetByG_P_S_PrevAndNext(session, journalFolder,
5475                                            groupId, parentFolderId, status, orderByComparator, false);
5476    
5477                            return array;
5478                    }
5479                    catch (Exception e) {
5480                            throw processException(e);
5481                    }
5482                    finally {
5483                            closeSession(session);
5484                    }
5485            }
5486    
5487            protected JournalFolder filterGetByG_P_S_PrevAndNext(Session session,
5488                    JournalFolder journalFolder, long groupId, long parentFolderId,
5489                    int status, OrderByComparator orderByComparator, boolean previous) {
5490                    StringBundler query = null;
5491    
5492                    if (orderByComparator != null) {
5493                            query = new StringBundler(6 +
5494                                            (orderByComparator.getOrderByFields().length * 6));
5495                    }
5496                    else {
5497                            query = new StringBundler(3);
5498                    }
5499    
5500                    if (getDB().isSupportsInlineDistinct()) {
5501                            query.append(_FILTER_SQL_SELECT_JOURNALFOLDER_WHERE);
5502                    }
5503                    else {
5504                            query.append(_FILTER_SQL_SELECT_JOURNALFOLDER_NO_INLINE_DISTINCT_WHERE_1);
5505                    }
5506    
5507                    query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
5508    
5509                    query.append(_FINDER_COLUMN_G_P_S_PARENTFOLDERID_2);
5510    
5511                    query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
5512    
5513                    if (!getDB().isSupportsInlineDistinct()) {
5514                            query.append(_FILTER_SQL_SELECT_JOURNALFOLDER_NO_INLINE_DISTINCT_WHERE_2);
5515                    }
5516    
5517                    if (orderByComparator != null) {
5518                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5519    
5520                            if (orderByConditionFields.length > 0) {
5521                                    query.append(WHERE_AND);
5522                            }
5523    
5524                            for (int i = 0; i < orderByConditionFields.length; i++) {
5525                                    if (getDB().isSupportsInlineDistinct()) {
5526                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5527                                    }
5528                                    else {
5529                                            query.append(_ORDER_BY_ENTITY_TABLE);
5530                                    }
5531    
5532                                    query.append(orderByConditionFields[i]);
5533    
5534                                    if ((i + 1) < orderByConditionFields.length) {
5535                                            if (orderByComparator.isAscending() ^ previous) {
5536                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5537                                            }
5538                                            else {
5539                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5540                                            }
5541                                    }
5542                                    else {
5543                                            if (orderByComparator.isAscending() ^ previous) {
5544                                                    query.append(WHERE_GREATER_THAN);
5545                                            }
5546                                            else {
5547                                                    query.append(WHERE_LESSER_THAN);
5548                                            }
5549                                    }
5550                            }
5551    
5552                            query.append(ORDER_BY_CLAUSE);
5553    
5554                            String[] orderByFields = orderByComparator.getOrderByFields();
5555    
5556                            for (int i = 0; i < orderByFields.length; i++) {
5557                                    if (getDB().isSupportsInlineDistinct()) {
5558                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5559                                    }
5560                                    else {
5561                                            query.append(_ORDER_BY_ENTITY_TABLE);
5562                                    }
5563    
5564                                    query.append(orderByFields[i]);
5565    
5566                                    if ((i + 1) < orderByFields.length) {
5567                                            if (orderByComparator.isAscending() ^ previous) {
5568                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5569                                            }
5570                                            else {
5571                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5572                                            }
5573                                    }
5574                                    else {
5575                                            if (orderByComparator.isAscending() ^ previous) {
5576                                                    query.append(ORDER_BY_ASC);
5577                                            }
5578                                            else {
5579                                                    query.append(ORDER_BY_DESC);
5580                                            }
5581                                    }
5582                            }
5583                    }
5584                    else {
5585                            if (getDB().isSupportsInlineDistinct()) {
5586                                    query.append(JournalFolderModelImpl.ORDER_BY_JPQL);
5587                            }
5588                            else {
5589                                    query.append(JournalFolderModelImpl.ORDER_BY_SQL);
5590                            }
5591                    }
5592    
5593                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5594                                    JournalFolder.class.getName(),
5595                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5596    
5597                    SQLQuery q = session.createSQLQuery(sql);
5598    
5599                    q.setFirstResult(0);
5600                    q.setMaxResults(2);
5601    
5602                    if (getDB().isSupportsInlineDistinct()) {
5603                            q.addEntity(_FILTER_ENTITY_ALIAS, JournalFolderImpl.class);
5604                    }
5605                    else {
5606                            q.addEntity(_FILTER_ENTITY_TABLE, JournalFolderImpl.class);
5607                    }
5608    
5609                    QueryPos qPos = QueryPos.getInstance(q);
5610    
5611                    qPos.add(groupId);
5612    
5613                    qPos.add(parentFolderId);
5614    
5615                    qPos.add(status);
5616    
5617                    if (orderByComparator != null) {
5618                            Object[] values = orderByComparator.getOrderByConditionValues(journalFolder);
5619    
5620                            for (Object value : values) {
5621                                    qPos.add(value);
5622                            }
5623                    }
5624    
5625                    List<JournalFolder> list = q.list();
5626    
5627                    if (list.size() == 2) {
5628                            return list.get(1);
5629                    }
5630                    else {
5631                            return null;
5632                    }
5633            }
5634    
5635            /**
5636             * Removes all the journal folders where groupId = &#63; and parentFolderId = &#63; and status = &#63; from the database.
5637             *
5638             * @param groupId the group ID
5639             * @param parentFolderId the parent folder ID
5640             * @param status the status
5641             * @throws SystemException if a system exception occurred
5642             */
5643            @Override
5644            public void removeByG_P_S(long groupId, long parentFolderId, int status)
5645                    throws SystemException {
5646                    for (JournalFolder journalFolder : findByG_P_S(groupId, parentFolderId,
5647                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5648                            remove(journalFolder);
5649                    }
5650            }
5651    
5652            /**
5653             * Returns the number of journal folders where groupId = &#63; and parentFolderId = &#63; and status = &#63;.
5654             *
5655             * @param groupId the group ID
5656             * @param parentFolderId the parent folder ID
5657             * @param status the status
5658             * @return the number of matching journal folders
5659             * @throws SystemException if a system exception occurred
5660             */
5661            @Override
5662            public int countByG_P_S(long groupId, long parentFolderId, int status)
5663                    throws SystemException {
5664                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_S;
5665    
5666                    Object[] finderArgs = new Object[] { groupId, parentFolderId, status };
5667    
5668                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5669                                    this);
5670    
5671                    if (count == null) {
5672                            StringBundler query = new StringBundler(4);
5673    
5674                            query.append(_SQL_COUNT_JOURNALFOLDER_WHERE);
5675    
5676                            query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
5677    
5678                            query.append(_FINDER_COLUMN_G_P_S_PARENTFOLDERID_2);
5679    
5680                            query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
5681    
5682                            String sql = query.toString();
5683    
5684                            Session session = null;
5685    
5686                            try {
5687                                    session = openSession();
5688    
5689                                    Query q = session.createQuery(sql);
5690    
5691                                    QueryPos qPos = QueryPos.getInstance(q);
5692    
5693                                    qPos.add(groupId);
5694    
5695                                    qPos.add(parentFolderId);
5696    
5697                                    qPos.add(status);
5698    
5699                                    count = (Long)q.uniqueResult();
5700    
5701                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5702                            }
5703                            catch (Exception e) {
5704                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5705    
5706                                    throw processException(e);
5707                            }
5708                            finally {
5709                                    closeSession(session);
5710                            }
5711                    }
5712    
5713                    return count.intValue();
5714            }
5715    
5716            /**
5717             * Returns the number of journal folders that the user has permission to view where groupId = &#63; and parentFolderId = &#63; and status = &#63;.
5718             *
5719             * @param groupId the group ID
5720             * @param parentFolderId the parent folder ID
5721             * @param status the status
5722             * @return the number of matching journal folders that the user has permission to view
5723             * @throws SystemException if a system exception occurred
5724             */
5725            @Override
5726            public int filterCountByG_P_S(long groupId, long parentFolderId, int status)
5727                    throws SystemException {
5728                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5729                            return countByG_P_S(groupId, parentFolderId, status);
5730                    }
5731    
5732                    StringBundler query = new StringBundler(4);
5733    
5734                    query.append(_FILTER_SQL_COUNT_JOURNALFOLDER_WHERE);
5735    
5736                    query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
5737    
5738                    query.append(_FINDER_COLUMN_G_P_S_PARENTFOLDERID_2);
5739    
5740                    query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
5741    
5742                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5743                                    JournalFolder.class.getName(),
5744                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5745    
5746                    Session session = null;
5747    
5748                    try {
5749                            session = openSession();
5750    
5751                            SQLQuery q = session.createSQLQuery(sql);
5752    
5753                            q.addScalar(COUNT_COLUMN_NAME,
5754                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
5755    
5756                            QueryPos qPos = QueryPos.getInstance(q);
5757    
5758                            qPos.add(groupId);
5759    
5760                            qPos.add(parentFolderId);
5761    
5762                            qPos.add(status);
5763    
5764                            Long count = (Long)q.uniqueResult();
5765    
5766                            return count.intValue();
5767                    }
5768                    catch (Exception e) {
5769                            throw processException(e);
5770                    }
5771                    finally {
5772                            closeSession(session);
5773                    }
5774            }
5775    
5776            private static final String _FINDER_COLUMN_G_P_S_GROUPID_2 = "journalFolder.groupId = ? AND ";
5777            private static final String _FINDER_COLUMN_G_P_S_PARENTFOLDERID_2 = "journalFolder.parentFolderId = ? AND ";
5778            private static final String _FINDER_COLUMN_G_P_S_STATUS_2 = "journalFolder.status = ?";
5779            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_NOTS = new FinderPath(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
5780                            JournalFolderModelImpl.FINDER_CACHE_ENABLED,
5781                            JournalFolderImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
5782                            "findByG_P_NotS",
5783                            new String[] {
5784                                    Long.class.getName(), Long.class.getName(),
5785                                    Integer.class.getName(),
5786                                    
5787                            Integer.class.getName(), Integer.class.getName(),
5788                                    OrderByComparator.class.getName()
5789                            });
5790            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P_NOTS =
5791                    new FinderPath(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
5792                            JournalFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
5793                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_P_NotS",
5794                            new String[] {
5795                                    Long.class.getName(), Long.class.getName(),
5796                                    Integer.class.getName()
5797                            });
5798    
5799            /**
5800             * Returns all the journal folders where groupId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
5801             *
5802             * @param groupId the group ID
5803             * @param parentFolderId the parent folder ID
5804             * @param status the status
5805             * @return the matching journal folders
5806             * @throws SystemException if a system exception occurred
5807             */
5808            @Override
5809            public List<JournalFolder> findByG_P_NotS(long groupId,
5810                    long parentFolderId, int status) throws SystemException {
5811                    return findByG_P_NotS(groupId, parentFolderId, status,
5812                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5813            }
5814    
5815            /**
5816             * Returns a range of all the journal folders where groupId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
5817             *
5818             * <p>
5819             * 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.
5820             * </p>
5821             *
5822             * @param groupId the group ID
5823             * @param parentFolderId the parent folder ID
5824             * @param status the status
5825             * @param start the lower bound of the range of journal folders
5826             * @param end the upper bound of the range of journal folders (not inclusive)
5827             * @return the range of matching journal folders
5828             * @throws SystemException if a system exception occurred
5829             */
5830            @Override
5831            public List<JournalFolder> findByG_P_NotS(long groupId,
5832                    long parentFolderId, int status, int start, int end)
5833                    throws SystemException {
5834                    return findByG_P_NotS(groupId, parentFolderId, status, start, end, null);
5835            }
5836    
5837            /**
5838             * Returns an ordered range of all the journal folders where groupId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
5839             *
5840             * <p>
5841             * 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.
5842             * </p>
5843             *
5844             * @param groupId the group ID
5845             * @param parentFolderId the parent folder ID
5846             * @param status the status
5847             * @param start the lower bound of the range of journal folders
5848             * @param end the upper bound of the range of journal folders (not inclusive)
5849             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5850             * @return the ordered range of matching journal folders
5851             * @throws SystemException if a system exception occurred
5852             */
5853            @Override
5854            public List<JournalFolder> findByG_P_NotS(long groupId,
5855                    long parentFolderId, int status, int start, int end,
5856                    OrderByComparator orderByComparator) throws SystemException {
5857                    boolean pagination = true;
5858                    FinderPath finderPath = null;
5859                    Object[] finderArgs = null;
5860    
5861                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_NOTS;
5862                    finderArgs = new Object[] {
5863                                    groupId, parentFolderId, status,
5864                                    
5865                                    start, end, orderByComparator
5866                            };
5867    
5868                    List<JournalFolder> list = (List<JournalFolder>)FinderCacheUtil.getResult(finderPath,
5869                                    finderArgs, this);
5870    
5871                    if ((list != null) && !list.isEmpty()) {
5872                            for (JournalFolder journalFolder : list) {
5873                                    if ((groupId != journalFolder.getGroupId()) ||
5874                                                    (parentFolderId != journalFolder.getParentFolderId()) ||
5875                                                    (status != journalFolder.getStatus())) {
5876                                            list = null;
5877    
5878                                            break;
5879                                    }
5880                            }
5881                    }
5882    
5883                    if (list == null) {
5884                            StringBundler query = null;
5885    
5886                            if (orderByComparator != null) {
5887                                    query = new StringBundler(5 +
5888                                                    (orderByComparator.getOrderByFields().length * 3));
5889                            }
5890                            else {
5891                                    query = new StringBundler(5);
5892                            }
5893    
5894                            query.append(_SQL_SELECT_JOURNALFOLDER_WHERE);
5895    
5896                            query.append(_FINDER_COLUMN_G_P_NOTS_GROUPID_2);
5897    
5898                            query.append(_FINDER_COLUMN_G_P_NOTS_PARENTFOLDERID_2);
5899    
5900                            query.append(_FINDER_COLUMN_G_P_NOTS_STATUS_2);
5901    
5902                            if (orderByComparator != null) {
5903                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5904                                            orderByComparator);
5905                            }
5906                            else
5907                             if (pagination) {
5908                                    query.append(JournalFolderModelImpl.ORDER_BY_JPQL);
5909                            }
5910    
5911                            String sql = query.toString();
5912    
5913                            Session session = null;
5914    
5915                            try {
5916                                    session = openSession();
5917    
5918                                    Query q = session.createQuery(sql);
5919    
5920                                    QueryPos qPos = QueryPos.getInstance(q);
5921    
5922                                    qPos.add(groupId);
5923    
5924                                    qPos.add(parentFolderId);
5925    
5926                                    qPos.add(status);
5927    
5928                                    if (!pagination) {
5929                                            list = (List<JournalFolder>)QueryUtil.list(q, getDialect(),
5930                                                            start, end, false);
5931    
5932                                            Collections.sort(list);
5933    
5934                                            list = new UnmodifiableList<JournalFolder>(list);
5935                                    }
5936                                    else {
5937                                            list = (List<JournalFolder>)QueryUtil.list(q, getDialect(),
5938                                                            start, end);
5939                                    }
5940    
5941                                    cacheResult(list);
5942    
5943                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5944                            }
5945                            catch (Exception e) {
5946                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5947    
5948                                    throw processException(e);
5949                            }
5950                            finally {
5951                                    closeSession(session);
5952                            }
5953                    }
5954    
5955                    return list;
5956            }
5957    
5958            /**
5959             * Returns the first journal folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
5960             *
5961             * @param groupId the group ID
5962             * @param parentFolderId the parent folder ID
5963             * @param status the status
5964             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5965             * @return the first matching journal folder
5966             * @throws com.liferay.portlet.journal.NoSuchFolderException if a matching journal folder could not be found
5967             * @throws SystemException if a system exception occurred
5968             */
5969            @Override
5970            public JournalFolder findByG_P_NotS_First(long groupId,
5971                    long parentFolderId, int status, OrderByComparator orderByComparator)
5972                    throws NoSuchFolderException, SystemException {
5973                    JournalFolder journalFolder = fetchByG_P_NotS_First(groupId,
5974                                    parentFolderId, status, orderByComparator);
5975    
5976                    if (journalFolder != null) {
5977                            return journalFolder;
5978                    }
5979    
5980                    StringBundler msg = new StringBundler(8);
5981    
5982                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5983    
5984                    msg.append("groupId=");
5985                    msg.append(groupId);
5986    
5987                    msg.append(", parentFolderId=");
5988                    msg.append(parentFolderId);
5989    
5990                    msg.append(", status=");
5991                    msg.append(status);
5992    
5993                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5994    
5995                    throw new NoSuchFolderException(msg.toString());
5996            }
5997    
5998            /**
5999             * Returns the first journal folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
6000             *
6001             * @param groupId the group ID
6002             * @param parentFolderId the parent folder ID
6003             * @param status the status
6004             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6005             * @return the first matching journal folder, or <code>null</code> if a matching journal folder could not be found
6006             * @throws SystemException if a system exception occurred
6007             */
6008            @Override
6009            public JournalFolder fetchByG_P_NotS_First(long groupId,
6010                    long parentFolderId, int status, OrderByComparator orderByComparator)
6011                    throws SystemException {
6012                    List<JournalFolder> list = findByG_P_NotS(groupId, parentFolderId,
6013                                    status, 0, 1, orderByComparator);
6014    
6015                    if (!list.isEmpty()) {
6016                            return list.get(0);
6017                    }
6018    
6019                    return null;
6020            }
6021    
6022            /**
6023             * Returns the last journal folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
6024             *
6025             * @param groupId the group ID
6026             * @param parentFolderId the parent folder ID
6027             * @param status the status
6028             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6029             * @return the last matching journal folder
6030             * @throws com.liferay.portlet.journal.NoSuchFolderException if a matching journal folder could not be found
6031             * @throws SystemException if a system exception occurred
6032             */
6033            @Override
6034            public JournalFolder findByG_P_NotS_Last(long groupId, long parentFolderId,
6035                    int status, OrderByComparator orderByComparator)
6036                    throws NoSuchFolderException, SystemException {
6037                    JournalFolder journalFolder = fetchByG_P_NotS_Last(groupId,
6038                                    parentFolderId, status, orderByComparator);
6039    
6040                    if (journalFolder != null) {
6041                            return journalFolder;
6042                    }
6043    
6044                    StringBundler msg = new StringBundler(8);
6045    
6046                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6047    
6048                    msg.append("groupId=");
6049                    msg.append(groupId);
6050    
6051                    msg.append(", parentFolderId=");
6052                    msg.append(parentFolderId);
6053    
6054                    msg.append(", status=");
6055                    msg.append(status);
6056    
6057                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6058    
6059                    throw new NoSuchFolderException(msg.toString());
6060            }
6061    
6062            /**
6063             * Returns the last journal folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
6064             *
6065             * @param groupId the group ID
6066             * @param parentFolderId the parent folder ID
6067             * @param status the status
6068             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6069             * @return the last matching journal folder, or <code>null</code> if a matching journal folder could not be found
6070             * @throws SystemException if a system exception occurred
6071             */
6072            @Override
6073            public JournalFolder fetchByG_P_NotS_Last(long groupId,
6074                    long parentFolderId, int status, OrderByComparator orderByComparator)
6075                    throws SystemException {
6076                    int count = countByG_P_NotS(groupId, parentFolderId, status);
6077    
6078                    if (count == 0) {
6079                            return null;
6080                    }
6081    
6082                    List<JournalFolder> list = findByG_P_NotS(groupId, parentFolderId,
6083                                    status, count - 1, count, orderByComparator);
6084    
6085                    if (!list.isEmpty()) {
6086                            return list.get(0);
6087                    }
6088    
6089                    return null;
6090            }
6091    
6092            /**
6093             * 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;.
6094             *
6095             * @param folderId the primary key of the current journal folder
6096             * @param groupId the group ID
6097             * @param parentFolderId the parent folder ID
6098             * @param status the status
6099             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6100             * @return the previous, current, and next journal folder
6101             * @throws com.liferay.portlet.journal.NoSuchFolderException if a journal folder with the primary key could not be found
6102             * @throws SystemException if a system exception occurred
6103             */
6104            @Override
6105            public JournalFolder[] findByG_P_NotS_PrevAndNext(long folderId,
6106                    long groupId, long parentFolderId, int status,
6107                    OrderByComparator orderByComparator)
6108                    throws NoSuchFolderException, SystemException {
6109                    JournalFolder journalFolder = findByPrimaryKey(folderId);
6110    
6111                    Session session = null;
6112    
6113                    try {
6114                            session = openSession();
6115    
6116                            JournalFolder[] array = new JournalFolderImpl[3];
6117    
6118                            array[0] = getByG_P_NotS_PrevAndNext(session, journalFolder,
6119                                            groupId, parentFolderId, status, orderByComparator, true);
6120    
6121                            array[1] = journalFolder;
6122    
6123                            array[2] = getByG_P_NotS_PrevAndNext(session, journalFolder,
6124                                            groupId, parentFolderId, status, orderByComparator, false);
6125    
6126                            return array;
6127                    }
6128                    catch (Exception e) {
6129                            throw processException(e);
6130                    }
6131                    finally {
6132                            closeSession(session);
6133                    }
6134            }
6135    
6136            protected JournalFolder getByG_P_NotS_PrevAndNext(Session session,
6137                    JournalFolder journalFolder, long groupId, long parentFolderId,
6138                    int status, OrderByComparator orderByComparator, boolean previous) {
6139                    StringBundler query = null;
6140    
6141                    if (orderByComparator != null) {
6142                            query = new StringBundler(6 +
6143                                            (orderByComparator.getOrderByFields().length * 6));
6144                    }
6145                    else {
6146                            query = new StringBundler(3);
6147                    }
6148    
6149                    query.append(_SQL_SELECT_JOURNALFOLDER_WHERE);
6150    
6151                    query.append(_FINDER_COLUMN_G_P_NOTS_GROUPID_2);
6152    
6153                    query.append(_FINDER_COLUMN_G_P_NOTS_PARENTFOLDERID_2);
6154    
6155                    query.append(_FINDER_COLUMN_G_P_NOTS_STATUS_2);
6156    
6157                    if (orderByComparator != null) {
6158                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6159    
6160                            if (orderByConditionFields.length > 0) {
6161                                    query.append(WHERE_AND);
6162                            }
6163    
6164                            for (int i = 0; i < orderByConditionFields.length; i++) {
6165                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6166                                    query.append(orderByConditionFields[i]);
6167    
6168                                    if ((i + 1) < orderByConditionFields.length) {
6169                                            if (orderByComparator.isAscending() ^ previous) {
6170                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6171                                            }
6172                                            else {
6173                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6174                                            }
6175                                    }
6176                                    else {
6177                                            if (orderByComparator.isAscending() ^ previous) {
6178                                                    query.append(WHERE_GREATER_THAN);
6179                                            }
6180                                            else {
6181                                                    query.append(WHERE_LESSER_THAN);
6182                                            }
6183                                    }
6184                            }
6185    
6186                            query.append(ORDER_BY_CLAUSE);
6187    
6188                            String[] orderByFields = orderByComparator.getOrderByFields();
6189    
6190                            for (int i = 0; i < orderByFields.length; i++) {
6191                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6192                                    query.append(orderByFields[i]);
6193    
6194                                    if ((i + 1) < orderByFields.length) {
6195                                            if (orderByComparator.isAscending() ^ previous) {
6196                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6197                                            }
6198                                            else {
6199                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6200                                            }
6201                                    }
6202                                    else {
6203                                            if (orderByComparator.isAscending() ^ previous) {
6204                                                    query.append(ORDER_BY_ASC);
6205                                            }
6206                                            else {
6207                                                    query.append(ORDER_BY_DESC);
6208                                            }
6209                                    }
6210                            }
6211                    }
6212                    else {
6213                            query.append(JournalFolderModelImpl.ORDER_BY_JPQL);
6214                    }
6215    
6216                    String sql = query.toString();
6217    
6218                    Query q = session.createQuery(sql);
6219    
6220                    q.setFirstResult(0);
6221                    q.setMaxResults(2);
6222    
6223                    QueryPos qPos = QueryPos.getInstance(q);
6224    
6225                    qPos.add(groupId);
6226    
6227                    qPos.add(parentFolderId);
6228    
6229                    qPos.add(status);
6230    
6231                    if (orderByComparator != null) {
6232                            Object[] values = orderByComparator.getOrderByConditionValues(journalFolder);
6233    
6234                            for (Object value : values) {
6235                                    qPos.add(value);
6236                            }
6237                    }
6238    
6239                    List<JournalFolder> list = q.list();
6240    
6241                    if (list.size() == 2) {
6242                            return list.get(1);
6243                    }
6244                    else {
6245                            return null;
6246                    }
6247            }
6248    
6249            /**
6250             * Returns all the journal folders that the user has permission to view where groupId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
6251             *
6252             * @param groupId the group ID
6253             * @param parentFolderId the parent folder ID
6254             * @param status the status
6255             * @return the matching journal folders that the user has permission to view
6256             * @throws SystemException if a system exception occurred
6257             */
6258            @Override
6259            public List<JournalFolder> filterFindByG_P_NotS(long groupId,
6260                    long parentFolderId, int status) throws SystemException {
6261                    return filterFindByG_P_NotS(groupId, parentFolderId, status,
6262                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6263            }
6264    
6265            /**
6266             * 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;.
6267             *
6268             * <p>
6269             * 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.
6270             * </p>
6271             *
6272             * @param groupId the group ID
6273             * @param parentFolderId the parent folder ID
6274             * @param status the status
6275             * @param start the lower bound of the range of journal folders
6276             * @param end the upper bound of the range of journal folders (not inclusive)
6277             * @return the range of matching journal folders that the user has permission to view
6278             * @throws SystemException if a system exception occurred
6279             */
6280            @Override
6281            public List<JournalFolder> filterFindByG_P_NotS(long groupId,
6282                    long parentFolderId, int status, int start, int end)
6283                    throws SystemException {
6284                    return filterFindByG_P_NotS(groupId, parentFolderId, status, start,
6285                            end, null);
6286            }
6287    
6288            /**
6289             * 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;.
6290             *
6291             * <p>
6292             * 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.
6293             * </p>
6294             *
6295             * @param groupId the group ID
6296             * @param parentFolderId the parent folder ID
6297             * @param status the status
6298             * @param start the lower bound of the range of journal folders
6299             * @param end the upper bound of the range of journal folders (not inclusive)
6300             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6301             * @return the ordered range of matching journal folders that the user has permission to view
6302             * @throws SystemException if a system exception occurred
6303             */
6304            @Override
6305            public List<JournalFolder> filterFindByG_P_NotS(long groupId,
6306                    long parentFolderId, int status, int start, int end,
6307                    OrderByComparator orderByComparator) throws SystemException {
6308                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6309                            return findByG_P_NotS(groupId, parentFolderId, status, start, end,
6310                                    orderByComparator);
6311                    }
6312    
6313                    StringBundler query = null;
6314    
6315                    if (orderByComparator != null) {
6316                            query = new StringBundler(5 +
6317                                            (orderByComparator.getOrderByFields().length * 3));
6318                    }
6319                    else {
6320                            query = new StringBundler(5);
6321                    }
6322    
6323                    if (getDB().isSupportsInlineDistinct()) {
6324                            query.append(_FILTER_SQL_SELECT_JOURNALFOLDER_WHERE);
6325                    }
6326                    else {
6327                            query.append(_FILTER_SQL_SELECT_JOURNALFOLDER_NO_INLINE_DISTINCT_WHERE_1);
6328                    }
6329    
6330                    query.append(_FINDER_COLUMN_G_P_NOTS_GROUPID_2);
6331    
6332                    query.append(_FINDER_COLUMN_G_P_NOTS_PARENTFOLDERID_2);
6333    
6334                    query.append(_FINDER_COLUMN_G_P_NOTS_STATUS_2);
6335    
6336                    if (!getDB().isSupportsInlineDistinct()) {
6337                            query.append(_FILTER_SQL_SELECT_JOURNALFOLDER_NO_INLINE_DISTINCT_WHERE_2);
6338                    }
6339    
6340                    if (orderByComparator != null) {
6341                            if (getDB().isSupportsInlineDistinct()) {
6342                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6343                                            orderByComparator, true);
6344                            }
6345                            else {
6346                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6347                                            orderByComparator, true);
6348                            }
6349                    }
6350                    else {
6351                            if (getDB().isSupportsInlineDistinct()) {
6352                                    query.append(JournalFolderModelImpl.ORDER_BY_JPQL);
6353                            }
6354                            else {
6355                                    query.append(JournalFolderModelImpl.ORDER_BY_SQL);
6356                            }
6357                    }
6358    
6359                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6360                                    JournalFolder.class.getName(),
6361                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6362    
6363                    Session session = null;
6364    
6365                    try {
6366                            session = openSession();
6367    
6368                            SQLQuery q = session.createSQLQuery(sql);
6369    
6370                            if (getDB().isSupportsInlineDistinct()) {
6371                                    q.addEntity(_FILTER_ENTITY_ALIAS, JournalFolderImpl.class);
6372                            }
6373                            else {
6374                                    q.addEntity(_FILTER_ENTITY_TABLE, JournalFolderImpl.class);
6375                            }
6376    
6377                            QueryPos qPos = QueryPos.getInstance(q);
6378    
6379                            qPos.add(groupId);
6380    
6381                            qPos.add(parentFolderId);
6382    
6383                            qPos.add(status);
6384    
6385                            return (List<JournalFolder>)QueryUtil.list(q, getDialect(), start,
6386                                    end);
6387                    }
6388                    catch (Exception e) {
6389                            throw processException(e);
6390                    }
6391                    finally {
6392                            closeSession(session);
6393                    }
6394            }
6395    
6396            /**
6397             * 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;.
6398             *
6399             * @param folderId the primary key of the current journal folder
6400             * @param groupId the group ID
6401             * @param parentFolderId the parent folder ID
6402             * @param status the status
6403             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6404             * @return the previous, current, and next journal folder
6405             * @throws com.liferay.portlet.journal.NoSuchFolderException if a journal folder with the primary key could not be found
6406             * @throws SystemException if a system exception occurred
6407             */
6408            @Override
6409            public JournalFolder[] filterFindByG_P_NotS_PrevAndNext(long folderId,
6410                    long groupId, long parentFolderId, int status,
6411                    OrderByComparator orderByComparator)
6412                    throws NoSuchFolderException, SystemException {
6413                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6414                            return findByG_P_NotS_PrevAndNext(folderId, groupId,
6415                                    parentFolderId, status, orderByComparator);
6416                    }
6417    
6418                    JournalFolder journalFolder = findByPrimaryKey(folderId);
6419    
6420                    Session session = null;
6421    
6422                    try {
6423                            session = openSession();
6424    
6425                            JournalFolder[] array = new JournalFolderImpl[3];
6426    
6427                            array[0] = filterGetByG_P_NotS_PrevAndNext(session, journalFolder,
6428                                            groupId, parentFolderId, status, orderByComparator, true);
6429    
6430                            array[1] = journalFolder;
6431    
6432                            array[2] = filterGetByG_P_NotS_PrevAndNext(session, journalFolder,
6433                                            groupId, parentFolderId, status, orderByComparator, false);
6434    
6435                            return array;
6436                    }
6437                    catch (Exception e) {
6438                            throw processException(e);
6439                    }
6440                    finally {
6441                            closeSession(session);
6442                    }
6443            }
6444    
6445            protected JournalFolder filterGetByG_P_NotS_PrevAndNext(Session session,
6446                    JournalFolder journalFolder, long groupId, long parentFolderId,
6447                    int status, OrderByComparator orderByComparator, boolean previous) {
6448                    StringBundler query = null;
6449    
6450                    if (orderByComparator != null) {
6451                            query = new StringBundler(6 +
6452                                            (orderByComparator.getOrderByFields().length * 6));
6453                    }
6454                    else {
6455                            query = new StringBundler(3);
6456                    }
6457    
6458                    if (getDB().isSupportsInlineDistinct()) {
6459                            query.append(_FILTER_SQL_SELECT_JOURNALFOLDER_WHERE);
6460                    }
6461                    else {
6462                            query.append(_FILTER_SQL_SELECT_JOURNALFOLDER_NO_INLINE_DISTINCT_WHERE_1);
6463                    }
6464    
6465                    query.append(_FINDER_COLUMN_G_P_NOTS_GROUPID_2);
6466    
6467                    query.append(_FINDER_COLUMN_G_P_NOTS_PARENTFOLDERID_2);
6468    
6469                    query.append(_FINDER_COLUMN_G_P_NOTS_STATUS_2);
6470    
6471                    if (!getDB().isSupportsInlineDistinct()) {
6472                            query.append(_FILTER_SQL_SELECT_JOURNALFOLDER_NO_INLINE_DISTINCT_WHERE_2);
6473                    }
6474    
6475                    if (orderByComparator != null) {
6476                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6477    
6478                            if (orderByConditionFields.length > 0) {
6479                                    query.append(WHERE_AND);
6480                            }
6481    
6482                            for (int i = 0; i < orderByConditionFields.length; i++) {
6483                                    if (getDB().isSupportsInlineDistinct()) {
6484                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6485                                    }
6486                                    else {
6487                                            query.append(_ORDER_BY_ENTITY_TABLE);
6488                                    }
6489    
6490                                    query.append(orderByConditionFields[i]);
6491    
6492                                    if ((i + 1) < orderByConditionFields.length) {
6493                                            if (orderByComparator.isAscending() ^ previous) {
6494                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6495                                            }
6496                                            else {
6497                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6498                                            }
6499                                    }
6500                                    else {
6501                                            if (orderByComparator.isAscending() ^ previous) {
6502                                                    query.append(WHERE_GREATER_THAN);
6503                                            }
6504                                            else {
6505                                                    query.append(WHERE_LESSER_THAN);
6506                                            }
6507                                    }
6508                            }
6509    
6510                            query.append(ORDER_BY_CLAUSE);
6511    
6512                            String[] orderByFields = orderByComparator.getOrderByFields();
6513    
6514                            for (int i = 0; i < orderByFields.length; i++) {
6515                                    if (getDB().isSupportsInlineDistinct()) {
6516                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6517                                    }
6518                                    else {
6519                                            query.append(_ORDER_BY_ENTITY_TABLE);
6520                                    }
6521    
6522                                    query.append(orderByFields[i]);
6523    
6524                                    if ((i + 1) < orderByFields.length) {
6525                                            if (orderByComparator.isAscending() ^ previous) {
6526                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6527                                            }
6528                                            else {
6529                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6530                                            }
6531                                    }
6532                                    else {
6533                                            if (orderByComparator.isAscending() ^ previous) {
6534                                                    query.append(ORDER_BY_ASC);
6535                                            }
6536                                            else {
6537                                                    query.append(ORDER_BY_DESC);
6538                                            }
6539                                    }
6540                            }
6541                    }
6542                    else {
6543                            if (getDB().isSupportsInlineDistinct()) {
6544                                    query.append(JournalFolderModelImpl.ORDER_BY_JPQL);
6545                            }
6546                            else {
6547                                    query.append(JournalFolderModelImpl.ORDER_BY_SQL);
6548                            }
6549                    }
6550    
6551                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6552                                    JournalFolder.class.getName(),
6553                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6554    
6555                    SQLQuery q = session.createSQLQuery(sql);
6556    
6557                    q.setFirstResult(0);
6558                    q.setMaxResults(2);
6559    
6560                    if (getDB().isSupportsInlineDistinct()) {
6561                            q.addEntity(_FILTER_ENTITY_ALIAS, JournalFolderImpl.class);
6562                    }
6563                    else {
6564                            q.addEntity(_FILTER_ENTITY_TABLE, JournalFolderImpl.class);
6565                    }
6566    
6567                    QueryPos qPos = QueryPos.getInstance(q);
6568    
6569                    qPos.add(groupId);
6570    
6571                    qPos.add(parentFolderId);
6572    
6573                    qPos.add(status);
6574    
6575                    if (orderByComparator != null) {
6576                            Object[] values = orderByComparator.getOrderByConditionValues(journalFolder);
6577    
6578                            for (Object value : values) {
6579                                    qPos.add(value);
6580                            }
6581                    }
6582    
6583                    List<JournalFolder> list = q.list();
6584    
6585                    if (list.size() == 2) {
6586                            return list.get(1);
6587                    }
6588                    else {
6589                            return null;
6590                    }
6591            }
6592    
6593            /**
6594             * Removes all the journal folders where groupId = &#63; and parentFolderId = &#63; and status &ne; &#63; from the database.
6595             *
6596             * @param groupId the group ID
6597             * @param parentFolderId the parent folder ID
6598             * @param status the status
6599             * @throws SystemException if a system exception occurred
6600             */
6601            @Override
6602            public void removeByG_P_NotS(long groupId, long parentFolderId, int status)
6603                    throws SystemException {
6604                    for (JournalFolder journalFolder : findByG_P_NotS(groupId,
6605                                    parentFolderId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
6606                                    null)) {
6607                            remove(journalFolder);
6608                    }
6609            }
6610    
6611            /**
6612             * Returns the number of journal folders where groupId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
6613             *
6614             * @param groupId the group ID
6615             * @param parentFolderId the parent folder ID
6616             * @param status the status
6617             * @return the number of matching journal folders
6618             * @throws SystemException if a system exception occurred
6619             */
6620            @Override
6621            public int countByG_P_NotS(long groupId, long parentFolderId, int status)
6622                    throws SystemException {
6623                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P_NOTS;
6624    
6625                    Object[] finderArgs = new Object[] { groupId, parentFolderId, status };
6626    
6627                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6628                                    this);
6629    
6630                    if (count == null) {
6631                            StringBundler query = new StringBundler(4);
6632    
6633                            query.append(_SQL_COUNT_JOURNALFOLDER_WHERE);
6634    
6635                            query.append(_FINDER_COLUMN_G_P_NOTS_GROUPID_2);
6636    
6637                            query.append(_FINDER_COLUMN_G_P_NOTS_PARENTFOLDERID_2);
6638    
6639                            query.append(_FINDER_COLUMN_G_P_NOTS_STATUS_2);
6640    
6641                            String sql = query.toString();
6642    
6643                            Session session = null;
6644    
6645                            try {
6646                                    session = openSession();
6647    
6648                                    Query q = session.createQuery(sql);
6649    
6650                                    QueryPos qPos = QueryPos.getInstance(q);
6651    
6652                                    qPos.add(groupId);
6653    
6654                                    qPos.add(parentFolderId);
6655    
6656                                    qPos.add(status);
6657    
6658                                    count = (Long)q.uniqueResult();
6659    
6660                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
6661                            }
6662                            catch (Exception e) {
6663                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6664    
6665                                    throw processException(e);
6666                            }
6667                            finally {
6668                                    closeSession(session);
6669                            }
6670                    }
6671    
6672                    return count.intValue();
6673            }
6674    
6675            /**
6676             * Returns the number of journal folders that the user has permission to view where groupId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
6677             *
6678             * @param groupId the group ID
6679             * @param parentFolderId the parent folder ID
6680             * @param status the status
6681             * @return the number of matching journal folders that the user has permission to view
6682             * @throws SystemException if a system exception occurred
6683             */
6684            @Override
6685            public int filterCountByG_P_NotS(long groupId, long parentFolderId,
6686                    int status) throws SystemException {
6687                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6688                            return countByG_P_NotS(groupId, parentFolderId, status);
6689                    }
6690    
6691                    StringBundler query = new StringBundler(4);
6692    
6693                    query.append(_FILTER_SQL_COUNT_JOURNALFOLDER_WHERE);
6694    
6695                    query.append(_FINDER_COLUMN_G_P_NOTS_GROUPID_2);
6696    
6697                    query.append(_FINDER_COLUMN_G_P_NOTS_PARENTFOLDERID_2);
6698    
6699                    query.append(_FINDER_COLUMN_G_P_NOTS_STATUS_2);
6700    
6701                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6702                                    JournalFolder.class.getName(),
6703                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6704    
6705                    Session session = null;
6706    
6707                    try {
6708                            session = openSession();
6709    
6710                            SQLQuery q = session.createSQLQuery(sql);
6711    
6712                            q.addScalar(COUNT_COLUMN_NAME,
6713                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
6714    
6715                            QueryPos qPos = QueryPos.getInstance(q);
6716    
6717                            qPos.add(groupId);
6718    
6719                            qPos.add(parentFolderId);
6720    
6721                            qPos.add(status);
6722    
6723                            Long count = (Long)q.uniqueResult();
6724    
6725                            return count.intValue();
6726                    }
6727                    catch (Exception e) {
6728                            throw processException(e);
6729                    }
6730                    finally {
6731                            closeSession(session);
6732                    }
6733            }
6734    
6735            private static final String _FINDER_COLUMN_G_P_NOTS_GROUPID_2 = "journalFolder.groupId = ? AND ";
6736            private static final String _FINDER_COLUMN_G_P_NOTS_PARENTFOLDERID_2 = "journalFolder.parentFolderId = ? AND ";
6737            private static final String _FINDER_COLUMN_G_P_NOTS_STATUS_2 = "journalFolder.status != ?";
6738    
6739            public JournalFolderPersistenceImpl() {
6740                    setModelClass(JournalFolder.class);
6741            }
6742    
6743            /**
6744             * Caches the journal folder in the entity cache if it is enabled.
6745             *
6746             * @param journalFolder the journal folder
6747             */
6748            @Override
6749            public void cacheResult(JournalFolder journalFolder) {
6750                    EntityCacheUtil.putResult(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
6751                            JournalFolderImpl.class, journalFolder.getPrimaryKey(),
6752                            journalFolder);
6753    
6754                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
6755                            new Object[] { journalFolder.getUuid(), journalFolder.getGroupId() },
6756                            journalFolder);
6757    
6758                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
6759                            new Object[] { journalFolder.getGroupId(), journalFolder.getName() },
6760                            journalFolder);
6761    
6762                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N,
6763                            new Object[] {
6764                                    journalFolder.getGroupId(), journalFolder.getParentFolderId(),
6765                                    journalFolder.getName()
6766                            }, journalFolder);
6767    
6768                    journalFolder.resetOriginalValues();
6769            }
6770    
6771            /**
6772             * Caches the journal folders in the entity cache if it is enabled.
6773             *
6774             * @param journalFolders the journal folders
6775             */
6776            @Override
6777            public void cacheResult(List<JournalFolder> journalFolders) {
6778                    for (JournalFolder journalFolder : journalFolders) {
6779                            if (EntityCacheUtil.getResult(
6780                                                    JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
6781                                                    JournalFolderImpl.class, journalFolder.getPrimaryKey()) == null) {
6782                                    cacheResult(journalFolder);
6783                            }
6784                            else {
6785                                    journalFolder.resetOriginalValues();
6786                            }
6787                    }
6788            }
6789    
6790            /**
6791             * Clears the cache for all journal folders.
6792             *
6793             * <p>
6794             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
6795             * </p>
6796             */
6797            @Override
6798            public void clearCache() {
6799                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
6800                            CacheRegistryUtil.clear(JournalFolderImpl.class.getName());
6801                    }
6802    
6803                    EntityCacheUtil.clearCache(JournalFolderImpl.class.getName());
6804    
6805                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
6806                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6807                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6808            }
6809    
6810            /**
6811             * Clears the cache for the journal folder.
6812             *
6813             * <p>
6814             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
6815             * </p>
6816             */
6817            @Override
6818            public void clearCache(JournalFolder journalFolder) {
6819                    EntityCacheUtil.removeResult(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
6820                            JournalFolderImpl.class, journalFolder.getPrimaryKey());
6821    
6822                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6823                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6824    
6825                    clearUniqueFindersCache(journalFolder);
6826            }
6827    
6828            @Override
6829            public void clearCache(List<JournalFolder> journalFolders) {
6830                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6831                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6832    
6833                    for (JournalFolder journalFolder : journalFolders) {
6834                            EntityCacheUtil.removeResult(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
6835                                    JournalFolderImpl.class, journalFolder.getPrimaryKey());
6836    
6837                            clearUniqueFindersCache(journalFolder);
6838                    }
6839            }
6840    
6841            protected void cacheUniqueFindersCache(JournalFolder journalFolder) {
6842                    if (journalFolder.isNew()) {
6843                            Object[] args = new Object[] {
6844                                            journalFolder.getUuid(), journalFolder.getGroupId()
6845                                    };
6846    
6847                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
6848                                    Long.valueOf(1));
6849                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
6850                                    journalFolder);
6851    
6852                            args = new Object[] {
6853                                            journalFolder.getGroupId(), journalFolder.getName()
6854                                    };
6855    
6856                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N, args,
6857                                    Long.valueOf(1));
6858                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N, args,
6859                                    journalFolder);
6860    
6861                            args = new Object[] {
6862                                            journalFolder.getGroupId(),
6863                                            journalFolder.getParentFolderId(), journalFolder.getName()
6864                                    };
6865    
6866                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P_N, args,
6867                                    Long.valueOf(1));
6868                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N, args,
6869                                    journalFolder);
6870                    }
6871                    else {
6872                            JournalFolderModelImpl journalFolderModelImpl = (JournalFolderModelImpl)journalFolder;
6873    
6874                            if ((journalFolderModelImpl.getColumnBitmask() &
6875                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
6876                                    Object[] args = new Object[] {
6877                                                    journalFolder.getUuid(), journalFolder.getGroupId()
6878                                            };
6879    
6880                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
6881                                            Long.valueOf(1));
6882                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
6883                                            journalFolder);
6884                            }
6885    
6886                            if ((journalFolderModelImpl.getColumnBitmask() &
6887                                            FINDER_PATH_FETCH_BY_G_N.getColumnBitmask()) != 0) {
6888                                    Object[] args = new Object[] {
6889                                                    journalFolder.getGroupId(), journalFolder.getName()
6890                                            };
6891    
6892                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N, args,
6893                                            Long.valueOf(1));
6894                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N, args,
6895                                            journalFolder);
6896                            }
6897    
6898                            if ((journalFolderModelImpl.getColumnBitmask() &
6899                                            FINDER_PATH_FETCH_BY_G_P_N.getColumnBitmask()) != 0) {
6900                                    Object[] args = new Object[] {
6901                                                    journalFolder.getGroupId(),
6902                                                    journalFolder.getParentFolderId(),
6903                                                    journalFolder.getName()
6904                                            };
6905    
6906                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P_N, args,
6907                                            Long.valueOf(1));
6908                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N, args,
6909                                            journalFolder);
6910                            }
6911                    }
6912            }
6913    
6914            protected void clearUniqueFindersCache(JournalFolder journalFolder) {
6915                    JournalFolderModelImpl journalFolderModelImpl = (JournalFolderModelImpl)journalFolder;
6916    
6917                    Object[] args = new Object[] {
6918                                    journalFolder.getUuid(), journalFolder.getGroupId()
6919                            };
6920    
6921                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
6922                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
6923    
6924                    if ((journalFolderModelImpl.getColumnBitmask() &
6925                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
6926                            args = new Object[] {
6927                                            journalFolderModelImpl.getOriginalUuid(),
6928                                            journalFolderModelImpl.getOriginalGroupId()
6929                                    };
6930    
6931                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
6932                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
6933                    }
6934    
6935                    args = new Object[] { journalFolder.getGroupId(), journalFolder.getName() };
6936    
6937                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N, args);
6938                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N, args);
6939    
6940                    if ((journalFolderModelImpl.getColumnBitmask() &
6941                                    FINDER_PATH_FETCH_BY_G_N.getColumnBitmask()) != 0) {
6942                            args = new Object[] {
6943                                            journalFolderModelImpl.getOriginalGroupId(),
6944                                            journalFolderModelImpl.getOriginalName()
6945                                    };
6946    
6947                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N, args);
6948                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N, args);
6949                    }
6950    
6951                    args = new Object[] {
6952                                    journalFolder.getGroupId(), journalFolder.getParentFolderId(),
6953                                    journalFolder.getName()
6954                            };
6955    
6956                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_N, args);
6957                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_N, args);
6958    
6959                    if ((journalFolderModelImpl.getColumnBitmask() &
6960                                    FINDER_PATH_FETCH_BY_G_P_N.getColumnBitmask()) != 0) {
6961                            args = new Object[] {
6962                                            journalFolderModelImpl.getOriginalGroupId(),
6963                                            journalFolderModelImpl.getOriginalParentFolderId(),
6964                                            journalFolderModelImpl.getOriginalName()
6965                                    };
6966    
6967                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_N, args);
6968                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_N, args);
6969                    }
6970            }
6971    
6972            /**
6973             * Creates a new journal folder with the primary key. Does not add the journal folder to the database.
6974             *
6975             * @param folderId the primary key for the new journal folder
6976             * @return the new journal folder
6977             */
6978            @Override
6979            public JournalFolder create(long folderId) {
6980                    JournalFolder journalFolder = new JournalFolderImpl();
6981    
6982                    journalFolder.setNew(true);
6983                    journalFolder.setPrimaryKey(folderId);
6984    
6985                    String uuid = PortalUUIDUtil.generate();
6986    
6987                    journalFolder.setUuid(uuid);
6988    
6989                    return journalFolder;
6990            }
6991    
6992            /**
6993             * Removes the journal folder with the primary key from the database. Also notifies the appropriate model listeners.
6994             *
6995             * @param folderId the primary key of the journal folder
6996             * @return the journal folder that was removed
6997             * @throws com.liferay.portlet.journal.NoSuchFolderException if a journal folder with the primary key could not be found
6998             * @throws SystemException if a system exception occurred
6999             */
7000            @Override
7001            public JournalFolder remove(long folderId)
7002                    throws NoSuchFolderException, SystemException {
7003                    return remove((Serializable)folderId);
7004            }
7005    
7006            /**
7007             * Removes the journal folder with the primary key from the database. Also notifies the appropriate model listeners.
7008             *
7009             * @param primaryKey the primary key of the journal folder
7010             * @return the journal folder that was removed
7011             * @throws com.liferay.portlet.journal.NoSuchFolderException if a journal folder with the primary key could not be found
7012             * @throws SystemException if a system exception occurred
7013             */
7014            @Override
7015            public JournalFolder remove(Serializable primaryKey)
7016                    throws NoSuchFolderException, SystemException {
7017                    Session session = null;
7018    
7019                    try {
7020                            session = openSession();
7021    
7022                            JournalFolder journalFolder = (JournalFolder)session.get(JournalFolderImpl.class,
7023                                            primaryKey);
7024    
7025                            if (journalFolder == null) {
7026                                    if (_log.isWarnEnabled()) {
7027                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
7028                                    }
7029    
7030                                    throw new NoSuchFolderException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
7031                                            primaryKey);
7032                            }
7033    
7034                            return remove(journalFolder);
7035                    }
7036                    catch (NoSuchFolderException nsee) {
7037                            throw nsee;
7038                    }
7039                    catch (Exception e) {
7040                            throw processException(e);
7041                    }
7042                    finally {
7043                            closeSession(session);
7044                    }
7045            }
7046    
7047            @Override
7048            protected JournalFolder removeImpl(JournalFolder journalFolder)
7049                    throws SystemException {
7050                    journalFolder = toUnwrappedModel(journalFolder);
7051    
7052                    Session session = null;
7053    
7054                    try {
7055                            session = openSession();
7056    
7057                            if (!session.contains(journalFolder)) {
7058                                    journalFolder = (JournalFolder)session.get(JournalFolderImpl.class,
7059                                                    journalFolder.getPrimaryKeyObj());
7060                            }
7061    
7062                            if (journalFolder != null) {
7063                                    session.delete(journalFolder);
7064                            }
7065                    }
7066                    catch (Exception e) {
7067                            throw processException(e);
7068                    }
7069                    finally {
7070                            closeSession(session);
7071                    }
7072    
7073                    if (journalFolder != null) {
7074                            clearCache(journalFolder);
7075                    }
7076    
7077                    return journalFolder;
7078            }
7079    
7080            @Override
7081            public JournalFolder updateImpl(
7082                    com.liferay.portlet.journal.model.JournalFolder journalFolder)
7083                    throws SystemException {
7084                    journalFolder = toUnwrappedModel(journalFolder);
7085    
7086                    boolean isNew = journalFolder.isNew();
7087    
7088                    JournalFolderModelImpl journalFolderModelImpl = (JournalFolderModelImpl)journalFolder;
7089    
7090                    if (Validator.isNull(journalFolder.getUuid())) {
7091                            String uuid = PortalUUIDUtil.generate();
7092    
7093                            journalFolder.setUuid(uuid);
7094                    }
7095    
7096                    Session session = null;
7097    
7098                    try {
7099                            session = openSession();
7100    
7101                            if (journalFolder.isNew()) {
7102                                    session.save(journalFolder);
7103    
7104                                    journalFolder.setNew(false);
7105                            }
7106                            else {
7107                                    session.merge(journalFolder);
7108                            }
7109                    }
7110                    catch (Exception e) {
7111                            throw processException(e);
7112                    }
7113                    finally {
7114                            closeSession(session);
7115                    }
7116    
7117                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7118    
7119                    if (isNew || !JournalFolderModelImpl.COLUMN_BITMASK_ENABLED) {
7120                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7121                    }
7122    
7123                    else {
7124                            if ((journalFolderModelImpl.getColumnBitmask() &
7125                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
7126                                    Object[] args = new Object[] {
7127                                                    journalFolderModelImpl.getOriginalUuid()
7128                                            };
7129    
7130                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
7131                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
7132                                            args);
7133    
7134                                    args = new Object[] { journalFolderModelImpl.getUuid() };
7135    
7136                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
7137                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
7138                                            args);
7139                            }
7140    
7141                            if ((journalFolderModelImpl.getColumnBitmask() &
7142                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
7143                                    Object[] args = new Object[] {
7144                                                    journalFolderModelImpl.getOriginalUuid(),
7145                                                    journalFolderModelImpl.getOriginalCompanyId()
7146                                            };
7147    
7148                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
7149                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
7150                                            args);
7151    
7152                                    args = new Object[] {
7153                                                    journalFolderModelImpl.getUuid(),
7154                                                    journalFolderModelImpl.getCompanyId()
7155                                            };
7156    
7157                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
7158                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
7159                                            args);
7160                            }
7161    
7162                            if ((journalFolderModelImpl.getColumnBitmask() &
7163                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
7164                                    Object[] args = new Object[] {
7165                                                    journalFolderModelImpl.getOriginalGroupId()
7166                                            };
7167    
7168                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
7169                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
7170                                            args);
7171    
7172                                    args = new Object[] { journalFolderModelImpl.getGroupId() };
7173    
7174                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
7175                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
7176                                            args);
7177                            }
7178    
7179                            if ((journalFolderModelImpl.getColumnBitmask() &
7180                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
7181                                    Object[] args = new Object[] {
7182                                                    journalFolderModelImpl.getOriginalCompanyId()
7183                                            };
7184    
7185                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
7186                                            args);
7187                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
7188                                            args);
7189    
7190                                    args = new Object[] { journalFolderModelImpl.getCompanyId() };
7191    
7192                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
7193                                            args);
7194                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
7195                                            args);
7196                            }
7197    
7198                            if ((journalFolderModelImpl.getColumnBitmask() &
7199                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P.getColumnBitmask()) != 0) {
7200                                    Object[] args = new Object[] {
7201                                                    journalFolderModelImpl.getOriginalGroupId(),
7202                                                    journalFolderModelImpl.getOriginalParentFolderId()
7203                                            };
7204    
7205                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
7206                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
7207                                            args);
7208    
7209                                    args = new Object[] {
7210                                                    journalFolderModelImpl.getGroupId(),
7211                                                    journalFolderModelImpl.getParentFolderId()
7212                                            };
7213    
7214                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
7215                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
7216                                            args);
7217                            }
7218    
7219                            if ((journalFolderModelImpl.getColumnBitmask() &
7220                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_S.getColumnBitmask()) != 0) {
7221                                    Object[] args = new Object[] {
7222                                                    journalFolderModelImpl.getOriginalGroupId(),
7223                                                    journalFolderModelImpl.getOriginalParentFolderId(),
7224                                                    journalFolderModelImpl.getOriginalStatus()
7225                                            };
7226    
7227                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_S, args);
7228                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_S,
7229                                            args);
7230    
7231                                    args = new Object[] {
7232                                                    journalFolderModelImpl.getGroupId(),
7233                                                    journalFolderModelImpl.getParentFolderId(),
7234                                                    journalFolderModelImpl.getStatus()
7235                                            };
7236    
7237                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_S, args);
7238                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_S,
7239                                            args);
7240                            }
7241                    }
7242    
7243                    EntityCacheUtil.putResult(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
7244                            JournalFolderImpl.class, journalFolder.getPrimaryKey(),
7245                            journalFolder);
7246    
7247                    clearUniqueFindersCache(journalFolder);
7248                    cacheUniqueFindersCache(journalFolder);
7249    
7250                    return journalFolder;
7251            }
7252    
7253            protected JournalFolder toUnwrappedModel(JournalFolder journalFolder) {
7254                    if (journalFolder instanceof JournalFolderImpl) {
7255                            return journalFolder;
7256                    }
7257    
7258                    JournalFolderImpl journalFolderImpl = new JournalFolderImpl();
7259    
7260                    journalFolderImpl.setNew(journalFolder.isNew());
7261                    journalFolderImpl.setPrimaryKey(journalFolder.getPrimaryKey());
7262    
7263                    journalFolderImpl.setUuid(journalFolder.getUuid());
7264                    journalFolderImpl.setFolderId(journalFolder.getFolderId());
7265                    journalFolderImpl.setGroupId(journalFolder.getGroupId());
7266                    journalFolderImpl.setCompanyId(journalFolder.getCompanyId());
7267                    journalFolderImpl.setUserId(journalFolder.getUserId());
7268                    journalFolderImpl.setUserName(journalFolder.getUserName());
7269                    journalFolderImpl.setCreateDate(journalFolder.getCreateDate());
7270                    journalFolderImpl.setModifiedDate(journalFolder.getModifiedDate());
7271                    journalFolderImpl.setParentFolderId(journalFolder.getParentFolderId());
7272                    journalFolderImpl.setTreePath(journalFolder.getTreePath());
7273                    journalFolderImpl.setName(journalFolder.getName());
7274                    journalFolderImpl.setDescription(journalFolder.getDescription());
7275                    journalFolderImpl.setStatus(journalFolder.getStatus());
7276                    journalFolderImpl.setStatusByUserId(journalFolder.getStatusByUserId());
7277                    journalFolderImpl.setStatusByUserName(journalFolder.getStatusByUserName());
7278                    journalFolderImpl.setStatusDate(journalFolder.getStatusDate());
7279    
7280                    return journalFolderImpl;
7281            }
7282    
7283            /**
7284             * Returns the journal folder with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
7285             *
7286             * @param primaryKey the primary key of the journal folder
7287             * @return the journal folder
7288             * @throws com.liferay.portlet.journal.NoSuchFolderException if a journal folder with the primary key could not be found
7289             * @throws SystemException if a system exception occurred
7290             */
7291            @Override
7292            public JournalFolder findByPrimaryKey(Serializable primaryKey)
7293                    throws NoSuchFolderException, SystemException {
7294                    JournalFolder journalFolder = fetchByPrimaryKey(primaryKey);
7295    
7296                    if (journalFolder == null) {
7297                            if (_log.isWarnEnabled()) {
7298                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
7299                            }
7300    
7301                            throw new NoSuchFolderException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
7302                                    primaryKey);
7303                    }
7304    
7305                    return journalFolder;
7306            }
7307    
7308            /**
7309             * Returns the journal folder with the primary key or throws a {@link com.liferay.portlet.journal.NoSuchFolderException} if it could not be found.
7310             *
7311             * @param folderId the primary key of the journal folder
7312             * @return the journal folder
7313             * @throws com.liferay.portlet.journal.NoSuchFolderException if a journal folder with the primary key could not be found
7314             * @throws SystemException if a system exception occurred
7315             */
7316            @Override
7317            public JournalFolder findByPrimaryKey(long folderId)
7318                    throws NoSuchFolderException, SystemException {
7319                    return findByPrimaryKey((Serializable)folderId);
7320            }
7321    
7322            /**
7323             * Returns the journal folder with the primary key or returns <code>null</code> if it could not be found.
7324             *
7325             * @param primaryKey the primary key of the journal folder
7326             * @return the journal folder, or <code>null</code> if a journal folder with the primary key could not be found
7327             * @throws SystemException if a system exception occurred
7328             */
7329            @Override
7330            public JournalFolder fetchByPrimaryKey(Serializable primaryKey)
7331                    throws SystemException {
7332                    JournalFolder journalFolder = (JournalFolder)EntityCacheUtil.getResult(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
7333                                    JournalFolderImpl.class, primaryKey);
7334    
7335                    if (journalFolder == _nullJournalFolder) {
7336                            return null;
7337                    }
7338    
7339                    if (journalFolder == null) {
7340                            Session session = null;
7341    
7342                            try {
7343                                    session = openSession();
7344    
7345                                    journalFolder = (JournalFolder)session.get(JournalFolderImpl.class,
7346                                                    primaryKey);
7347    
7348                                    if (journalFolder != null) {
7349                                            cacheResult(journalFolder);
7350                                    }
7351                                    else {
7352                                            EntityCacheUtil.putResult(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
7353                                                    JournalFolderImpl.class, primaryKey, _nullJournalFolder);
7354                                    }
7355                            }
7356                            catch (Exception e) {
7357                                    EntityCacheUtil.removeResult(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
7358                                            JournalFolderImpl.class, primaryKey);
7359    
7360                                    throw processException(e);
7361                            }
7362                            finally {
7363                                    closeSession(session);
7364                            }
7365                    }
7366    
7367                    return journalFolder;
7368            }
7369    
7370            /**
7371             * Returns the journal folder with the primary key or returns <code>null</code> if it could not be found.
7372             *
7373             * @param folderId the primary key of the journal folder
7374             * @return the journal folder, or <code>null</code> if a journal folder with the primary key could not be found
7375             * @throws SystemException if a system exception occurred
7376             */
7377            @Override
7378            public JournalFolder fetchByPrimaryKey(long folderId)
7379                    throws SystemException {
7380                    return fetchByPrimaryKey((Serializable)folderId);
7381            }
7382    
7383            /**
7384             * Returns all the journal folders.
7385             *
7386             * @return the journal folders
7387             * @throws SystemException if a system exception occurred
7388             */
7389            @Override
7390            public List<JournalFolder> findAll() throws SystemException {
7391                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7392            }
7393    
7394            /**
7395             * Returns a range of all the journal folders.
7396             *
7397             * <p>
7398             * 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.
7399             * </p>
7400             *
7401             * @param start the lower bound of the range of journal folders
7402             * @param end the upper bound of the range of journal folders (not inclusive)
7403             * @return the range of journal folders
7404             * @throws SystemException if a system exception occurred
7405             */
7406            @Override
7407            public List<JournalFolder> findAll(int start, int end)
7408                    throws SystemException {
7409                    return findAll(start, end, null);
7410            }
7411    
7412            /**
7413             * Returns an ordered range of all the journal folders.
7414             *
7415             * <p>
7416             * 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.
7417             * </p>
7418             *
7419             * @param start the lower bound of the range of journal folders
7420             * @param end the upper bound of the range of journal folders (not inclusive)
7421             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7422             * @return the ordered range of journal folders
7423             * @throws SystemException if a system exception occurred
7424             */
7425            @Override
7426            public List<JournalFolder> findAll(int start, int end,
7427                    OrderByComparator orderByComparator) throws SystemException {
7428                    boolean pagination = true;
7429                    FinderPath finderPath = null;
7430                    Object[] finderArgs = null;
7431    
7432                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7433                                    (orderByComparator == null)) {
7434                            pagination = false;
7435                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
7436                            finderArgs = FINDER_ARGS_EMPTY;
7437                    }
7438                    else {
7439                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
7440                            finderArgs = new Object[] { start, end, orderByComparator };
7441                    }
7442    
7443                    List<JournalFolder> list = (List<JournalFolder>)FinderCacheUtil.getResult(finderPath,
7444                                    finderArgs, this);
7445    
7446                    if (list == null) {
7447                            StringBundler query = null;
7448                            String sql = null;
7449    
7450                            if (orderByComparator != null) {
7451                                    query = new StringBundler(2 +
7452                                                    (orderByComparator.getOrderByFields().length * 3));
7453    
7454                                    query.append(_SQL_SELECT_JOURNALFOLDER);
7455    
7456                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7457                                            orderByComparator);
7458    
7459                                    sql = query.toString();
7460                            }
7461                            else {
7462                                    sql = _SQL_SELECT_JOURNALFOLDER;
7463    
7464                                    if (pagination) {
7465                                            sql = sql.concat(JournalFolderModelImpl.ORDER_BY_JPQL);
7466                                    }
7467                            }
7468    
7469                            Session session = null;
7470    
7471                            try {
7472                                    session = openSession();
7473    
7474                                    Query q = session.createQuery(sql);
7475    
7476                                    if (!pagination) {
7477                                            list = (List<JournalFolder>)QueryUtil.list(q, getDialect(),
7478                                                            start, end, false);
7479    
7480                                            Collections.sort(list);
7481    
7482                                            list = new UnmodifiableList<JournalFolder>(list);
7483                                    }
7484                                    else {
7485                                            list = (List<JournalFolder>)QueryUtil.list(q, getDialect(),
7486                                                            start, end);
7487                                    }
7488    
7489                                    cacheResult(list);
7490    
7491                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
7492                            }
7493                            catch (Exception e) {
7494                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7495    
7496                                    throw processException(e);
7497                            }
7498                            finally {
7499                                    closeSession(session);
7500                            }
7501                    }
7502    
7503                    return list;
7504            }
7505    
7506            /**
7507             * Removes all the journal folders from the database.
7508             *
7509             * @throws SystemException if a system exception occurred
7510             */
7511            @Override
7512            public void removeAll() throws SystemException {
7513                    for (JournalFolder journalFolder : findAll()) {
7514                            remove(journalFolder);
7515                    }
7516            }
7517    
7518            /**
7519             * Returns the number of journal folders.
7520             *
7521             * @return the number of journal folders
7522             * @throws SystemException if a system exception occurred
7523             */
7524            @Override
7525            public int countAll() throws SystemException {
7526                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
7527                                    FINDER_ARGS_EMPTY, this);
7528    
7529                    if (count == null) {
7530                            Session session = null;
7531    
7532                            try {
7533                                    session = openSession();
7534    
7535                                    Query q = session.createQuery(_SQL_COUNT_JOURNALFOLDER);
7536    
7537                                    count = (Long)q.uniqueResult();
7538    
7539                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
7540                                            FINDER_ARGS_EMPTY, count);
7541                            }
7542                            catch (Exception e) {
7543                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
7544                                            FINDER_ARGS_EMPTY);
7545    
7546                                    throw processException(e);
7547                            }
7548                            finally {
7549                                    closeSession(session);
7550                            }
7551                    }
7552    
7553                    return count.intValue();
7554            }
7555    
7556            @Override
7557            protected Set<String> getBadColumnNames() {
7558                    return _badColumnNames;
7559            }
7560    
7561            /**
7562             * Initializes the journal folder persistence.
7563             */
7564            public void afterPropertiesSet() {
7565                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
7566                                            com.liferay.portal.util.PropsUtil.get(
7567                                                    "value.object.listener.com.liferay.portlet.journal.model.JournalFolder")));
7568    
7569                    if (listenerClassNames.length > 0) {
7570                            try {
7571                                    List<ModelListener<JournalFolder>> listenersList = new ArrayList<ModelListener<JournalFolder>>();
7572    
7573                                    for (String listenerClassName : listenerClassNames) {
7574                                            listenersList.add((ModelListener<JournalFolder>)InstanceFactory.newInstance(
7575                                                            getClassLoader(), listenerClassName));
7576                                    }
7577    
7578                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
7579                            }
7580                            catch (Exception e) {
7581                                    _log.error(e);
7582                            }
7583                    }
7584            }
7585    
7586            public void destroy() {
7587                    EntityCacheUtil.removeCache(JournalFolderImpl.class.getName());
7588                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
7589                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7590                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7591            }
7592    
7593            private static final String _SQL_SELECT_JOURNALFOLDER = "SELECT journalFolder FROM JournalFolder journalFolder";
7594            private static final String _SQL_SELECT_JOURNALFOLDER_WHERE = "SELECT journalFolder FROM JournalFolder journalFolder WHERE ";
7595            private static final String _SQL_COUNT_JOURNALFOLDER = "SELECT COUNT(journalFolder) FROM JournalFolder journalFolder";
7596            private static final String _SQL_COUNT_JOURNALFOLDER_WHERE = "SELECT COUNT(journalFolder) FROM JournalFolder journalFolder WHERE ";
7597            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "journalFolder.folderId";
7598            private static final String _FILTER_SQL_SELECT_JOURNALFOLDER_WHERE = "SELECT DISTINCT {journalFolder.*} FROM JournalFolder journalFolder WHERE ";
7599            private static final String _FILTER_SQL_SELECT_JOURNALFOLDER_NO_INLINE_DISTINCT_WHERE_1 =
7600                    "SELECT {JournalFolder.*} FROM (SELECT DISTINCT journalFolder.folderId FROM JournalFolder journalFolder WHERE ";
7601            private static final String _FILTER_SQL_SELECT_JOURNALFOLDER_NO_INLINE_DISTINCT_WHERE_2 =
7602                    ") TEMP_TABLE INNER JOIN JournalFolder ON TEMP_TABLE.folderId = JournalFolder.folderId";
7603            private static final String _FILTER_SQL_COUNT_JOURNALFOLDER_WHERE = "SELECT COUNT(DISTINCT journalFolder.folderId) AS COUNT_VALUE FROM JournalFolder journalFolder WHERE ";
7604            private static final String _FILTER_ENTITY_ALIAS = "journalFolder";
7605            private static final String _FILTER_ENTITY_TABLE = "JournalFolder";
7606            private static final String _ORDER_BY_ENTITY_ALIAS = "journalFolder.";
7607            private static final String _ORDER_BY_ENTITY_TABLE = "JournalFolder.";
7608            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No JournalFolder exists with the primary key ";
7609            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No JournalFolder exists with the key {";
7610            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
7611            private static Log _log = LogFactoryUtil.getLog(JournalFolderPersistenceImpl.class);
7612            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
7613                                    "uuid"
7614                            });
7615            private static JournalFolder _nullJournalFolder = new JournalFolderImpl() {
7616                            @Override
7617                            public Object clone() {
7618                                    return this;
7619                            }
7620    
7621                            @Override
7622                            public CacheModel<JournalFolder> toCacheModel() {
7623                                    return _nullJournalFolderCacheModel;
7624                            }
7625                    };
7626    
7627            private static CacheModel<JournalFolder> _nullJournalFolderCacheModel = new CacheModel<JournalFolder>() {
7628                            @Override
7629                            public JournalFolder toEntityModel() {
7630                                    return _nullJournalFolder;
7631                            }
7632                    };
7633    }