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