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