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