001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.journal.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
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.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.kernel.util.UnmodifiableList;
037    import com.liferay.portal.kernel.util.Validator;
038    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
039    import com.liferay.portal.model.CacheModel;
040    import com.liferay.portal.model.ModelListener;
041    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
042    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043    
044    import com.liferay.portlet.journal.NoSuchFolderException;
045    import com.liferay.portlet.journal.model.JournalFolder;
046    import com.liferay.portlet.journal.model.impl.JournalFolderImpl;
047    import com.liferay.portlet.journal.model.impl.JournalFolderModelImpl;
048    
049    import java.io.Serializable;
050    
051    import java.util.ArrayList;
052    import java.util.Collections;
053    import java.util.List;
054    
055    /**
056     * The persistence implementation for the journal folder service.
057     *
058     * <p>
059     * Caching information and settings can be found in <code>portal.properties</code>
060     * </p>
061     *
062     * @author Brian Wing Shun Chan
063     * @see JournalFolderPersistence
064     * @see JournalFolderUtil
065     * @generated
066     */
067    public class JournalFolderPersistenceImpl extends BasePersistenceImpl<JournalFolder>
068            implements JournalFolderPersistence {
069            /*
070             * NOTE FOR DEVELOPERS:
071             *
072             * 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.
073             */
074            public static final String FINDER_CLASS_NAME_ENTITY = JournalFolderImpl.class.getName();
075            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
076                    ".List1";
077            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
078                    ".List2";
079            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
080                            JournalFolderModelImpl.FINDER_CACHE_ENABLED,
081                            JournalFolderImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
082                            "findAll", new String[0]);
083            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
084                            JournalFolderModelImpl.FINDER_CACHE_ENABLED,
085                            JournalFolderImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
086                            "findAll", new String[0]);
087            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
088                            JournalFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
089                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
090            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
091                            JournalFolderModelImpl.FINDER_CACHE_ENABLED,
092                            JournalFolderImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
093                            "findByUuid",
094                            new String[] {
095                                    String.class.getName(),
096                                    
097                            Integer.class.getName(), Integer.class.getName(),
098                                    OrderByComparator.class.getName()
099                            });
100            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
101                            JournalFolderModelImpl.FINDER_CACHE_ENABLED,
102                            JournalFolderImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
103                            "findByUuid", new String[] { String.class.getName() },
104                            JournalFolderModelImpl.UUID_COLUMN_BITMASK |
105                            JournalFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
106                            JournalFolderModelImpl.NAME_COLUMN_BITMASK);
107            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
108                            JournalFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
109                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
110                            new String[] { String.class.getName() });
111    
112            /**
113             * Returns all the journal folders where uuid = &#63;.
114             *
115             * @param uuid the uuid
116             * @return the matching journal folders
117             * @throws SystemException if a system exception occurred
118             */
119            public List<JournalFolder> findByUuid(String uuid)
120                    throws SystemException {
121                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
122            }
123    
124            /**
125             * Returns a range of all the journal folders where uuid = &#63;.
126             *
127             * <p>
128             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
129             * </p>
130             *
131             * @param uuid the uuid
132             * @param start the lower bound of the range of journal folders
133             * @param end the upper bound of the range of journal folders (not inclusive)
134             * @return the range of matching journal folders
135             * @throws SystemException if a system exception occurred
136             */
137            public List<JournalFolder> findByUuid(String uuid, int start, int end)
138                    throws SystemException {
139                    return findByUuid(uuid, start, end, null);
140            }
141    
142            /**
143             * Returns an ordered range of all the journal folders where uuid = &#63;.
144             *
145             * <p>
146             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
147             * </p>
148             *
149             * @param uuid the uuid
150             * @param start the lower bound of the range of journal folders
151             * @param end the upper bound of the range of journal folders (not inclusive)
152             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
153             * @return the ordered range of matching journal folders
154             * @throws SystemException if a system exception occurred
155             */
156            public List<JournalFolder> findByUuid(String uuid, int start, int end,
157                    OrderByComparator orderByComparator) throws SystemException {
158                    boolean pagination = true;
159                    FinderPath finderPath = null;
160                    Object[] finderArgs = null;
161    
162                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
163                                    (orderByComparator == null)) {
164                            pagination = false;
165                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
166                            finderArgs = new Object[] { uuid };
167                    }
168                    else {
169                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
170                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
171                    }
172    
173                    List<JournalFolder> list = (List<JournalFolder>)FinderCacheUtil.getResult(finderPath,
174                                    finderArgs, this);
175    
176                    if ((list != null) && !list.isEmpty()) {
177                            for (JournalFolder journalFolder : list) {
178                                    if (!Validator.equals(uuid, journalFolder.getUuid())) {
179                                            list = null;
180    
181                                            break;
182                                    }
183                            }
184                    }
185    
186                    if (list == null) {
187                            StringBundler query = null;
188    
189                            if (orderByComparator != null) {
190                                    query = new StringBundler(3 +
191                                                    (orderByComparator.getOrderByFields().length * 3));
192                            }
193                            else {
194                                    query = new StringBundler(3);
195                            }
196    
197                            query.append(_SQL_SELECT_JOURNALFOLDER_WHERE);
198    
199                            if (uuid == null) {
200                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
201                            }
202                            else {
203                                    if (uuid.equals(StringPool.BLANK)) {
204                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
205                                    }
206                                    else {
207                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
208                                    }
209                            }
210    
211                            if (orderByComparator != null) {
212                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
213                                            orderByComparator);
214                            }
215                            else
216                             if (pagination) {
217                                    query.append(JournalFolderModelImpl.ORDER_BY_JPQL);
218                            }
219    
220                            String sql = query.toString();
221    
222                            Session session = null;
223    
224                            try {
225                                    session = openSession();
226    
227                                    Query q = session.createQuery(sql);
228    
229                                    QueryPos qPos = QueryPos.getInstance(q);
230    
231                                    if (uuid != null) {
232                                            qPos.add(uuid);
233                                    }
234    
235                                    if (!pagination) {
236                                            list = (List<JournalFolder>)QueryUtil.list(q, getDialect(),
237                                                            start, end, false);
238    
239                                            Collections.sort(list);
240    
241                                            list = new UnmodifiableList<JournalFolder>(list);
242                                    }
243                                    else {
244                                            list = (List<JournalFolder>)QueryUtil.list(q, getDialect(),
245                                                            start, end);
246                                    }
247    
248                                    cacheResult(list);
249    
250                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
251                            }
252                            catch (Exception e) {
253                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
254    
255                                    throw processException(e);
256                            }
257                            finally {
258                                    closeSession(session);
259                            }
260                    }
261    
262                    return list;
263            }
264    
265            /**
266             * Returns the first journal folder in the ordered set where uuid = &#63;.
267             *
268             * @param uuid the uuid
269             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
270             * @return the first matching journal folder
271             * @throws com.liferay.portlet.journal.NoSuchFolderException if a matching journal folder could not be found
272             * @throws SystemException if a system exception occurred
273             */
274            public JournalFolder findByUuid_First(String uuid,
275                    OrderByComparator orderByComparator)
276                    throws NoSuchFolderException, SystemException {
277                    JournalFolder journalFolder = fetchByUuid_First(uuid, orderByComparator);
278    
279                    if (journalFolder != null) {
280                            return journalFolder;
281                    }
282    
283                    StringBundler msg = new StringBundler(4);
284    
285                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
286    
287                    msg.append("uuid=");
288                    msg.append(uuid);
289    
290                    msg.append(StringPool.CLOSE_CURLY_BRACE);
291    
292                    throw new NoSuchFolderException(msg.toString());
293            }
294    
295            /**
296             * Returns the first journal folder in the ordered set where uuid = &#63;.
297             *
298             * @param uuid the uuid
299             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
300             * @return the first matching journal folder, or <code>null</code> if a matching journal folder could not be found
301             * @throws SystemException if a system exception occurred
302             */
303            public JournalFolder fetchByUuid_First(String uuid,
304                    OrderByComparator orderByComparator) throws SystemException {
305                    List<JournalFolder> list = findByUuid(uuid, 0, 1, orderByComparator);
306    
307                    if (!list.isEmpty()) {
308                            return list.get(0);
309                    }
310    
311                    return null;
312            }
313    
314            /**
315             * Returns the last journal folder in the ordered set where uuid = &#63;.
316             *
317             * @param uuid the uuid
318             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
319             * @return the last matching journal folder
320             * @throws com.liferay.portlet.journal.NoSuchFolderException if a matching journal folder could not be found
321             * @throws SystemException if a system exception occurred
322             */
323            public JournalFolder findByUuid_Last(String uuid,
324                    OrderByComparator orderByComparator)
325                    throws NoSuchFolderException, SystemException {
326                    JournalFolder journalFolder = fetchByUuid_Last(uuid, orderByComparator);
327    
328                    if (journalFolder != null) {
329                            return journalFolder;
330                    }
331    
332                    StringBundler msg = new StringBundler(4);
333    
334                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
335    
336                    msg.append("uuid=");
337                    msg.append(uuid);
338    
339                    msg.append(StringPool.CLOSE_CURLY_BRACE);
340    
341                    throw new NoSuchFolderException(msg.toString());
342            }
343    
344            /**
345             * Returns the last journal folder in the ordered set where uuid = &#63;.
346             *
347             * @param uuid the uuid
348             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
349             * @return the last matching journal folder, or <code>null</code> if a matching journal folder could not be found
350             * @throws SystemException if a system exception occurred
351             */
352            public JournalFolder fetchByUuid_Last(String uuid,
353                    OrderByComparator orderByComparator) throws SystemException {
354                    int count = countByUuid(uuid);
355    
356                    List<JournalFolder> list = findByUuid(uuid, count - 1, count,
357                                    orderByComparator);
358    
359                    if (!list.isEmpty()) {
360                            return list.get(0);
361                    }
362    
363                    return null;
364            }
365    
366            /**
367             * Returns the journal folders before and after the current journal folder in the ordered set where uuid = &#63;.
368             *
369             * @param folderId the primary key of the current journal folder
370             * @param uuid the uuid
371             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
372             * @return the previous, current, and next journal folder
373             * @throws com.liferay.portlet.journal.NoSuchFolderException if a journal folder with the primary key could not be found
374             * @throws SystemException if a system exception occurred
375             */
376            public JournalFolder[] findByUuid_PrevAndNext(long folderId, String uuid,
377                    OrderByComparator orderByComparator)
378                    throws NoSuchFolderException, SystemException {
379                    JournalFolder journalFolder = findByPrimaryKey(folderId);
380    
381                    Session session = null;
382    
383                    try {
384                            session = openSession();
385    
386                            JournalFolder[] array = new JournalFolderImpl[3];
387    
388                            array[0] = getByUuid_PrevAndNext(session, journalFolder, uuid,
389                                            orderByComparator, true);
390    
391                            array[1] = journalFolder;
392    
393                            array[2] = getByUuid_PrevAndNext(session, journalFolder, uuid,
394                                            orderByComparator, false);
395    
396                            return array;
397                    }
398                    catch (Exception e) {
399                            throw processException(e);
400                    }
401                    finally {
402                            closeSession(session);
403                    }
404            }
405    
406            protected JournalFolder getByUuid_PrevAndNext(Session session,
407                    JournalFolder journalFolder, String uuid,
408                    OrderByComparator orderByComparator, boolean previous) {
409                    StringBundler query = null;
410    
411                    if (orderByComparator != null) {
412                            query = new StringBundler(6 +
413                                            (orderByComparator.getOrderByFields().length * 6));
414                    }
415                    else {
416                            query = new StringBundler(3);
417                    }
418    
419                    query.append(_SQL_SELECT_JOURNALFOLDER_WHERE);
420    
421                    if (uuid == null) {
422                            query.append(_FINDER_COLUMN_UUID_UUID_1);
423                    }
424                    else {
425                            if (uuid.equals(StringPool.BLANK)) {
426                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
427                            }
428                            else {
429                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
430                            }
431                    }
432    
433                    if (orderByComparator != null) {
434                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
435    
436                            if (orderByConditionFields.length > 0) {
437                                    query.append(WHERE_AND);
438                            }
439    
440                            for (int i = 0; i < orderByConditionFields.length; i++) {
441                                    query.append(_ORDER_BY_ENTITY_ALIAS);
442                                    query.append(orderByConditionFields[i]);
443    
444                                    if ((i + 1) < orderByConditionFields.length) {
445                                            if (orderByComparator.isAscending() ^ previous) {
446                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
447                                            }
448                                            else {
449                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
450                                            }
451                                    }
452                                    else {
453                                            if (orderByComparator.isAscending() ^ previous) {
454                                                    query.append(WHERE_GREATER_THAN);
455                                            }
456                                            else {
457                                                    query.append(WHERE_LESSER_THAN);
458                                            }
459                                    }
460                            }
461    
462                            query.append(ORDER_BY_CLAUSE);
463    
464                            String[] orderByFields = orderByComparator.getOrderByFields();
465    
466                            for (int i = 0; i < orderByFields.length; i++) {
467                                    query.append(_ORDER_BY_ENTITY_ALIAS);
468                                    query.append(orderByFields[i]);
469    
470                                    if ((i + 1) < orderByFields.length) {
471                                            if (orderByComparator.isAscending() ^ previous) {
472                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
473                                            }
474                                            else {
475                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
476                                            }
477                                    }
478                                    else {
479                                            if (orderByComparator.isAscending() ^ previous) {
480                                                    query.append(ORDER_BY_ASC);
481                                            }
482                                            else {
483                                                    query.append(ORDER_BY_DESC);
484                                            }
485                                    }
486                            }
487                    }
488                    else {
489                            query.append(JournalFolderModelImpl.ORDER_BY_JPQL);
490                    }
491    
492                    String sql = query.toString();
493    
494                    Query q = session.createQuery(sql);
495    
496                    q.setFirstResult(0);
497                    q.setMaxResults(2);
498    
499                    QueryPos qPos = QueryPos.getInstance(q);
500    
501                    if (uuid != null) {
502                            qPos.add(uuid);
503                    }
504    
505                    if (orderByComparator != null) {
506                            Object[] values = orderByComparator.getOrderByConditionValues(journalFolder);
507    
508                            for (Object value : values) {
509                                    qPos.add(value);
510                            }
511                    }
512    
513                    List<JournalFolder> list = q.list();
514    
515                    if (list.size() == 2) {
516                            return list.get(1);
517                    }
518                    else {
519                            return null;
520                    }
521            }
522    
523            /**
524             * Removes all the journal folders where uuid = &#63; from the database.
525             *
526             * @param uuid the uuid
527             * @throws SystemException if a system exception occurred
528             */
529            public void removeByUuid(String uuid) throws SystemException {
530                    for (JournalFolder journalFolder : findByUuid(uuid, QueryUtil.ALL_POS,
531                                    QueryUtil.ALL_POS, null)) {
532                            remove(journalFolder);
533                    }
534            }
535    
536            /**
537             * Returns the number of journal folders where uuid = &#63;.
538             *
539             * @param uuid the uuid
540             * @return the number of matching journal folders
541             * @throws SystemException if a system exception occurred
542             */
543            public int countByUuid(String uuid) throws SystemException {
544                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
545    
546                    Object[] finderArgs = new Object[] { uuid };
547    
548                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
549                                    this);
550    
551                    if (count == null) {
552                            StringBundler query = new StringBundler(2);
553    
554                            query.append(_SQL_COUNT_JOURNALFOLDER_WHERE);
555    
556                            if (uuid == null) {
557                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
558                            }
559                            else {
560                                    if (uuid.equals(StringPool.BLANK)) {
561                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
562                                    }
563                                    else {
564                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
565                                    }
566                            }
567    
568                            String sql = query.toString();
569    
570                            Session session = null;
571    
572                            try {
573                                    session = openSession();
574    
575                                    Query q = session.createQuery(sql);
576    
577                                    QueryPos qPos = QueryPos.getInstance(q);
578    
579                                    if (uuid != null) {
580                                            qPos.add(uuid);
581                                    }
582    
583                                    count = (Long)q.uniqueResult();
584    
585                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
586                            }
587                            catch (Exception e) {
588                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
589    
590                                    throw processException(e);
591                            }
592                            finally {
593                                    closeSession(session);
594                            }
595                    }
596    
597                    return count.intValue();
598            }
599    
600            private static final String _FINDER_COLUMN_UUID_UUID_1 = "journalFolder.uuid IS NULL";
601            private static final String _FINDER_COLUMN_UUID_UUID_2 = "journalFolder.uuid = ?";
602            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(journalFolder.uuid IS NULL OR journalFolder.uuid = ?)";
603            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
604                            JournalFolderModelImpl.FINDER_CACHE_ENABLED,
605                            JournalFolderImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
606                            new String[] { String.class.getName(), Long.class.getName() },
607                            JournalFolderModelImpl.UUID_COLUMN_BITMASK |
608                            JournalFolderModelImpl.GROUPID_COLUMN_BITMASK);
609            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
610                            JournalFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
611                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
612                            new String[] { String.class.getName(), Long.class.getName() });
613    
614            /**
615             * Returns the journal folder where uuid = &#63; and groupId = &#63; or throws a {@link com.liferay.portlet.journal.NoSuchFolderException} if it could not be found.
616             *
617             * @param uuid the uuid
618             * @param groupId the group ID
619             * @return the matching journal folder
620             * @throws com.liferay.portlet.journal.NoSuchFolderException if a matching journal folder could not be found
621             * @throws SystemException if a system exception occurred
622             */
623            public JournalFolder findByUUID_G(String uuid, long groupId)
624                    throws NoSuchFolderException, SystemException {
625                    JournalFolder journalFolder = fetchByUUID_G(uuid, groupId);
626    
627                    if (journalFolder == null) {
628                            StringBundler msg = new StringBundler(6);
629    
630                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
631    
632                            msg.append("uuid=");
633                            msg.append(uuid);
634    
635                            msg.append(", groupId=");
636                            msg.append(groupId);
637    
638                            msg.append(StringPool.CLOSE_CURLY_BRACE);
639    
640                            if (_log.isWarnEnabled()) {
641                                    _log.warn(msg.toString());
642                            }
643    
644                            throw new NoSuchFolderException(msg.toString());
645                    }
646    
647                    return journalFolder;
648            }
649    
650            /**
651             * 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.
652             *
653             * @param uuid the uuid
654             * @param groupId the group ID
655             * @return the matching journal folder, or <code>null</code> if a matching journal folder could not be found
656             * @throws SystemException if a system exception occurred
657             */
658            public JournalFolder fetchByUUID_G(String uuid, long groupId)
659                    throws SystemException {
660                    return fetchByUUID_G(uuid, groupId, true);
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, optionally using the finder cache.
665             *
666             * @param uuid the uuid
667             * @param groupId the group ID
668             * @param retrieveFromCache whether to use the finder cache
669             * @return the matching journal folder, or <code>null</code> if a matching journal folder could not be found
670             * @throws SystemException if a system exception occurred
671             */
672            public JournalFolder fetchByUUID_G(String uuid, long groupId,
673                    boolean retrieveFromCache) throws SystemException {
674                    Object[] finderArgs = new Object[] { uuid, groupId };
675    
676                    Object result = null;
677    
678                    if (retrieveFromCache) {
679                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
680                                            finderArgs, this);
681                    }
682    
683                    if (result instanceof JournalFolder) {
684                            JournalFolder journalFolder = (JournalFolder)result;
685    
686                            if (!Validator.equals(uuid, journalFolder.getUuid()) ||
687                                            (groupId != journalFolder.getGroupId())) {
688                                    result = null;
689                            }
690                    }
691    
692                    if (result == null) {
693                            StringBundler query = new StringBundler(4);
694    
695                            query.append(_SQL_SELECT_JOURNALFOLDER_WHERE);
696    
697                            if (uuid == null) {
698                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
699                            }
700                            else {
701                                    if (uuid.equals(StringPool.BLANK)) {
702                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
703                                    }
704                                    else {
705                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
706                                    }
707                            }
708    
709                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
710    
711                            String sql = query.toString();
712    
713                            Session session = null;
714    
715                            try {
716                                    session = openSession();
717    
718                                    Query q = session.createQuery(sql);
719    
720                                    QueryPos qPos = QueryPos.getInstance(q);
721    
722                                    if (uuid != null) {
723                                            qPos.add(uuid);
724                                    }
725    
726                                    qPos.add(groupId);
727    
728                                    List<JournalFolder> list = q.list();
729    
730                                    if (list.isEmpty()) {
731                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
732                                                    finderArgs, list);
733                                    }
734                                    else {
735                                            JournalFolder journalFolder = list.get(0);
736    
737                                            result = journalFolder;
738    
739                                            cacheResult(journalFolder);
740    
741                                            if ((journalFolder.getUuid() == null) ||
742                                                            !journalFolder.getUuid().equals(uuid) ||
743                                                            (journalFolder.getGroupId() != groupId)) {
744                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
745                                                            finderArgs, journalFolder);
746                                            }
747                                    }
748                            }
749                            catch (Exception e) {
750                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
751                                            finderArgs);
752    
753                                    throw processException(e);
754                            }
755                            finally {
756                                    closeSession(session);
757                            }
758                    }
759    
760                    if (result instanceof List<?>) {
761                            return null;
762                    }
763                    else {
764                            return (JournalFolder)result;
765                    }
766            }
767    
768            /**
769             * Removes the journal folder where uuid = &#63; and groupId = &#63; from the database.
770             *
771             * @param uuid the uuid
772             * @param groupId the group ID
773             * @return the journal folder that was removed
774             * @throws SystemException if a system exception occurred
775             */
776            public JournalFolder removeByUUID_G(String uuid, long groupId)
777                    throws NoSuchFolderException, SystemException {
778                    JournalFolder journalFolder = findByUUID_G(uuid, groupId);
779    
780                    return remove(journalFolder);
781            }
782    
783            /**
784             * Returns the number of journal folders where uuid = &#63; and groupId = &#63;.
785             *
786             * @param uuid the uuid
787             * @param groupId the group ID
788             * @return the number of matching journal folders
789             * @throws SystemException if a system exception occurred
790             */
791            public int countByUUID_G(String uuid, long groupId)
792                    throws SystemException {
793                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
794    
795                    Object[] finderArgs = new Object[] { uuid, groupId };
796    
797                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
798                                    this);
799    
800                    if (count == null) {
801                            StringBundler query = new StringBundler(3);
802    
803                            query.append(_SQL_COUNT_JOURNALFOLDER_WHERE);
804    
805                            if (uuid == null) {
806                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
807                            }
808                            else {
809                                    if (uuid.equals(StringPool.BLANK)) {
810                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
811                                    }
812                                    else {
813                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
814                                    }
815                            }
816    
817                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
818    
819                            String sql = query.toString();
820    
821                            Session session = null;
822    
823                            try {
824                                    session = openSession();
825    
826                                    Query q = session.createQuery(sql);
827    
828                                    QueryPos qPos = QueryPos.getInstance(q);
829    
830                                    if (uuid != null) {
831                                            qPos.add(uuid);
832                                    }
833    
834                                    qPos.add(groupId);
835    
836                                    count = (Long)q.uniqueResult();
837    
838                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
839                            }
840                            catch (Exception e) {
841                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
842    
843                                    throw processException(e);
844                            }
845                            finally {
846                                    closeSession(session);
847                            }
848                    }
849    
850                    return count.intValue();
851            }
852    
853            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "journalFolder.uuid IS NULL AND ";
854            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "journalFolder.uuid = ? AND ";
855            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(journalFolder.uuid IS NULL OR journalFolder.uuid = ?) AND ";
856            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "journalFolder.groupId = ?";
857            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
858                            JournalFolderModelImpl.FINDER_CACHE_ENABLED,
859                            JournalFolderImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
860                            "findByUuid_C",
861                            new String[] {
862                                    String.class.getName(), Long.class.getName(),
863                                    
864                            Integer.class.getName(), Integer.class.getName(),
865                                    OrderByComparator.class.getName()
866                            });
867            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
868                    new FinderPath(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
869                            JournalFolderModelImpl.FINDER_CACHE_ENABLED,
870                            JournalFolderImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
871                            "findByUuid_C",
872                            new String[] { String.class.getName(), Long.class.getName() },
873                            JournalFolderModelImpl.UUID_COLUMN_BITMASK |
874                            JournalFolderModelImpl.COMPANYID_COLUMN_BITMASK |
875                            JournalFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
876                            JournalFolderModelImpl.NAME_COLUMN_BITMASK);
877            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
878                            JournalFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
879                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
880                            new String[] { String.class.getName(), Long.class.getName() });
881    
882            /**
883             * Returns all the journal folders where uuid = &#63; and companyId = &#63;.
884             *
885             * @param uuid the uuid
886             * @param companyId the company ID
887             * @return the matching journal folders
888             * @throws SystemException if a system exception occurred
889             */
890            public List<JournalFolder> findByUuid_C(String uuid, long companyId)
891                    throws SystemException {
892                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
893                            QueryUtil.ALL_POS, null);
894            }
895    
896            /**
897             * Returns a range of all the journal folders where uuid = &#63; and companyId = &#63;.
898             *
899             * <p>
900             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
901             * </p>
902             *
903             * @param uuid the uuid
904             * @param companyId the company ID
905             * @param start the lower bound of the range of journal folders
906             * @param end the upper bound of the range of journal folders (not inclusive)
907             * @return the range of matching journal folders
908             * @throws SystemException if a system exception occurred
909             */
910            public List<JournalFolder> findByUuid_C(String uuid, long companyId,
911                    int start, int end) throws SystemException {
912                    return findByUuid_C(uuid, companyId, start, end, null);
913            }
914    
915            /**
916             * Returns an ordered range of all the journal folders where uuid = &#63; and companyId = &#63;.
917             *
918             * <p>
919             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
920             * </p>
921             *
922             * @param uuid the uuid
923             * @param companyId the company ID
924             * @param start the lower bound of the range of journal folders
925             * @param end the upper bound of the range of journal folders (not inclusive)
926             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
927             * @return the ordered range of matching journal folders
928             * @throws SystemException if a system exception occurred
929             */
930            public List<JournalFolder> findByUuid_C(String uuid, long companyId,
931                    int start, int end, OrderByComparator orderByComparator)
932                    throws SystemException {
933                    boolean pagination = true;
934                    FinderPath finderPath = null;
935                    Object[] finderArgs = null;
936    
937                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
938                                    (orderByComparator == null)) {
939                            pagination = false;
940                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
941                            finderArgs = new Object[] { uuid, companyId };
942                    }
943                    else {
944                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
945                            finderArgs = new Object[] {
946                                            uuid, companyId,
947                                            
948                                            start, end, orderByComparator
949                                    };
950                    }
951    
952                    List<JournalFolder> list = (List<JournalFolder>)FinderCacheUtil.getResult(finderPath,
953                                    finderArgs, this);
954    
955                    if ((list != null) && !list.isEmpty()) {
956                            for (JournalFolder journalFolder : list) {
957                                    if (!Validator.equals(uuid, journalFolder.getUuid()) ||
958                                                    (companyId != journalFolder.getCompanyId())) {
959                                            list = null;
960    
961                                            break;
962                                    }
963                            }
964                    }
965    
966                    if (list == null) {
967                            StringBundler query = null;
968    
969                            if (orderByComparator != null) {
970                                    query = new StringBundler(4 +
971                                                    (orderByComparator.getOrderByFields().length * 3));
972                            }
973                            else {
974                                    query = new StringBundler(4);
975                            }
976    
977                            query.append(_SQL_SELECT_JOURNALFOLDER_WHERE);
978    
979                            if (uuid == null) {
980                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
981                            }
982                            else {
983                                    if (uuid.equals(StringPool.BLANK)) {
984                                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
985                                    }
986                                    else {
987                                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
988                                    }
989                            }
990    
991                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
992    
993                            if (orderByComparator != null) {
994                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
995                                            orderByComparator);
996                            }
997                            else
998                             if (pagination) {
999                                    query.append(JournalFolderModelImpl.ORDER_BY_JPQL);
1000                            }
1001    
1002                            String sql = query.toString();
1003    
1004                            Session session = null;
1005    
1006                            try {
1007                                    session = openSession();
1008    
1009                                    Query q = session.createQuery(sql);
1010    
1011                                    QueryPos qPos = QueryPos.getInstance(q);
1012    
1013                                    if (uuid != null) {
1014                                            qPos.add(uuid);
1015                                    }
1016    
1017                                    qPos.add(companyId);
1018    
1019                                    if (!pagination) {
1020                                            list = (List<JournalFolder>)QueryUtil.list(q, getDialect(),
1021                                                            start, end, false);
1022    
1023                                            Collections.sort(list);
1024    
1025                                            list = new UnmodifiableList<JournalFolder>(list);
1026                                    }
1027                                    else {
1028                                            list = (List<JournalFolder>)QueryUtil.list(q, getDialect(),
1029                                                            start, end);
1030                                    }
1031    
1032                                    cacheResult(list);
1033    
1034                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1035                            }
1036                            catch (Exception e) {
1037                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1038    
1039                                    throw processException(e);
1040                            }
1041                            finally {
1042                                    closeSession(session);
1043                            }
1044                    }
1045    
1046                    return list;
1047            }
1048    
1049            /**
1050             * Returns the first journal folder in the ordered set where uuid = &#63; and companyId = &#63;.
1051             *
1052             * @param uuid the uuid
1053             * @param companyId the company ID
1054             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1055             * @return the first matching journal folder
1056             * @throws com.liferay.portlet.journal.NoSuchFolderException if a matching journal folder could not be found
1057             * @throws SystemException if a system exception occurred
1058             */
1059            public JournalFolder findByUuid_C_First(String uuid, long companyId,
1060                    OrderByComparator orderByComparator)
1061                    throws NoSuchFolderException, SystemException {
1062                    JournalFolder journalFolder = fetchByUuid_C_First(uuid, companyId,
1063                                    orderByComparator);
1064    
1065                    if (journalFolder != null) {
1066                            return journalFolder;
1067                    }
1068    
1069                    StringBundler msg = new StringBundler(6);
1070    
1071                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1072    
1073                    msg.append("uuid=");
1074                    msg.append(uuid);
1075    
1076                    msg.append(", companyId=");
1077                    msg.append(companyId);
1078    
1079                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1080    
1081                    throw new NoSuchFolderException(msg.toString());
1082            }
1083    
1084            /**
1085             * Returns the first journal folder in the ordered set where uuid = &#63; and companyId = &#63;.
1086             *
1087             * @param uuid the uuid
1088             * @param companyId the company ID
1089             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1090             * @return the first matching journal folder, or <code>null</code> if a matching journal folder could not be found
1091             * @throws SystemException if a system exception occurred
1092             */
1093            public JournalFolder fetchByUuid_C_First(String uuid, long companyId,
1094                    OrderByComparator orderByComparator) throws SystemException {
1095                    List<JournalFolder> list = findByUuid_C(uuid, companyId, 0, 1,
1096                                    orderByComparator);
1097    
1098                    if (!list.isEmpty()) {
1099                            return list.get(0);
1100                    }
1101    
1102                    return null;
1103            }
1104    
1105            /**
1106             * Returns the last journal folder in the ordered set where uuid = &#63; and companyId = &#63;.
1107             *
1108             * @param uuid the uuid
1109             * @param companyId the company ID
1110             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1111             * @return the last matching journal folder
1112             * @throws com.liferay.portlet.journal.NoSuchFolderException if a matching journal folder could not be found
1113             * @throws SystemException if a system exception occurred
1114             */
1115            public JournalFolder findByUuid_C_Last(String uuid, long companyId,
1116                    OrderByComparator orderByComparator)
1117                    throws NoSuchFolderException, SystemException {
1118                    JournalFolder journalFolder = fetchByUuid_C_Last(uuid, companyId,
1119                                    orderByComparator);
1120    
1121                    if (journalFolder != null) {
1122                            return journalFolder;
1123                    }
1124    
1125                    StringBundler msg = new StringBundler(6);
1126    
1127                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1128    
1129                    msg.append("uuid=");
1130                    msg.append(uuid);
1131    
1132                    msg.append(", companyId=");
1133                    msg.append(companyId);
1134    
1135                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1136    
1137                    throw new NoSuchFolderException(msg.toString());
1138            }
1139    
1140            /**
1141             * Returns the last journal folder in the ordered set where uuid = &#63; and companyId = &#63;.
1142             *
1143             * @param uuid the uuid
1144             * @param companyId the company ID
1145             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1146             * @return the last matching journal folder, or <code>null</code> if a matching journal folder could not be found
1147             * @throws SystemException if a system exception occurred
1148             */
1149            public JournalFolder fetchByUuid_C_Last(String uuid, long companyId,
1150                    OrderByComparator orderByComparator) throws SystemException {
1151                    int count = countByUuid_C(uuid, companyId);
1152    
1153                    List<JournalFolder> list = findByUuid_C(uuid, companyId, count - 1,
1154                                    count, orderByComparator);
1155    
1156                    if (!list.isEmpty()) {
1157                            return list.get(0);
1158                    }
1159    
1160                    return null;
1161            }
1162    
1163            /**
1164             * Returns the journal folders before and after the current journal folder in the ordered set where uuid = &#63; and companyId = &#63;.
1165             *
1166             * @param folderId the primary key of the current journal folder
1167             * @param uuid the uuid
1168             * @param companyId the company ID
1169             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1170             * @return the previous, current, and next journal folder
1171             * @throws com.liferay.portlet.journal.NoSuchFolderException if a journal folder with the primary key could not be found
1172             * @throws SystemException if a system exception occurred
1173             */
1174            public JournalFolder[] findByUuid_C_PrevAndNext(long folderId, String uuid,
1175                    long companyId, OrderByComparator orderByComparator)
1176                    throws NoSuchFolderException, SystemException {
1177                    JournalFolder journalFolder = findByPrimaryKey(folderId);
1178    
1179                    Session session = null;
1180    
1181                    try {
1182                            session = openSession();
1183    
1184                            JournalFolder[] array = new JournalFolderImpl[3];
1185    
1186                            array[0] = getByUuid_C_PrevAndNext(session, journalFolder, uuid,
1187                                            companyId, orderByComparator, true);
1188    
1189                            array[1] = journalFolder;
1190    
1191                            array[2] = getByUuid_C_PrevAndNext(session, journalFolder, uuid,
1192                                            companyId, orderByComparator, false);
1193    
1194                            return array;
1195                    }
1196                    catch (Exception e) {
1197                            throw processException(e);
1198                    }
1199                    finally {
1200                            closeSession(session);
1201                    }
1202            }
1203    
1204            protected JournalFolder getByUuid_C_PrevAndNext(Session session,
1205                    JournalFolder journalFolder, String uuid, long companyId,
1206                    OrderByComparator orderByComparator, boolean previous) {
1207                    StringBundler query = null;
1208    
1209                    if (orderByComparator != null) {
1210                            query = new StringBundler(6 +
1211                                            (orderByComparator.getOrderByFields().length * 6));
1212                    }
1213                    else {
1214                            query = new StringBundler(3);
1215                    }
1216    
1217                    query.append(_SQL_SELECT_JOURNALFOLDER_WHERE);
1218    
1219                    if (uuid == null) {
1220                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1221                    }
1222                    else {
1223                            if (uuid.equals(StringPool.BLANK)) {
1224                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1225                            }
1226                            else {
1227                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1228                            }
1229                    }
1230    
1231                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1232    
1233                    if (orderByComparator != null) {
1234                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1235    
1236                            if (orderByConditionFields.length > 0) {
1237                                    query.append(WHERE_AND);
1238                            }
1239    
1240                            for (int i = 0; i < orderByConditionFields.length; i++) {
1241                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1242                                    query.append(orderByConditionFields[i]);
1243    
1244                                    if ((i + 1) < orderByConditionFields.length) {
1245                                            if (orderByComparator.isAscending() ^ previous) {
1246                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1247                                            }
1248                                            else {
1249                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1250                                            }
1251                                    }
1252                                    else {
1253                                            if (orderByComparator.isAscending() ^ previous) {
1254                                                    query.append(WHERE_GREATER_THAN);
1255                                            }
1256                                            else {
1257                                                    query.append(WHERE_LESSER_THAN);
1258                                            }
1259                                    }
1260                            }
1261    
1262                            query.append(ORDER_BY_CLAUSE);
1263    
1264                            String[] orderByFields = orderByComparator.getOrderByFields();
1265    
1266                            for (int i = 0; i < orderByFields.length; i++) {
1267                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1268                                    query.append(orderByFields[i]);
1269    
1270                                    if ((i + 1) < orderByFields.length) {
1271                                            if (orderByComparator.isAscending() ^ previous) {
1272                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1273                                            }
1274                                            else {
1275                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1276                                            }
1277                                    }
1278                                    else {
1279                                            if (orderByComparator.isAscending() ^ previous) {
1280                                                    query.append(ORDER_BY_ASC);
1281                                            }
1282                                            else {
1283                                                    query.append(ORDER_BY_DESC);
1284                                            }
1285                                    }
1286                            }
1287                    }
1288                    else {
1289                            query.append(JournalFolderModelImpl.ORDER_BY_JPQL);
1290                    }
1291    
1292                    String sql = query.toString();
1293    
1294                    Query q = session.createQuery(sql);
1295    
1296                    q.setFirstResult(0);
1297                    q.setMaxResults(2);
1298    
1299                    QueryPos qPos = QueryPos.getInstance(q);
1300    
1301                    if (uuid != null) {
1302                            qPos.add(uuid);
1303                    }
1304    
1305                    qPos.add(companyId);
1306    
1307                    if (orderByComparator != null) {
1308                            Object[] values = orderByComparator.getOrderByConditionValues(journalFolder);
1309    
1310                            for (Object value : values) {
1311                                    qPos.add(value);
1312                            }
1313                    }
1314    
1315                    List<JournalFolder> list = q.list();
1316    
1317                    if (list.size() == 2) {
1318                            return list.get(1);
1319                    }
1320                    else {
1321                            return null;
1322                    }
1323            }
1324    
1325            /**
1326             * Removes all the journal folders where uuid = &#63; and companyId = &#63; from the database.
1327             *
1328             * @param uuid the uuid
1329             * @param companyId the company ID
1330             * @throws SystemException if a system exception occurred
1331             */
1332            public void removeByUuid_C(String uuid, long companyId)
1333                    throws SystemException {
1334                    for (JournalFolder journalFolder : findByUuid_C(uuid, companyId,
1335                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1336                            remove(journalFolder);
1337                    }
1338            }
1339    
1340            /**
1341             * Returns the number of journal folders where uuid = &#63; and companyId = &#63;.
1342             *
1343             * @param uuid the uuid
1344             * @param companyId the company ID
1345             * @return the number of matching journal folders
1346             * @throws SystemException if a system exception occurred
1347             */
1348            public int countByUuid_C(String uuid, long companyId)
1349                    throws SystemException {
1350                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1351    
1352                    Object[] finderArgs = new Object[] { uuid, companyId };
1353    
1354                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1355                                    this);
1356    
1357                    if (count == null) {
1358                            StringBundler query = new StringBundler(3);
1359    
1360                            query.append(_SQL_COUNT_JOURNALFOLDER_WHERE);
1361    
1362                            if (uuid == null) {
1363                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1364                            }
1365                            else {
1366                                    if (uuid.equals(StringPool.BLANK)) {
1367                                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1368                                    }
1369                                    else {
1370                                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1371                                    }
1372                            }
1373    
1374                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1375    
1376                            String sql = query.toString();
1377    
1378                            Session session = null;
1379    
1380                            try {
1381                                    session = openSession();
1382    
1383                                    Query q = session.createQuery(sql);
1384    
1385                                    QueryPos qPos = QueryPos.getInstance(q);
1386    
1387                                    if (uuid != null) {
1388                                            qPos.add(uuid);
1389                                    }
1390    
1391                                    qPos.add(companyId);
1392    
1393                                    count = (Long)q.uniqueResult();
1394    
1395                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1396                            }
1397                            catch (Exception e) {
1398                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1399    
1400                                    throw processException(e);
1401                            }
1402                            finally {
1403                                    closeSession(session);
1404                            }
1405                    }
1406    
1407                    return count.intValue();
1408            }
1409    
1410            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "journalFolder.uuid IS NULL AND ";
1411            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "journalFolder.uuid = ? AND ";
1412            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(journalFolder.uuid IS NULL OR journalFolder.uuid = ?) AND ";
1413            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "journalFolder.companyId = ?";
1414            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
1415                            JournalFolderModelImpl.FINDER_CACHE_ENABLED,
1416                            JournalFolderImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1417                            "findByGroupId",
1418                            new String[] {
1419                                    Long.class.getName(),
1420                                    
1421                            Integer.class.getName(), Integer.class.getName(),
1422                                    OrderByComparator.class.getName()
1423                            });
1424            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1425                    new FinderPath(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
1426                            JournalFolderModelImpl.FINDER_CACHE_ENABLED,
1427                            JournalFolderImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
1428                            "findByGroupId", new String[] { Long.class.getName() },
1429                            JournalFolderModelImpl.GROUPID_COLUMN_BITMASK |
1430                            JournalFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
1431                            JournalFolderModelImpl.NAME_COLUMN_BITMASK);
1432            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
1433                            JournalFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
1434                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1435                            new String[] { Long.class.getName() });
1436    
1437            /**
1438             * Returns all the journal folders where groupId = &#63;.
1439             *
1440             * @param groupId the group ID
1441             * @return the matching journal folders
1442             * @throws SystemException if a system exception occurred
1443             */
1444            public List<JournalFolder> findByGroupId(long groupId)
1445                    throws SystemException {
1446                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1447            }
1448    
1449            /**
1450             * Returns a range of all the journal folders where groupId = &#63;.
1451             *
1452             * <p>
1453             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1454             * </p>
1455             *
1456             * @param groupId the group ID
1457             * @param start the lower bound of the range of journal folders
1458             * @param end the upper bound of the range of journal folders (not inclusive)
1459             * @return the range of matching journal folders
1460             * @throws SystemException if a system exception occurred
1461             */
1462            public List<JournalFolder> findByGroupId(long groupId, int start, int end)
1463                    throws SystemException {
1464                    return findByGroupId(groupId, start, end, null);
1465            }
1466    
1467            /**
1468             * Returns an ordered range of all the journal folders where groupId = &#63;.
1469             *
1470             * <p>
1471             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1472             * </p>
1473             *
1474             * @param groupId the group ID
1475             * @param start the lower bound of the range of journal folders
1476             * @param end the upper bound of the range of journal folders (not inclusive)
1477             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1478             * @return the ordered range of matching journal folders
1479             * @throws SystemException if a system exception occurred
1480             */
1481            public List<JournalFolder> findByGroupId(long groupId, int start, int end,
1482                    OrderByComparator orderByComparator) throws SystemException {
1483                    boolean pagination = true;
1484                    FinderPath finderPath = null;
1485                    Object[] finderArgs = null;
1486    
1487                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1488                                    (orderByComparator == null)) {
1489                            pagination = false;
1490                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1491                            finderArgs = new Object[] { groupId };
1492                    }
1493                    else {
1494                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1495                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1496                    }
1497    
1498                    List<JournalFolder> list = (List<JournalFolder>)FinderCacheUtil.getResult(finderPath,
1499                                    finderArgs, this);
1500    
1501                    if ((list != null) && !list.isEmpty()) {
1502                            for (JournalFolder journalFolder : list) {
1503                                    if ((groupId != journalFolder.getGroupId())) {
1504                                            list = null;
1505    
1506                                            break;
1507                                    }
1508                            }
1509                    }
1510    
1511                    if (list == null) {
1512                            StringBundler query = null;
1513    
1514                            if (orderByComparator != null) {
1515                                    query = new StringBundler(3 +
1516                                                    (orderByComparator.getOrderByFields().length * 3));
1517                            }
1518                            else {
1519                                    query = new StringBundler(3);
1520                            }
1521    
1522                            query.append(_SQL_SELECT_JOURNALFOLDER_WHERE);
1523    
1524                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1525    
1526                            if (orderByComparator != null) {
1527                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1528                                            orderByComparator);
1529                            }
1530                            else
1531                             if (pagination) {
1532                                    query.append(JournalFolderModelImpl.ORDER_BY_JPQL);
1533                            }
1534    
1535                            String sql = query.toString();
1536    
1537                            Session session = null;
1538    
1539                            try {
1540                                    session = openSession();
1541    
1542                                    Query q = session.createQuery(sql);
1543    
1544                                    QueryPos qPos = QueryPos.getInstance(q);
1545    
1546                                    qPos.add(groupId);
1547    
1548                                    if (!pagination) {
1549                                            list = (List<JournalFolder>)QueryUtil.list(q, getDialect(),
1550                                                            start, end, false);
1551    
1552                                            Collections.sort(list);
1553    
1554                                            list = new UnmodifiableList<JournalFolder>(list);
1555                                    }
1556                                    else {
1557                                            list = (List<JournalFolder>)QueryUtil.list(q, getDialect(),
1558                                                            start, end);
1559                                    }
1560    
1561                                    cacheResult(list);
1562    
1563                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1564                            }
1565                            catch (Exception e) {
1566                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1567    
1568                                    throw processException(e);
1569                            }
1570                            finally {
1571                                    closeSession(session);
1572                            }
1573                    }
1574    
1575                    return list;
1576            }
1577    
1578            /**
1579             * Returns the first journal folder in the ordered set where groupId = &#63;.
1580             *
1581             * @param groupId the group ID
1582             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1583             * @return the first matching journal folder
1584             * @throws com.liferay.portlet.journal.NoSuchFolderException if a matching journal folder could not be found
1585             * @throws SystemException if a system exception occurred
1586             */
1587            public JournalFolder findByGroupId_First(long groupId,
1588                    OrderByComparator orderByComparator)
1589                    throws NoSuchFolderException, SystemException {
1590                    JournalFolder journalFolder = fetchByGroupId_First(groupId,
1591                                    orderByComparator);
1592    
1593                    if (journalFolder != null) {
1594                            return journalFolder;
1595                    }
1596    
1597                    StringBundler msg = new StringBundler(4);
1598    
1599                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1600    
1601                    msg.append("groupId=");
1602                    msg.append(groupId);
1603    
1604                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1605    
1606                    throw new NoSuchFolderException(msg.toString());
1607            }
1608    
1609            /**
1610             * Returns the first journal folder in the ordered set where groupId = &#63;.
1611             *
1612             * @param groupId the group ID
1613             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1614             * @return the first matching journal folder, or <code>null</code> if a matching journal folder could not be found
1615             * @throws SystemException if a system exception occurred
1616             */
1617            public JournalFolder fetchByGroupId_First(long groupId,
1618                    OrderByComparator orderByComparator) throws SystemException {
1619                    List<JournalFolder> list = findByGroupId(groupId, 0, 1,
1620                                    orderByComparator);
1621    
1622                    if (!list.isEmpty()) {
1623                            return list.get(0);
1624                    }
1625    
1626                    return null;
1627            }
1628    
1629            /**
1630             * Returns the last journal folder in the ordered set where groupId = &#63;.
1631             *
1632             * @param groupId the group ID
1633             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1634             * @return the last matching journal folder
1635             * @throws com.liferay.portlet.journal.NoSuchFolderException if a matching journal folder could not be found
1636             * @throws SystemException if a system exception occurred
1637             */
1638            public JournalFolder findByGroupId_Last(long groupId,
1639                    OrderByComparator orderByComparator)
1640                    throws NoSuchFolderException, SystemException {
1641                    JournalFolder journalFolder = fetchByGroupId_Last(groupId,
1642                                    orderByComparator);
1643    
1644                    if (journalFolder != null) {
1645                            return journalFolder;
1646                    }
1647    
1648                    StringBundler msg = new StringBundler(4);
1649    
1650                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1651    
1652                    msg.append("groupId=");
1653                    msg.append(groupId);
1654    
1655                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1656    
1657                    throw new NoSuchFolderException(msg.toString());
1658            }
1659    
1660            /**
1661             * Returns the last journal folder in the ordered set where groupId = &#63;.
1662             *
1663             * @param groupId the group ID
1664             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1665             * @return the last matching journal folder, or <code>null</code> if a matching journal folder could not be found
1666             * @throws SystemException if a system exception occurred
1667             */
1668            public JournalFolder fetchByGroupId_Last(long groupId,
1669                    OrderByComparator orderByComparator) throws SystemException {
1670                    int count = countByGroupId(groupId);
1671    
1672                    List<JournalFolder> list = findByGroupId(groupId, count - 1, count,
1673                                    orderByComparator);
1674    
1675                    if (!list.isEmpty()) {
1676                            return list.get(0);
1677                    }
1678    
1679                    return null;
1680            }
1681    
1682            /**
1683             * Returns the journal folders before and after the current journal folder in the ordered set where groupId = &#63;.
1684             *
1685             * @param folderId the primary key of the current journal folder
1686             * @param groupId the group ID
1687             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1688             * @return the previous, current, and next journal folder
1689             * @throws com.liferay.portlet.journal.NoSuchFolderException if a journal folder with the primary key could not be found
1690             * @throws SystemException if a system exception occurred
1691             */
1692            public JournalFolder[] findByGroupId_PrevAndNext(long folderId,
1693                    long groupId, OrderByComparator orderByComparator)
1694                    throws NoSuchFolderException, SystemException {
1695                    JournalFolder journalFolder = findByPrimaryKey(folderId);
1696    
1697                    Session session = null;
1698    
1699                    try {
1700                            session = openSession();
1701    
1702                            JournalFolder[] array = new JournalFolderImpl[3];
1703    
1704                            array[0] = getByGroupId_PrevAndNext(session, journalFolder,
1705                                            groupId, orderByComparator, true);
1706    
1707                            array[1] = journalFolder;
1708    
1709                            array[2] = getByGroupId_PrevAndNext(session, journalFolder,
1710                                            groupId, orderByComparator, false);
1711    
1712                            return array;
1713                    }
1714                    catch (Exception e) {
1715                            throw processException(e);
1716                    }
1717                    finally {
1718                            closeSession(session);
1719                    }
1720            }
1721    
1722            protected JournalFolder getByGroupId_PrevAndNext(Session session,
1723                    JournalFolder journalFolder, long groupId,
1724                    OrderByComparator orderByComparator, boolean previous) {
1725                    StringBundler query = null;
1726    
1727                    if (orderByComparator != null) {
1728                            query = new StringBundler(6 +
1729                                            (orderByComparator.getOrderByFields().length * 6));
1730                    }
1731                    else {
1732                            query = new StringBundler(3);
1733                    }
1734    
1735                    query.append(_SQL_SELECT_JOURNALFOLDER_WHERE);
1736    
1737                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1738    
1739                    if (orderByComparator != null) {
1740                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1741    
1742                            if (orderByConditionFields.length > 0) {
1743                                    query.append(WHERE_AND);
1744                            }
1745    
1746                            for (int i = 0; i < orderByConditionFields.length; i++) {
1747                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1748                                    query.append(orderByConditionFields[i]);
1749    
1750                                    if ((i + 1) < orderByConditionFields.length) {
1751                                            if (orderByComparator.isAscending() ^ previous) {
1752                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1753                                            }
1754                                            else {
1755                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1756                                            }
1757                                    }
1758                                    else {
1759                                            if (orderByComparator.isAscending() ^ previous) {
1760                                                    query.append(WHERE_GREATER_THAN);
1761                                            }
1762                                            else {
1763                                                    query.append(WHERE_LESSER_THAN);
1764                                            }
1765                                    }
1766                            }
1767    
1768                            query.append(ORDER_BY_CLAUSE);
1769    
1770                            String[] orderByFields = orderByComparator.getOrderByFields();
1771    
1772                            for (int i = 0; i < orderByFields.length; i++) {
1773                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1774                                    query.append(orderByFields[i]);
1775    
1776                                    if ((i + 1) < orderByFields.length) {
1777                                            if (orderByComparator.isAscending() ^ previous) {
1778                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1779                                            }
1780                                            else {
1781                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1782                                            }
1783                                    }
1784                                    else {
1785                                            if (orderByComparator.isAscending() ^ previous) {
1786                                                    query.append(ORDER_BY_ASC);
1787                                            }
1788                                            else {
1789                                                    query.append(ORDER_BY_DESC);
1790                                            }
1791                                    }
1792                            }
1793                    }
1794                    else {
1795                            query.append(JournalFolderModelImpl.ORDER_BY_JPQL);
1796                    }
1797    
1798                    String sql = query.toString();
1799    
1800                    Query q = session.createQuery(sql);
1801    
1802                    q.setFirstResult(0);
1803                    q.setMaxResults(2);
1804    
1805                    QueryPos qPos = QueryPos.getInstance(q);
1806    
1807                    qPos.add(groupId);
1808    
1809                    if (orderByComparator != null) {
1810                            Object[] values = orderByComparator.getOrderByConditionValues(journalFolder);
1811    
1812                            for (Object value : values) {
1813                                    qPos.add(value);
1814                            }
1815                    }
1816    
1817                    List<JournalFolder> list = q.list();
1818    
1819                    if (list.size() == 2) {
1820                            return list.get(1);
1821                    }
1822                    else {
1823                            return null;
1824                    }
1825            }
1826    
1827            /**
1828             * Returns all the journal folders that the user has permission to view where groupId = &#63;.
1829             *
1830             * @param groupId the group ID
1831             * @return the matching journal folders that the user has permission to view
1832             * @throws SystemException if a system exception occurred
1833             */
1834            public List<JournalFolder> filterFindByGroupId(long groupId)
1835                    throws SystemException {
1836                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1837                            QueryUtil.ALL_POS, null);
1838            }
1839    
1840            /**
1841             * Returns a range of all the journal folders that the user has permission to view where groupId = &#63;.
1842             *
1843             * <p>
1844             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1845             * </p>
1846             *
1847             * @param groupId the group ID
1848             * @param start the lower bound of the range of journal folders
1849             * @param end the upper bound of the range of journal folders (not inclusive)
1850             * @return the range of matching journal folders that the user has permission to view
1851             * @throws SystemException if a system exception occurred
1852             */
1853            public List<JournalFolder> filterFindByGroupId(long groupId, int start,
1854                    int end) throws SystemException {
1855                    return filterFindByGroupId(groupId, start, end, null);
1856            }
1857    
1858            /**
1859             * Returns an ordered range of all the journal folders that the user has permissions to view where groupId = &#63;.
1860             *
1861             * <p>
1862             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1863             * </p>
1864             *
1865             * @param groupId the group ID
1866             * @param start the lower bound of the range of journal folders
1867             * @param end the upper bound of the range of journal folders (not inclusive)
1868             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1869             * @return the ordered range of matching journal folders that the user has permission to view
1870             * @throws SystemException if a system exception occurred
1871             */
1872            public List<JournalFolder> filterFindByGroupId(long groupId, int start,
1873                    int end, OrderByComparator orderByComparator) throws SystemException {
1874                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1875                            return findByGroupId(groupId, start, end, orderByComparator);
1876                    }
1877    
1878                    StringBundler query = null;
1879    
1880                    if (orderByComparator != null) {
1881                            query = new StringBundler(3 +
1882                                            (orderByComparator.getOrderByFields().length * 3));
1883                    }
1884                    else {
1885                            query = new StringBundler(3);
1886                    }
1887    
1888                    if (getDB().isSupportsInlineDistinct()) {
1889                            query.append(_FILTER_SQL_SELECT_JOURNALFOLDER_WHERE);
1890                    }
1891                    else {
1892                            query.append(_FILTER_SQL_SELECT_JOURNALFOLDER_NO_INLINE_DISTINCT_WHERE_1);
1893                    }
1894    
1895                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1896    
1897                    if (!getDB().isSupportsInlineDistinct()) {
1898                            query.append(_FILTER_SQL_SELECT_JOURNALFOLDER_NO_INLINE_DISTINCT_WHERE_2);
1899                    }
1900    
1901                    if (orderByComparator != null) {
1902                            if (getDB().isSupportsInlineDistinct()) {
1903                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1904                                            orderByComparator);
1905                            }
1906                            else {
1907                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1908                                            orderByComparator);
1909                            }
1910                    }
1911                    else {
1912                            if (getDB().isSupportsInlineDistinct()) {
1913                                    query.append(JournalFolderModelImpl.ORDER_BY_JPQL);
1914                            }
1915                            else {
1916                                    query.append(JournalFolderModelImpl.ORDER_BY_SQL);
1917                            }
1918                    }
1919    
1920                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1921                                    JournalFolder.class.getName(),
1922                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1923    
1924                    Session session = null;
1925    
1926                    try {
1927                            session = openSession();
1928    
1929                            SQLQuery q = session.createSQLQuery(sql);
1930    
1931                            if (getDB().isSupportsInlineDistinct()) {
1932                                    q.addEntity(_FILTER_ENTITY_ALIAS, JournalFolderImpl.class);
1933                            }
1934                            else {
1935                                    q.addEntity(_FILTER_ENTITY_TABLE, JournalFolderImpl.class);
1936                            }
1937    
1938                            QueryPos qPos = QueryPos.getInstance(q);
1939    
1940                            qPos.add(groupId);
1941    
1942                            return (List<JournalFolder>)QueryUtil.list(q, getDialect(), start,
1943                                    end);
1944                    }
1945                    catch (Exception e) {
1946                            throw processException(e);
1947                    }
1948                    finally {
1949                            closeSession(session);
1950                    }
1951            }
1952    
1953            /**
1954             * 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;.
1955             *
1956             * @param folderId the primary key of the current journal folder
1957             * @param groupId the group ID
1958             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1959             * @return the previous, current, and next journal folder
1960             * @throws com.liferay.portlet.journal.NoSuchFolderException if a journal folder with the primary key could not be found
1961             * @throws SystemException if a system exception occurred
1962             */
1963            public JournalFolder[] filterFindByGroupId_PrevAndNext(long folderId,
1964                    long groupId, OrderByComparator orderByComparator)
1965                    throws NoSuchFolderException, SystemException {
1966                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1967                            return findByGroupId_PrevAndNext(folderId, groupId,
1968                                    orderByComparator);
1969                    }
1970    
1971                    JournalFolder journalFolder = findByPrimaryKey(folderId);
1972    
1973                    Session session = null;
1974    
1975                    try {
1976                            session = openSession();
1977    
1978                            JournalFolder[] array = new JournalFolderImpl[3];
1979    
1980                            array[0] = filterGetByGroupId_PrevAndNext(session, journalFolder,
1981                                            groupId, orderByComparator, true);
1982    
1983                            array[1] = journalFolder;
1984    
1985                            array[2] = filterGetByGroupId_PrevAndNext(session, journalFolder,
1986                                            groupId, orderByComparator, false);
1987    
1988                            return array;
1989                    }
1990                    catch (Exception e) {
1991                            throw processException(e);
1992                    }
1993                    finally {
1994                            closeSession(session);
1995                    }
1996            }
1997    
1998            protected JournalFolder filterGetByGroupId_PrevAndNext(Session session,
1999                    JournalFolder journalFolder, long groupId,
2000                    OrderByComparator orderByComparator, boolean previous) {
2001                    StringBundler query = null;
2002    
2003                    if (orderByComparator != null) {
2004                            query = new StringBundler(6 +
2005                                            (orderByComparator.getOrderByFields().length * 6));
2006                    }
2007                    else {
2008                            query = new StringBundler(3);
2009                    }
2010    
2011                    if (getDB().isSupportsInlineDistinct()) {
2012                            query.append(_FILTER_SQL_SELECT_JOURNALFOLDER_WHERE);
2013                    }
2014                    else {
2015                            query.append(_FILTER_SQL_SELECT_JOURNALFOLDER_NO_INLINE_DISTINCT_WHERE_1);
2016                    }
2017    
2018                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2019    
2020                    if (!getDB().isSupportsInlineDistinct()) {
2021                            query.append(_FILTER_SQL_SELECT_JOURNALFOLDER_NO_INLINE_DISTINCT_WHERE_2);
2022                    }
2023    
2024                    if (orderByComparator != null) {
2025                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2026    
2027                            if (orderByConditionFields.length > 0) {
2028                                    query.append(WHERE_AND);
2029                            }
2030    
2031                            for (int i = 0; i < orderByConditionFields.length; i++) {
2032                                    if (getDB().isSupportsInlineDistinct()) {
2033                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2034                                    }
2035                                    else {
2036                                            query.append(_ORDER_BY_ENTITY_TABLE);
2037                                    }
2038    
2039                                    query.append(orderByConditionFields[i]);
2040    
2041                                    if ((i + 1) < orderByConditionFields.length) {
2042                                            if (orderByComparator.isAscending() ^ previous) {
2043                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2044                                            }
2045                                            else {
2046                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2047                                            }
2048                                    }
2049                                    else {
2050                                            if (orderByComparator.isAscending() ^ previous) {
2051                                                    query.append(WHERE_GREATER_THAN);
2052                                            }
2053                                            else {
2054                                                    query.append(WHERE_LESSER_THAN);
2055                                            }
2056                                    }
2057                            }
2058    
2059                            query.append(ORDER_BY_CLAUSE);
2060    
2061                            String[] orderByFields = orderByComparator.getOrderByFields();
2062    
2063                            for (int i = 0; i < orderByFields.length; i++) {
2064                                    if (getDB().isSupportsInlineDistinct()) {
2065                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2066                                    }
2067                                    else {
2068                                            query.append(_ORDER_BY_ENTITY_TABLE);
2069                                    }
2070    
2071                                    query.append(orderByFields[i]);
2072    
2073                                    if ((i + 1) < orderByFields.length) {
2074                                            if (orderByComparator.isAscending() ^ previous) {
2075                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2076                                            }
2077                                            else {
2078                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2079                                            }
2080                                    }
2081                                    else {
2082                                            if (orderByComparator.isAscending() ^ previous) {
2083                                                    query.append(ORDER_BY_ASC);
2084                                            }
2085                                            else {
2086                                                    query.append(ORDER_BY_DESC);
2087                                            }
2088                                    }
2089                            }
2090                    }
2091                    else {
2092                            if (getDB().isSupportsInlineDistinct()) {
2093                                    query.append(JournalFolderModelImpl.ORDER_BY_JPQL);
2094                            }
2095                            else {
2096                                    query.append(JournalFolderModelImpl.ORDER_BY_SQL);
2097                            }
2098                    }
2099    
2100                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2101                                    JournalFolder.class.getName(),
2102                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2103    
2104                    SQLQuery q = session.createSQLQuery(sql);
2105    
2106                    q.setFirstResult(0);
2107                    q.setMaxResults(2);
2108    
2109                    if (getDB().isSupportsInlineDistinct()) {
2110                            q.addEntity(_FILTER_ENTITY_ALIAS, JournalFolderImpl.class);
2111                    }
2112                    else {
2113                            q.addEntity(_FILTER_ENTITY_TABLE, JournalFolderImpl.class);
2114                    }
2115    
2116                    QueryPos qPos = QueryPos.getInstance(q);
2117    
2118                    qPos.add(groupId);
2119    
2120                    if (orderByComparator != null) {
2121                            Object[] values = orderByComparator.getOrderByConditionValues(journalFolder);
2122    
2123                            for (Object value : values) {
2124                                    qPos.add(value);
2125                            }
2126                    }
2127    
2128                    List<JournalFolder> list = q.list();
2129    
2130                    if (list.size() == 2) {
2131                            return list.get(1);
2132                    }
2133                    else {
2134                            return null;
2135                    }
2136            }
2137    
2138            /**
2139             * Removes all the journal folders where groupId = &#63; from the database.
2140             *
2141             * @param groupId the group ID
2142             * @throws SystemException if a system exception occurred
2143             */
2144            public void removeByGroupId(long groupId) throws SystemException {
2145                    for (JournalFolder journalFolder : findByGroupId(groupId,
2146                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2147                            remove(journalFolder);
2148                    }
2149            }
2150    
2151            /**
2152             * Returns the number of journal folders where groupId = &#63;.
2153             *
2154             * @param groupId the group ID
2155             * @return the number of matching journal folders
2156             * @throws SystemException if a system exception occurred
2157             */
2158            public int countByGroupId(long groupId) throws SystemException {
2159                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2160    
2161                    Object[] finderArgs = new Object[] { groupId };
2162    
2163                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2164                                    this);
2165    
2166                    if (count == null) {
2167                            StringBundler query = new StringBundler(2);
2168    
2169                            query.append(_SQL_COUNT_JOURNALFOLDER_WHERE);
2170    
2171                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2172    
2173                            String sql = query.toString();
2174    
2175                            Session session = null;
2176    
2177                            try {
2178                                    session = openSession();
2179    
2180                                    Query q = session.createQuery(sql);
2181    
2182                                    QueryPos qPos = QueryPos.getInstance(q);
2183    
2184                                    qPos.add(groupId);
2185    
2186                                    count = (Long)q.uniqueResult();
2187    
2188                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2189                            }
2190                            catch (Exception e) {
2191                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2192    
2193                                    throw processException(e);
2194                            }
2195                            finally {
2196                                    closeSession(session);
2197                            }
2198                    }
2199    
2200                    return count.intValue();
2201            }
2202    
2203            /**
2204             * Returns the number of journal folders that the user has permission to view where groupId = &#63;.
2205             *
2206             * @param groupId the group ID
2207             * @return the number of matching journal folders that the user has permission to view
2208             * @throws SystemException if a system exception occurred
2209             */
2210            public int filterCountByGroupId(long groupId) throws SystemException {
2211                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2212                            return countByGroupId(groupId);
2213                    }
2214    
2215                    StringBundler query = new StringBundler(2);
2216    
2217                    query.append(_FILTER_SQL_COUNT_JOURNALFOLDER_WHERE);
2218    
2219                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2220    
2221                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2222                                    JournalFolder.class.getName(),
2223                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2224    
2225                    Session session = null;
2226    
2227                    try {
2228                            session = openSession();
2229    
2230                            SQLQuery q = session.createSQLQuery(sql);
2231    
2232                            q.addScalar(COUNT_COLUMN_NAME,
2233                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2234    
2235                            QueryPos qPos = QueryPos.getInstance(q);
2236    
2237                            qPos.add(groupId);
2238    
2239                            Long count = (Long)q.uniqueResult();
2240    
2241                            return count.intValue();
2242                    }
2243                    catch (Exception e) {
2244                            throw processException(e);
2245                    }
2246                    finally {
2247                            closeSession(session);
2248                    }
2249            }
2250    
2251            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "journalFolder.groupId = ?";
2252            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
2253                    new FinderPath(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
2254                            JournalFolderModelImpl.FINDER_CACHE_ENABLED,
2255                            JournalFolderImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
2256                            "findByCompanyId",
2257                            new String[] {
2258                                    Long.class.getName(),
2259                                    
2260                            Integer.class.getName(), Integer.class.getName(),
2261                                    OrderByComparator.class.getName()
2262                            });
2263            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
2264                    new FinderPath(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
2265                            JournalFolderModelImpl.FINDER_CACHE_ENABLED,
2266                            JournalFolderImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
2267                            "findByCompanyId", new String[] { Long.class.getName() },
2268                            JournalFolderModelImpl.COMPANYID_COLUMN_BITMASK |
2269                            JournalFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
2270                            JournalFolderModelImpl.NAME_COLUMN_BITMASK);
2271            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
2272                            JournalFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
2273                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
2274                            new String[] { Long.class.getName() });
2275    
2276            /**
2277             * Returns all the journal folders where companyId = &#63;.
2278             *
2279             * @param companyId the company ID
2280             * @return the matching journal folders
2281             * @throws SystemException if a system exception occurred
2282             */
2283            public List<JournalFolder> findByCompanyId(long companyId)
2284                    throws SystemException {
2285                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2286                            null);
2287            }
2288    
2289            /**
2290             * Returns a range of all the journal folders where companyId = &#63;.
2291             *
2292             * <p>
2293             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2294             * </p>
2295             *
2296             * @param companyId the company ID
2297             * @param start the lower bound of the range of journal folders
2298             * @param end the upper bound of the range of journal folders (not inclusive)
2299             * @return the range of matching journal folders
2300             * @throws SystemException if a system exception occurred
2301             */
2302            public List<JournalFolder> findByCompanyId(long companyId, int start,
2303                    int end) throws SystemException {
2304                    return findByCompanyId(companyId, start, end, null);
2305            }
2306    
2307            /**
2308             * Returns an ordered range of all the journal folders where companyId = &#63;.
2309             *
2310             * <p>
2311             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2312             * </p>
2313             *
2314             * @param companyId the company ID
2315             * @param start the lower bound of the range of journal folders
2316             * @param end the upper bound of the range of journal folders (not inclusive)
2317             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2318             * @return the ordered range of matching journal folders
2319             * @throws SystemException if a system exception occurred
2320             */
2321            public List<JournalFolder> findByCompanyId(long companyId, int start,
2322                    int end, OrderByComparator orderByComparator) throws SystemException {
2323                    boolean pagination = true;
2324                    FinderPath finderPath = null;
2325                    Object[] finderArgs = null;
2326    
2327                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2328                                    (orderByComparator == null)) {
2329                            pagination = false;
2330                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2331                            finderArgs = new Object[] { companyId };
2332                    }
2333                    else {
2334                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2335                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
2336                    }
2337    
2338                    List<JournalFolder> list = (List<JournalFolder>)FinderCacheUtil.getResult(finderPath,
2339                                    finderArgs, this);
2340    
2341                    if ((list != null) && !list.isEmpty()) {
2342                            for (JournalFolder journalFolder : list) {
2343                                    if ((companyId != journalFolder.getCompanyId())) {
2344                                            list = null;
2345    
2346                                            break;
2347                                    }
2348                            }
2349                    }
2350    
2351                    if (list == null) {
2352                            StringBundler query = null;
2353    
2354                            if (orderByComparator != null) {
2355                                    query = new StringBundler(3 +
2356                                                    (orderByComparator.getOrderByFields().length * 3));
2357                            }
2358                            else {
2359                                    query = new StringBundler(3);
2360                            }
2361    
2362                            query.append(_SQL_SELECT_JOURNALFOLDER_WHERE);
2363    
2364                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2365    
2366                            if (orderByComparator != null) {
2367                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2368                                            orderByComparator);
2369                            }
2370                            else
2371                             if (pagination) {
2372                                    query.append(JournalFolderModelImpl.ORDER_BY_JPQL);
2373                            }
2374    
2375                            String sql = query.toString();
2376    
2377                            Session session = null;
2378    
2379                            try {
2380                                    session = openSession();
2381    
2382                                    Query q = session.createQuery(sql);
2383    
2384                                    QueryPos qPos = QueryPos.getInstance(q);
2385    
2386                                    qPos.add(companyId);
2387    
2388                                    if (!pagination) {
2389                                            list = (List<JournalFolder>)QueryUtil.list(q, getDialect(),
2390                                                            start, end, false);
2391    
2392                                            Collections.sort(list);
2393    
2394                                            list = new UnmodifiableList<JournalFolder>(list);
2395                                    }
2396                                    else {
2397                                            list = (List<JournalFolder>)QueryUtil.list(q, getDialect(),
2398                                                            start, end);
2399                                    }
2400    
2401                                    cacheResult(list);
2402    
2403                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2404                            }
2405                            catch (Exception e) {
2406                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2407    
2408                                    throw processException(e);
2409                            }
2410                            finally {
2411                                    closeSession(session);
2412                            }
2413                    }
2414    
2415                    return list;
2416            }
2417    
2418            /**
2419             * Returns the first journal folder in the ordered set where companyId = &#63;.
2420             *
2421             * @param companyId the company ID
2422             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2423             * @return the first matching journal folder
2424             * @throws com.liferay.portlet.journal.NoSuchFolderException if a matching journal folder could not be found
2425             * @throws SystemException if a system exception occurred
2426             */
2427            public JournalFolder findByCompanyId_First(long companyId,
2428                    OrderByComparator orderByComparator)
2429                    throws NoSuchFolderException, SystemException {
2430                    JournalFolder journalFolder = fetchByCompanyId_First(companyId,
2431                                    orderByComparator);
2432    
2433                    if (journalFolder != null) {
2434                            return journalFolder;
2435                    }
2436    
2437                    StringBundler msg = new StringBundler(4);
2438    
2439                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2440    
2441                    msg.append("companyId=");
2442                    msg.append(companyId);
2443    
2444                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2445    
2446                    throw new NoSuchFolderException(msg.toString());
2447            }
2448    
2449            /**
2450             * Returns the first journal folder in the ordered set where companyId = &#63;.
2451             *
2452             * @param companyId the company ID
2453             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2454             * @return the first matching journal folder, or <code>null</code> if a matching journal folder could not be found
2455             * @throws SystemException if a system exception occurred
2456             */
2457            public JournalFolder fetchByCompanyId_First(long companyId,
2458                    OrderByComparator orderByComparator) throws SystemException {
2459                    List<JournalFolder> list = findByCompanyId(companyId, 0, 1,
2460                                    orderByComparator);
2461    
2462                    if (!list.isEmpty()) {
2463                            return list.get(0);
2464                    }
2465    
2466                    return null;
2467            }
2468    
2469            /**
2470             * Returns the last journal folder in the ordered set where companyId = &#63;.
2471             *
2472             * @param companyId the company ID
2473             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2474             * @return the last matching journal folder
2475             * @throws com.liferay.portlet.journal.NoSuchFolderException if a matching journal folder could not be found
2476             * @throws SystemException if a system exception occurred
2477             */
2478            public JournalFolder findByCompanyId_Last(long companyId,
2479                    OrderByComparator orderByComparator)
2480                    throws NoSuchFolderException, SystemException {
2481                    JournalFolder journalFolder = fetchByCompanyId_Last(companyId,
2482                                    orderByComparator);
2483    
2484                    if (journalFolder != null) {
2485                            return journalFolder;
2486                    }
2487    
2488                    StringBundler msg = new StringBundler(4);
2489    
2490                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2491    
2492                    msg.append("companyId=");
2493                    msg.append(companyId);
2494    
2495                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2496    
2497                    throw new NoSuchFolderException(msg.toString());
2498            }
2499    
2500            /**
2501             * Returns the last journal folder in the ordered set where companyId = &#63;.
2502             *
2503             * @param companyId the company ID
2504             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2505             * @return the last matching journal folder, or <code>null</code> if a matching journal folder could not be found
2506             * @throws SystemException if a system exception occurred
2507             */
2508            public JournalFolder fetchByCompanyId_Last(long companyId,
2509                    OrderByComparator orderByComparator) throws SystemException {
2510                    int count = countByCompanyId(companyId);
2511    
2512                    List<JournalFolder> list = findByCompanyId(companyId, count - 1, count,
2513                                    orderByComparator);
2514    
2515                    if (!list.isEmpty()) {
2516                            return list.get(0);
2517                    }
2518    
2519                    return null;
2520            }
2521    
2522            /**
2523             * Returns the journal folders before and after the current journal folder in the ordered set where companyId = &#63;.
2524             *
2525             * @param folderId the primary key of the current journal folder
2526             * @param companyId the company ID
2527             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2528             * @return the previous, current, and next journal folder
2529             * @throws com.liferay.portlet.journal.NoSuchFolderException if a journal folder with the primary key could not be found
2530             * @throws SystemException if a system exception occurred
2531             */
2532            public JournalFolder[] findByCompanyId_PrevAndNext(long folderId,
2533                    long companyId, OrderByComparator orderByComparator)
2534                    throws NoSuchFolderException, SystemException {
2535                    JournalFolder journalFolder = findByPrimaryKey(folderId);
2536    
2537                    Session session = null;
2538    
2539                    try {
2540                            session = openSession();
2541    
2542                            JournalFolder[] array = new JournalFolderImpl[3];
2543    
2544                            array[0] = getByCompanyId_PrevAndNext(session, journalFolder,
2545                                            companyId, orderByComparator, true);
2546    
2547                            array[1] = journalFolder;
2548    
2549                            array[2] = getByCompanyId_PrevAndNext(session, journalFolder,
2550                                            companyId, orderByComparator, false);
2551    
2552                            return array;
2553                    }
2554                    catch (Exception e) {
2555                            throw processException(e);
2556                    }
2557                    finally {
2558                            closeSession(session);
2559                    }
2560            }
2561    
2562            protected JournalFolder getByCompanyId_PrevAndNext(Session session,
2563                    JournalFolder journalFolder, long companyId,
2564                    OrderByComparator orderByComparator, boolean previous) {
2565                    StringBundler query = null;
2566    
2567                    if (orderByComparator != null) {
2568                            query = new StringBundler(6 +
2569                                            (orderByComparator.getOrderByFields().length * 6));
2570                    }
2571                    else {
2572                            query = new StringBundler(3);
2573                    }
2574    
2575                    query.append(_SQL_SELECT_JOURNALFOLDER_WHERE);
2576    
2577                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2578    
2579                    if (orderByComparator != null) {
2580                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2581    
2582                            if (orderByConditionFields.length > 0) {
2583                                    query.append(WHERE_AND);
2584                            }
2585    
2586                            for (int i = 0; i < orderByConditionFields.length; i++) {
2587                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2588                                    query.append(orderByConditionFields[i]);
2589    
2590                                    if ((i + 1) < orderByConditionFields.length) {
2591                                            if (orderByComparator.isAscending() ^ previous) {
2592                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2593                                            }
2594                                            else {
2595                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2596                                            }
2597                                    }
2598                                    else {
2599                                            if (orderByComparator.isAscending() ^ previous) {
2600                                                    query.append(WHERE_GREATER_THAN);
2601                                            }
2602                                            else {
2603                                                    query.append(WHERE_LESSER_THAN);
2604                                            }
2605                                    }
2606                            }
2607    
2608                            query.append(ORDER_BY_CLAUSE);
2609    
2610                            String[] orderByFields = orderByComparator.getOrderByFields();
2611    
2612                            for (int i = 0; i < orderByFields.length; i++) {
2613                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2614                                    query.append(orderByFields[i]);
2615    
2616                                    if ((i + 1) < orderByFields.length) {
2617                                            if (orderByComparator.isAscending() ^ previous) {
2618                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2619                                            }
2620                                            else {
2621                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2622                                            }
2623                                    }
2624                                    else {
2625                                            if (orderByComparator.isAscending() ^ previous) {
2626                                                    query.append(ORDER_BY_ASC);
2627                                            }
2628                                            else {
2629                                                    query.append(ORDER_BY_DESC);
2630                                            }
2631                                    }
2632                            }
2633                    }
2634                    else {
2635                            query.append(JournalFolderModelImpl.ORDER_BY_JPQL);
2636                    }
2637    
2638                    String sql = query.toString();
2639    
2640                    Query q = session.createQuery(sql);
2641    
2642                    q.setFirstResult(0);
2643                    q.setMaxResults(2);
2644    
2645                    QueryPos qPos = QueryPos.getInstance(q);
2646    
2647                    qPos.add(companyId);
2648    
2649                    if (orderByComparator != null) {
2650                            Object[] values = orderByComparator.getOrderByConditionValues(journalFolder);
2651    
2652                            for (Object value : values) {
2653                                    qPos.add(value);
2654                            }
2655                    }
2656    
2657                    List<JournalFolder> list = q.list();
2658    
2659                    if (list.size() == 2) {
2660                            return list.get(1);
2661                    }
2662                    else {
2663                            return null;
2664                    }
2665            }
2666    
2667            /**
2668             * Removes all the journal folders where companyId = &#63; from the database.
2669             *
2670             * @param companyId the company ID
2671             * @throws SystemException if a system exception occurred
2672             */
2673            public void removeByCompanyId(long companyId) throws SystemException {
2674                    for (JournalFolder journalFolder : findByCompanyId(companyId,
2675                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2676                            remove(journalFolder);
2677                    }
2678            }
2679    
2680            /**
2681             * Returns the number of journal folders where companyId = &#63;.
2682             *
2683             * @param companyId the company ID
2684             * @return the number of matching journal folders
2685             * @throws SystemException if a system exception occurred
2686             */
2687            public int countByCompanyId(long companyId) throws SystemException {
2688                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
2689    
2690                    Object[] finderArgs = new Object[] { companyId };
2691    
2692                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2693                                    this);
2694    
2695                    if (count == null) {
2696                            StringBundler query = new StringBundler(2);
2697    
2698                            query.append(_SQL_COUNT_JOURNALFOLDER_WHERE);
2699    
2700                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2701    
2702                            String sql = query.toString();
2703    
2704                            Session session = null;
2705    
2706                            try {
2707                                    session = openSession();
2708    
2709                                    Query q = session.createQuery(sql);
2710    
2711                                    QueryPos qPos = QueryPos.getInstance(q);
2712    
2713                                    qPos.add(companyId);
2714    
2715                                    count = (Long)q.uniqueResult();
2716    
2717                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2718                            }
2719                            catch (Exception e) {
2720                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2721    
2722                                    throw processException(e);
2723                            }
2724                            finally {
2725                                    closeSession(session);
2726                            }
2727                    }
2728    
2729                    return count.intValue();
2730            }
2731    
2732            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "journalFolder.companyId = ?";
2733            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P = new FinderPath(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
2734                            JournalFolderModelImpl.FINDER_CACHE_ENABLED,
2735                            JournalFolderImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
2736                            "findByG_P",
2737                            new String[] {
2738                                    Long.class.getName(), Long.class.getName(),
2739                                    
2740                            Integer.class.getName(), Integer.class.getName(),
2741                                    OrderByComparator.class.getName()
2742                            });
2743            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P = new FinderPath(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
2744                            JournalFolderModelImpl.FINDER_CACHE_ENABLED,
2745                            JournalFolderImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
2746                            "findByG_P",
2747                            new String[] { Long.class.getName(), Long.class.getName() },
2748                            JournalFolderModelImpl.GROUPID_COLUMN_BITMASK |
2749                            JournalFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
2750                            JournalFolderModelImpl.NAME_COLUMN_BITMASK);
2751            public static final FinderPath FINDER_PATH_COUNT_BY_G_P = new FinderPath(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
2752                            JournalFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
2753                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P",
2754                            new String[] { Long.class.getName(), Long.class.getName() });
2755    
2756            /**
2757             * Returns all the journal folders where groupId = &#63; and parentFolderId = &#63;.
2758             *
2759             * @param groupId the group ID
2760             * @param parentFolderId the parent folder ID
2761             * @return the matching journal folders
2762             * @throws SystemException if a system exception occurred
2763             */
2764            public List<JournalFolder> findByG_P(long groupId, long parentFolderId)
2765                    throws SystemException {
2766                    return findByG_P(groupId, parentFolderId, QueryUtil.ALL_POS,
2767                            QueryUtil.ALL_POS, null);
2768            }
2769    
2770            /**
2771             * Returns a range of all the journal folders where groupId = &#63; and parentFolderId = &#63;.
2772             *
2773             * <p>
2774             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2775             * </p>
2776             *
2777             * @param groupId the group ID
2778             * @param parentFolderId the parent folder ID
2779             * @param start the lower bound of the range of journal folders
2780             * @param end the upper bound of the range of journal folders (not inclusive)
2781             * @return the range of matching journal folders
2782             * @throws SystemException if a system exception occurred
2783             */
2784            public List<JournalFolder> findByG_P(long groupId, long parentFolderId,
2785                    int start, int end) throws SystemException {
2786                    return findByG_P(groupId, parentFolderId, start, end, null);
2787            }
2788    
2789            /**
2790             * Returns an ordered range of all the journal folders where groupId = &#63; and parentFolderId = &#63;.
2791             *
2792             * <p>
2793             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2794             * </p>
2795             *
2796             * @param groupId the group ID
2797             * @param parentFolderId the parent folder ID
2798             * @param start the lower bound of the range of journal folders
2799             * @param end the upper bound of the range of journal folders (not inclusive)
2800             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2801             * @return the ordered range of matching journal folders
2802             * @throws SystemException if a system exception occurred
2803             */
2804            public List<JournalFolder> findByG_P(long groupId, long parentFolderId,
2805                    int start, int end, OrderByComparator orderByComparator)
2806                    throws SystemException {
2807                    boolean pagination = true;
2808                    FinderPath finderPath = null;
2809                    Object[] finderArgs = null;
2810    
2811                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2812                                    (orderByComparator == null)) {
2813                            pagination = false;
2814                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P;
2815                            finderArgs = new Object[] { groupId, parentFolderId };
2816                    }
2817                    else {
2818                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P;
2819                            finderArgs = new Object[] {
2820                                            groupId, parentFolderId,
2821                                            
2822                                            start, end, orderByComparator
2823                                    };
2824                    }
2825    
2826                    List<JournalFolder> list = (List<JournalFolder>)FinderCacheUtil.getResult(finderPath,
2827                                    finderArgs, this);
2828    
2829                    if ((list != null) && !list.isEmpty()) {
2830                            for (JournalFolder journalFolder : list) {
2831                                    if ((groupId != journalFolder.getGroupId()) ||
2832                                                    (parentFolderId != journalFolder.getParentFolderId())) {
2833                                            list = null;
2834    
2835                                            break;
2836                                    }
2837                            }
2838                    }
2839    
2840                    if (list == null) {
2841                            StringBundler query = null;
2842    
2843                            if (orderByComparator != null) {
2844                                    query = new StringBundler(4 +
2845                                                    (orderByComparator.getOrderByFields().length * 3));
2846                            }
2847                            else {
2848                                    query = new StringBundler(4);
2849                            }
2850    
2851                            query.append(_SQL_SELECT_JOURNALFOLDER_WHERE);
2852    
2853                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
2854    
2855                            query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
2856    
2857                            if (orderByComparator != null) {
2858                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2859                                            orderByComparator);
2860                            }
2861                            else
2862                             if (pagination) {
2863                                    query.append(JournalFolderModelImpl.ORDER_BY_JPQL);
2864                            }
2865    
2866                            String sql = query.toString();
2867    
2868                            Session session = null;
2869    
2870                            try {
2871                                    session = openSession();
2872    
2873                                    Query q = session.createQuery(sql);
2874    
2875                                    QueryPos qPos = QueryPos.getInstance(q);
2876    
2877                                    qPos.add(groupId);
2878    
2879                                    qPos.add(parentFolderId);
2880    
2881                                    if (!pagination) {
2882                                            list = (List<JournalFolder>)QueryUtil.list(q, getDialect(),
2883                                                            start, end, false);
2884    
2885                                            Collections.sort(list);
2886    
2887                                            list = new UnmodifiableList<JournalFolder>(list);
2888                                    }
2889                                    else {
2890                                            list = (List<JournalFolder>)QueryUtil.list(q, getDialect(),
2891                                                            start, end);
2892                                    }
2893    
2894                                    cacheResult(list);
2895    
2896                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2897                            }
2898                            catch (Exception e) {
2899                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2900    
2901                                    throw processException(e);
2902                            }
2903                            finally {
2904                                    closeSession(session);
2905                            }
2906                    }
2907    
2908                    return list;
2909            }
2910    
2911            /**
2912             * Returns the first journal folder in the ordered set where groupId = &#63; and parentFolderId = &#63;.
2913             *
2914             * @param groupId the group ID
2915             * @param parentFolderId the parent folder ID
2916             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2917             * @return the first matching journal folder
2918             * @throws com.liferay.portlet.journal.NoSuchFolderException if a matching journal folder could not be found
2919             * @throws SystemException if a system exception occurred
2920             */
2921            public JournalFolder findByG_P_First(long groupId, long parentFolderId,
2922                    OrderByComparator orderByComparator)
2923                    throws NoSuchFolderException, SystemException {
2924                    JournalFolder journalFolder = fetchByG_P_First(groupId, parentFolderId,
2925                                    orderByComparator);
2926    
2927                    if (journalFolder != null) {
2928                            return journalFolder;
2929                    }
2930    
2931                    StringBundler msg = new StringBundler(6);
2932    
2933                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2934    
2935                    msg.append("groupId=");
2936                    msg.append(groupId);
2937    
2938                    msg.append(", parentFolderId=");
2939                    msg.append(parentFolderId);
2940    
2941                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2942    
2943                    throw new NoSuchFolderException(msg.toString());
2944            }
2945    
2946            /**
2947             * Returns the first journal folder in the ordered set where groupId = &#63; and parentFolderId = &#63;.
2948             *
2949             * @param groupId the group ID
2950             * @param parentFolderId the parent folder ID
2951             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2952             * @return the first matching journal folder, or <code>null</code> if a matching journal folder could not be found
2953             * @throws SystemException if a system exception occurred
2954             */
2955            public JournalFolder fetchByG_P_First(long groupId, long parentFolderId,
2956                    OrderByComparator orderByComparator) throws SystemException {
2957                    List<JournalFolder> list = findByG_P(groupId, parentFolderId, 0, 1,
2958                                    orderByComparator);
2959    
2960                    if (!list.isEmpty()) {
2961                            return list.get(0);
2962                    }
2963    
2964                    return null;
2965            }
2966    
2967            /**
2968             * Returns the last journal folder in the ordered set where groupId = &#63; and parentFolderId = &#63;.
2969             *
2970             * @param groupId the group ID
2971             * @param parentFolderId the parent folder ID
2972             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2973             * @return the last matching journal folder
2974             * @throws com.liferay.portlet.journal.NoSuchFolderException if a matching journal folder could not be found
2975             * @throws SystemException if a system exception occurred
2976             */
2977            public JournalFolder findByG_P_Last(long groupId, long parentFolderId,
2978                    OrderByComparator orderByComparator)
2979                    throws NoSuchFolderException, SystemException {
2980                    JournalFolder journalFolder = fetchByG_P_Last(groupId, parentFolderId,
2981                                    orderByComparator);
2982    
2983                    if (journalFolder != null) {
2984                            return journalFolder;
2985                    }
2986    
2987                    StringBundler msg = new StringBundler(6);
2988    
2989                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2990    
2991                    msg.append("groupId=");
2992                    msg.append(groupId);
2993    
2994                    msg.append(", parentFolderId=");
2995                    msg.append(parentFolderId);
2996    
2997                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2998    
2999                    throw new NoSuchFolderException(msg.toString());
3000            }
3001    
3002            /**
3003             * Returns the last journal folder in the ordered set where groupId = &#63; and parentFolderId = &#63;.
3004             *
3005             * @param groupId the group ID
3006             * @param parentFolderId the parent folder ID
3007             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3008             * @return the last matching journal folder, or <code>null</code> if a matching journal folder could not be found
3009             * @throws SystemException if a system exception occurred
3010             */
3011            public JournalFolder fetchByG_P_Last(long groupId, long parentFolderId,
3012                    OrderByComparator orderByComparator) throws SystemException {
3013                    int count = countByG_P(groupId, parentFolderId);
3014    
3015                    List<JournalFolder> list = findByG_P(groupId, parentFolderId,
3016                                    count - 1, count, orderByComparator);
3017    
3018                    if (!list.isEmpty()) {
3019                            return list.get(0);
3020                    }
3021    
3022                    return null;
3023            }
3024    
3025            /**
3026             * Returns the journal folders before and after the current journal folder in the ordered set where groupId = &#63; and parentFolderId = &#63;.
3027             *
3028             * @param folderId the primary key of the current journal folder
3029             * @param groupId the group ID
3030             * @param parentFolderId the parent folder ID
3031             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3032             * @return the previous, current, and next journal folder
3033             * @throws com.liferay.portlet.journal.NoSuchFolderException if a journal folder with the primary key could not be found
3034             * @throws SystemException if a system exception occurred
3035             */
3036            public JournalFolder[] findByG_P_PrevAndNext(long folderId, long groupId,
3037                    long parentFolderId, OrderByComparator orderByComparator)
3038                    throws NoSuchFolderException, SystemException {
3039                    JournalFolder journalFolder = findByPrimaryKey(folderId);
3040    
3041                    Session session = null;
3042    
3043                    try {
3044                            session = openSession();
3045    
3046                            JournalFolder[] array = new JournalFolderImpl[3];
3047    
3048                            array[0] = getByG_P_PrevAndNext(session, journalFolder, groupId,
3049                                            parentFolderId, orderByComparator, true);
3050    
3051                            array[1] = journalFolder;
3052    
3053                            array[2] = getByG_P_PrevAndNext(session, journalFolder, groupId,
3054                                            parentFolderId, orderByComparator, false);
3055    
3056                            return array;
3057                    }
3058                    catch (Exception e) {
3059                            throw processException(e);
3060                    }
3061                    finally {
3062                            closeSession(session);
3063                    }
3064            }
3065    
3066            protected JournalFolder getByG_P_PrevAndNext(Session session,
3067                    JournalFolder journalFolder, long groupId, long parentFolderId,
3068                    OrderByComparator orderByComparator, boolean previous) {
3069                    StringBundler query = null;
3070    
3071                    if (orderByComparator != null) {
3072                            query = new StringBundler(6 +
3073                                            (orderByComparator.getOrderByFields().length * 6));
3074                    }
3075                    else {
3076                            query = new StringBundler(3);
3077                    }
3078    
3079                    query.append(_SQL_SELECT_JOURNALFOLDER_WHERE);
3080    
3081                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3082    
3083                    query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
3084    
3085                    if (orderByComparator != null) {
3086                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3087    
3088                            if (orderByConditionFields.length > 0) {
3089                                    query.append(WHERE_AND);
3090                            }
3091    
3092                            for (int i = 0; i < orderByConditionFields.length; i++) {
3093                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3094                                    query.append(orderByConditionFields[i]);
3095    
3096                                    if ((i + 1) < orderByConditionFields.length) {
3097                                            if (orderByComparator.isAscending() ^ previous) {
3098                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3099                                            }
3100                                            else {
3101                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3102                                            }
3103                                    }
3104                                    else {
3105                                            if (orderByComparator.isAscending() ^ previous) {
3106                                                    query.append(WHERE_GREATER_THAN);
3107                                            }
3108                                            else {
3109                                                    query.append(WHERE_LESSER_THAN);
3110                                            }
3111                                    }
3112                            }
3113    
3114                            query.append(ORDER_BY_CLAUSE);
3115    
3116                            String[] orderByFields = orderByComparator.getOrderByFields();
3117    
3118                            for (int i = 0; i < orderByFields.length; i++) {
3119                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3120                                    query.append(orderByFields[i]);
3121    
3122                                    if ((i + 1) < orderByFields.length) {
3123                                            if (orderByComparator.isAscending() ^ previous) {
3124                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3125                                            }
3126                                            else {
3127                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3128                                            }
3129                                    }
3130                                    else {
3131                                            if (orderByComparator.isAscending() ^ previous) {
3132                                                    query.append(ORDER_BY_ASC);
3133                                            }
3134                                            else {
3135                                                    query.append(ORDER_BY_DESC);
3136                                            }
3137                                    }
3138                            }
3139                    }
3140                    else {
3141                            query.append(JournalFolderModelImpl.ORDER_BY_JPQL);
3142                    }
3143    
3144                    String sql = query.toString();
3145    
3146                    Query q = session.createQuery(sql);
3147    
3148                    q.setFirstResult(0);
3149                    q.setMaxResults(2);
3150    
3151                    QueryPos qPos = QueryPos.getInstance(q);
3152    
3153                    qPos.add(groupId);
3154    
3155                    qPos.add(parentFolderId);
3156    
3157                    if (orderByComparator != null) {
3158                            Object[] values = orderByComparator.getOrderByConditionValues(journalFolder);
3159    
3160                            for (Object value : values) {
3161                                    qPos.add(value);
3162                            }
3163                    }
3164    
3165                    List<JournalFolder> list = q.list();
3166    
3167                    if (list.size() == 2) {
3168                            return list.get(1);
3169                    }
3170                    else {
3171                            return null;
3172                    }
3173            }
3174    
3175            /**
3176             * Returns all the journal folders that the user has permission to view where groupId = &#63; and parentFolderId = &#63;.
3177             *
3178             * @param groupId the group ID
3179             * @param parentFolderId the parent folder ID
3180             * @return the matching journal folders that the user has permission to view
3181             * @throws SystemException if a system exception occurred
3182             */
3183            public List<JournalFolder> filterFindByG_P(long groupId, long parentFolderId)
3184                    throws SystemException {
3185                    return filterFindByG_P(groupId, parentFolderId, QueryUtil.ALL_POS,
3186                            QueryUtil.ALL_POS, null);
3187            }
3188    
3189            /**
3190             * Returns a range of all the journal folders that the user has permission to view where groupId = &#63; and parentFolderId = &#63;.
3191             *
3192             * <p>
3193             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3194             * </p>
3195             *
3196             * @param groupId the group ID
3197             * @param parentFolderId the parent folder ID
3198             * @param start the lower bound of the range of journal folders
3199             * @param end the upper bound of the range of journal folders (not inclusive)
3200             * @return the range of matching journal folders that the user has permission to view
3201             * @throws SystemException if a system exception occurred
3202             */
3203            public List<JournalFolder> filterFindByG_P(long groupId,
3204                    long parentFolderId, int start, int end) throws SystemException {
3205                    return filterFindByG_P(groupId, parentFolderId, start, end, null);
3206            }
3207    
3208            /**
3209             * Returns an ordered range of all the journal folders that the user has permissions to view where groupId = &#63; and parentFolderId = &#63;.
3210             *
3211             * <p>
3212             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3213             * </p>
3214             *
3215             * @param groupId the group ID
3216             * @param parentFolderId the parent folder ID
3217             * @param start the lower bound of the range of journal folders
3218             * @param end the upper bound of the range of journal folders (not inclusive)
3219             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3220             * @return the ordered range of matching journal folders that the user has permission to view
3221             * @throws SystemException if a system exception occurred
3222             */
3223            public List<JournalFolder> filterFindByG_P(long groupId,
3224                    long parentFolderId, int start, int end,
3225                    OrderByComparator orderByComparator) throws SystemException {
3226                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3227                            return findByG_P(groupId, parentFolderId, start, end,
3228                                    orderByComparator);
3229                    }
3230    
3231                    StringBundler query = null;
3232    
3233                    if (orderByComparator != null) {
3234                            query = new StringBundler(4 +
3235                                            (orderByComparator.getOrderByFields().length * 3));
3236                    }
3237                    else {
3238                            query = new StringBundler(4);
3239                    }
3240    
3241                    if (getDB().isSupportsInlineDistinct()) {
3242                            query.append(_FILTER_SQL_SELECT_JOURNALFOLDER_WHERE);
3243                    }
3244                    else {
3245                            query.append(_FILTER_SQL_SELECT_JOURNALFOLDER_NO_INLINE_DISTINCT_WHERE_1);
3246                    }
3247    
3248                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3249    
3250                    query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
3251    
3252                    if (!getDB().isSupportsInlineDistinct()) {
3253                            query.append(_FILTER_SQL_SELECT_JOURNALFOLDER_NO_INLINE_DISTINCT_WHERE_2);
3254                    }
3255    
3256                    if (orderByComparator != null) {
3257                            if (getDB().isSupportsInlineDistinct()) {
3258                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3259                                            orderByComparator);
3260                            }
3261                            else {
3262                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3263                                            orderByComparator);
3264                            }
3265                    }
3266                    else {
3267                            if (getDB().isSupportsInlineDistinct()) {
3268                                    query.append(JournalFolderModelImpl.ORDER_BY_JPQL);
3269                            }
3270                            else {
3271                                    query.append(JournalFolderModelImpl.ORDER_BY_SQL);
3272                            }
3273                    }
3274    
3275                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3276                                    JournalFolder.class.getName(),
3277                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3278    
3279                    Session session = null;
3280    
3281                    try {
3282                            session = openSession();
3283    
3284                            SQLQuery q = session.createSQLQuery(sql);
3285    
3286                            if (getDB().isSupportsInlineDistinct()) {
3287                                    q.addEntity(_FILTER_ENTITY_ALIAS, JournalFolderImpl.class);
3288                            }
3289                            else {
3290                                    q.addEntity(_FILTER_ENTITY_TABLE, JournalFolderImpl.class);
3291                            }
3292    
3293                            QueryPos qPos = QueryPos.getInstance(q);
3294    
3295                            qPos.add(groupId);
3296    
3297                            qPos.add(parentFolderId);
3298    
3299                            return (List<JournalFolder>)QueryUtil.list(q, getDialect(), start,
3300                                    end);
3301                    }
3302                    catch (Exception e) {
3303                            throw processException(e);
3304                    }
3305                    finally {
3306                            closeSession(session);
3307                    }
3308            }
3309    
3310            /**
3311             * 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;.
3312             *
3313             * @param folderId the primary key of the current journal folder
3314             * @param groupId the group ID
3315             * @param parentFolderId the parent folder ID
3316             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3317             * @return the previous, current, and next journal folder
3318             * @throws com.liferay.portlet.journal.NoSuchFolderException if a journal folder with the primary key could not be found
3319             * @throws SystemException if a system exception occurred
3320             */
3321            public JournalFolder[] filterFindByG_P_PrevAndNext(long folderId,
3322                    long groupId, long parentFolderId, OrderByComparator orderByComparator)
3323                    throws NoSuchFolderException, SystemException {
3324                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3325                            return findByG_P_PrevAndNext(folderId, groupId, parentFolderId,
3326                                    orderByComparator);
3327                    }
3328    
3329                    JournalFolder journalFolder = findByPrimaryKey(folderId);
3330    
3331                    Session session = null;
3332    
3333                    try {
3334                            session = openSession();
3335    
3336                            JournalFolder[] array = new JournalFolderImpl[3];
3337    
3338                            array[0] = filterGetByG_P_PrevAndNext(session, journalFolder,
3339                                            groupId, parentFolderId, orderByComparator, true);
3340    
3341                            array[1] = journalFolder;
3342    
3343                            array[2] = filterGetByG_P_PrevAndNext(session, journalFolder,
3344                                            groupId, parentFolderId, orderByComparator, false);
3345    
3346                            return array;
3347                    }
3348                    catch (Exception e) {
3349                            throw processException(e);
3350                    }
3351                    finally {
3352                            closeSession(session);
3353                    }
3354            }
3355    
3356            protected JournalFolder filterGetByG_P_PrevAndNext(Session session,
3357                    JournalFolder journalFolder, long groupId, long parentFolderId,
3358                    OrderByComparator orderByComparator, boolean previous) {
3359                    StringBundler query = null;
3360    
3361                    if (orderByComparator != null) {
3362                            query = new StringBundler(6 +
3363                                            (orderByComparator.getOrderByFields().length * 6));
3364                    }
3365                    else {
3366                            query = new StringBundler(3);
3367                    }
3368    
3369                    if (getDB().isSupportsInlineDistinct()) {
3370                            query.append(_FILTER_SQL_SELECT_JOURNALFOLDER_WHERE);
3371                    }
3372                    else {
3373                            query.append(_FILTER_SQL_SELECT_JOURNALFOLDER_NO_INLINE_DISTINCT_WHERE_1);
3374                    }
3375    
3376                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3377    
3378                    query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
3379    
3380                    if (!getDB().isSupportsInlineDistinct()) {
3381                            query.append(_FILTER_SQL_SELECT_JOURNALFOLDER_NO_INLINE_DISTINCT_WHERE_2);
3382                    }
3383    
3384                    if (orderByComparator != null) {
3385                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3386    
3387                            if (orderByConditionFields.length > 0) {
3388                                    query.append(WHERE_AND);
3389                            }
3390    
3391                            for (int i = 0; i < orderByConditionFields.length; i++) {
3392                                    if (getDB().isSupportsInlineDistinct()) {
3393                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3394                                    }
3395                                    else {
3396                                            query.append(_ORDER_BY_ENTITY_TABLE);
3397                                    }
3398    
3399                                    query.append(orderByConditionFields[i]);
3400    
3401                                    if ((i + 1) < orderByConditionFields.length) {
3402                                            if (orderByComparator.isAscending() ^ previous) {
3403                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3404                                            }
3405                                            else {
3406                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3407                                            }
3408                                    }
3409                                    else {
3410                                            if (orderByComparator.isAscending() ^ previous) {
3411                                                    query.append(WHERE_GREATER_THAN);
3412                                            }
3413                                            else {
3414                                                    query.append(WHERE_LESSER_THAN);
3415                                            }
3416                                    }
3417                            }
3418    
3419                            query.append(ORDER_BY_CLAUSE);
3420    
3421                            String[] orderByFields = orderByComparator.getOrderByFields();
3422    
3423                            for (int i = 0; i < orderByFields.length; i++) {
3424                                    if (getDB().isSupportsInlineDistinct()) {
3425                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3426                                    }
3427                                    else {
3428                                            query.append(_ORDER_BY_ENTITY_TABLE);
3429                                    }
3430    
3431                                    query.append(orderByFields[i]);
3432    
3433                                    if ((i + 1) < orderByFields.length) {
3434                                            if (orderByComparator.isAscending() ^ previous) {
3435                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3436                                            }
3437                                            else {
3438                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3439                                            }
3440                                    }
3441                                    else {
3442                                            if (orderByComparator.isAscending() ^ previous) {
3443                                                    query.append(ORDER_BY_ASC);
3444                                            }
3445                                            else {
3446                                                    query.append(ORDER_BY_DESC);
3447                                            }
3448                                    }
3449                            }
3450                    }
3451                    else {
3452                            if (getDB().isSupportsInlineDistinct()) {
3453                                    query.append(JournalFolderModelImpl.ORDER_BY_JPQL);
3454                            }
3455                            else {
3456                                    query.append(JournalFolderModelImpl.ORDER_BY_SQL);
3457                            }
3458                    }
3459    
3460                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3461                                    JournalFolder.class.getName(),
3462                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3463    
3464                    SQLQuery q = session.createSQLQuery(sql);
3465    
3466                    q.setFirstResult(0);
3467                    q.setMaxResults(2);
3468    
3469                    if (getDB().isSupportsInlineDistinct()) {
3470                            q.addEntity(_FILTER_ENTITY_ALIAS, JournalFolderImpl.class);
3471                    }
3472                    else {
3473                            q.addEntity(_FILTER_ENTITY_TABLE, JournalFolderImpl.class);
3474                    }
3475    
3476                    QueryPos qPos = QueryPos.getInstance(q);
3477    
3478                    qPos.add(groupId);
3479    
3480                    qPos.add(parentFolderId);
3481    
3482                    if (orderByComparator != null) {
3483                            Object[] values = orderByComparator.getOrderByConditionValues(journalFolder);
3484    
3485                            for (Object value : values) {
3486                                    qPos.add(value);
3487                            }
3488                    }
3489    
3490                    List<JournalFolder> list = q.list();
3491    
3492                    if (list.size() == 2) {
3493                            return list.get(1);
3494                    }
3495                    else {
3496                            return null;
3497                    }
3498            }
3499    
3500            /**
3501             * Removes all the journal folders where groupId = &#63; and parentFolderId = &#63; from the database.
3502             *
3503             * @param groupId the group ID
3504             * @param parentFolderId the parent folder ID
3505             * @throws SystemException if a system exception occurred
3506             */
3507            public void removeByG_P(long groupId, long parentFolderId)
3508                    throws SystemException {
3509                    for (JournalFolder journalFolder : findByG_P(groupId, parentFolderId,
3510                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3511                            remove(journalFolder);
3512                    }
3513            }
3514    
3515            /**
3516             * Returns the number of journal folders where groupId = &#63; and parentFolderId = &#63;.
3517             *
3518             * @param groupId the group ID
3519             * @param parentFolderId the parent folder ID
3520             * @return the number of matching journal folders
3521             * @throws SystemException if a system exception occurred
3522             */
3523            public int countByG_P(long groupId, long parentFolderId)
3524                    throws SystemException {
3525                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P;
3526    
3527                    Object[] finderArgs = new Object[] { groupId, parentFolderId };
3528    
3529                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3530                                    this);
3531    
3532                    if (count == null) {
3533                            StringBundler query = new StringBundler(3);
3534    
3535                            query.append(_SQL_COUNT_JOURNALFOLDER_WHERE);
3536    
3537                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3538    
3539                            query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
3540    
3541                            String sql = query.toString();
3542    
3543                            Session session = null;
3544    
3545                            try {
3546                                    session = openSession();
3547    
3548                                    Query q = session.createQuery(sql);
3549    
3550                                    QueryPos qPos = QueryPos.getInstance(q);
3551    
3552                                    qPos.add(groupId);
3553    
3554                                    qPos.add(parentFolderId);
3555    
3556                                    count = (Long)q.uniqueResult();
3557    
3558                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3559                            }
3560                            catch (Exception e) {
3561                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3562    
3563                                    throw processException(e);
3564                            }
3565                            finally {
3566                                    closeSession(session);
3567                            }
3568                    }
3569    
3570                    return count.intValue();
3571            }
3572    
3573            /**
3574             * Returns the number of journal folders that the user has permission to view where groupId = &#63; and parentFolderId = &#63;.
3575             *
3576             * @param groupId the group ID
3577             * @param parentFolderId the parent folder ID
3578             * @return the number of matching journal folders that the user has permission to view
3579             * @throws SystemException if a system exception occurred
3580             */
3581            public int filterCountByG_P(long groupId, long parentFolderId)
3582                    throws SystemException {
3583                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3584                            return countByG_P(groupId, parentFolderId);
3585                    }
3586    
3587                    StringBundler query = new StringBundler(3);
3588    
3589                    query.append(_FILTER_SQL_COUNT_JOURNALFOLDER_WHERE);
3590    
3591                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3592    
3593                    query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
3594    
3595                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3596                                    JournalFolder.class.getName(),
3597                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3598    
3599                    Session session = null;
3600    
3601                    try {
3602                            session = openSession();
3603    
3604                            SQLQuery q = session.createSQLQuery(sql);
3605    
3606                            q.addScalar(COUNT_COLUMN_NAME,
3607                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
3608    
3609                            QueryPos qPos = QueryPos.getInstance(q);
3610    
3611                            qPos.add(groupId);
3612    
3613                            qPos.add(parentFolderId);
3614    
3615                            Long count = (Long)q.uniqueResult();
3616    
3617                            return count.intValue();
3618                    }
3619                    catch (Exception e) {
3620                            throw processException(e);
3621                    }
3622                    finally {
3623                            closeSession(session);
3624                    }
3625            }
3626    
3627            private static final String _FINDER_COLUMN_G_P_GROUPID_2 = "journalFolder.groupId = ? AND ";
3628            private static final String _FINDER_COLUMN_G_P_PARENTFOLDERID_2 = "journalFolder.parentFolderId = ?";
3629            public static final FinderPath FINDER_PATH_FETCH_BY_G_N = new FinderPath(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
3630                            JournalFolderModelImpl.FINDER_CACHE_ENABLED,
3631                            JournalFolderImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByG_N",
3632                            new String[] { Long.class.getName(), String.class.getName() },
3633                            JournalFolderModelImpl.GROUPID_COLUMN_BITMASK |
3634                            JournalFolderModelImpl.NAME_COLUMN_BITMASK);
3635            public static final FinderPath FINDER_PATH_COUNT_BY_G_N = new FinderPath(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
3636                            JournalFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
3637                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N",
3638                            new String[] { Long.class.getName(), String.class.getName() });
3639    
3640            /**
3641             * Returns the journal folder where groupId = &#63; and name = &#63; or throws a {@link com.liferay.portlet.journal.NoSuchFolderException} if it could not be found.
3642             *
3643             * @param groupId the group ID
3644             * @param name the name
3645             * @return the matching journal folder
3646             * @throws com.liferay.portlet.journal.NoSuchFolderException if a matching journal folder could not be found
3647             * @throws SystemException if a system exception occurred
3648             */
3649            public JournalFolder findByG_N(long groupId, String name)
3650                    throws NoSuchFolderException, SystemException {
3651                    JournalFolder journalFolder = fetchByG_N(groupId, name);
3652    
3653                    if (journalFolder == null) {
3654                            StringBundler msg = new StringBundler(6);
3655    
3656                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3657    
3658                            msg.append("groupId=");
3659                            msg.append(groupId);
3660    
3661                            msg.append(", name=");
3662                            msg.append(name);
3663    
3664                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3665    
3666                            if (_log.isWarnEnabled()) {
3667                                    _log.warn(msg.toString());
3668                            }
3669    
3670                            throw new NoSuchFolderException(msg.toString());
3671                    }
3672    
3673                    return journalFolder;
3674            }
3675    
3676            /**
3677             * 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.
3678             *
3679             * @param groupId the group ID
3680             * @param name the name
3681             * @return the matching journal folder, or <code>null</code> if a matching journal folder could not be found
3682             * @throws SystemException if a system exception occurred
3683             */
3684            public JournalFolder fetchByG_N(long groupId, String name)
3685                    throws SystemException {
3686                    return fetchByG_N(groupId, name, true);
3687            }
3688    
3689            /**
3690             * 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.
3691             *
3692             * @param groupId the group ID
3693             * @param name the name
3694             * @param retrieveFromCache whether to use the finder cache
3695             * @return the matching journal folder, or <code>null</code> if a matching journal folder could not be found
3696             * @throws SystemException if a system exception occurred
3697             */
3698            public JournalFolder fetchByG_N(long groupId, String name,
3699                    boolean retrieveFromCache) throws SystemException {
3700                    Object[] finderArgs = new Object[] { groupId, name };
3701    
3702                    Object result = null;
3703    
3704                    if (retrieveFromCache) {
3705                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_N,
3706                                            finderArgs, this);
3707                    }
3708    
3709                    if (result instanceof JournalFolder) {
3710                            JournalFolder journalFolder = (JournalFolder)result;
3711    
3712                            if ((groupId != journalFolder.getGroupId()) ||
3713                                            !Validator.equals(name, journalFolder.getName())) {
3714                                    result = null;
3715                            }
3716                    }
3717    
3718                    if (result == null) {
3719                            StringBundler query = new StringBundler(4);
3720    
3721                            query.append(_SQL_SELECT_JOURNALFOLDER_WHERE);
3722    
3723                            query.append(_FINDER_COLUMN_G_N_GROUPID_2);
3724    
3725                            if (name == null) {
3726                                    query.append(_FINDER_COLUMN_G_N_NAME_1);
3727                            }
3728                            else {
3729                                    if (name.equals(StringPool.BLANK)) {
3730                                            query.append(_FINDER_COLUMN_G_N_NAME_3);
3731                                    }
3732                                    else {
3733                                            query.append(_FINDER_COLUMN_G_N_NAME_2);
3734                                    }
3735                            }
3736    
3737                            String sql = query.toString();
3738    
3739                            Session session = null;
3740    
3741                            try {
3742                                    session = openSession();
3743    
3744                                    Query q = session.createQuery(sql);
3745    
3746                                    QueryPos qPos = QueryPos.getInstance(q);
3747    
3748                                    qPos.add(groupId);
3749    
3750                                    if (name != null) {
3751                                            qPos.add(name);
3752                                    }
3753    
3754                                    List<JournalFolder> list = q.list();
3755    
3756                                    if (list.isEmpty()) {
3757                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
3758                                                    finderArgs, list);
3759                                    }
3760                                    else {
3761                                            if ((list.size() > 1) && _log.isWarnEnabled()) {
3762                                                    _log.warn(
3763                                                            "JournalFolderPersistenceImpl.fetchByG_N(long, String, boolean) with parameters (" +
3764                                                            StringUtil.merge(finderArgs) +
3765                                                            ") 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.");
3766                                            }
3767    
3768                                            JournalFolder journalFolder = list.get(0);
3769    
3770                                            result = journalFolder;
3771    
3772                                            cacheResult(journalFolder);
3773    
3774                                            if ((journalFolder.getGroupId() != groupId) ||
3775                                                            (journalFolder.getName() == null) ||
3776                                                            !journalFolder.getName().equals(name)) {
3777                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
3778                                                            finderArgs, journalFolder);
3779                                            }
3780                                    }
3781                            }
3782                            catch (Exception e) {
3783                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N,
3784                                            finderArgs);
3785    
3786                                    throw processException(e);
3787                            }
3788                            finally {
3789                                    closeSession(session);
3790                            }
3791                    }
3792    
3793                    if (result instanceof List<?>) {
3794                            return null;
3795                    }
3796                    else {
3797                            return (JournalFolder)result;
3798                    }
3799            }
3800    
3801            /**
3802             * Removes the journal folder where groupId = &#63; and name = &#63; from the database.
3803             *
3804             * @param groupId the group ID
3805             * @param name the name
3806             * @return the journal folder that was removed
3807             * @throws SystemException if a system exception occurred
3808             */
3809            public JournalFolder removeByG_N(long groupId, String name)
3810                    throws NoSuchFolderException, SystemException {
3811                    JournalFolder journalFolder = findByG_N(groupId, name);
3812    
3813                    return remove(journalFolder);
3814            }
3815    
3816            /**
3817             * Returns the number of journal folders where groupId = &#63; and name = &#63;.
3818             *
3819             * @param groupId the group ID
3820             * @param name the name
3821             * @return the number of matching journal folders
3822             * @throws SystemException if a system exception occurred
3823             */
3824            public int countByG_N(long groupId, String name) throws SystemException {
3825                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_N;
3826    
3827                    Object[] finderArgs = new Object[] { groupId, name };
3828    
3829                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3830                                    this);
3831    
3832                    if (count == null) {
3833                            StringBundler query = new StringBundler(3);
3834    
3835                            query.append(_SQL_COUNT_JOURNALFOLDER_WHERE);
3836    
3837                            query.append(_FINDER_COLUMN_G_N_GROUPID_2);
3838    
3839                            if (name == null) {
3840                                    query.append(_FINDER_COLUMN_G_N_NAME_1);
3841                            }
3842                            else {
3843                                    if (name.equals(StringPool.BLANK)) {
3844                                            query.append(_FINDER_COLUMN_G_N_NAME_3);
3845                                    }
3846                                    else {
3847                                            query.append(_FINDER_COLUMN_G_N_NAME_2);
3848                                    }
3849                            }
3850    
3851                            String sql = query.toString();
3852    
3853                            Session session = null;
3854    
3855                            try {
3856                                    session = openSession();
3857    
3858                                    Query q = session.createQuery(sql);
3859    
3860                                    QueryPos qPos = QueryPos.getInstance(q);
3861    
3862                                    qPos.add(groupId);
3863    
3864                                    if (name != null) {
3865                                            qPos.add(name);
3866                                    }
3867    
3868                                    count = (Long)q.uniqueResult();
3869    
3870                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3871                            }
3872                            catch (Exception e) {
3873                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3874    
3875                                    throw processException(e);
3876                            }
3877                            finally {
3878                                    closeSession(session);
3879                            }
3880                    }
3881    
3882                    return count.intValue();
3883            }
3884    
3885            private static final String _FINDER_COLUMN_G_N_GROUPID_2 = "journalFolder.groupId = ? AND ";
3886            private static final String _FINDER_COLUMN_G_N_NAME_1 = "journalFolder.name IS NULL";
3887            private static final String _FINDER_COLUMN_G_N_NAME_2 = "journalFolder.name = ?";
3888            private static final String _FINDER_COLUMN_G_N_NAME_3 = "(journalFolder.name IS NULL OR journalFolder.name = ?)";
3889            public static final FinderPath FINDER_PATH_FETCH_BY_G_P_N = new FinderPath(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
3890                            JournalFolderModelImpl.FINDER_CACHE_ENABLED,
3891                            JournalFolderImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByG_P_N",
3892                            new String[] {
3893                                    Long.class.getName(), Long.class.getName(),
3894                                    String.class.getName()
3895                            },
3896                            JournalFolderModelImpl.GROUPID_COLUMN_BITMASK |
3897                            JournalFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
3898                            JournalFolderModelImpl.NAME_COLUMN_BITMASK);
3899            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_N = new FinderPath(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
3900                            JournalFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
3901                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_N",
3902                            new String[] {
3903                                    Long.class.getName(), Long.class.getName(),
3904                                    String.class.getName()
3905                            });
3906    
3907            /**
3908             * Returns the journal folder where groupId = &#63; and parentFolderId = &#63; and name = &#63; or throws a {@link com.liferay.portlet.journal.NoSuchFolderException} if it could not be found.
3909             *
3910             * @param groupId the group ID
3911             * @param parentFolderId the parent folder ID
3912             * @param name the name
3913             * @return the matching journal folder
3914             * @throws com.liferay.portlet.journal.NoSuchFolderException if a matching journal folder could not be found
3915             * @throws SystemException if a system exception occurred
3916             */
3917            public JournalFolder findByG_P_N(long groupId, long parentFolderId,
3918                    String name) throws NoSuchFolderException, SystemException {
3919                    JournalFolder journalFolder = fetchByG_P_N(groupId, parentFolderId, name);
3920    
3921                    if (journalFolder == null) {
3922                            StringBundler msg = new StringBundler(8);
3923    
3924                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3925    
3926                            msg.append("groupId=");
3927                            msg.append(groupId);
3928    
3929                            msg.append(", parentFolderId=");
3930                            msg.append(parentFolderId);
3931    
3932                            msg.append(", name=");
3933                            msg.append(name);
3934    
3935                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3936    
3937                            if (_log.isWarnEnabled()) {
3938                                    _log.warn(msg.toString());
3939                            }
3940    
3941                            throw new NoSuchFolderException(msg.toString());
3942                    }
3943    
3944                    return journalFolder;
3945            }
3946    
3947            /**
3948             * 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.
3949             *
3950             * @param groupId the group ID
3951             * @param parentFolderId the parent folder ID
3952             * @param name the name
3953             * @return the matching journal folder, or <code>null</code> if a matching journal folder could not be found
3954             * @throws SystemException if a system exception occurred
3955             */
3956            public JournalFolder fetchByG_P_N(long groupId, long parentFolderId,
3957                    String name) throws SystemException {
3958                    return fetchByG_P_N(groupId, parentFolderId, name, true);
3959            }
3960    
3961            /**
3962             * 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.
3963             *
3964             * @param groupId the group ID
3965             * @param parentFolderId the parent folder ID
3966             * @param name the name
3967             * @param retrieveFromCache whether to use the finder cache
3968             * @return the matching journal folder, or <code>null</code> if a matching journal folder could not be found
3969             * @throws SystemException if a system exception occurred
3970             */
3971            public JournalFolder fetchByG_P_N(long groupId, long parentFolderId,
3972                    String name, boolean retrieveFromCache) throws SystemException {
3973                    Object[] finderArgs = new Object[] { groupId, parentFolderId, name };
3974    
3975                    Object result = null;
3976    
3977                    if (retrieveFromCache) {
3978                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_P_N,
3979                                            finderArgs, this);
3980                    }
3981    
3982                    if (result instanceof JournalFolder) {
3983                            JournalFolder journalFolder = (JournalFolder)result;
3984    
3985                            if ((groupId != journalFolder.getGroupId()) ||
3986                                            (parentFolderId != journalFolder.getParentFolderId()) ||
3987                                            !Validator.equals(name, journalFolder.getName())) {
3988                                    result = null;
3989                            }
3990                    }
3991    
3992                    if (result == null) {
3993                            StringBundler query = new StringBundler(5);
3994    
3995                            query.append(_SQL_SELECT_JOURNALFOLDER_WHERE);
3996    
3997                            query.append(_FINDER_COLUMN_G_P_N_GROUPID_2);
3998    
3999                            query.append(_FINDER_COLUMN_G_P_N_PARENTFOLDERID_2);
4000    
4001                            if (name == null) {
4002                                    query.append(_FINDER_COLUMN_G_P_N_NAME_1);
4003                            }
4004                            else {
4005                                    if (name.equals(StringPool.BLANK)) {
4006                                            query.append(_FINDER_COLUMN_G_P_N_NAME_3);
4007                                    }
4008                                    else {
4009                                            query.append(_FINDER_COLUMN_G_P_N_NAME_2);
4010                                    }
4011                            }
4012    
4013                            String sql = query.toString();
4014    
4015                            Session session = null;
4016    
4017                            try {
4018                                    session = openSession();
4019    
4020                                    Query q = session.createQuery(sql);
4021    
4022                                    QueryPos qPos = QueryPos.getInstance(q);
4023    
4024                                    qPos.add(groupId);
4025    
4026                                    qPos.add(parentFolderId);
4027    
4028                                    if (name != null) {
4029                                            qPos.add(name);
4030                                    }
4031    
4032                                    List<JournalFolder> list = q.list();
4033    
4034                                    if (list.isEmpty()) {
4035                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N,
4036                                                    finderArgs, list);
4037                                    }
4038                                    else {
4039                                            JournalFolder journalFolder = list.get(0);
4040    
4041                                            result = journalFolder;
4042    
4043                                            cacheResult(journalFolder);
4044    
4045                                            if ((journalFolder.getGroupId() != groupId) ||
4046                                                            (journalFolder.getParentFolderId() != parentFolderId) ||
4047                                                            (journalFolder.getName() == null) ||
4048                                                            !journalFolder.getName().equals(name)) {
4049                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N,
4050                                                            finderArgs, journalFolder);
4051                                            }
4052                                    }
4053                            }
4054                            catch (Exception e) {
4055                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_N,
4056                                            finderArgs);
4057    
4058                                    throw processException(e);
4059                            }
4060                            finally {
4061                                    closeSession(session);
4062                            }
4063                    }
4064    
4065                    if (result instanceof List<?>) {
4066                            return null;
4067                    }
4068                    else {
4069                            return (JournalFolder)result;
4070                    }
4071            }
4072    
4073            /**
4074             * Removes the journal folder where groupId = &#63; and parentFolderId = &#63; and name = &#63; from the database.
4075             *
4076             * @param groupId the group ID
4077             * @param parentFolderId the parent folder ID
4078             * @param name the name
4079             * @return the journal folder that was removed
4080             * @throws SystemException if a system exception occurred
4081             */
4082            public JournalFolder removeByG_P_N(long groupId, long parentFolderId,
4083                    String name) throws NoSuchFolderException, SystemException {
4084                    JournalFolder journalFolder = findByG_P_N(groupId, parentFolderId, name);
4085    
4086                    return remove(journalFolder);
4087            }
4088    
4089            /**
4090             * Returns the number of journal folders where groupId = &#63; and parentFolderId = &#63; and name = &#63;.
4091             *
4092             * @param groupId the group ID
4093             * @param parentFolderId the parent folder ID
4094             * @param name the name
4095             * @return the number of matching journal folders
4096             * @throws SystemException if a system exception occurred
4097             */
4098            public int countByG_P_N(long groupId, long parentFolderId, String name)
4099                    throws SystemException {
4100                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_N;
4101    
4102                    Object[] finderArgs = new Object[] { groupId, parentFolderId, name };
4103    
4104                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4105                                    this);
4106    
4107                    if (count == null) {
4108                            StringBundler query = new StringBundler(4);
4109    
4110                            query.append(_SQL_COUNT_JOURNALFOLDER_WHERE);
4111    
4112                            query.append(_FINDER_COLUMN_G_P_N_GROUPID_2);
4113    
4114                            query.append(_FINDER_COLUMN_G_P_N_PARENTFOLDERID_2);
4115    
4116                            if (name == null) {
4117                                    query.append(_FINDER_COLUMN_G_P_N_NAME_1);
4118                            }
4119                            else {
4120                                    if (name.equals(StringPool.BLANK)) {
4121                                            query.append(_FINDER_COLUMN_G_P_N_NAME_3);
4122                                    }
4123                                    else {
4124                                            query.append(_FINDER_COLUMN_G_P_N_NAME_2);
4125                                    }
4126                            }
4127    
4128                            String sql = query.toString();
4129    
4130                            Session session = null;
4131    
4132                            try {
4133                                    session = openSession();
4134    
4135                                    Query q = session.createQuery(sql);
4136    
4137                                    QueryPos qPos = QueryPos.getInstance(q);
4138    
4139                                    qPos.add(groupId);
4140    
4141                                    qPos.add(parentFolderId);
4142    
4143                                    if (name != null) {
4144                                            qPos.add(name);
4145                                    }
4146    
4147                                    count = (Long)q.uniqueResult();
4148    
4149                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4150                            }
4151                            catch (Exception e) {
4152                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4153    
4154                                    throw processException(e);
4155                            }
4156                            finally {
4157                                    closeSession(session);
4158                            }
4159                    }
4160    
4161                    return count.intValue();
4162            }
4163    
4164            private static final String _FINDER_COLUMN_G_P_N_GROUPID_2 = "journalFolder.groupId = ? AND ";
4165            private static final String _FINDER_COLUMN_G_P_N_PARENTFOLDERID_2 = "journalFolder.parentFolderId = ? AND ";
4166            private static final String _FINDER_COLUMN_G_P_N_NAME_1 = "journalFolder.name IS NULL";
4167            private static final String _FINDER_COLUMN_G_P_N_NAME_2 = "journalFolder.name = ?";
4168            private static final String _FINDER_COLUMN_G_P_N_NAME_3 = "(journalFolder.name IS NULL OR journalFolder.name = ?)";
4169    
4170            /**
4171             * Caches the journal folder in the entity cache if it is enabled.
4172             *
4173             * @param journalFolder the journal folder
4174             */
4175            public void cacheResult(JournalFolder journalFolder) {
4176                    EntityCacheUtil.putResult(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
4177                            JournalFolderImpl.class, journalFolder.getPrimaryKey(),
4178                            journalFolder);
4179    
4180                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
4181                            new Object[] {
4182                                    journalFolder.getUuid(),
4183                                    Long.valueOf(journalFolder.getGroupId())
4184                            }, journalFolder);
4185    
4186                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
4187                            new Object[] {
4188                                    Long.valueOf(journalFolder.getGroupId()),
4189                                    
4190                            journalFolder.getName()
4191                            }, journalFolder);
4192    
4193                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N,
4194                            new Object[] {
4195                                    Long.valueOf(journalFolder.getGroupId()),
4196                                    Long.valueOf(journalFolder.getParentFolderId()),
4197                                    
4198                            journalFolder.getName()
4199                            }, journalFolder);
4200    
4201                    journalFolder.resetOriginalValues();
4202            }
4203    
4204            /**
4205             * Caches the journal folders in the entity cache if it is enabled.
4206             *
4207             * @param journalFolders the journal folders
4208             */
4209            public void cacheResult(List<JournalFolder> journalFolders) {
4210                    for (JournalFolder journalFolder : journalFolders) {
4211                            if (EntityCacheUtil.getResult(
4212                                                    JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
4213                                                    JournalFolderImpl.class, journalFolder.getPrimaryKey()) == null) {
4214                                    cacheResult(journalFolder);
4215                            }
4216                            else {
4217                                    journalFolder.resetOriginalValues();
4218                            }
4219                    }
4220            }
4221    
4222            /**
4223             * Clears the cache for all journal folders.
4224             *
4225             * <p>
4226             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
4227             * </p>
4228             */
4229            @Override
4230            public void clearCache() {
4231                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
4232                            CacheRegistryUtil.clear(JournalFolderImpl.class.getName());
4233                    }
4234    
4235                    EntityCacheUtil.clearCache(JournalFolderImpl.class.getName());
4236    
4237                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
4238                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4239                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4240            }
4241    
4242            /**
4243             * Clears the cache for the journal folder.
4244             *
4245             * <p>
4246             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
4247             * </p>
4248             */
4249            @Override
4250            public void clearCache(JournalFolder journalFolder) {
4251                    EntityCacheUtil.removeResult(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
4252                            JournalFolderImpl.class, journalFolder.getPrimaryKey());
4253    
4254                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4255                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4256    
4257                    clearUniqueFindersCache(journalFolder);
4258            }
4259    
4260            @Override
4261            public void clearCache(List<JournalFolder> journalFolders) {
4262                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4263                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4264    
4265                    for (JournalFolder journalFolder : journalFolders) {
4266                            EntityCacheUtil.removeResult(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
4267                                    JournalFolderImpl.class, journalFolder.getPrimaryKey());
4268    
4269                            clearUniqueFindersCache(journalFolder);
4270                    }
4271            }
4272    
4273            protected void cacheUniqueFindersCache(JournalFolder journalFolder) {
4274                    if (journalFolder.isNew()) {
4275                            Object[] args = new Object[] {
4276                                            journalFolder.getUuid(),
4277                                            Long.valueOf(journalFolder.getGroupId())
4278                                    };
4279    
4280                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
4281                                    Long.valueOf(1));
4282                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
4283                                    journalFolder);
4284    
4285                            args = new Object[] {
4286                                            Long.valueOf(journalFolder.getGroupId()),
4287                                            
4288                                            journalFolder.getName()
4289                                    };
4290    
4291                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N, args,
4292                                    Long.valueOf(1));
4293                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N, args,
4294                                    journalFolder);
4295    
4296                            args = new Object[] {
4297                                            Long.valueOf(journalFolder.getGroupId()),
4298                                            Long.valueOf(journalFolder.getParentFolderId()),
4299                                            
4300                                            journalFolder.getName()
4301                                    };
4302    
4303                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P_N, args,
4304                                    Long.valueOf(1));
4305                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N, args,
4306                                    journalFolder);
4307                    }
4308                    else {
4309                            JournalFolderModelImpl journalFolderModelImpl = (JournalFolderModelImpl)journalFolder;
4310    
4311                            if ((journalFolderModelImpl.getColumnBitmask() &
4312                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
4313                                    Object[] args = new Object[] {
4314                                                    journalFolder.getUuid(),
4315                                                    Long.valueOf(journalFolder.getGroupId())
4316                                            };
4317    
4318                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
4319                                            Long.valueOf(1));
4320                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
4321                                            journalFolder);
4322                            }
4323    
4324                            if ((journalFolderModelImpl.getColumnBitmask() &
4325                                            FINDER_PATH_FETCH_BY_G_N.getColumnBitmask()) != 0) {
4326                                    Object[] args = new Object[] {
4327                                                    Long.valueOf(journalFolder.getGroupId()),
4328                                                    
4329                                                    journalFolder.getName()
4330                                            };
4331    
4332                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N, args,
4333                                            Long.valueOf(1));
4334                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N, args,
4335                                            journalFolder);
4336                            }
4337    
4338                            if ((journalFolderModelImpl.getColumnBitmask() &
4339                                            FINDER_PATH_FETCH_BY_G_P_N.getColumnBitmask()) != 0) {
4340                                    Object[] args = new Object[] {
4341                                                    Long.valueOf(journalFolder.getGroupId()),
4342                                                    Long.valueOf(journalFolder.getParentFolderId()),
4343                                                    
4344                                                    journalFolder.getName()
4345                                            };
4346    
4347                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P_N, args,
4348                                            Long.valueOf(1));
4349                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N, args,
4350                                            journalFolder);
4351                            }
4352                    }
4353            }
4354    
4355            protected void clearUniqueFindersCache(JournalFolder journalFolder) {
4356                    JournalFolderModelImpl journalFolderModelImpl = (JournalFolderModelImpl)journalFolder;
4357    
4358                    Object[] args = new Object[] {
4359                                    journalFolder.getUuid(),
4360                                    Long.valueOf(journalFolder.getGroupId())
4361                            };
4362    
4363                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
4364                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
4365    
4366                    if ((journalFolderModelImpl.getColumnBitmask() &
4367                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
4368                            args = new Object[] {
4369                                            journalFolderModelImpl.getOriginalUuid(),
4370                                            Long.valueOf(journalFolderModelImpl.getOriginalGroupId())
4371                                    };
4372    
4373                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
4374                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
4375                    }
4376    
4377                    args = new Object[] {
4378                                    Long.valueOf(journalFolder.getGroupId()),
4379                                    
4380                                    journalFolder.getName()
4381                            };
4382    
4383                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N, args);
4384                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N, args);
4385    
4386                    if ((journalFolderModelImpl.getColumnBitmask() &
4387                                    FINDER_PATH_FETCH_BY_G_N.getColumnBitmask()) != 0) {
4388                            args = new Object[] {
4389                                            Long.valueOf(journalFolderModelImpl.getOriginalGroupId()),
4390                                            
4391                                            journalFolderModelImpl.getOriginalName()
4392                                    };
4393    
4394                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N, args);
4395                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N, args);
4396                    }
4397    
4398                    args = new Object[] {
4399                                    Long.valueOf(journalFolder.getGroupId()),
4400                                    Long.valueOf(journalFolder.getParentFolderId()),
4401                                    
4402                                    journalFolder.getName()
4403                            };
4404    
4405                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_N, args);
4406                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_N, args);
4407    
4408                    if ((journalFolderModelImpl.getColumnBitmask() &
4409                                    FINDER_PATH_FETCH_BY_G_P_N.getColumnBitmask()) != 0) {
4410                            args = new Object[] {
4411                                            Long.valueOf(journalFolderModelImpl.getOriginalGroupId()),
4412                                            Long.valueOf(journalFolderModelImpl.getOriginalParentFolderId()),
4413                                            
4414                                            journalFolderModelImpl.getOriginalName()
4415                                    };
4416    
4417                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_N, args);
4418                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_N, args);
4419                    }
4420            }
4421    
4422            /**
4423             * Creates a new journal folder with the primary key. Does not add the journal folder to the database.
4424             *
4425             * @param folderId the primary key for the new journal folder
4426             * @return the new journal folder
4427             */
4428            public JournalFolder create(long folderId) {
4429                    JournalFolder journalFolder = new JournalFolderImpl();
4430    
4431                    journalFolder.setNew(true);
4432                    journalFolder.setPrimaryKey(folderId);
4433    
4434                    String uuid = PortalUUIDUtil.generate();
4435    
4436                    journalFolder.setUuid(uuid);
4437    
4438                    return journalFolder;
4439            }
4440    
4441            /**
4442             * Removes the journal folder with the primary key from the database. Also notifies the appropriate model listeners.
4443             *
4444             * @param folderId the primary key of the journal folder
4445             * @return the journal folder that was removed
4446             * @throws com.liferay.portlet.journal.NoSuchFolderException if a journal folder with the primary key could not be found
4447             * @throws SystemException if a system exception occurred
4448             */
4449            public JournalFolder remove(long folderId)
4450                    throws NoSuchFolderException, SystemException {
4451                    return remove(Long.valueOf(folderId));
4452            }
4453    
4454            /**
4455             * Removes the journal folder with the primary key from the database. Also notifies the appropriate model listeners.
4456             *
4457             * @param primaryKey the primary key of the journal folder
4458             * @return the journal folder that was removed
4459             * @throws com.liferay.portlet.journal.NoSuchFolderException if a journal folder with the primary key could not be found
4460             * @throws SystemException if a system exception occurred
4461             */
4462            @Override
4463            public JournalFolder remove(Serializable primaryKey)
4464                    throws NoSuchFolderException, SystemException {
4465                    Session session = null;
4466    
4467                    try {
4468                            session = openSession();
4469    
4470                            JournalFolder journalFolder = (JournalFolder)session.get(JournalFolderImpl.class,
4471                                            primaryKey);
4472    
4473                            if (journalFolder == null) {
4474                                    if (_log.isWarnEnabled()) {
4475                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
4476                                    }
4477    
4478                                    throw new NoSuchFolderException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
4479                                            primaryKey);
4480                            }
4481    
4482                            return remove(journalFolder);
4483                    }
4484                    catch (NoSuchFolderException nsee) {
4485                            throw nsee;
4486                    }
4487                    catch (Exception e) {
4488                            throw processException(e);
4489                    }
4490                    finally {
4491                            closeSession(session);
4492                    }
4493            }
4494    
4495            @Override
4496            protected JournalFolder removeImpl(JournalFolder journalFolder)
4497                    throws SystemException {
4498                    journalFolder = toUnwrappedModel(journalFolder);
4499    
4500                    Session session = null;
4501    
4502                    try {
4503                            session = openSession();
4504    
4505                            if (!session.contains(journalFolder)) {
4506                                    journalFolder = (JournalFolder)session.get(JournalFolderImpl.class,
4507                                                    journalFolder.getPrimaryKeyObj());
4508                            }
4509    
4510                            if (journalFolder != null) {
4511                                    session.delete(journalFolder);
4512                            }
4513                    }
4514                    catch (Exception e) {
4515                            throw processException(e);
4516                    }
4517                    finally {
4518                            closeSession(session);
4519                    }
4520    
4521                    if (journalFolder != null) {
4522                            clearCache(journalFolder);
4523                    }
4524    
4525                    return journalFolder;
4526            }
4527    
4528            @Override
4529            public JournalFolder updateImpl(
4530                    com.liferay.portlet.journal.model.JournalFolder journalFolder)
4531                    throws SystemException {
4532                    journalFolder = toUnwrappedModel(journalFolder);
4533    
4534                    boolean isNew = journalFolder.isNew();
4535    
4536                    JournalFolderModelImpl journalFolderModelImpl = (JournalFolderModelImpl)journalFolder;
4537    
4538                    if (Validator.isNull(journalFolder.getUuid())) {
4539                            String uuid = PortalUUIDUtil.generate();
4540    
4541                            journalFolder.setUuid(uuid);
4542                    }
4543    
4544                    Session session = null;
4545    
4546                    try {
4547                            session = openSession();
4548    
4549                            if (journalFolder.isNew()) {
4550                                    session.save(journalFolder);
4551    
4552                                    journalFolder.setNew(false);
4553                            }
4554                            else {
4555                                    session.merge(journalFolder);
4556                            }
4557                    }
4558                    catch (Exception e) {
4559                            throw processException(e);
4560                    }
4561                    finally {
4562                            closeSession(session);
4563                    }
4564    
4565                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4566    
4567                    if (isNew || !JournalFolderModelImpl.COLUMN_BITMASK_ENABLED) {
4568                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4569                    }
4570    
4571                    else {
4572                            if ((journalFolderModelImpl.getColumnBitmask() &
4573                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
4574                                    Object[] args = new Object[] {
4575                                                    journalFolderModelImpl.getOriginalUuid()
4576                                            };
4577    
4578                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
4579                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
4580                                            args);
4581    
4582                                    args = new Object[] { journalFolderModelImpl.getUuid() };
4583    
4584                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
4585                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
4586                                            args);
4587                            }
4588    
4589                            if ((journalFolderModelImpl.getColumnBitmask() &
4590                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
4591                                    Object[] args = new Object[] {
4592                                                    journalFolderModelImpl.getOriginalUuid(),
4593                                                    Long.valueOf(journalFolderModelImpl.getOriginalCompanyId())
4594                                            };
4595    
4596                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
4597                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
4598                                            args);
4599    
4600                                    args = new Object[] {
4601                                                    journalFolderModelImpl.getUuid(),
4602                                                    Long.valueOf(journalFolderModelImpl.getCompanyId())
4603                                            };
4604    
4605                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
4606                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
4607                                            args);
4608                            }
4609    
4610                            if ((journalFolderModelImpl.getColumnBitmask() &
4611                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
4612                                    Object[] args = new Object[] {
4613                                                    Long.valueOf(journalFolderModelImpl.getOriginalGroupId())
4614                                            };
4615    
4616                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
4617                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
4618                                            args);
4619    
4620                                    args = new Object[] {
4621                                                    Long.valueOf(journalFolderModelImpl.getGroupId())
4622                                            };
4623    
4624                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
4625                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
4626                                            args);
4627                            }
4628    
4629                            if ((journalFolderModelImpl.getColumnBitmask() &
4630                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
4631                                    Object[] args = new Object[] {
4632                                                    Long.valueOf(journalFolderModelImpl.getOriginalCompanyId())
4633                                            };
4634    
4635                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
4636                                            args);
4637                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
4638                                            args);
4639    
4640                                    args = new Object[] {
4641                                                    Long.valueOf(journalFolderModelImpl.getCompanyId())
4642                                            };
4643    
4644                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
4645                                            args);
4646                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
4647                                            args);
4648                            }
4649    
4650                            if ((journalFolderModelImpl.getColumnBitmask() &
4651                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P.getColumnBitmask()) != 0) {
4652                                    Object[] args = new Object[] {
4653                                                    Long.valueOf(journalFolderModelImpl.getOriginalGroupId()),
4654                                                    Long.valueOf(journalFolderModelImpl.getOriginalParentFolderId())
4655                                            };
4656    
4657                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
4658                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
4659                                            args);
4660    
4661                                    args = new Object[] {
4662                                                    Long.valueOf(journalFolderModelImpl.getGroupId()),
4663                                                    Long.valueOf(journalFolderModelImpl.getParentFolderId())
4664                                            };
4665    
4666                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
4667                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
4668                                            args);
4669                            }
4670                    }
4671    
4672                    EntityCacheUtil.putResult(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
4673                            JournalFolderImpl.class, journalFolder.getPrimaryKey(),
4674                            journalFolder);
4675    
4676                    clearUniqueFindersCache(journalFolder);
4677                    cacheUniqueFindersCache(journalFolder);
4678    
4679                    return journalFolder;
4680            }
4681    
4682            protected JournalFolder toUnwrappedModel(JournalFolder journalFolder) {
4683                    if (journalFolder instanceof JournalFolderImpl) {
4684                            return journalFolder;
4685                    }
4686    
4687                    JournalFolderImpl journalFolderImpl = new JournalFolderImpl();
4688    
4689                    journalFolderImpl.setNew(journalFolder.isNew());
4690                    journalFolderImpl.setPrimaryKey(journalFolder.getPrimaryKey());
4691    
4692                    journalFolderImpl.setUuid(journalFolder.getUuid());
4693                    journalFolderImpl.setFolderId(journalFolder.getFolderId());
4694                    journalFolderImpl.setGroupId(journalFolder.getGroupId());
4695                    journalFolderImpl.setCompanyId(journalFolder.getCompanyId());
4696                    journalFolderImpl.setUserId(journalFolder.getUserId());
4697                    journalFolderImpl.setUserName(journalFolder.getUserName());
4698                    journalFolderImpl.setCreateDate(journalFolder.getCreateDate());
4699                    journalFolderImpl.setModifiedDate(journalFolder.getModifiedDate());
4700                    journalFolderImpl.setParentFolderId(journalFolder.getParentFolderId());
4701                    journalFolderImpl.setName(journalFolder.getName());
4702                    journalFolderImpl.setDescription(journalFolder.getDescription());
4703    
4704                    return journalFolderImpl;
4705            }
4706    
4707            /**
4708             * Returns the journal folder with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
4709             *
4710             * @param primaryKey the primary key of the journal folder
4711             * @return the journal folder
4712             * @throws com.liferay.portal.NoSuchModelException if a journal folder with the primary key could not be found
4713             * @throws SystemException if a system exception occurred
4714             */
4715            @Override
4716            public JournalFolder findByPrimaryKey(Serializable primaryKey)
4717                    throws NoSuchModelException, SystemException {
4718                    return findByPrimaryKey(((Long)primaryKey).longValue());
4719            }
4720    
4721            /**
4722             * Returns the journal folder with the primary key or throws a {@link com.liferay.portlet.journal.NoSuchFolderException} if it could not be found.
4723             *
4724             * @param folderId the primary key of the journal folder
4725             * @return the journal folder
4726             * @throws com.liferay.portlet.journal.NoSuchFolderException if a journal folder with the primary key could not be found
4727             * @throws SystemException if a system exception occurred
4728             */
4729            public JournalFolder findByPrimaryKey(long folderId)
4730                    throws NoSuchFolderException, SystemException {
4731                    JournalFolder journalFolder = fetchByPrimaryKey(folderId);
4732    
4733                    if (journalFolder == null) {
4734                            if (_log.isWarnEnabled()) {
4735                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + folderId);
4736                            }
4737    
4738                            throw new NoSuchFolderException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
4739                                    folderId);
4740                    }
4741    
4742                    return journalFolder;
4743            }
4744    
4745            /**
4746             * Returns the journal folder with the primary key or returns <code>null</code> if it could not be found.
4747             *
4748             * @param primaryKey the primary key of the journal folder
4749             * @return the journal folder, or <code>null</code> if a journal folder with the primary key could not be found
4750             * @throws SystemException if a system exception occurred
4751             */
4752            @Override
4753            public JournalFolder fetchByPrimaryKey(Serializable primaryKey)
4754                    throws SystemException {
4755                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
4756            }
4757    
4758            /**
4759             * Returns the journal folder with the primary key or returns <code>null</code> if it could not be found.
4760             *
4761             * @param folderId the primary key of the journal folder
4762             * @return the journal folder, or <code>null</code> if a journal folder with the primary key could not be found
4763             * @throws SystemException if a system exception occurred
4764             */
4765            public JournalFolder fetchByPrimaryKey(long folderId)
4766                    throws SystemException {
4767                    JournalFolder journalFolder = (JournalFolder)EntityCacheUtil.getResult(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
4768                                    JournalFolderImpl.class, folderId);
4769    
4770                    if (journalFolder == _nullJournalFolder) {
4771                            return null;
4772                    }
4773    
4774                    if (journalFolder == null) {
4775                            Session session = null;
4776    
4777                            try {
4778                                    session = openSession();
4779    
4780                                    journalFolder = (JournalFolder)session.get(JournalFolderImpl.class,
4781                                                    Long.valueOf(folderId));
4782    
4783                                    if (journalFolder != null) {
4784                                            cacheResult(journalFolder);
4785                                    }
4786                                    else {
4787                                            EntityCacheUtil.putResult(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
4788                                                    JournalFolderImpl.class, folderId, _nullJournalFolder);
4789                                    }
4790                            }
4791                            catch (Exception e) {
4792                                    EntityCacheUtil.removeResult(JournalFolderModelImpl.ENTITY_CACHE_ENABLED,
4793                                            JournalFolderImpl.class, folderId);
4794    
4795                                    throw processException(e);
4796                            }
4797                            finally {
4798                                    closeSession(session);
4799                            }
4800                    }
4801    
4802                    return journalFolder;
4803            }
4804    
4805            /**
4806             * Returns all the journal folders.
4807             *
4808             * @return the journal folders
4809             * @throws SystemException if a system exception occurred
4810             */
4811            public List<JournalFolder> findAll() throws SystemException {
4812                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4813            }
4814    
4815            /**
4816             * Returns a range of all the journal folders.
4817             *
4818             * <p>
4819             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4820             * </p>
4821             *
4822             * @param start the lower bound of the range of journal folders
4823             * @param end the upper bound of the range of journal folders (not inclusive)
4824             * @return the range of journal folders
4825             * @throws SystemException if a system exception occurred
4826             */
4827            public List<JournalFolder> findAll(int start, int end)
4828                    throws SystemException {
4829                    return findAll(start, end, null);
4830            }
4831    
4832            /**
4833             * Returns an ordered range of all the journal folders.
4834             *
4835             * <p>
4836             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalFolderModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4837             * </p>
4838             *
4839             * @param start the lower bound of the range of journal folders
4840             * @param end the upper bound of the range of journal folders (not inclusive)
4841             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4842             * @return the ordered range of journal folders
4843             * @throws SystemException if a system exception occurred
4844             */
4845            public List<JournalFolder> findAll(int start, int end,
4846                    OrderByComparator orderByComparator) throws SystemException {
4847                    boolean pagination = true;
4848                    FinderPath finderPath = null;
4849                    Object[] finderArgs = null;
4850    
4851                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4852                                    (orderByComparator == null)) {
4853                            pagination = false;
4854                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
4855                            finderArgs = FINDER_ARGS_EMPTY;
4856                    }
4857                    else {
4858                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
4859                            finderArgs = new Object[] { start, end, orderByComparator };
4860                    }
4861    
4862                    List<JournalFolder> list = (List<JournalFolder>)FinderCacheUtil.getResult(finderPath,
4863                                    finderArgs, this);
4864    
4865                    if (list == null) {
4866                            StringBundler query = null;
4867                            String sql = null;
4868    
4869                            if (orderByComparator != null) {
4870                                    query = new StringBundler(2 +
4871                                                    (orderByComparator.getOrderByFields().length * 3));
4872    
4873                                    query.append(_SQL_SELECT_JOURNALFOLDER);
4874    
4875                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4876                                            orderByComparator);
4877    
4878                                    sql = query.toString();
4879                            }
4880                            else {
4881                                    sql = _SQL_SELECT_JOURNALFOLDER;
4882    
4883                                    if (pagination) {
4884                                            sql = sql.concat(JournalFolderModelImpl.ORDER_BY_JPQL);
4885                                    }
4886                            }
4887    
4888                            Session session = null;
4889    
4890                            try {
4891                                    session = openSession();
4892    
4893                                    Query q = session.createQuery(sql);
4894    
4895                                    if (!pagination) {
4896                                            list = (List<JournalFolder>)QueryUtil.list(q, getDialect(),
4897                                                            start, end, false);
4898    
4899                                            Collections.sort(list);
4900    
4901                                            list = new UnmodifiableList<JournalFolder>(list);
4902                                    }
4903                                    else {
4904                                            list = (List<JournalFolder>)QueryUtil.list(q, getDialect(),
4905                                                            start, end);
4906                                    }
4907    
4908                                    cacheResult(list);
4909    
4910                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4911                            }
4912                            catch (Exception e) {
4913                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4914    
4915                                    throw processException(e);
4916                            }
4917                            finally {
4918                                    closeSession(session);
4919                            }
4920                    }
4921    
4922                    return list;
4923            }
4924    
4925            /**
4926             * Removes all the journal folders from the database.
4927             *
4928             * @throws SystemException if a system exception occurred
4929             */
4930            public void removeAll() throws SystemException {
4931                    for (JournalFolder journalFolder : findAll()) {
4932                            remove(journalFolder);
4933                    }
4934            }
4935    
4936            /**
4937             * Returns the number of journal folders.
4938             *
4939             * @return the number of journal folders
4940             * @throws SystemException if a system exception occurred
4941             */
4942            public int countAll() throws SystemException {
4943                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
4944                                    FINDER_ARGS_EMPTY, this);
4945    
4946                    if (count == null) {
4947                            Session session = null;
4948    
4949                            try {
4950                                    session = openSession();
4951    
4952                                    Query q = session.createQuery(_SQL_COUNT_JOURNALFOLDER);
4953    
4954                                    count = (Long)q.uniqueResult();
4955    
4956                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
4957                                            FINDER_ARGS_EMPTY, count);
4958                            }
4959                            catch (Exception e) {
4960                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
4961                                            FINDER_ARGS_EMPTY);
4962    
4963                                    throw processException(e);
4964                            }
4965                            finally {
4966                                    closeSession(session);
4967                            }
4968                    }
4969    
4970                    return count.intValue();
4971            }
4972    
4973            /**
4974             * Initializes the journal folder persistence.
4975             */
4976            public void afterPropertiesSet() {
4977                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
4978                                            com.liferay.portal.util.PropsUtil.get(
4979                                                    "value.object.listener.com.liferay.portlet.journal.model.JournalFolder")));
4980    
4981                    if (listenerClassNames.length > 0) {
4982                            try {
4983                                    List<ModelListener<JournalFolder>> listenersList = new ArrayList<ModelListener<JournalFolder>>();
4984    
4985                                    for (String listenerClassName : listenerClassNames) {
4986                                            listenersList.add((ModelListener<JournalFolder>)InstanceFactory.newInstance(
4987                                                            listenerClassName));
4988                                    }
4989    
4990                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
4991                            }
4992                            catch (Exception e) {
4993                                    _log.error(e);
4994                            }
4995                    }
4996            }
4997    
4998            public void destroy() {
4999                    EntityCacheUtil.removeCache(JournalFolderImpl.class.getName());
5000                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
5001                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
5002                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5003            }
5004    
5005            private static final String _SQL_SELECT_JOURNALFOLDER = "SELECT journalFolder FROM JournalFolder journalFolder";
5006            private static final String _SQL_SELECT_JOURNALFOLDER_WHERE = "SELECT journalFolder FROM JournalFolder journalFolder WHERE ";
5007            private static final String _SQL_COUNT_JOURNALFOLDER = "SELECT COUNT(journalFolder) FROM JournalFolder journalFolder";
5008            private static final String _SQL_COUNT_JOURNALFOLDER_WHERE = "SELECT COUNT(journalFolder) FROM JournalFolder journalFolder WHERE ";
5009            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "journalFolder.folderId";
5010            private static final String _FILTER_SQL_SELECT_JOURNALFOLDER_WHERE = "SELECT DISTINCT {journalFolder.*} FROM JournalFolder journalFolder WHERE ";
5011            private static final String _FILTER_SQL_SELECT_JOURNALFOLDER_NO_INLINE_DISTINCT_WHERE_1 =
5012                    "SELECT {JournalFolder.*} FROM (SELECT DISTINCT journalFolder.folderId FROM JournalFolder journalFolder WHERE ";
5013            private static final String _FILTER_SQL_SELECT_JOURNALFOLDER_NO_INLINE_DISTINCT_WHERE_2 =
5014                    ") TEMP_TABLE INNER JOIN JournalFolder ON TEMP_TABLE.folderId = JournalFolder.folderId";
5015            private static final String _FILTER_SQL_COUNT_JOURNALFOLDER_WHERE = "SELECT COUNT(DISTINCT journalFolder.folderId) AS COUNT_VALUE FROM JournalFolder journalFolder WHERE ";
5016            private static final String _FILTER_ENTITY_ALIAS = "journalFolder";
5017            private static final String _FILTER_ENTITY_TABLE = "JournalFolder";
5018            private static final String _ORDER_BY_ENTITY_ALIAS = "journalFolder.";
5019            private static final String _ORDER_BY_ENTITY_TABLE = "JournalFolder.";
5020            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No JournalFolder exists with the primary key ";
5021            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No JournalFolder exists with the key {";
5022            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
5023            private static Log _log = LogFactoryUtil.getLog(JournalFolderPersistenceImpl.class);
5024            private static JournalFolder _nullJournalFolder = new JournalFolderImpl() {
5025                            @Override
5026                            public Object clone() {
5027                                    return this;
5028                            }
5029    
5030                            @Override
5031                            public CacheModel<JournalFolder> toCacheModel() {
5032                                    return _nullJournalFolderCacheModel;
5033                            }
5034                    };
5035    
5036            private static CacheModel<JournalFolder> _nullJournalFolderCacheModel = new CacheModel<JournalFolder>() {
5037                            public JournalFolder toEntityModel() {
5038                                    return _nullJournalFolder;
5039                            }
5040                    };
5041    }