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