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