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_WITH_PAGINATION_FIND_BY_F_C_P_NOTS =
4516                    new FinderPath(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
4517                            JournalFolderModelImpl.FINDER_CACHE_ENABLED,
4518                            JournalFolderImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
4519                            "findByF_C_P_NotS",
4520                            new String[] {
4521                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
4522                                    Integer.class.getName(),
4523                                    
4524                            Integer.class.getName(), Integer.class.getName(),
4525                                    OrderByComparator.class.getName()
4526                            });
4527            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_F_C_P_NOTS =
4528                    new FinderPath(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
4529                            JournalFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
4530                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByF_C_P_NotS",
4531                            new String[] {
4532                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
4533                                    Integer.class.getName()
4534                            });
4535    
4536            /**
4537             * Returns all the journal folders where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
4538             *
4539             * @param folderId the folder ID
4540             * @param companyId the company ID
4541             * @param parentFolderId the parent folder ID
4542             * @param status the status
4543             * @return the matching journal folders
4544             * @throws SystemException if a system exception occurred
4545             */
4546            @Override
4547            public List<JournalFolder> findByF_C_P_NotS(long folderId, long companyId,
4548                    long parentFolderId, int status) throws SystemException {
4549                    return findByF_C_P_NotS(folderId, companyId, parentFolderId, status,
4550                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4551            }
4552    
4553            /**
4554             * Returns a range of all the journal folders where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
4555             *
4556             * <p>
4557             * 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.
4558             * </p>
4559             *
4560             * @param folderId the folder ID
4561             * @param companyId the company ID
4562             * @param parentFolderId the parent folder ID
4563             * @param status the status
4564             * @param start the lower bound of the range of journal folders
4565             * @param end the upper bound of the range of journal folders (not inclusive)
4566             * @return the range of matching journal folders
4567             * @throws SystemException if a system exception occurred
4568             */
4569            @Override
4570            public List<JournalFolder> findByF_C_P_NotS(long folderId, long companyId,
4571                    long parentFolderId, int status, int start, int end)
4572                    throws SystemException {
4573                    return findByF_C_P_NotS(folderId, companyId, parentFolderId, status,
4574                            start, end, null);
4575            }
4576    
4577            /**
4578             * Returns an ordered range of all the journal folders where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
4579             *
4580             * <p>
4581             * 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.
4582             * </p>
4583             *
4584             * @param folderId the folder ID
4585             * @param companyId the company ID
4586             * @param parentFolderId the parent folder ID
4587             * @param status the status
4588             * @param start the lower bound of the range of journal folders
4589             * @param end the upper bound of the range of journal folders (not inclusive)
4590             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4591             * @return the ordered range of matching journal folders
4592             * @throws SystemException if a system exception occurred
4593             */
4594            @Override
4595            public List<JournalFolder> findByF_C_P_NotS(long folderId, long companyId,
4596                    long parentFolderId, int status, int start, int end,
4597                    OrderByComparator orderByComparator) throws SystemException {
4598                    boolean pagination = true;
4599                    FinderPath finderPath = null;
4600                    Object[] finderArgs = null;
4601    
4602                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_F_C_P_NOTS;
4603                    finderArgs = new Object[] {
4604                                    folderId, companyId, parentFolderId, status,
4605                                    
4606                                    start, end, orderByComparator
4607                            };
4608    
4609                    List<JournalFolder> list = (List<JournalFolder>)FinderCacheUtil.getResult(finderPath,
4610                                    finderArgs, this);
4611    
4612                    if ((list != null) && !list.isEmpty()) {
4613                            for (JournalFolder journalFolder : list) {
4614                                    if ((folderId >= journalFolder.getFolderId()) ||
4615                                                    (companyId != journalFolder.getCompanyId()) ||
4616                                                    (parentFolderId != journalFolder.getParentFolderId()) ||
4617                                                    (status == journalFolder.getStatus())) {
4618                                            list = null;
4619    
4620                                            break;
4621                                    }
4622                            }
4623                    }
4624    
4625                    if (list == null) {
4626                            StringBundler query = null;
4627    
4628                            if (orderByComparator != null) {
4629                                    query = new StringBundler(6 +
4630                                                    (orderByComparator.getOrderByFields().length * 3));
4631                            }
4632                            else {
4633                                    query = new StringBundler(6);
4634                            }
4635    
4636                            query.append(_SQL_SELECT_JOURNALFOLDER_WHERE);
4637    
4638                            query.append(_FINDER_COLUMN_F_C_P_NOTS_FOLDERID_2);
4639    
4640                            query.append(_FINDER_COLUMN_F_C_P_NOTS_COMPANYID_2);
4641    
4642                            query.append(_FINDER_COLUMN_F_C_P_NOTS_PARENTFOLDERID_2);
4643    
4644                            query.append(_FINDER_COLUMN_F_C_P_NOTS_STATUS_2);
4645    
4646                            if (orderByComparator != null) {
4647                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4648                                            orderByComparator);
4649                            }
4650                            else
4651                             if (pagination) {
4652                                    query.append(JournalFolderModelImpl.ORDER_BY_JPQL);
4653                            }
4654    
4655                            String sql = query.toString();
4656    
4657                            Session session = null;
4658    
4659                            try {
4660                                    session = openSession();
4661    
4662                                    Query q = session.createQuery(sql);
4663    
4664                                    QueryPos qPos = QueryPos.getInstance(q);
4665    
4666                                    qPos.add(folderId);
4667    
4668                                    qPos.add(companyId);
4669    
4670                                    qPos.add(parentFolderId);
4671    
4672                                    qPos.add(status);
4673    
4674                                    if (!pagination) {
4675                                            list = (List<JournalFolder>)QueryUtil.list(q, getDialect(),
4676                                                            start, end, false);
4677    
4678                                            Collections.sort(list);
4679    
4680                                            list = new UnmodifiableList<JournalFolder>(list);
4681                                    }
4682                                    else {
4683                                            list = (List<JournalFolder>)QueryUtil.list(q, getDialect(),
4684                                                            start, end);
4685                                    }
4686    
4687                                    cacheResult(list);
4688    
4689                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4690                            }
4691                            catch (Exception e) {
4692                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4693    
4694                                    throw processException(e);
4695                            }
4696                            finally {
4697                                    closeSession(session);
4698                            }
4699                    }
4700    
4701                    return list;
4702            }
4703    
4704            /**
4705             * Returns the first journal folder in the ordered set where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
4706             *
4707             * @param folderId the folder ID
4708             * @param companyId the company ID
4709             * @param parentFolderId the parent folder ID
4710             * @param status the status
4711             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4712             * @return the first matching journal folder
4713             * @throws com.liferay.portlet.journal.NoSuchFolderException if a matching journal folder could not be found
4714             * @throws SystemException if a system exception occurred
4715             */
4716            @Override
4717            public JournalFolder findByF_C_P_NotS_First(long folderId, long companyId,
4718                    long parentFolderId, int status, OrderByComparator orderByComparator)
4719                    throws NoSuchFolderException, SystemException {
4720                    JournalFolder journalFolder = fetchByF_C_P_NotS_First(folderId,
4721                                    companyId, parentFolderId, status, orderByComparator);
4722    
4723                    if (journalFolder != null) {
4724                            return journalFolder;
4725                    }
4726    
4727                    StringBundler msg = new StringBundler(10);
4728    
4729                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4730    
4731                    msg.append("folderId=");
4732                    msg.append(folderId);
4733    
4734                    msg.append(", companyId=");
4735                    msg.append(companyId);
4736    
4737                    msg.append(", parentFolderId=");
4738                    msg.append(parentFolderId);
4739    
4740                    msg.append(", status=");
4741                    msg.append(status);
4742    
4743                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4744    
4745                    throw new NoSuchFolderException(msg.toString());
4746            }
4747    
4748            /**
4749             * Returns the first journal folder in the ordered set where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
4750             *
4751             * @param folderId the folder ID
4752             * @param companyId the company ID
4753             * @param parentFolderId the parent folder ID
4754             * @param status the status
4755             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4756             * @return the first matching journal folder, or <code>null</code> if a matching journal folder could not be found
4757             * @throws SystemException if a system exception occurred
4758             */
4759            @Override
4760            public JournalFolder fetchByF_C_P_NotS_First(long folderId, long companyId,
4761                    long parentFolderId, int status, OrderByComparator orderByComparator)
4762                    throws SystemException {
4763                    List<JournalFolder> list = findByF_C_P_NotS(folderId, companyId,
4764                                    parentFolderId, status, 0, 1, orderByComparator);
4765    
4766                    if (!list.isEmpty()) {
4767                            return list.get(0);
4768                    }
4769    
4770                    return null;
4771            }
4772    
4773            /**
4774             * Returns the last journal folder in the ordered set where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
4775             *
4776             * @param folderId the folder ID
4777             * @param companyId the company ID
4778             * @param parentFolderId the parent folder ID
4779             * @param status the status
4780             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4781             * @return the last matching journal folder
4782             * @throws com.liferay.portlet.journal.NoSuchFolderException if a matching journal folder could not be found
4783             * @throws SystemException if a system exception occurred
4784             */
4785            @Override
4786            public JournalFolder findByF_C_P_NotS_Last(long folderId, long companyId,
4787                    long parentFolderId, int status, OrderByComparator orderByComparator)
4788                    throws NoSuchFolderException, SystemException {
4789                    JournalFolder journalFolder = fetchByF_C_P_NotS_Last(folderId,
4790                                    companyId, parentFolderId, status, orderByComparator);
4791    
4792                    if (journalFolder != null) {
4793                            return journalFolder;
4794                    }
4795    
4796                    StringBundler msg = new StringBundler(10);
4797    
4798                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4799    
4800                    msg.append("folderId=");
4801                    msg.append(folderId);
4802    
4803                    msg.append(", companyId=");
4804                    msg.append(companyId);
4805    
4806                    msg.append(", parentFolderId=");
4807                    msg.append(parentFolderId);
4808    
4809                    msg.append(", status=");
4810                    msg.append(status);
4811    
4812                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4813    
4814                    throw new NoSuchFolderException(msg.toString());
4815            }
4816    
4817            /**
4818             * Returns the last journal folder in the ordered set where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
4819             *
4820             * @param folderId the folder ID
4821             * @param companyId the company ID
4822             * @param parentFolderId the parent folder ID
4823             * @param status the status
4824             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4825             * @return the last matching journal folder, or <code>null</code> if a matching journal folder could not be found
4826             * @throws SystemException if a system exception occurred
4827             */
4828            @Override
4829            public JournalFolder fetchByF_C_P_NotS_Last(long folderId, long companyId,
4830                    long parentFolderId, int status, OrderByComparator orderByComparator)
4831                    throws SystemException {
4832                    int count = countByF_C_P_NotS(folderId, companyId, parentFolderId,
4833                                    status);
4834    
4835                    if (count == 0) {
4836                            return null;
4837                    }
4838    
4839                    List<JournalFolder> list = findByF_C_P_NotS(folderId, companyId,
4840                                    parentFolderId, status, count - 1, count, orderByComparator);
4841    
4842                    if (!list.isEmpty()) {
4843                            return list.get(0);
4844                    }
4845    
4846                    return null;
4847            }
4848    
4849            /**
4850             * Removes all the journal folders where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63; from the database.
4851             *
4852             * @param folderId the folder ID
4853             * @param companyId the company ID
4854             * @param parentFolderId the parent folder ID
4855             * @param status the status
4856             * @throws SystemException if a system exception occurred
4857             */
4858            @Override
4859            public void removeByF_C_P_NotS(long folderId, long companyId,
4860                    long parentFolderId, int status) throws SystemException {
4861                    for (JournalFolder journalFolder : findByF_C_P_NotS(folderId,
4862                                    companyId, parentFolderId, status, QueryUtil.ALL_POS,
4863                                    QueryUtil.ALL_POS, null)) {
4864                            remove(journalFolder);
4865                    }
4866            }
4867    
4868            /**
4869             * Returns the number of journal folders where folderId &gt; &#63; and companyId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
4870             *
4871             * @param folderId the folder ID
4872             * @param companyId the company ID
4873             * @param parentFolderId the parent folder ID
4874             * @param status the status
4875             * @return the number of matching journal folders
4876             * @throws SystemException if a system exception occurred
4877             */
4878            @Override
4879            public int countByF_C_P_NotS(long folderId, long companyId,
4880                    long parentFolderId, int status) throws SystemException {
4881                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_F_C_P_NOTS;
4882    
4883                    Object[] finderArgs = new Object[] {
4884                                    folderId, companyId, parentFolderId, status
4885                            };
4886    
4887                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4888                                    this);
4889    
4890                    if (count == null) {
4891                            StringBundler query = new StringBundler(5);
4892    
4893                            query.append(_SQL_COUNT_JOURNALFOLDER_WHERE);
4894    
4895                            query.append(_FINDER_COLUMN_F_C_P_NOTS_FOLDERID_2);
4896    
4897                            query.append(_FINDER_COLUMN_F_C_P_NOTS_COMPANYID_2);
4898    
4899                            query.append(_FINDER_COLUMN_F_C_P_NOTS_PARENTFOLDERID_2);
4900    
4901                            query.append(_FINDER_COLUMN_F_C_P_NOTS_STATUS_2);
4902    
4903                            String sql = query.toString();
4904    
4905                            Session session = null;
4906    
4907                            try {
4908                                    session = openSession();
4909    
4910                                    Query q = session.createQuery(sql);
4911    
4912                                    QueryPos qPos = QueryPos.getInstance(q);
4913    
4914                                    qPos.add(folderId);
4915    
4916                                    qPos.add(companyId);
4917    
4918                                    qPos.add(parentFolderId);
4919    
4920                                    qPos.add(status);
4921    
4922                                    count = (Long)q.uniqueResult();
4923    
4924                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4925                            }
4926                            catch (Exception e) {
4927                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4928    
4929                                    throw processException(e);
4930                            }
4931                            finally {
4932                                    closeSession(session);
4933                            }
4934                    }
4935    
4936                    return count.intValue();
4937            }
4938    
4939            private static final String _FINDER_COLUMN_F_C_P_NOTS_FOLDERID_2 = "journalFolder.folderId > ? AND ";
4940            private static final String _FINDER_COLUMN_F_C_P_NOTS_COMPANYID_2 = "journalFolder.companyId = ? AND ";
4941            private static final String _FINDER_COLUMN_F_C_P_NOTS_PARENTFOLDERID_2 = "journalFolder.parentFolderId = ? AND ";
4942            private static final String _FINDER_COLUMN_F_C_P_NOTS_STATUS_2 = "journalFolder.status != ?";
4943            public static final FinderPath FINDER_PATH_FETCH_BY_G_P_N = new FinderPath(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
4944                            JournalFolderModelImpl.FINDER_CACHE_ENABLED,
4945                            JournalFolderImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByG_P_N",
4946                            new String[] {
4947                                    Long.class.getName(), Long.class.getName(),
4948                                    String.class.getName()
4949                            },
4950                            JournalFolderModelImpl.GROUPID_COLUMN_BITMASK |
4951                            JournalFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
4952                            JournalFolderModelImpl.NAME_COLUMN_BITMASK);
4953            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_N = new FinderPath(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
4954                            JournalFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
4955                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_N",
4956                            new String[] {
4957                                    Long.class.getName(), Long.class.getName(),
4958                                    String.class.getName()
4959                            });
4960    
4961            /**
4962             * 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.
4963             *
4964             * @param groupId the group ID
4965             * @param parentFolderId the parent folder ID
4966             * @param name the name
4967             * @return the matching journal folder
4968             * @throws com.liferay.portlet.journal.NoSuchFolderException if a matching journal folder could not be found
4969             * @throws SystemException if a system exception occurred
4970             */
4971            @Override
4972            public JournalFolder findByG_P_N(long groupId, long parentFolderId,
4973                    String name) throws NoSuchFolderException, SystemException {
4974                    JournalFolder journalFolder = fetchByG_P_N(groupId, parentFolderId, name);
4975    
4976                    if (journalFolder == null) {
4977                            StringBundler msg = new StringBundler(8);
4978    
4979                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4980    
4981                            msg.append("groupId=");
4982                            msg.append(groupId);
4983    
4984                            msg.append(", parentFolderId=");
4985                            msg.append(parentFolderId);
4986    
4987                            msg.append(", name=");
4988                            msg.append(name);
4989    
4990                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4991    
4992                            if (_log.isWarnEnabled()) {
4993                                    _log.warn(msg.toString());
4994                            }
4995    
4996                            throw new NoSuchFolderException(msg.toString());
4997                    }
4998    
4999                    return journalFolder;
5000            }
5001    
5002            /**
5003             * 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.
5004             *
5005             * @param groupId the group ID
5006             * @param parentFolderId the parent folder ID
5007             * @param name the name
5008             * @return the matching journal folder, or <code>null</code> if a matching journal folder could not be found
5009             * @throws SystemException if a system exception occurred
5010             */
5011            @Override
5012            public JournalFolder fetchByG_P_N(long groupId, long parentFolderId,
5013                    String name) throws SystemException {
5014                    return fetchByG_P_N(groupId, parentFolderId, name, true);
5015            }
5016    
5017            /**
5018             * 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.
5019             *
5020             * @param groupId the group ID
5021             * @param parentFolderId the parent folder ID
5022             * @param name the name
5023             * @param retrieveFromCache whether to use the finder cache
5024             * @return the matching journal folder, or <code>null</code> if a matching journal folder could not be found
5025             * @throws SystemException if a system exception occurred
5026             */
5027            @Override
5028            public JournalFolder fetchByG_P_N(long groupId, long parentFolderId,
5029                    String name, boolean retrieveFromCache) throws SystemException {
5030                    Object[] finderArgs = new Object[] { groupId, parentFolderId, name };
5031    
5032                    Object result = null;
5033    
5034                    if (retrieveFromCache) {
5035                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_P_N,
5036                                            finderArgs, this);
5037                    }
5038    
5039                    if (result instanceof JournalFolder) {
5040                            JournalFolder journalFolder = (JournalFolder)result;
5041    
5042                            if ((groupId != journalFolder.getGroupId()) ||
5043                                            (parentFolderId != journalFolder.getParentFolderId()) ||
5044                                            !Validator.equals(name, journalFolder.getName())) {
5045                                    result = null;
5046                            }
5047                    }
5048    
5049                    if (result == null) {
5050                            StringBundler query = new StringBundler(5);
5051    
5052                            query.append(_SQL_SELECT_JOURNALFOLDER_WHERE);
5053    
5054                            query.append(_FINDER_COLUMN_G_P_N_GROUPID_2);
5055    
5056                            query.append(_FINDER_COLUMN_G_P_N_PARENTFOLDERID_2);
5057    
5058                            boolean bindName = false;
5059    
5060                            if (name == null) {
5061                                    query.append(_FINDER_COLUMN_G_P_N_NAME_1);
5062                            }
5063                            else if (name.equals(StringPool.BLANK)) {
5064                                    query.append(_FINDER_COLUMN_G_P_N_NAME_3);
5065                            }
5066                            else {
5067                                    bindName = true;
5068    
5069                                    query.append(_FINDER_COLUMN_G_P_N_NAME_2);
5070                            }
5071    
5072                            String sql = query.toString();
5073    
5074                            Session session = null;
5075    
5076                            try {
5077                                    session = openSession();
5078    
5079                                    Query q = session.createQuery(sql);
5080    
5081                                    QueryPos qPos = QueryPos.getInstance(q);
5082    
5083                                    qPos.add(groupId);
5084    
5085                                    qPos.add(parentFolderId);
5086    
5087                                    if (bindName) {
5088                                            qPos.add(name);
5089                                    }
5090    
5091                                    List<JournalFolder> list = q.list();
5092    
5093                                    if (list.isEmpty()) {
5094                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N,
5095                                                    finderArgs, list);
5096                                    }
5097                                    else {
5098                                            JournalFolder journalFolder = list.get(0);
5099    
5100                                            result = journalFolder;
5101    
5102                                            cacheResult(journalFolder);
5103    
5104                                            if ((journalFolder.getGroupId() != groupId) ||
5105                                                            (journalFolder.getParentFolderId() != parentFolderId) ||
5106                                                            (journalFolder.getName() == null) ||
5107                                                            !journalFolder.getName().equals(name)) {
5108                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N,
5109                                                            finderArgs, journalFolder);
5110                                            }
5111                                    }
5112                            }
5113                            catch (Exception e) {
5114                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_N,
5115                                            finderArgs);
5116    
5117                                    throw processException(e);
5118                            }
5119                            finally {
5120                                    closeSession(session);
5121                            }
5122                    }
5123    
5124                    if (result instanceof List<?>) {
5125                            return null;
5126                    }
5127                    else {
5128                            return (JournalFolder)result;
5129                    }
5130            }
5131    
5132            /**
5133             * Removes the journal folder where groupId = &#63; and parentFolderId = &#63; and name = &#63; from the database.
5134             *
5135             * @param groupId the group ID
5136             * @param parentFolderId the parent folder ID
5137             * @param name the name
5138             * @return the journal folder that was removed
5139             * @throws SystemException if a system exception occurred
5140             */
5141            @Override
5142            public JournalFolder removeByG_P_N(long groupId, long parentFolderId,
5143                    String name) throws NoSuchFolderException, SystemException {
5144                    JournalFolder journalFolder = findByG_P_N(groupId, parentFolderId, name);
5145    
5146                    return remove(journalFolder);
5147            }
5148    
5149            /**
5150             * Returns the number of journal folders where groupId = &#63; and parentFolderId = &#63; and name = &#63;.
5151             *
5152             * @param groupId the group ID
5153             * @param parentFolderId the parent folder ID
5154             * @param name the name
5155             * @return the number of matching journal folders
5156             * @throws SystemException if a system exception occurred
5157             */
5158            @Override
5159            public int countByG_P_N(long groupId, long parentFolderId, String name)
5160                    throws SystemException {
5161                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_N;
5162    
5163                    Object[] finderArgs = new Object[] { groupId, parentFolderId, name };
5164    
5165                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5166                                    this);
5167    
5168                    if (count == null) {
5169                            StringBundler query = new StringBundler(4);
5170    
5171                            query.append(_SQL_COUNT_JOURNALFOLDER_WHERE);
5172    
5173                            query.append(_FINDER_COLUMN_G_P_N_GROUPID_2);
5174    
5175                            query.append(_FINDER_COLUMN_G_P_N_PARENTFOLDERID_2);
5176    
5177                            boolean bindName = false;
5178    
5179                            if (name == null) {
5180                                    query.append(_FINDER_COLUMN_G_P_N_NAME_1);
5181                            }
5182                            else if (name.equals(StringPool.BLANK)) {
5183                                    query.append(_FINDER_COLUMN_G_P_N_NAME_3);
5184                            }
5185                            else {
5186                                    bindName = true;
5187    
5188                                    query.append(_FINDER_COLUMN_G_P_N_NAME_2);
5189                            }
5190    
5191                            String sql = query.toString();
5192    
5193                            Session session = null;
5194    
5195                            try {
5196                                    session = openSession();
5197    
5198                                    Query q = session.createQuery(sql);
5199    
5200                                    QueryPos qPos = QueryPos.getInstance(q);
5201    
5202                                    qPos.add(groupId);
5203    
5204                                    qPos.add(parentFolderId);
5205    
5206                                    if (bindName) {
5207                                            qPos.add(name);
5208                                    }
5209    
5210                                    count = (Long)q.uniqueResult();
5211    
5212                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5213                            }
5214                            catch (Exception e) {
5215                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5216    
5217                                    throw processException(e);
5218                            }
5219                            finally {
5220                                    closeSession(session);
5221                            }
5222                    }
5223    
5224                    return count.intValue();
5225            }
5226    
5227            private static final String _FINDER_COLUMN_G_P_N_GROUPID_2 = "journalFolder.groupId = ? AND ";
5228            private static final String _FINDER_COLUMN_G_P_N_PARENTFOLDERID_2 = "journalFolder.parentFolderId = ? AND ";
5229            private static final String _FINDER_COLUMN_G_P_N_NAME_1 = "journalFolder.name IS NULL";
5230            private static final String _FINDER_COLUMN_G_P_N_NAME_2 = "journalFolder.name = ?";
5231            private static final String _FINDER_COLUMN_G_P_N_NAME_3 = "(journalFolder.name IS NULL OR journalFolder.name = '')";
5232            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_S = new FinderPath(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
5233                            JournalFolderModelImpl.FINDER_CACHE_ENABLED,
5234                            JournalFolderImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
5235                            "findByG_P_S",
5236                            new String[] {
5237                                    Long.class.getName(), Long.class.getName(),
5238                                    Integer.class.getName(),
5239                                    
5240                            Integer.class.getName(), Integer.class.getName(),
5241                                    OrderByComparator.class.getName()
5242                            });
5243            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_S = new FinderPath(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
5244                            JournalFolderModelImpl.FINDER_CACHE_ENABLED,
5245                            JournalFolderImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
5246                            "findByG_P_S",
5247                            new String[] {
5248                                    Long.class.getName(), Long.class.getName(),
5249                                    Integer.class.getName()
5250                            },
5251                            JournalFolderModelImpl.GROUPID_COLUMN_BITMASK |
5252                            JournalFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
5253                            JournalFolderModelImpl.STATUS_COLUMN_BITMASK |
5254                            JournalFolderModelImpl.NAME_COLUMN_BITMASK);
5255            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_S = new FinderPath(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
5256                            JournalFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
5257                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_S",
5258                            new String[] {
5259                                    Long.class.getName(), Long.class.getName(),
5260                                    Integer.class.getName()
5261                            });
5262    
5263            /**
5264             * Returns all the journal folders where groupId = &#63; and parentFolderId = &#63; and status = &#63;.
5265             *
5266             * @param groupId the group ID
5267             * @param parentFolderId the parent folder ID
5268             * @param status the status
5269             * @return the matching journal folders
5270             * @throws SystemException if a system exception occurred
5271             */
5272            @Override
5273            public List<JournalFolder> findByG_P_S(long groupId, long parentFolderId,
5274                    int status) throws SystemException {
5275                    return findByG_P_S(groupId, parentFolderId, status, QueryUtil.ALL_POS,
5276                            QueryUtil.ALL_POS, null);
5277            }
5278    
5279            /**
5280             * Returns a range of all the journal folders where groupId = &#63; and parentFolderId = &#63; and status = &#63;.
5281             *
5282             * <p>
5283             * 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.
5284             * </p>
5285             *
5286             * @param groupId the group ID
5287             * @param parentFolderId the parent folder ID
5288             * @param status the status
5289             * @param start the lower bound of the range of journal folders
5290             * @param end the upper bound of the range of journal folders (not inclusive)
5291             * @return the range of matching journal folders
5292             * @throws SystemException if a system exception occurred
5293             */
5294            @Override
5295            public List<JournalFolder> findByG_P_S(long groupId, long parentFolderId,
5296                    int status, int start, int end) throws SystemException {
5297                    return findByG_P_S(groupId, parentFolderId, status, start, end, null);
5298            }
5299    
5300            /**
5301             * Returns an ordered range of all the journal folders where groupId = &#63; and parentFolderId = &#63; and status = &#63;.
5302             *
5303             * <p>
5304             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5305             * </p>
5306             *
5307             * @param groupId the group ID
5308             * @param parentFolderId the parent folder ID
5309             * @param status the status
5310             * @param start the lower bound of the range of journal folders
5311             * @param end the upper bound of the range of journal folders (not inclusive)
5312             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5313             * @return the ordered range of matching journal folders
5314             * @throws SystemException if a system exception occurred
5315             */
5316            @Override
5317            public List<JournalFolder> findByG_P_S(long groupId, long parentFolderId,
5318                    int status, int start, int end, OrderByComparator orderByComparator)
5319                    throws SystemException {
5320                    boolean pagination = true;
5321                    FinderPath finderPath = null;
5322                    Object[] finderArgs = null;
5323    
5324                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5325                                    (orderByComparator == null)) {
5326                            pagination = false;
5327                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_S;
5328                            finderArgs = new Object[] { groupId, parentFolderId, status };
5329                    }
5330                    else {
5331                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_S;
5332                            finderArgs = new Object[] {
5333                                            groupId, parentFolderId, status,
5334                                            
5335                                            start, end, orderByComparator
5336                                    };
5337                    }
5338    
5339                    List<JournalFolder> list = (List<JournalFolder>)FinderCacheUtil.getResult(finderPath,
5340                                    finderArgs, this);
5341    
5342                    if ((list != null) && !list.isEmpty()) {
5343                            for (JournalFolder journalFolder : list) {
5344                                    if ((groupId != journalFolder.getGroupId()) ||
5345                                                    (parentFolderId != journalFolder.getParentFolderId()) ||
5346                                                    (status != journalFolder.getStatus())) {
5347                                            list = null;
5348    
5349                                            break;
5350                                    }
5351                            }
5352                    }
5353    
5354                    if (list == null) {
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                            query.append(_SQL_SELECT_JOURNALFOLDER_WHERE);
5366    
5367                            query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
5368    
5369                            query.append(_FINDER_COLUMN_G_P_S_PARENTFOLDERID_2);
5370    
5371                            query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
5372    
5373                            if (orderByComparator != null) {
5374                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5375                                            orderByComparator);
5376                            }
5377                            else
5378                             if (pagination) {
5379                                    query.append(JournalFolderModelImpl.ORDER_BY_JPQL);
5380                            }
5381    
5382                            String sql = query.toString();
5383    
5384                            Session session = null;
5385    
5386                            try {
5387                                    session = openSession();
5388    
5389                                    Query q = session.createQuery(sql);
5390    
5391                                    QueryPos qPos = QueryPos.getInstance(q);
5392    
5393                                    qPos.add(groupId);
5394    
5395                                    qPos.add(parentFolderId);
5396    
5397                                    qPos.add(status);
5398    
5399                                    if (!pagination) {
5400                                            list = (List<JournalFolder>)QueryUtil.list(q, getDialect(),
5401                                                            start, end, false);
5402    
5403                                            Collections.sort(list);
5404    
5405                                            list = new UnmodifiableList<JournalFolder>(list);
5406                                    }
5407                                    else {
5408                                            list = (List<JournalFolder>)QueryUtil.list(q, getDialect(),
5409                                                            start, end);
5410                                    }
5411    
5412                                    cacheResult(list);
5413    
5414                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5415                            }
5416                            catch (Exception e) {
5417                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5418    
5419                                    throw processException(e);
5420                            }
5421                            finally {
5422                                    closeSession(session);
5423                            }
5424                    }
5425    
5426                    return list;
5427            }
5428    
5429            /**
5430             * Returns the first journal folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and status = &#63;.
5431             *
5432             * @param groupId the group ID
5433             * @param parentFolderId the parent folder ID
5434             * @param status the status
5435             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5436             * @return the first matching journal folder
5437             * @throws com.liferay.portlet.journal.NoSuchFolderException if a matching journal folder could not be found
5438             * @throws SystemException if a system exception occurred
5439             */
5440            @Override
5441            public JournalFolder findByG_P_S_First(long groupId, long parentFolderId,
5442                    int status, OrderByComparator orderByComparator)
5443                    throws NoSuchFolderException, SystemException {
5444                    JournalFolder journalFolder = fetchByG_P_S_First(groupId,
5445                                    parentFolderId, status, orderByComparator);
5446    
5447                    if (journalFolder != null) {
5448                            return journalFolder;
5449                    }
5450    
5451                    StringBundler msg = new StringBundler(8);
5452    
5453                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5454    
5455                    msg.append("groupId=");
5456                    msg.append(groupId);
5457    
5458                    msg.append(", parentFolderId=");
5459                    msg.append(parentFolderId);
5460    
5461                    msg.append(", status=");
5462                    msg.append(status);
5463    
5464                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5465    
5466                    throw new NoSuchFolderException(msg.toString());
5467            }
5468    
5469            /**
5470             * Returns the first journal folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and status = &#63;.
5471             *
5472             * @param groupId the group ID
5473             * @param parentFolderId the parent folder ID
5474             * @param status the status
5475             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5476             * @return the first matching journal folder, or <code>null</code> if a matching journal folder could not be found
5477             * @throws SystemException if a system exception occurred
5478             */
5479            @Override
5480            public JournalFolder fetchByG_P_S_First(long groupId, long parentFolderId,
5481                    int status, OrderByComparator orderByComparator)
5482                    throws SystemException {
5483                    List<JournalFolder> list = findByG_P_S(groupId, parentFolderId, status,
5484                                    0, 1, orderByComparator);
5485    
5486                    if (!list.isEmpty()) {
5487                            return list.get(0);
5488                    }
5489    
5490                    return null;
5491            }
5492    
5493            /**
5494             * Returns the last journal folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and status = &#63;.
5495             *
5496             * @param groupId the group ID
5497             * @param parentFolderId the parent folder ID
5498             * @param status the status
5499             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5500             * @return the last matching journal folder
5501             * @throws com.liferay.portlet.journal.NoSuchFolderException if a matching journal folder could not be found
5502             * @throws SystemException if a system exception occurred
5503             */
5504            @Override
5505            public JournalFolder findByG_P_S_Last(long groupId, long parentFolderId,
5506                    int status, OrderByComparator orderByComparator)
5507                    throws NoSuchFolderException, SystemException {
5508                    JournalFolder journalFolder = fetchByG_P_S_Last(groupId,
5509                                    parentFolderId, status, orderByComparator);
5510    
5511                    if (journalFolder != null) {
5512                            return journalFolder;
5513                    }
5514    
5515                    StringBundler msg = new StringBundler(8);
5516    
5517                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5518    
5519                    msg.append("groupId=");
5520                    msg.append(groupId);
5521    
5522                    msg.append(", parentFolderId=");
5523                    msg.append(parentFolderId);
5524    
5525                    msg.append(", status=");
5526                    msg.append(status);
5527    
5528                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5529    
5530                    throw new NoSuchFolderException(msg.toString());
5531            }
5532    
5533            /**
5534             * Returns the last journal folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and status = &#63;.
5535             *
5536             * @param groupId the group ID
5537             * @param parentFolderId the parent folder ID
5538             * @param status the status
5539             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5540             * @return the last matching journal folder, or <code>null</code> if a matching journal folder could not be found
5541             * @throws SystemException if a system exception occurred
5542             */
5543            @Override
5544            public JournalFolder fetchByG_P_S_Last(long groupId, long parentFolderId,
5545                    int status, OrderByComparator orderByComparator)
5546                    throws SystemException {
5547                    int count = countByG_P_S(groupId, parentFolderId, status);
5548    
5549                    if (count == 0) {
5550                            return null;
5551                    }
5552    
5553                    List<JournalFolder> list = findByG_P_S(groupId, parentFolderId, status,
5554                                    count - 1, count, orderByComparator);
5555    
5556                    if (!list.isEmpty()) {
5557                            return list.get(0);
5558                    }
5559    
5560                    return null;
5561            }
5562    
5563            /**
5564             * Returns the journal folders before and after the current journal folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and status = &#63;.
5565             *
5566             * @param folderId the primary key of the current journal folder
5567             * @param groupId the group ID
5568             * @param parentFolderId the parent folder ID
5569             * @param status the status
5570             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5571             * @return the previous, current, and next journal folder
5572             * @throws com.liferay.portlet.journal.NoSuchFolderException if a journal folder with the primary key could not be found
5573             * @throws SystemException if a system exception occurred
5574             */
5575            @Override
5576            public JournalFolder[] findByG_P_S_PrevAndNext(long folderId, long groupId,
5577                    long parentFolderId, int status, OrderByComparator orderByComparator)
5578                    throws NoSuchFolderException, SystemException {
5579                    JournalFolder journalFolder = findByPrimaryKey(folderId);
5580    
5581                    Session session = null;
5582    
5583                    try {
5584                            session = openSession();
5585    
5586                            JournalFolder[] array = new JournalFolderImpl[3];
5587    
5588                            array[0] = getByG_P_S_PrevAndNext(session, journalFolder, groupId,
5589                                            parentFolderId, status, orderByComparator, true);
5590    
5591                            array[1] = journalFolder;
5592    
5593                            array[2] = getByG_P_S_PrevAndNext(session, journalFolder, groupId,
5594                                            parentFolderId, status, orderByComparator, false);
5595    
5596                            return array;
5597                    }
5598                    catch (Exception e) {
5599                            throw processException(e);
5600                    }
5601                    finally {
5602                            closeSession(session);
5603                    }
5604            }
5605    
5606            protected JournalFolder getByG_P_S_PrevAndNext(Session session,
5607                    JournalFolder journalFolder, long groupId, long parentFolderId,
5608                    int status, OrderByComparator orderByComparator, boolean previous) {
5609                    StringBundler query = null;
5610    
5611                    if (orderByComparator != null) {
5612                            query = new StringBundler(6 +
5613                                            (orderByComparator.getOrderByFields().length * 6));
5614                    }
5615                    else {
5616                            query = new StringBundler(3);
5617                    }
5618    
5619                    query.append(_SQL_SELECT_JOURNALFOLDER_WHERE);
5620    
5621                    query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
5622    
5623                    query.append(_FINDER_COLUMN_G_P_S_PARENTFOLDERID_2);
5624    
5625                    query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
5626    
5627                    if (orderByComparator != null) {
5628                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5629    
5630                            if (orderByConditionFields.length > 0) {
5631                                    query.append(WHERE_AND);
5632                            }
5633    
5634                            for (int i = 0; i < orderByConditionFields.length; i++) {
5635                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5636                                    query.append(orderByConditionFields[i]);
5637    
5638                                    if ((i + 1) < orderByConditionFields.length) {
5639                                            if (orderByComparator.isAscending() ^ previous) {
5640                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5641                                            }
5642                                            else {
5643                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5644                                            }
5645                                    }
5646                                    else {
5647                                            if (orderByComparator.isAscending() ^ previous) {
5648                                                    query.append(WHERE_GREATER_THAN);
5649                                            }
5650                                            else {
5651                                                    query.append(WHERE_LESSER_THAN);
5652                                            }
5653                                    }
5654                            }
5655    
5656                            query.append(ORDER_BY_CLAUSE);
5657    
5658                            String[] orderByFields = orderByComparator.getOrderByFields();
5659    
5660                            for (int i = 0; i < orderByFields.length; i++) {
5661                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5662                                    query.append(orderByFields[i]);
5663    
5664                                    if ((i + 1) < orderByFields.length) {
5665                                            if (orderByComparator.isAscending() ^ previous) {
5666                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5667                                            }
5668                                            else {
5669                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5670                                            }
5671                                    }
5672                                    else {
5673                                            if (orderByComparator.isAscending() ^ previous) {
5674                                                    query.append(ORDER_BY_ASC);
5675                                            }
5676                                            else {
5677                                                    query.append(ORDER_BY_DESC);
5678                                            }
5679                                    }
5680                            }
5681                    }
5682                    else {
5683                            query.append(JournalFolderModelImpl.ORDER_BY_JPQL);
5684                    }
5685    
5686                    String sql = query.toString();
5687    
5688                    Query q = session.createQuery(sql);
5689    
5690                    q.setFirstResult(0);
5691                    q.setMaxResults(2);
5692    
5693                    QueryPos qPos = QueryPos.getInstance(q);
5694    
5695                    qPos.add(groupId);
5696    
5697                    qPos.add(parentFolderId);
5698    
5699                    qPos.add(status);
5700    
5701                    if (orderByComparator != null) {
5702                            Object[] values = orderByComparator.getOrderByConditionValues(journalFolder);
5703    
5704                            for (Object value : values) {
5705                                    qPos.add(value);
5706                            }
5707                    }
5708    
5709                    List<JournalFolder> list = q.list();
5710    
5711                    if (list.size() == 2) {
5712                            return list.get(1);
5713                    }
5714                    else {
5715                            return null;
5716                    }
5717            }
5718    
5719            /**
5720             * Returns all the journal folders that the user has permission to view where groupId = &#63; and parentFolderId = &#63; and status = &#63;.
5721             *
5722             * @param groupId the group ID
5723             * @param parentFolderId the parent folder ID
5724             * @param status the status
5725             * @return the matching journal folders that the user has permission to view
5726             * @throws SystemException if a system exception occurred
5727             */
5728            @Override
5729            public List<JournalFolder> filterFindByG_P_S(long groupId,
5730                    long parentFolderId, int status) throws SystemException {
5731                    return filterFindByG_P_S(groupId, parentFolderId, status,
5732                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5733            }
5734    
5735            /**
5736             * Returns a range of all the journal folders that the user has permission to view where groupId = &#63; and parentFolderId = &#63; and status = &#63;.
5737             *
5738             * <p>
5739             * 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.
5740             * </p>
5741             *
5742             * @param groupId the group ID
5743             * @param parentFolderId the parent folder ID
5744             * @param status the status
5745             * @param start the lower bound of the range of journal folders
5746             * @param end the upper bound of the range of journal folders (not inclusive)
5747             * @return the range of matching journal folders that the user has permission to view
5748             * @throws SystemException if a system exception occurred
5749             */
5750            @Override
5751            public List<JournalFolder> filterFindByG_P_S(long groupId,
5752                    long parentFolderId, int status, int start, int end)
5753                    throws SystemException {
5754                    return filterFindByG_P_S(groupId, parentFolderId, status, start, end,
5755                            null);
5756            }
5757    
5758            /**
5759             * 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;.
5760             *
5761             * <p>
5762             * 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.
5763             * </p>
5764             *
5765             * @param groupId the group ID
5766             * @param parentFolderId the parent folder ID
5767             * @param status the status
5768             * @param start the lower bound of the range of journal folders
5769             * @param end the upper bound of the range of journal folders (not inclusive)
5770             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5771             * @return the ordered range of matching journal folders that the user has permission to view
5772             * @throws SystemException if a system exception occurred
5773             */
5774            @Override
5775            public List<JournalFolder> filterFindByG_P_S(long groupId,
5776                    long parentFolderId, int status, int start, int end,
5777                    OrderByComparator orderByComparator) throws SystemException {
5778                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5779                            return findByG_P_S(groupId, parentFolderId, status, start, end,
5780                                    orderByComparator);
5781                    }
5782    
5783                    StringBundler query = null;
5784    
5785                    if (orderByComparator != null) {
5786                            query = new StringBundler(5 +
5787                                            (orderByComparator.getOrderByFields().length * 3));
5788                    }
5789                    else {
5790                            query = new StringBundler(5);
5791                    }
5792    
5793                    if (getDB().isSupportsInlineDistinct()) {
5794                            query.append(_FILTER_SQL_SELECT_JOURNALFOLDER_WHERE);
5795                    }
5796                    else {
5797                            query.append(_FILTER_SQL_SELECT_JOURNALFOLDER_NO_INLINE_DISTINCT_WHERE_1);
5798                    }
5799    
5800                    query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
5801    
5802                    query.append(_FINDER_COLUMN_G_P_S_PARENTFOLDERID_2);
5803    
5804                    query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
5805    
5806                    if (!getDB().isSupportsInlineDistinct()) {
5807                            query.append(_FILTER_SQL_SELECT_JOURNALFOLDER_NO_INLINE_DISTINCT_WHERE_2);
5808                    }
5809    
5810                    if (orderByComparator != null) {
5811                            if (getDB().isSupportsInlineDistinct()) {
5812                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5813                                            orderByComparator, true);
5814                            }
5815                            else {
5816                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5817                                            orderByComparator, true);
5818                            }
5819                    }
5820                    else {
5821                            if (getDB().isSupportsInlineDistinct()) {
5822                                    query.append(JournalFolderModelImpl.ORDER_BY_JPQL);
5823                            }
5824                            else {
5825                                    query.append(JournalFolderModelImpl.ORDER_BY_SQL);
5826                            }
5827                    }
5828    
5829                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5830                                    JournalFolder.class.getName(),
5831                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5832    
5833                    Session session = null;
5834    
5835                    try {
5836                            session = openSession();
5837    
5838                            SQLQuery q = session.createSQLQuery(sql);
5839    
5840                            if (getDB().isSupportsInlineDistinct()) {
5841                                    q.addEntity(_FILTER_ENTITY_ALIAS, JournalFolderImpl.class);
5842                            }
5843                            else {
5844                                    q.addEntity(_FILTER_ENTITY_TABLE, JournalFolderImpl.class);
5845                            }
5846    
5847                            QueryPos qPos = QueryPos.getInstance(q);
5848    
5849                            qPos.add(groupId);
5850    
5851                            qPos.add(parentFolderId);
5852    
5853                            qPos.add(status);
5854    
5855                            return (List<JournalFolder>)QueryUtil.list(q, getDialect(), start,
5856                                    end);
5857                    }
5858                    catch (Exception e) {
5859                            throw processException(e);
5860                    }
5861                    finally {
5862                            closeSession(session);
5863                    }
5864            }
5865    
5866            /**
5867             * 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;.
5868             *
5869             * @param folderId the primary key of the current journal folder
5870             * @param groupId the group ID
5871             * @param parentFolderId the parent folder ID
5872             * @param status the status
5873             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5874             * @return the previous, current, and next journal folder
5875             * @throws com.liferay.portlet.journal.NoSuchFolderException if a journal folder with the primary key could not be found
5876             * @throws SystemException if a system exception occurred
5877             */
5878            @Override
5879            public JournalFolder[] filterFindByG_P_S_PrevAndNext(long folderId,
5880                    long groupId, long parentFolderId, int status,
5881                    OrderByComparator orderByComparator)
5882                    throws NoSuchFolderException, SystemException {
5883                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5884                            return findByG_P_S_PrevAndNext(folderId, groupId, parentFolderId,
5885                                    status, orderByComparator);
5886                    }
5887    
5888                    JournalFolder journalFolder = findByPrimaryKey(folderId);
5889    
5890                    Session session = null;
5891    
5892                    try {
5893                            session = openSession();
5894    
5895                            JournalFolder[] array = new JournalFolderImpl[3];
5896    
5897                            array[0] = filterGetByG_P_S_PrevAndNext(session, journalFolder,
5898                                            groupId, parentFolderId, status, orderByComparator, true);
5899    
5900                            array[1] = journalFolder;
5901    
5902                            array[2] = filterGetByG_P_S_PrevAndNext(session, journalFolder,
5903                                            groupId, parentFolderId, status, orderByComparator, false);
5904    
5905                            return array;
5906                    }
5907                    catch (Exception e) {
5908                            throw processException(e);
5909                    }
5910                    finally {
5911                            closeSession(session);
5912                    }
5913            }
5914    
5915            protected JournalFolder filterGetByG_P_S_PrevAndNext(Session session,
5916                    JournalFolder journalFolder, long groupId, long parentFolderId,
5917                    int status, OrderByComparator orderByComparator, boolean previous) {
5918                    StringBundler query = null;
5919    
5920                    if (orderByComparator != null) {
5921                            query = new StringBundler(6 +
5922                                            (orderByComparator.getOrderByFields().length * 6));
5923                    }
5924                    else {
5925                            query = new StringBundler(3);
5926                    }
5927    
5928                    if (getDB().isSupportsInlineDistinct()) {
5929                            query.append(_FILTER_SQL_SELECT_JOURNALFOLDER_WHERE);
5930                    }
5931                    else {
5932                            query.append(_FILTER_SQL_SELECT_JOURNALFOLDER_NO_INLINE_DISTINCT_WHERE_1);
5933                    }
5934    
5935                    query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
5936    
5937                    query.append(_FINDER_COLUMN_G_P_S_PARENTFOLDERID_2);
5938    
5939                    query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
5940    
5941                    if (!getDB().isSupportsInlineDistinct()) {
5942                            query.append(_FILTER_SQL_SELECT_JOURNALFOLDER_NO_INLINE_DISTINCT_WHERE_2);
5943                    }
5944    
5945                    if (orderByComparator != null) {
5946                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5947    
5948                            if (orderByConditionFields.length > 0) {
5949                                    query.append(WHERE_AND);
5950                            }
5951    
5952                            for (int i = 0; i < orderByConditionFields.length; i++) {
5953                                    if (getDB().isSupportsInlineDistinct()) {
5954                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5955                                    }
5956                                    else {
5957                                            query.append(_ORDER_BY_ENTITY_TABLE);
5958                                    }
5959    
5960                                    query.append(orderByConditionFields[i]);
5961    
5962                                    if ((i + 1) < orderByConditionFields.length) {
5963                                            if (orderByComparator.isAscending() ^ previous) {
5964                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5965                                            }
5966                                            else {
5967                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5968                                            }
5969                                    }
5970                                    else {
5971                                            if (orderByComparator.isAscending() ^ previous) {
5972                                                    query.append(WHERE_GREATER_THAN);
5973                                            }
5974                                            else {
5975                                                    query.append(WHERE_LESSER_THAN);
5976                                            }
5977                                    }
5978                            }
5979    
5980                            query.append(ORDER_BY_CLAUSE);
5981    
5982                            String[] orderByFields = orderByComparator.getOrderByFields();
5983    
5984                            for (int i = 0; i < orderByFields.length; i++) {
5985                                    if (getDB().isSupportsInlineDistinct()) {
5986                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5987                                    }
5988                                    else {
5989                                            query.append(_ORDER_BY_ENTITY_TABLE);
5990                                    }
5991    
5992                                    query.append(orderByFields[i]);
5993    
5994                                    if ((i + 1) < orderByFields.length) {
5995                                            if (orderByComparator.isAscending() ^ previous) {
5996                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5997                                            }
5998                                            else {
5999                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6000                                            }
6001                                    }
6002                                    else {
6003                                            if (orderByComparator.isAscending() ^ previous) {
6004                                                    query.append(ORDER_BY_ASC);
6005                                            }
6006                                            else {
6007                                                    query.append(ORDER_BY_DESC);
6008                                            }
6009                                    }
6010                            }
6011                    }
6012                    else {
6013                            if (getDB().isSupportsInlineDistinct()) {
6014                                    query.append(JournalFolderModelImpl.ORDER_BY_JPQL);
6015                            }
6016                            else {
6017                                    query.append(JournalFolderModelImpl.ORDER_BY_SQL);
6018                            }
6019                    }
6020    
6021                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6022                                    JournalFolder.class.getName(),
6023                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6024    
6025                    SQLQuery q = session.createSQLQuery(sql);
6026    
6027                    q.setFirstResult(0);
6028                    q.setMaxResults(2);
6029    
6030                    if (getDB().isSupportsInlineDistinct()) {
6031                            q.addEntity(_FILTER_ENTITY_ALIAS, JournalFolderImpl.class);
6032                    }
6033                    else {
6034                            q.addEntity(_FILTER_ENTITY_TABLE, JournalFolderImpl.class);
6035                    }
6036    
6037                    QueryPos qPos = QueryPos.getInstance(q);
6038    
6039                    qPos.add(groupId);
6040    
6041                    qPos.add(parentFolderId);
6042    
6043                    qPos.add(status);
6044    
6045                    if (orderByComparator != null) {
6046                            Object[] values = orderByComparator.getOrderByConditionValues(journalFolder);
6047    
6048                            for (Object value : values) {
6049                                    qPos.add(value);
6050                            }
6051                    }
6052    
6053                    List<JournalFolder> list = q.list();
6054    
6055                    if (list.size() == 2) {
6056                            return list.get(1);
6057                    }
6058                    else {
6059                            return null;
6060                    }
6061            }
6062    
6063            /**
6064             * Removes all the journal folders where groupId = &#63; and parentFolderId = &#63; and status = &#63; from the database.
6065             *
6066             * @param groupId the group ID
6067             * @param parentFolderId the parent folder ID
6068             * @param status the status
6069             * @throws SystemException if a system exception occurred
6070             */
6071            @Override
6072            public void removeByG_P_S(long groupId, long parentFolderId, int status)
6073                    throws SystemException {
6074                    for (JournalFolder journalFolder : findByG_P_S(groupId, parentFolderId,
6075                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6076                            remove(journalFolder);
6077                    }
6078            }
6079    
6080            /**
6081             * Returns the number of journal folders where groupId = &#63; and parentFolderId = &#63; and status = &#63;.
6082             *
6083             * @param groupId the group ID
6084             * @param parentFolderId the parent folder ID
6085             * @param status the status
6086             * @return the number of matching journal folders
6087             * @throws SystemException if a system exception occurred
6088             */
6089            @Override
6090            public int countByG_P_S(long groupId, long parentFolderId, int status)
6091                    throws SystemException {
6092                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_S;
6093    
6094                    Object[] finderArgs = new Object[] { groupId, parentFolderId, status };
6095    
6096                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6097                                    this);
6098    
6099                    if (count == null) {
6100                            StringBundler query = new StringBundler(4);
6101    
6102                            query.append(_SQL_COUNT_JOURNALFOLDER_WHERE);
6103    
6104                            query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
6105    
6106                            query.append(_FINDER_COLUMN_G_P_S_PARENTFOLDERID_2);
6107    
6108                            query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
6109    
6110                            String sql = query.toString();
6111    
6112                            Session session = null;
6113    
6114                            try {
6115                                    session = openSession();
6116    
6117                                    Query q = session.createQuery(sql);
6118    
6119                                    QueryPos qPos = QueryPos.getInstance(q);
6120    
6121                                    qPos.add(groupId);
6122    
6123                                    qPos.add(parentFolderId);
6124    
6125                                    qPos.add(status);
6126    
6127                                    count = (Long)q.uniqueResult();
6128    
6129                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
6130                            }
6131                            catch (Exception e) {
6132                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6133    
6134                                    throw processException(e);
6135                            }
6136                            finally {
6137                                    closeSession(session);
6138                            }
6139                    }
6140    
6141                    return count.intValue();
6142            }
6143    
6144            /**
6145             * Returns the number of journal folders that the user has permission to view where groupId = &#63; and parentFolderId = &#63; and status = &#63;.
6146             *
6147             * @param groupId the group ID
6148             * @param parentFolderId the parent folder ID
6149             * @param status the status
6150             * @return the number of matching journal folders that the user has permission to view
6151             * @throws SystemException if a system exception occurred
6152             */
6153            @Override
6154            public int filterCountByG_P_S(long groupId, long parentFolderId, int status)
6155                    throws SystemException {
6156                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6157                            return countByG_P_S(groupId, parentFolderId, status);
6158                    }
6159    
6160                    StringBundler query = new StringBundler(4);
6161    
6162                    query.append(_FILTER_SQL_COUNT_JOURNALFOLDER_WHERE);
6163    
6164                    query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
6165    
6166                    query.append(_FINDER_COLUMN_G_P_S_PARENTFOLDERID_2);
6167    
6168                    query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
6169    
6170                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6171                                    JournalFolder.class.getName(),
6172                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6173    
6174                    Session session = null;
6175    
6176                    try {
6177                            session = openSession();
6178    
6179                            SQLQuery q = session.createSQLQuery(sql);
6180    
6181                            q.addScalar(COUNT_COLUMN_NAME,
6182                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
6183    
6184                            QueryPos qPos = QueryPos.getInstance(q);
6185    
6186                            qPos.add(groupId);
6187    
6188                            qPos.add(parentFolderId);
6189    
6190                            qPos.add(status);
6191    
6192                            Long count = (Long)q.uniqueResult();
6193    
6194                            return count.intValue();
6195                    }
6196                    catch (Exception e) {
6197                            throw processException(e);
6198                    }
6199                    finally {
6200                            closeSession(session);
6201                    }
6202            }
6203    
6204            private static final String _FINDER_COLUMN_G_P_S_GROUPID_2 = "journalFolder.groupId = ? AND ";
6205            private static final String _FINDER_COLUMN_G_P_S_PARENTFOLDERID_2 = "journalFolder.parentFolderId = ? AND ";
6206            private static final String _FINDER_COLUMN_G_P_S_STATUS_2 = "journalFolder.status = ?";
6207            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_NOTS = new FinderPath(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
6208                            JournalFolderModelImpl.FINDER_CACHE_ENABLED,
6209                            JournalFolderImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
6210                            "findByG_P_NotS",
6211                            new String[] {
6212                                    Long.class.getName(), Long.class.getName(),
6213                                    Integer.class.getName(),
6214                                    
6215                            Integer.class.getName(), Integer.class.getName(),
6216                                    OrderByComparator.class.getName()
6217                            });
6218            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P_NOTS =
6219                    new FinderPath(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
6220                            JournalFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
6221                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_P_NotS",
6222                            new String[] {
6223                                    Long.class.getName(), Long.class.getName(),
6224                                    Integer.class.getName()
6225                            });
6226    
6227            /**
6228             * Returns all the journal folders where groupId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
6229             *
6230             * @param groupId the group ID
6231             * @param parentFolderId the parent folder ID
6232             * @param status the status
6233             * @return the matching journal folders
6234             * @throws SystemException if a system exception occurred
6235             */
6236            @Override
6237            public List<JournalFolder> findByG_P_NotS(long groupId,
6238                    long parentFolderId, int status) throws SystemException {
6239                    return findByG_P_NotS(groupId, parentFolderId, status,
6240                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6241            }
6242    
6243            /**
6244             * Returns a range of all the journal folders where groupId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
6245             *
6246             * <p>
6247             * 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.
6248             * </p>
6249             *
6250             * @param groupId the group ID
6251             * @param parentFolderId the parent folder ID
6252             * @param status the status
6253             * @param start the lower bound of the range of journal folders
6254             * @param end the upper bound of the range of journal folders (not inclusive)
6255             * @return the range of matching journal folders
6256             * @throws SystemException if a system exception occurred
6257             */
6258            @Override
6259            public List<JournalFolder> findByG_P_NotS(long groupId,
6260                    long parentFolderId, int status, int start, int end)
6261                    throws SystemException {
6262                    return findByG_P_NotS(groupId, parentFolderId, status, start, end, null);
6263            }
6264    
6265            /**
6266             * Returns an ordered range of all the journal folders 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             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6278             * @return the ordered range of matching journal folders
6279             * @throws SystemException if a system exception occurred
6280             */
6281            @Override
6282            public List<JournalFolder> findByG_P_NotS(long groupId,
6283                    long parentFolderId, int status, int start, int end,
6284                    OrderByComparator orderByComparator) throws SystemException {
6285                    boolean pagination = true;
6286                    FinderPath finderPath = null;
6287                    Object[] finderArgs = null;
6288    
6289                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_NOTS;
6290                    finderArgs = new Object[] {
6291                                    groupId, parentFolderId, status,
6292                                    
6293                                    start, end, orderByComparator
6294                            };
6295    
6296                    List<JournalFolder> list = (List<JournalFolder>)FinderCacheUtil.getResult(finderPath,
6297                                    finderArgs, this);
6298    
6299                    if ((list != null) && !list.isEmpty()) {
6300                            for (JournalFolder journalFolder : list) {
6301                                    if ((groupId != journalFolder.getGroupId()) ||
6302                                                    (parentFolderId != journalFolder.getParentFolderId()) ||
6303                                                    (status == journalFolder.getStatus())) {
6304                                            list = null;
6305    
6306                                            break;
6307                                    }
6308                            }
6309                    }
6310    
6311                    if (list == null) {
6312                            StringBundler query = null;
6313    
6314                            if (orderByComparator != null) {
6315                                    query = new StringBundler(5 +
6316                                                    (orderByComparator.getOrderByFields().length * 3));
6317                            }
6318                            else {
6319                                    query = new StringBundler(5);
6320                            }
6321    
6322                            query.append(_SQL_SELECT_JOURNALFOLDER_WHERE);
6323    
6324                            query.append(_FINDER_COLUMN_G_P_NOTS_GROUPID_2);
6325    
6326                            query.append(_FINDER_COLUMN_G_P_NOTS_PARENTFOLDERID_2);
6327    
6328                            query.append(_FINDER_COLUMN_G_P_NOTS_STATUS_2);
6329    
6330                            if (orderByComparator != null) {
6331                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6332                                            orderByComparator);
6333                            }
6334                            else
6335                             if (pagination) {
6336                                    query.append(JournalFolderModelImpl.ORDER_BY_JPQL);
6337                            }
6338    
6339                            String sql = query.toString();
6340    
6341                            Session session = null;
6342    
6343                            try {
6344                                    session = openSession();
6345    
6346                                    Query q = session.createQuery(sql);
6347    
6348                                    QueryPos qPos = QueryPos.getInstance(q);
6349    
6350                                    qPos.add(groupId);
6351    
6352                                    qPos.add(parentFolderId);
6353    
6354                                    qPos.add(status);
6355    
6356                                    if (!pagination) {
6357                                            list = (List<JournalFolder>)QueryUtil.list(q, getDialect(),
6358                                                            start, end, false);
6359    
6360                                            Collections.sort(list);
6361    
6362                                            list = new UnmodifiableList<JournalFolder>(list);
6363                                    }
6364                                    else {
6365                                            list = (List<JournalFolder>)QueryUtil.list(q, getDialect(),
6366                                                            start, end);
6367                                    }
6368    
6369                                    cacheResult(list);
6370    
6371                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
6372                            }
6373                            catch (Exception e) {
6374                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6375    
6376                                    throw processException(e);
6377                            }
6378                            finally {
6379                                    closeSession(session);
6380                            }
6381                    }
6382    
6383                    return list;
6384            }
6385    
6386            /**
6387             * Returns the first journal folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
6388             *
6389             * @param groupId the group ID
6390             * @param parentFolderId the parent folder ID
6391             * @param status the status
6392             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6393             * @return the first matching journal folder
6394             * @throws com.liferay.portlet.journal.NoSuchFolderException if a matching journal folder could not be found
6395             * @throws SystemException if a system exception occurred
6396             */
6397            @Override
6398            public JournalFolder findByG_P_NotS_First(long groupId,
6399                    long parentFolderId, int status, OrderByComparator orderByComparator)
6400                    throws NoSuchFolderException, SystemException {
6401                    JournalFolder journalFolder = fetchByG_P_NotS_First(groupId,
6402                                    parentFolderId, status, orderByComparator);
6403    
6404                    if (journalFolder != null) {
6405                            return journalFolder;
6406                    }
6407    
6408                    StringBundler msg = new StringBundler(8);
6409    
6410                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6411    
6412                    msg.append("groupId=");
6413                    msg.append(groupId);
6414    
6415                    msg.append(", parentFolderId=");
6416                    msg.append(parentFolderId);
6417    
6418                    msg.append(", status=");
6419                    msg.append(status);
6420    
6421                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6422    
6423                    throw new NoSuchFolderException(msg.toString());
6424            }
6425    
6426            /**
6427             * Returns the first journal folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
6428             *
6429             * @param groupId the group ID
6430             * @param parentFolderId the parent folder ID
6431             * @param status the status
6432             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6433             * @return the first matching journal folder, or <code>null</code> if a matching journal folder could not be found
6434             * @throws SystemException if a system exception occurred
6435             */
6436            @Override
6437            public JournalFolder fetchByG_P_NotS_First(long groupId,
6438                    long parentFolderId, int status, OrderByComparator orderByComparator)
6439                    throws SystemException {
6440                    List<JournalFolder> list = findByG_P_NotS(groupId, parentFolderId,
6441                                    status, 0, 1, orderByComparator);
6442    
6443                    if (!list.isEmpty()) {
6444                            return list.get(0);
6445                    }
6446    
6447                    return null;
6448            }
6449    
6450            /**
6451             * Returns the last journal folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
6452             *
6453             * @param groupId the group ID
6454             * @param parentFolderId the parent folder ID
6455             * @param status the status
6456             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6457             * @return the last matching journal folder
6458             * @throws com.liferay.portlet.journal.NoSuchFolderException if a matching journal folder could not be found
6459             * @throws SystemException if a system exception occurred
6460             */
6461            @Override
6462            public JournalFolder findByG_P_NotS_Last(long groupId, long parentFolderId,
6463                    int status, OrderByComparator orderByComparator)
6464                    throws NoSuchFolderException, SystemException {
6465                    JournalFolder journalFolder = fetchByG_P_NotS_Last(groupId,
6466                                    parentFolderId, status, orderByComparator);
6467    
6468                    if (journalFolder != null) {
6469                            return journalFolder;
6470                    }
6471    
6472                    StringBundler msg = new StringBundler(8);
6473    
6474                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6475    
6476                    msg.append("groupId=");
6477                    msg.append(groupId);
6478    
6479                    msg.append(", parentFolderId=");
6480                    msg.append(parentFolderId);
6481    
6482                    msg.append(", status=");
6483                    msg.append(status);
6484    
6485                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6486    
6487                    throw new NoSuchFolderException(msg.toString());
6488            }
6489    
6490            /**
6491             * Returns the last journal folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
6492             *
6493             * @param groupId the group ID
6494             * @param parentFolderId the parent folder ID
6495             * @param status the status
6496             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6497             * @return the last matching journal folder, or <code>null</code> if a matching journal folder could not be found
6498             * @throws SystemException if a system exception occurred
6499             */
6500            @Override
6501            public JournalFolder fetchByG_P_NotS_Last(long groupId,
6502                    long parentFolderId, int status, OrderByComparator orderByComparator)
6503                    throws SystemException {
6504                    int count = countByG_P_NotS(groupId, parentFolderId, status);
6505    
6506                    if (count == 0) {
6507                            return null;
6508                    }
6509    
6510                    List<JournalFolder> list = findByG_P_NotS(groupId, parentFolderId,
6511                                    status, count - 1, count, orderByComparator);
6512    
6513                    if (!list.isEmpty()) {
6514                            return list.get(0);
6515                    }
6516    
6517                    return null;
6518            }
6519    
6520            /**
6521             * 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;.
6522             *
6523             * @param folderId the primary key of the current journal folder
6524             * @param groupId the group ID
6525             * @param parentFolderId the parent folder ID
6526             * @param status the status
6527             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6528             * @return the previous, current, and next journal folder
6529             * @throws com.liferay.portlet.journal.NoSuchFolderException if a journal folder with the primary key could not be found
6530             * @throws SystemException if a system exception occurred
6531             */
6532            @Override
6533            public JournalFolder[] findByG_P_NotS_PrevAndNext(long folderId,
6534                    long groupId, long parentFolderId, int status,
6535                    OrderByComparator orderByComparator)
6536                    throws NoSuchFolderException, SystemException {
6537                    JournalFolder journalFolder = findByPrimaryKey(folderId);
6538    
6539                    Session session = null;
6540    
6541                    try {
6542                            session = openSession();
6543    
6544                            JournalFolder[] array = new JournalFolderImpl[3];
6545    
6546                            array[0] = getByG_P_NotS_PrevAndNext(session, journalFolder,
6547                                            groupId, parentFolderId, status, orderByComparator, true);
6548    
6549                            array[1] = journalFolder;
6550    
6551                            array[2] = getByG_P_NotS_PrevAndNext(session, journalFolder,
6552                                            groupId, parentFolderId, status, orderByComparator, false);
6553    
6554                            return array;
6555                    }
6556                    catch (Exception e) {
6557                            throw processException(e);
6558                    }
6559                    finally {
6560                            closeSession(session);
6561                    }
6562            }
6563    
6564            protected JournalFolder getByG_P_NotS_PrevAndNext(Session session,
6565                    JournalFolder journalFolder, long groupId, long parentFolderId,
6566                    int status, OrderByComparator orderByComparator, boolean previous) {
6567                    StringBundler query = null;
6568    
6569                    if (orderByComparator != null) {
6570                            query = new StringBundler(6 +
6571                                            (orderByComparator.getOrderByFields().length * 6));
6572                    }
6573                    else {
6574                            query = new StringBundler(3);
6575                    }
6576    
6577                    query.append(_SQL_SELECT_JOURNALFOLDER_WHERE);
6578    
6579                    query.append(_FINDER_COLUMN_G_P_NOTS_GROUPID_2);
6580    
6581                    query.append(_FINDER_COLUMN_G_P_NOTS_PARENTFOLDERID_2);
6582    
6583                    query.append(_FINDER_COLUMN_G_P_NOTS_STATUS_2);
6584    
6585                    if (orderByComparator != null) {
6586                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6587    
6588                            if (orderByConditionFields.length > 0) {
6589                                    query.append(WHERE_AND);
6590                            }
6591    
6592                            for (int i = 0; i < orderByConditionFields.length; i++) {
6593                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6594                                    query.append(orderByConditionFields[i]);
6595    
6596                                    if ((i + 1) < orderByConditionFields.length) {
6597                                            if (orderByComparator.isAscending() ^ previous) {
6598                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6599                                            }
6600                                            else {
6601                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6602                                            }
6603                                    }
6604                                    else {
6605                                            if (orderByComparator.isAscending() ^ previous) {
6606                                                    query.append(WHERE_GREATER_THAN);
6607                                            }
6608                                            else {
6609                                                    query.append(WHERE_LESSER_THAN);
6610                                            }
6611                                    }
6612                            }
6613    
6614                            query.append(ORDER_BY_CLAUSE);
6615    
6616                            String[] orderByFields = orderByComparator.getOrderByFields();
6617    
6618                            for (int i = 0; i < orderByFields.length; i++) {
6619                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6620                                    query.append(orderByFields[i]);
6621    
6622                                    if ((i + 1) < orderByFields.length) {
6623                                            if (orderByComparator.isAscending() ^ previous) {
6624                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6625                                            }
6626                                            else {
6627                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6628                                            }
6629                                    }
6630                                    else {
6631                                            if (orderByComparator.isAscending() ^ previous) {
6632                                                    query.append(ORDER_BY_ASC);
6633                                            }
6634                                            else {
6635                                                    query.append(ORDER_BY_DESC);
6636                                            }
6637                                    }
6638                            }
6639                    }
6640                    else {
6641                            query.append(JournalFolderModelImpl.ORDER_BY_JPQL);
6642                    }
6643    
6644                    String sql = query.toString();
6645    
6646                    Query q = session.createQuery(sql);
6647    
6648                    q.setFirstResult(0);
6649                    q.setMaxResults(2);
6650    
6651                    QueryPos qPos = QueryPos.getInstance(q);
6652    
6653                    qPos.add(groupId);
6654    
6655                    qPos.add(parentFolderId);
6656    
6657                    qPos.add(status);
6658    
6659                    if (orderByComparator != null) {
6660                            Object[] values = orderByComparator.getOrderByConditionValues(journalFolder);
6661    
6662                            for (Object value : values) {
6663                                    qPos.add(value);
6664                            }
6665                    }
6666    
6667                    List<JournalFolder> list = q.list();
6668    
6669                    if (list.size() == 2) {
6670                            return list.get(1);
6671                    }
6672                    else {
6673                            return null;
6674                    }
6675            }
6676    
6677            /**
6678             * Returns all the journal folders that the user has permission to view where groupId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
6679             *
6680             * @param groupId the group ID
6681             * @param parentFolderId the parent folder ID
6682             * @param status the status
6683             * @return the matching journal folders that the user has permission to view
6684             * @throws SystemException if a system exception occurred
6685             */
6686            @Override
6687            public List<JournalFolder> filterFindByG_P_NotS(long groupId,
6688                    long parentFolderId, int status) throws SystemException {
6689                    return filterFindByG_P_NotS(groupId, parentFolderId, status,
6690                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6691            }
6692    
6693            /**
6694             * 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;.
6695             *
6696             * <p>
6697             * 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.
6698             * </p>
6699             *
6700             * @param groupId the group ID
6701             * @param parentFolderId the parent folder ID
6702             * @param status the status
6703             * @param start the lower bound of the range of journal folders
6704             * @param end the upper bound of the range of journal folders (not inclusive)
6705             * @return the range of matching journal folders that the user has permission to view
6706             * @throws SystemException if a system exception occurred
6707             */
6708            @Override
6709            public List<JournalFolder> filterFindByG_P_NotS(long groupId,
6710                    long parentFolderId, int status, int start, int end)
6711                    throws SystemException {
6712                    return filterFindByG_P_NotS(groupId, parentFolderId, status, start,
6713                            end, null);
6714            }
6715    
6716            /**
6717             * 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;.
6718             *
6719             * <p>
6720             * 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.
6721             * </p>
6722             *
6723             * @param groupId the group ID
6724             * @param parentFolderId the parent folder ID
6725             * @param status the status
6726             * @param start the lower bound of the range of journal folders
6727             * @param end the upper bound of the range of journal folders (not inclusive)
6728             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6729             * @return the ordered range of matching journal folders that the user has permission to view
6730             * @throws SystemException if a system exception occurred
6731             */
6732            @Override
6733            public List<JournalFolder> filterFindByG_P_NotS(long groupId,
6734                    long parentFolderId, int status, int start, int end,
6735                    OrderByComparator orderByComparator) throws SystemException {
6736                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6737                            return findByG_P_NotS(groupId, parentFolderId, status, start, end,
6738                                    orderByComparator);
6739                    }
6740    
6741                    StringBundler query = null;
6742    
6743                    if (orderByComparator != null) {
6744                            query = new StringBundler(5 +
6745                                            (orderByComparator.getOrderByFields().length * 3));
6746                    }
6747                    else {
6748                            query = new StringBundler(5);
6749                    }
6750    
6751                    if (getDB().isSupportsInlineDistinct()) {
6752                            query.append(_FILTER_SQL_SELECT_JOURNALFOLDER_WHERE);
6753                    }
6754                    else {
6755                            query.append(_FILTER_SQL_SELECT_JOURNALFOLDER_NO_INLINE_DISTINCT_WHERE_1);
6756                    }
6757    
6758                    query.append(_FINDER_COLUMN_G_P_NOTS_GROUPID_2);
6759    
6760                    query.append(_FINDER_COLUMN_G_P_NOTS_PARENTFOLDERID_2);
6761    
6762                    query.append(_FINDER_COLUMN_G_P_NOTS_STATUS_2);
6763    
6764                    if (!getDB().isSupportsInlineDistinct()) {
6765                            query.append(_FILTER_SQL_SELECT_JOURNALFOLDER_NO_INLINE_DISTINCT_WHERE_2);
6766                    }
6767    
6768                    if (orderByComparator != null) {
6769                            if (getDB().isSupportsInlineDistinct()) {
6770                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6771                                            orderByComparator, true);
6772                            }
6773                            else {
6774                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6775                                            orderByComparator, true);
6776                            }
6777                    }
6778                    else {
6779                            if (getDB().isSupportsInlineDistinct()) {
6780                                    query.append(JournalFolderModelImpl.ORDER_BY_JPQL);
6781                            }
6782                            else {
6783                                    query.append(JournalFolderModelImpl.ORDER_BY_SQL);
6784                            }
6785                    }
6786    
6787                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6788                                    JournalFolder.class.getName(),
6789                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6790    
6791                    Session session = null;
6792    
6793                    try {
6794                            session = openSession();
6795    
6796                            SQLQuery q = session.createSQLQuery(sql);
6797    
6798                            if (getDB().isSupportsInlineDistinct()) {
6799                                    q.addEntity(_FILTER_ENTITY_ALIAS, JournalFolderImpl.class);
6800                            }
6801                            else {
6802                                    q.addEntity(_FILTER_ENTITY_TABLE, JournalFolderImpl.class);
6803                            }
6804    
6805                            QueryPos qPos = QueryPos.getInstance(q);
6806    
6807                            qPos.add(groupId);
6808    
6809                            qPos.add(parentFolderId);
6810    
6811                            qPos.add(status);
6812    
6813                            return (List<JournalFolder>)QueryUtil.list(q, getDialect(), start,
6814                                    end);
6815                    }
6816                    catch (Exception e) {
6817                            throw processException(e);
6818                    }
6819                    finally {
6820                            closeSession(session);
6821                    }
6822            }
6823    
6824            /**
6825             * 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;.
6826             *
6827             * @param folderId the primary key of the current journal folder
6828             * @param groupId the group ID
6829             * @param parentFolderId the parent folder ID
6830             * @param status the status
6831             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6832             * @return the previous, current, and next journal folder
6833             * @throws com.liferay.portlet.journal.NoSuchFolderException if a journal folder with the primary key could not be found
6834             * @throws SystemException if a system exception occurred
6835             */
6836            @Override
6837            public JournalFolder[] filterFindByG_P_NotS_PrevAndNext(long folderId,
6838                    long groupId, long parentFolderId, int status,
6839                    OrderByComparator orderByComparator)
6840                    throws NoSuchFolderException, SystemException {
6841                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6842                            return findByG_P_NotS_PrevAndNext(folderId, groupId,
6843                                    parentFolderId, status, orderByComparator);
6844                    }
6845    
6846                    JournalFolder journalFolder = findByPrimaryKey(folderId);
6847    
6848                    Session session = null;
6849    
6850                    try {
6851                            session = openSession();
6852    
6853                            JournalFolder[] array = new JournalFolderImpl[3];
6854    
6855                            array[0] = filterGetByG_P_NotS_PrevAndNext(session, journalFolder,
6856                                            groupId, parentFolderId, status, orderByComparator, true);
6857    
6858                            array[1] = journalFolder;
6859    
6860                            array[2] = filterGetByG_P_NotS_PrevAndNext(session, journalFolder,
6861                                            groupId, parentFolderId, status, orderByComparator, false);
6862    
6863                            return array;
6864                    }
6865                    catch (Exception e) {
6866                            throw processException(e);
6867                    }
6868                    finally {
6869                            closeSession(session);
6870                    }
6871            }
6872    
6873            protected JournalFolder filterGetByG_P_NotS_PrevAndNext(Session session,
6874                    JournalFolder journalFolder, long groupId, long parentFolderId,
6875                    int status, OrderByComparator orderByComparator, boolean previous) {
6876                    StringBundler query = null;
6877    
6878                    if (orderByComparator != null) {
6879                            query = new StringBundler(6 +
6880                                            (orderByComparator.getOrderByFields().length * 6));
6881                    }
6882                    else {
6883                            query = new StringBundler(3);
6884                    }
6885    
6886                    if (getDB().isSupportsInlineDistinct()) {
6887                            query.append(_FILTER_SQL_SELECT_JOURNALFOLDER_WHERE);
6888                    }
6889                    else {
6890                            query.append(_FILTER_SQL_SELECT_JOURNALFOLDER_NO_INLINE_DISTINCT_WHERE_1);
6891                    }
6892    
6893                    query.append(_FINDER_COLUMN_G_P_NOTS_GROUPID_2);
6894    
6895                    query.append(_FINDER_COLUMN_G_P_NOTS_PARENTFOLDERID_2);
6896    
6897                    query.append(_FINDER_COLUMN_G_P_NOTS_STATUS_2);
6898    
6899                    if (!getDB().isSupportsInlineDistinct()) {
6900                            query.append(_FILTER_SQL_SELECT_JOURNALFOLDER_NO_INLINE_DISTINCT_WHERE_2);
6901                    }
6902    
6903                    if (orderByComparator != null) {
6904                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6905    
6906                            if (orderByConditionFields.length > 0) {
6907                                    query.append(WHERE_AND);
6908                            }
6909    
6910                            for (int i = 0; i < orderByConditionFields.length; i++) {
6911                                    if (getDB().isSupportsInlineDistinct()) {
6912                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6913                                    }
6914                                    else {
6915                                            query.append(_ORDER_BY_ENTITY_TABLE);
6916                                    }
6917    
6918                                    query.append(orderByConditionFields[i]);
6919    
6920                                    if ((i + 1) < orderByConditionFields.length) {
6921                                            if (orderByComparator.isAscending() ^ previous) {
6922                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6923                                            }
6924                                            else {
6925                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6926                                            }
6927                                    }
6928                                    else {
6929                                            if (orderByComparator.isAscending() ^ previous) {
6930                                                    query.append(WHERE_GREATER_THAN);
6931                                            }
6932                                            else {
6933                                                    query.append(WHERE_LESSER_THAN);
6934                                            }
6935                                    }
6936                            }
6937    
6938                            query.append(ORDER_BY_CLAUSE);
6939    
6940                            String[] orderByFields = orderByComparator.getOrderByFields();
6941    
6942                            for (int i = 0; i < orderByFields.length; i++) {
6943                                    if (getDB().isSupportsInlineDistinct()) {
6944                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6945                                    }
6946                                    else {
6947                                            query.append(_ORDER_BY_ENTITY_TABLE);
6948                                    }
6949    
6950                                    query.append(orderByFields[i]);
6951    
6952                                    if ((i + 1) < orderByFields.length) {
6953                                            if (orderByComparator.isAscending() ^ previous) {
6954                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6955                                            }
6956                                            else {
6957                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6958                                            }
6959                                    }
6960                                    else {
6961                                            if (orderByComparator.isAscending() ^ previous) {
6962                                                    query.append(ORDER_BY_ASC);
6963                                            }
6964                                            else {
6965                                                    query.append(ORDER_BY_DESC);
6966                                            }
6967                                    }
6968                            }
6969                    }
6970                    else {
6971                            if (getDB().isSupportsInlineDistinct()) {
6972                                    query.append(JournalFolderModelImpl.ORDER_BY_JPQL);
6973                            }
6974                            else {
6975                                    query.append(JournalFolderModelImpl.ORDER_BY_SQL);
6976                            }
6977                    }
6978    
6979                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6980                                    JournalFolder.class.getName(),
6981                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6982    
6983                    SQLQuery q = session.createSQLQuery(sql);
6984    
6985                    q.setFirstResult(0);
6986                    q.setMaxResults(2);
6987    
6988                    if (getDB().isSupportsInlineDistinct()) {
6989                            q.addEntity(_FILTER_ENTITY_ALIAS, JournalFolderImpl.class);
6990                    }
6991                    else {
6992                            q.addEntity(_FILTER_ENTITY_TABLE, JournalFolderImpl.class);
6993                    }
6994    
6995                    QueryPos qPos = QueryPos.getInstance(q);
6996    
6997                    qPos.add(groupId);
6998    
6999                    qPos.add(parentFolderId);
7000    
7001                    qPos.add(status);
7002    
7003                    if (orderByComparator != null) {
7004                            Object[] values = orderByComparator.getOrderByConditionValues(journalFolder);
7005    
7006                            for (Object value : values) {
7007                                    qPos.add(value);
7008                            }
7009                    }
7010    
7011                    List<JournalFolder> list = q.list();
7012    
7013                    if (list.size() == 2) {
7014                            return list.get(1);
7015                    }
7016                    else {
7017                            return null;
7018                    }
7019            }
7020    
7021            /**
7022             * Removes all the journal folders where groupId = &#63; and parentFolderId = &#63; and status &ne; &#63; from the database.
7023             *
7024             * @param groupId the group ID
7025             * @param parentFolderId the parent folder ID
7026             * @param status the status
7027             * @throws SystemException if a system exception occurred
7028             */
7029            @Override
7030            public void removeByG_P_NotS(long groupId, long parentFolderId, int status)
7031                    throws SystemException {
7032                    for (JournalFolder journalFolder : findByG_P_NotS(groupId,
7033                                    parentFolderId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
7034                                    null)) {
7035                            remove(journalFolder);
7036                    }
7037            }
7038    
7039            /**
7040             * Returns the number of journal folders where groupId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
7041             *
7042             * @param groupId the group ID
7043             * @param parentFolderId the parent folder ID
7044             * @param status the status
7045             * @return the number of matching journal folders
7046             * @throws SystemException if a system exception occurred
7047             */
7048            @Override
7049            public int countByG_P_NotS(long groupId, long parentFolderId, int status)
7050                    throws SystemException {
7051                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P_NOTS;
7052    
7053                    Object[] finderArgs = new Object[] { groupId, parentFolderId, status };
7054    
7055                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
7056                                    this);
7057    
7058                    if (count == null) {
7059                            StringBundler query = new StringBundler(4);
7060    
7061                            query.append(_SQL_COUNT_JOURNALFOLDER_WHERE);
7062    
7063                            query.append(_FINDER_COLUMN_G_P_NOTS_GROUPID_2);
7064    
7065                            query.append(_FINDER_COLUMN_G_P_NOTS_PARENTFOLDERID_2);
7066    
7067                            query.append(_FINDER_COLUMN_G_P_NOTS_STATUS_2);
7068    
7069                            String sql = query.toString();
7070    
7071                            Session session = null;
7072    
7073                            try {
7074                                    session = openSession();
7075    
7076                                    Query q = session.createQuery(sql);
7077    
7078                                    QueryPos qPos = QueryPos.getInstance(q);
7079    
7080                                    qPos.add(groupId);
7081    
7082                                    qPos.add(parentFolderId);
7083    
7084                                    qPos.add(status);
7085    
7086                                    count = (Long)q.uniqueResult();
7087    
7088                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
7089                            }
7090                            catch (Exception e) {
7091                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7092    
7093                                    throw processException(e);
7094                            }
7095                            finally {
7096                                    closeSession(session);
7097                            }
7098                    }
7099    
7100                    return count.intValue();
7101            }
7102    
7103            /**
7104             * Returns the number of journal folders that the user has permission to view where groupId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
7105             *
7106             * @param groupId the group ID
7107             * @param parentFolderId the parent folder ID
7108             * @param status the status
7109             * @return the number of matching journal folders that the user has permission to view
7110             * @throws SystemException if a system exception occurred
7111             */
7112            @Override
7113            public int filterCountByG_P_NotS(long groupId, long parentFolderId,
7114                    int status) throws SystemException {
7115                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7116                            return countByG_P_NotS(groupId, parentFolderId, status);
7117                    }
7118    
7119                    StringBundler query = new StringBundler(4);
7120    
7121                    query.append(_FILTER_SQL_COUNT_JOURNALFOLDER_WHERE);
7122    
7123                    query.append(_FINDER_COLUMN_G_P_NOTS_GROUPID_2);
7124    
7125                    query.append(_FINDER_COLUMN_G_P_NOTS_PARENTFOLDERID_2);
7126    
7127                    query.append(_FINDER_COLUMN_G_P_NOTS_STATUS_2);
7128    
7129                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7130                                    JournalFolder.class.getName(),
7131                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7132    
7133                    Session session = null;
7134    
7135                    try {
7136                            session = openSession();
7137    
7138                            SQLQuery q = session.createSQLQuery(sql);
7139    
7140                            q.addScalar(COUNT_COLUMN_NAME,
7141                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
7142    
7143                            QueryPos qPos = QueryPos.getInstance(q);
7144    
7145                            qPos.add(groupId);
7146    
7147                            qPos.add(parentFolderId);
7148    
7149                            qPos.add(status);
7150    
7151                            Long count = (Long)q.uniqueResult();
7152    
7153                            return count.intValue();
7154                    }
7155                    catch (Exception e) {
7156                            throw processException(e);
7157                    }
7158                    finally {
7159                            closeSession(session);
7160                    }
7161            }
7162    
7163            private static final String _FINDER_COLUMN_G_P_NOTS_GROUPID_2 = "journalFolder.groupId = ? AND ";
7164            private static final String _FINDER_COLUMN_G_P_NOTS_PARENTFOLDERID_2 = "journalFolder.parentFolderId = ? AND ";
7165            private static final String _FINDER_COLUMN_G_P_NOTS_STATUS_2 = "journalFolder.status != ?";
7166    
7167            public JournalFolderPersistenceImpl() {
7168                    setModelClass(JournalFolder.class);
7169            }
7170    
7171            /**
7172             * Caches the journal folder in the entity cache if it is enabled.
7173             *
7174             * @param journalFolder the journal folder
7175             */
7176            @Override
7177            public void cacheResult(JournalFolder journalFolder) {
7178                    EntityCacheUtil.putResult(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
7179                            JournalFolderImpl.class, journalFolder.getPrimaryKey(),
7180                            journalFolder);
7181    
7182                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
7183                            new Object[] { journalFolder.getUuid(), journalFolder.getGroupId() },
7184                            journalFolder);
7185    
7186                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
7187                            new Object[] { journalFolder.getGroupId(), journalFolder.getName() },
7188                            journalFolder);
7189    
7190                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N,
7191                            new Object[] {
7192                                    journalFolder.getGroupId(), journalFolder.getParentFolderId(),
7193                                    journalFolder.getName()
7194                            }, journalFolder);
7195    
7196                    journalFolder.resetOriginalValues();
7197            }
7198    
7199            /**
7200             * Caches the journal folders in the entity cache if it is enabled.
7201             *
7202             * @param journalFolders the journal folders
7203             */
7204            @Override
7205            public void cacheResult(List<JournalFolder> journalFolders) {
7206                    for (JournalFolder journalFolder : journalFolders) {
7207                            if (EntityCacheUtil.getResult(
7208                                                    JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
7209                                                    JournalFolderImpl.class, journalFolder.getPrimaryKey()) == null) {
7210                                    cacheResult(journalFolder);
7211                            }
7212                            else {
7213                                    journalFolder.resetOriginalValues();
7214                            }
7215                    }
7216            }
7217    
7218            /**
7219             * Clears the cache for all journal folders.
7220             *
7221             * <p>
7222             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
7223             * </p>
7224             */
7225            @Override
7226            public void clearCache() {
7227                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
7228                            CacheRegistryUtil.clear(JournalFolderImpl.class.getName());
7229                    }
7230    
7231                    EntityCacheUtil.clearCache(JournalFolderImpl.class.getName());
7232    
7233                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
7234                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7235                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7236            }
7237    
7238            /**
7239             * Clears the cache for the journal folder.
7240             *
7241             * <p>
7242             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
7243             * </p>
7244             */
7245            @Override
7246            public void clearCache(JournalFolder journalFolder) {
7247                    EntityCacheUtil.removeResult(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
7248                            JournalFolderImpl.class, journalFolder.getPrimaryKey());
7249    
7250                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7251                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7252    
7253                    clearUniqueFindersCache(journalFolder);
7254            }
7255    
7256            @Override
7257            public void clearCache(List<JournalFolder> journalFolders) {
7258                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7259                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7260    
7261                    for (JournalFolder journalFolder : journalFolders) {
7262                            EntityCacheUtil.removeResult(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
7263                                    JournalFolderImpl.class, journalFolder.getPrimaryKey());
7264    
7265                            clearUniqueFindersCache(journalFolder);
7266                    }
7267            }
7268    
7269            protected void cacheUniqueFindersCache(JournalFolder journalFolder) {
7270                    if (journalFolder.isNew()) {
7271                            Object[] args = new Object[] {
7272                                            journalFolder.getUuid(), journalFolder.getGroupId()
7273                                    };
7274    
7275                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
7276                                    Long.valueOf(1));
7277                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
7278                                    journalFolder);
7279    
7280                            args = new Object[] {
7281                                            journalFolder.getGroupId(), journalFolder.getName()
7282                                    };
7283    
7284                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N, args,
7285                                    Long.valueOf(1));
7286                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N, args,
7287                                    journalFolder);
7288    
7289                            args = new Object[] {
7290                                            journalFolder.getGroupId(),
7291                                            journalFolder.getParentFolderId(), journalFolder.getName()
7292                                    };
7293    
7294                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P_N, args,
7295                                    Long.valueOf(1));
7296                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N, args,
7297                                    journalFolder);
7298                    }
7299                    else {
7300                            JournalFolderModelImpl journalFolderModelImpl = (JournalFolderModelImpl)journalFolder;
7301    
7302                            if ((journalFolderModelImpl.getColumnBitmask() &
7303                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
7304                                    Object[] args = new Object[] {
7305                                                    journalFolder.getUuid(), journalFolder.getGroupId()
7306                                            };
7307    
7308                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
7309                                            Long.valueOf(1));
7310                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
7311                                            journalFolder);
7312                            }
7313    
7314                            if ((journalFolderModelImpl.getColumnBitmask() &
7315                                            FINDER_PATH_FETCH_BY_G_N.getColumnBitmask()) != 0) {
7316                                    Object[] args = new Object[] {
7317                                                    journalFolder.getGroupId(), journalFolder.getName()
7318                                            };
7319    
7320                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N, args,
7321                                            Long.valueOf(1));
7322                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N, args,
7323                                            journalFolder);
7324                            }
7325    
7326                            if ((journalFolderModelImpl.getColumnBitmask() &
7327                                            FINDER_PATH_FETCH_BY_G_P_N.getColumnBitmask()) != 0) {
7328                                    Object[] args = new Object[] {
7329                                                    journalFolder.getGroupId(),
7330                                                    journalFolder.getParentFolderId(),
7331                                                    journalFolder.getName()
7332                                            };
7333    
7334                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P_N, args,
7335                                            Long.valueOf(1));
7336                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N, args,
7337                                            journalFolder);
7338                            }
7339                    }
7340            }
7341    
7342            protected void clearUniqueFindersCache(JournalFolder journalFolder) {
7343                    JournalFolderModelImpl journalFolderModelImpl = (JournalFolderModelImpl)journalFolder;
7344    
7345                    Object[] args = new Object[] {
7346                                    journalFolder.getUuid(), journalFolder.getGroupId()
7347                            };
7348    
7349                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
7350                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
7351    
7352                    if ((journalFolderModelImpl.getColumnBitmask() &
7353                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
7354                            args = new Object[] {
7355                                            journalFolderModelImpl.getOriginalUuid(),
7356                                            journalFolderModelImpl.getOriginalGroupId()
7357                                    };
7358    
7359                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
7360                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
7361                    }
7362    
7363                    args = new Object[] { journalFolder.getGroupId(), journalFolder.getName() };
7364    
7365                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N, args);
7366                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N, args);
7367    
7368                    if ((journalFolderModelImpl.getColumnBitmask() &
7369                                    FINDER_PATH_FETCH_BY_G_N.getColumnBitmask()) != 0) {
7370                            args = new Object[] {
7371                                            journalFolderModelImpl.getOriginalGroupId(),
7372                                            journalFolderModelImpl.getOriginalName()
7373                                    };
7374    
7375                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N, args);
7376                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N, args);
7377                    }
7378    
7379                    args = new Object[] {
7380                                    journalFolder.getGroupId(), journalFolder.getParentFolderId(),
7381                                    journalFolder.getName()
7382                            };
7383    
7384                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_N, args);
7385                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_N, args);
7386    
7387                    if ((journalFolderModelImpl.getColumnBitmask() &
7388                                    FINDER_PATH_FETCH_BY_G_P_N.getColumnBitmask()) != 0) {
7389                            args = new Object[] {
7390                                            journalFolderModelImpl.getOriginalGroupId(),
7391                                            journalFolderModelImpl.getOriginalParentFolderId(),
7392                                            journalFolderModelImpl.getOriginalName()
7393                                    };
7394    
7395                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_N, args);
7396                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_N, args);
7397                    }
7398            }
7399    
7400            /**
7401             * Creates a new journal folder with the primary key. Does not add the journal folder to the database.
7402             *
7403             * @param folderId the primary key for the new journal folder
7404             * @return the new journal folder
7405             */
7406            @Override
7407            public JournalFolder create(long folderId) {
7408                    JournalFolder journalFolder = new JournalFolderImpl();
7409    
7410                    journalFolder.setNew(true);
7411                    journalFolder.setPrimaryKey(folderId);
7412    
7413                    String uuid = PortalUUIDUtil.generate();
7414    
7415                    journalFolder.setUuid(uuid);
7416    
7417                    return journalFolder;
7418            }
7419    
7420            /**
7421             * Removes the journal folder with the primary key from the database. Also notifies the appropriate model listeners.
7422             *
7423             * @param folderId the primary key of the journal folder
7424             * @return the journal folder that was removed
7425             * @throws com.liferay.portlet.journal.NoSuchFolderException if a journal folder with the primary key could not be found
7426             * @throws SystemException if a system exception occurred
7427             */
7428            @Override
7429            public JournalFolder remove(long folderId)
7430                    throws NoSuchFolderException, SystemException {
7431                    return remove((Serializable)folderId);
7432            }
7433    
7434            /**
7435             * Removes the journal folder with the primary key from the database. Also notifies the appropriate model listeners.
7436             *
7437             * @param primaryKey the primary key of the journal folder
7438             * @return the journal folder that was removed
7439             * @throws com.liferay.portlet.journal.NoSuchFolderException if a journal folder with the primary key could not be found
7440             * @throws SystemException if a system exception occurred
7441             */
7442            @Override
7443            public JournalFolder remove(Serializable primaryKey)
7444                    throws NoSuchFolderException, SystemException {
7445                    Session session = null;
7446    
7447                    try {
7448                            session = openSession();
7449    
7450                            JournalFolder journalFolder = (JournalFolder)session.get(JournalFolderImpl.class,
7451                                            primaryKey);
7452    
7453                            if (journalFolder == null) {
7454                                    if (_log.isWarnEnabled()) {
7455                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
7456                                    }
7457    
7458                                    throw new NoSuchFolderException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
7459                                            primaryKey);
7460                            }
7461    
7462                            return remove(journalFolder);
7463                    }
7464                    catch (NoSuchFolderException nsee) {
7465                            throw nsee;
7466                    }
7467                    catch (Exception e) {
7468                            throw processException(e);
7469                    }
7470                    finally {
7471                            closeSession(session);
7472                    }
7473            }
7474    
7475            @Override
7476            protected JournalFolder removeImpl(JournalFolder journalFolder)
7477                    throws SystemException {
7478                    journalFolder = toUnwrappedModel(journalFolder);
7479    
7480                    Session session = null;
7481    
7482                    try {
7483                            session = openSession();
7484    
7485                            if (!session.contains(journalFolder)) {
7486                                    journalFolder = (JournalFolder)session.get(JournalFolderImpl.class,
7487                                                    journalFolder.getPrimaryKeyObj());
7488                            }
7489    
7490                            if (journalFolder != null) {
7491                                    session.delete(journalFolder);
7492                            }
7493                    }
7494                    catch (Exception e) {
7495                            throw processException(e);
7496                    }
7497                    finally {
7498                            closeSession(session);
7499                    }
7500    
7501                    if (journalFolder != null) {
7502                            clearCache(journalFolder);
7503                    }
7504    
7505                    return journalFolder;
7506            }
7507    
7508            @Override
7509            public JournalFolder updateImpl(
7510                    com.liferay.portlet.journal.model.JournalFolder journalFolder)
7511                    throws SystemException {
7512                    journalFolder = toUnwrappedModel(journalFolder);
7513    
7514                    boolean isNew = journalFolder.isNew();
7515    
7516                    JournalFolderModelImpl journalFolderModelImpl = (JournalFolderModelImpl)journalFolder;
7517    
7518                    if (Validator.isNull(journalFolder.getUuid())) {
7519                            String uuid = PortalUUIDUtil.generate();
7520    
7521                            journalFolder.setUuid(uuid);
7522                    }
7523    
7524                    Session session = null;
7525    
7526                    try {
7527                            session = openSession();
7528    
7529                            if (journalFolder.isNew()) {
7530                                    session.save(journalFolder);
7531    
7532                                    journalFolder.setNew(false);
7533                            }
7534                            else {
7535                                    session.merge(journalFolder);
7536                            }
7537                    }
7538                    catch (Exception e) {
7539                            throw processException(e);
7540                    }
7541                    finally {
7542                            closeSession(session);
7543                    }
7544    
7545                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7546    
7547                    if (isNew || !JournalFolderModelImpl.COLUMN_BITMASK_ENABLED) {
7548                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7549                    }
7550    
7551                    else {
7552                            if ((journalFolderModelImpl.getColumnBitmask() &
7553                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
7554                                    Object[] args = new Object[] {
7555                                                    journalFolderModelImpl.getOriginalUuid()
7556                                            };
7557    
7558                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
7559                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
7560                                            args);
7561    
7562                                    args = new Object[] { journalFolderModelImpl.getUuid() };
7563    
7564                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
7565                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
7566                                            args);
7567                            }
7568    
7569                            if ((journalFolderModelImpl.getColumnBitmask() &
7570                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
7571                                    Object[] args = new Object[] {
7572                                                    journalFolderModelImpl.getOriginalUuid(),
7573                                                    journalFolderModelImpl.getOriginalCompanyId()
7574                                            };
7575    
7576                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
7577                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
7578                                            args);
7579    
7580                                    args = new Object[] {
7581                                                    journalFolderModelImpl.getUuid(),
7582                                                    journalFolderModelImpl.getCompanyId()
7583                                            };
7584    
7585                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
7586                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
7587                                            args);
7588                            }
7589    
7590                            if ((journalFolderModelImpl.getColumnBitmask() &
7591                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
7592                                    Object[] args = new Object[] {
7593                                                    journalFolderModelImpl.getOriginalGroupId()
7594                                            };
7595    
7596                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
7597                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
7598                                            args);
7599    
7600                                    args = new Object[] { journalFolderModelImpl.getGroupId() };
7601    
7602                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
7603                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
7604                                            args);
7605                            }
7606    
7607                            if ((journalFolderModelImpl.getColumnBitmask() &
7608                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
7609                                    Object[] args = new Object[] {
7610                                                    journalFolderModelImpl.getOriginalCompanyId()
7611                                            };
7612    
7613                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
7614                                            args);
7615                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
7616                                            args);
7617    
7618                                    args = new Object[] { journalFolderModelImpl.getCompanyId() };
7619    
7620                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
7621                                            args);
7622                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
7623                                            args);
7624                            }
7625    
7626                            if ((journalFolderModelImpl.getColumnBitmask() &
7627                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P.getColumnBitmask()) != 0) {
7628                                    Object[] args = new Object[] {
7629                                                    journalFolderModelImpl.getOriginalGroupId(),
7630                                                    journalFolderModelImpl.getOriginalParentFolderId()
7631                                            };
7632    
7633                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
7634                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
7635                                            args);
7636    
7637                                    args = new Object[] {
7638                                                    journalFolderModelImpl.getGroupId(),
7639                                                    journalFolderModelImpl.getParentFolderId()
7640                                            };
7641    
7642                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
7643                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
7644                                            args);
7645                            }
7646    
7647                            if ((journalFolderModelImpl.getColumnBitmask() &
7648                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_S.getColumnBitmask()) != 0) {
7649                                    Object[] args = new Object[] {
7650                                                    journalFolderModelImpl.getOriginalGroupId(),
7651                                                    journalFolderModelImpl.getOriginalParentFolderId(),
7652                                                    journalFolderModelImpl.getOriginalStatus()
7653                                            };
7654    
7655                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_S, args);
7656                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_S,
7657                                            args);
7658    
7659                                    args = new Object[] {
7660                                                    journalFolderModelImpl.getGroupId(),
7661                                                    journalFolderModelImpl.getParentFolderId(),
7662                                                    journalFolderModelImpl.getStatus()
7663                                            };
7664    
7665                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_S, args);
7666                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_S,
7667                                            args);
7668                            }
7669                    }
7670    
7671                    EntityCacheUtil.putResult(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
7672                            JournalFolderImpl.class, journalFolder.getPrimaryKey(),
7673                            journalFolder);
7674    
7675                    clearUniqueFindersCache(journalFolder);
7676                    cacheUniqueFindersCache(journalFolder);
7677    
7678                    return journalFolder;
7679            }
7680    
7681            protected JournalFolder toUnwrappedModel(JournalFolder journalFolder) {
7682                    if (journalFolder instanceof JournalFolderImpl) {
7683                            return journalFolder;
7684                    }
7685    
7686                    JournalFolderImpl journalFolderImpl = new JournalFolderImpl();
7687    
7688                    journalFolderImpl.setNew(journalFolder.isNew());
7689                    journalFolderImpl.setPrimaryKey(journalFolder.getPrimaryKey());
7690    
7691                    journalFolderImpl.setUuid(journalFolder.getUuid());
7692                    journalFolderImpl.setFolderId(journalFolder.getFolderId());
7693                    journalFolderImpl.setGroupId(journalFolder.getGroupId());
7694                    journalFolderImpl.setCompanyId(journalFolder.getCompanyId());
7695                    journalFolderImpl.setUserId(journalFolder.getUserId());
7696                    journalFolderImpl.setUserName(journalFolder.getUserName());
7697                    journalFolderImpl.setCreateDate(journalFolder.getCreateDate());
7698                    journalFolderImpl.setModifiedDate(journalFolder.getModifiedDate());
7699                    journalFolderImpl.setParentFolderId(journalFolder.getParentFolderId());
7700                    journalFolderImpl.setTreePath(journalFolder.getTreePath());
7701                    journalFolderImpl.setName(journalFolder.getName());
7702                    journalFolderImpl.setDescription(journalFolder.getDescription());
7703                    journalFolderImpl.setStatus(journalFolder.getStatus());
7704                    journalFolderImpl.setStatusByUserId(journalFolder.getStatusByUserId());
7705                    journalFolderImpl.setStatusByUserName(journalFolder.getStatusByUserName());
7706                    journalFolderImpl.setStatusDate(journalFolder.getStatusDate());
7707    
7708                    return journalFolderImpl;
7709            }
7710    
7711            /**
7712             * Returns the journal folder with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
7713             *
7714             * @param primaryKey the primary key of the journal folder
7715             * @return the journal folder
7716             * @throws com.liferay.portlet.journal.NoSuchFolderException if a journal folder with the primary key could not be found
7717             * @throws SystemException if a system exception occurred
7718             */
7719            @Override
7720            public JournalFolder findByPrimaryKey(Serializable primaryKey)
7721                    throws NoSuchFolderException, SystemException {
7722                    JournalFolder journalFolder = fetchByPrimaryKey(primaryKey);
7723    
7724                    if (journalFolder == null) {
7725                            if (_log.isWarnEnabled()) {
7726                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
7727                            }
7728    
7729                            throw new NoSuchFolderException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
7730                                    primaryKey);
7731                    }
7732    
7733                    return journalFolder;
7734            }
7735    
7736            /**
7737             * Returns the journal folder with the primary key or throws a {@link com.liferay.portlet.journal.NoSuchFolderException} if it could not be found.
7738             *
7739             * @param folderId the primary key of the journal folder
7740             * @return the journal folder
7741             * @throws com.liferay.portlet.journal.NoSuchFolderException if a journal folder with the primary key could not be found
7742             * @throws SystemException if a system exception occurred
7743             */
7744            @Override
7745            public JournalFolder findByPrimaryKey(long folderId)
7746                    throws NoSuchFolderException, SystemException {
7747                    return findByPrimaryKey((Serializable)folderId);
7748            }
7749    
7750            /**
7751             * Returns the journal folder with the primary key or returns <code>null</code> if it could not be found.
7752             *
7753             * @param primaryKey the primary key of the journal folder
7754             * @return the journal folder, or <code>null</code> if a journal folder with the primary key could not be found
7755             * @throws SystemException if a system exception occurred
7756             */
7757            @Override
7758            public JournalFolder fetchByPrimaryKey(Serializable primaryKey)
7759                    throws SystemException {
7760                    JournalFolder journalFolder = (JournalFolder)EntityCacheUtil.getResult(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
7761                                    JournalFolderImpl.class, primaryKey);
7762    
7763                    if (journalFolder == _nullJournalFolder) {
7764                            return null;
7765                    }
7766    
7767                    if (journalFolder == null) {
7768                            Session session = null;
7769    
7770                            try {
7771                                    session = openSession();
7772    
7773                                    journalFolder = (JournalFolder)session.get(JournalFolderImpl.class,
7774                                                    primaryKey);
7775    
7776                                    if (journalFolder != null) {
7777                                            cacheResult(journalFolder);
7778                                    }
7779                                    else {
7780                                            EntityCacheUtil.putResult(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
7781                                                    JournalFolderImpl.class, primaryKey, _nullJournalFolder);
7782                                    }
7783                            }
7784                            catch (Exception e) {
7785                                    EntityCacheUtil.removeResult(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
7786                                            JournalFolderImpl.class, primaryKey);
7787    
7788                                    throw processException(e);
7789                            }
7790                            finally {
7791                                    closeSession(session);
7792                            }
7793                    }
7794    
7795                    return journalFolder;
7796            }
7797    
7798            /**
7799             * Returns the journal folder with the primary key or returns <code>null</code> if it could not be found.
7800             *
7801             * @param folderId the primary key of the journal folder
7802             * @return the journal folder, or <code>null</code> if a journal folder with the primary key could not be found
7803             * @throws SystemException if a system exception occurred
7804             */
7805            @Override
7806            public JournalFolder fetchByPrimaryKey(long folderId)
7807                    throws SystemException {
7808                    return fetchByPrimaryKey((Serializable)folderId);
7809            }
7810    
7811            /**
7812             * Returns all the journal folders.
7813             *
7814             * @return the journal folders
7815             * @throws SystemException if a system exception occurred
7816             */
7817            @Override
7818            public List<JournalFolder> findAll() throws SystemException {
7819                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7820            }
7821    
7822            /**
7823             * Returns a range of all the journal folders.
7824             *
7825             * <p>
7826             * 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.
7827             * </p>
7828             *
7829             * @param start the lower bound of the range of journal folders
7830             * @param end the upper bound of the range of journal folders (not inclusive)
7831             * @return the range of journal folders
7832             * @throws SystemException if a system exception occurred
7833             */
7834            @Override
7835            public List<JournalFolder> findAll(int start, int end)
7836                    throws SystemException {
7837                    return findAll(start, end, null);
7838            }
7839    
7840            /**
7841             * Returns an ordered range of all the journal folders.
7842             *
7843             * <p>
7844             * 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.
7845             * </p>
7846             *
7847             * @param start the lower bound of the range of journal folders
7848             * @param end the upper bound of the range of journal folders (not inclusive)
7849             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7850             * @return the ordered range of journal folders
7851             * @throws SystemException if a system exception occurred
7852             */
7853            @Override
7854            public List<JournalFolder> findAll(int start, int end,
7855                    OrderByComparator orderByComparator) throws SystemException {
7856                    boolean pagination = true;
7857                    FinderPath finderPath = null;
7858                    Object[] finderArgs = null;
7859    
7860                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7861                                    (orderByComparator == null)) {
7862                            pagination = false;
7863                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
7864                            finderArgs = FINDER_ARGS_EMPTY;
7865                    }
7866                    else {
7867                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
7868                            finderArgs = new Object[] { start, end, orderByComparator };
7869                    }
7870    
7871                    List<JournalFolder> list = (List<JournalFolder>)FinderCacheUtil.getResult(finderPath,
7872                                    finderArgs, this);
7873    
7874                    if (list == null) {
7875                            StringBundler query = null;
7876                            String sql = null;
7877    
7878                            if (orderByComparator != null) {
7879                                    query = new StringBundler(2 +
7880                                                    (orderByComparator.getOrderByFields().length * 3));
7881    
7882                                    query.append(_SQL_SELECT_JOURNALFOLDER);
7883    
7884                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7885                                            orderByComparator);
7886    
7887                                    sql = query.toString();
7888                            }
7889                            else {
7890                                    sql = _SQL_SELECT_JOURNALFOLDER;
7891    
7892                                    if (pagination) {
7893                                            sql = sql.concat(JournalFolderModelImpl.ORDER_BY_JPQL);
7894                                    }
7895                            }
7896    
7897                            Session session = null;
7898    
7899                            try {
7900                                    session = openSession();
7901    
7902                                    Query q = session.createQuery(sql);
7903    
7904                                    if (!pagination) {
7905                                            list = (List<JournalFolder>)QueryUtil.list(q, getDialect(),
7906                                                            start, end, false);
7907    
7908                                            Collections.sort(list);
7909    
7910                                            list = new UnmodifiableList<JournalFolder>(list);
7911                                    }
7912                                    else {
7913                                            list = (List<JournalFolder>)QueryUtil.list(q, getDialect(),
7914                                                            start, end);
7915                                    }
7916    
7917                                    cacheResult(list);
7918    
7919                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
7920                            }
7921                            catch (Exception e) {
7922                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7923    
7924                                    throw processException(e);
7925                            }
7926                            finally {
7927                                    closeSession(session);
7928                            }
7929                    }
7930    
7931                    return list;
7932            }
7933    
7934            /**
7935             * Removes all the journal folders from the database.
7936             *
7937             * @throws SystemException if a system exception occurred
7938             */
7939            @Override
7940            public void removeAll() throws SystemException {
7941                    for (JournalFolder journalFolder : findAll()) {
7942                            remove(journalFolder);
7943                    }
7944            }
7945    
7946            /**
7947             * Returns the number of journal folders.
7948             *
7949             * @return the number of journal folders
7950             * @throws SystemException if a system exception occurred
7951             */
7952            @Override
7953            public int countAll() throws SystemException {
7954                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
7955                                    FINDER_ARGS_EMPTY, this);
7956    
7957                    if (count == null) {
7958                            Session session = null;
7959    
7960                            try {
7961                                    session = openSession();
7962    
7963                                    Query q = session.createQuery(_SQL_COUNT_JOURNALFOLDER);
7964    
7965                                    count = (Long)q.uniqueResult();
7966    
7967                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
7968                                            FINDER_ARGS_EMPTY, count);
7969                            }
7970                            catch (Exception e) {
7971                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
7972                                            FINDER_ARGS_EMPTY);
7973    
7974                                    throw processException(e);
7975                            }
7976                            finally {
7977                                    closeSession(session);
7978                            }
7979                    }
7980    
7981                    return count.intValue();
7982            }
7983    
7984            @Override
7985            protected Set<String> getBadColumnNames() {
7986                    return _badColumnNames;
7987            }
7988    
7989            /**
7990             * Initializes the journal folder persistence.
7991             */
7992            public void afterPropertiesSet() {
7993                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
7994                                            com.liferay.portal.util.PropsUtil.get(
7995                                                    "value.object.listener.com.liferay.portlet.journal.model.JournalFolder")));
7996    
7997                    if (listenerClassNames.length > 0) {
7998                            try {
7999                                    List<ModelListener<JournalFolder>> listenersList = new ArrayList<ModelListener<JournalFolder>>();
8000    
8001                                    for (String listenerClassName : listenerClassNames) {
8002                                            listenersList.add((ModelListener<JournalFolder>)InstanceFactory.newInstance(
8003                                                            getClassLoader(), listenerClassName));
8004                                    }
8005    
8006                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
8007                            }
8008                            catch (Exception e) {
8009                                    _log.error(e);
8010                            }
8011                    }
8012            }
8013    
8014            public void destroy() {
8015                    EntityCacheUtil.removeCache(JournalFolderImpl.class.getName());
8016                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
8017                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8018                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8019            }
8020    
8021            private static final String _SQL_SELECT_JOURNALFOLDER = "SELECT journalFolder FROM JournalFolder journalFolder";
8022            private static final String _SQL_SELECT_JOURNALFOLDER_WHERE = "SELECT journalFolder FROM JournalFolder journalFolder WHERE ";
8023            private static final String _SQL_COUNT_JOURNALFOLDER = "SELECT COUNT(journalFolder) FROM JournalFolder journalFolder";
8024            private static final String _SQL_COUNT_JOURNALFOLDER_WHERE = "SELECT COUNT(journalFolder) FROM JournalFolder journalFolder WHERE ";
8025            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "journalFolder.folderId";
8026            private static final String _FILTER_SQL_SELECT_JOURNALFOLDER_WHERE = "SELECT DISTINCT {journalFolder.*} FROM JournalFolder journalFolder WHERE ";
8027            private static final String _FILTER_SQL_SELECT_JOURNALFOLDER_NO_INLINE_DISTINCT_WHERE_1 =
8028                    "SELECT {JournalFolder.*} FROM (SELECT DISTINCT journalFolder.folderId FROM JournalFolder journalFolder WHERE ";
8029            private static final String _FILTER_SQL_SELECT_JOURNALFOLDER_NO_INLINE_DISTINCT_WHERE_2 =
8030                    ") TEMP_TABLE INNER JOIN JournalFolder ON TEMP_TABLE.folderId = JournalFolder.folderId";
8031            private static final String _FILTER_SQL_COUNT_JOURNALFOLDER_WHERE = "SELECT COUNT(DISTINCT journalFolder.folderId) AS COUNT_VALUE FROM JournalFolder journalFolder WHERE ";
8032            private static final String _FILTER_ENTITY_ALIAS = "journalFolder";
8033            private static final String _FILTER_ENTITY_TABLE = "JournalFolder";
8034            private static final String _ORDER_BY_ENTITY_ALIAS = "journalFolder.";
8035            private static final String _ORDER_BY_ENTITY_TABLE = "JournalFolder.";
8036            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No JournalFolder exists with the primary key ";
8037            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No JournalFolder exists with the key {";
8038            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
8039            private static Log _log = LogFactoryUtil.getLog(JournalFolderPersistenceImpl.class);
8040            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
8041                                    "uuid"
8042                            });
8043            private static JournalFolder _nullJournalFolder = new JournalFolderImpl() {
8044                            @Override
8045                            public Object clone() {
8046                                    return this;
8047                            }
8048    
8049                            @Override
8050                            public CacheModel<JournalFolder> toCacheModel() {
8051                                    return _nullJournalFolderCacheModel;
8052                            }
8053                    };
8054    
8055            private static CacheModel<JournalFolder> _nullJournalFolderCacheModel = new CacheModel<JournalFolder>() {
8056                            @Override
8057                            public JournalFolder toEntityModel() {
8058                                    return _nullJournalFolder;
8059                            }
8060                    };
8061    }