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