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_G_P_S = new FinderPath(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
4636                            BookmarksFolderModelImpl.FINDER_CACHE_ENABLED,
4637                            BookmarksFolderImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
4638                            "findByG_P_S",
4639                            new String[] {
4640                                    Long.class.getName(), Long.class.getName(),
4641                                    Integer.class.getName(),
4642                                    
4643                            Integer.class.getName(), Integer.class.getName(),
4644                                    OrderByComparator.class.getName()
4645                            });
4646            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_S = new FinderPath(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
4647                            BookmarksFolderModelImpl.FINDER_CACHE_ENABLED,
4648                            BookmarksFolderImpl.class,
4649                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P_S",
4650                            new String[] {
4651                                    Long.class.getName(), Long.class.getName(),
4652                                    Integer.class.getName()
4653                            },
4654                            BookmarksFolderModelImpl.GROUPID_COLUMN_BITMASK |
4655                            BookmarksFolderModelImpl.PARENTFOLDERID_COLUMN_BITMASK |
4656                            BookmarksFolderModelImpl.STATUS_COLUMN_BITMASK |
4657                            BookmarksFolderModelImpl.NAME_COLUMN_BITMASK);
4658            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_S = new FinderPath(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
4659                            BookmarksFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
4660                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_S",
4661                            new String[] {
4662                                    Long.class.getName(), Long.class.getName(),
4663                                    Integer.class.getName()
4664                            });
4665    
4666            /**
4667             * Returns all the bookmarks folders where groupId = &#63; and parentFolderId = &#63; and status = &#63;.
4668             *
4669             * @param groupId the group ID
4670             * @param parentFolderId the parent folder ID
4671             * @param status the status
4672             * @return the matching bookmarks folders
4673             * @throws SystemException if a system exception occurred
4674             */
4675            @Override
4676            public List<BookmarksFolder> findByG_P_S(long groupId, long parentFolderId,
4677                    int status) throws SystemException {
4678                    return findByG_P_S(groupId, parentFolderId, status, QueryUtil.ALL_POS,
4679                            QueryUtil.ALL_POS, null);
4680            }
4681    
4682            /**
4683             * Returns a range of all the bookmarks folders where groupId = &#63; and parentFolderId = &#63; and status = &#63;.
4684             *
4685             * <p>
4686             * 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.
4687             * </p>
4688             *
4689             * @param groupId the group ID
4690             * @param parentFolderId the parent folder ID
4691             * @param status the status
4692             * @param start the lower bound of the range of bookmarks folders
4693             * @param end the upper bound of the range of bookmarks folders (not inclusive)
4694             * @return the range of matching bookmarks folders
4695             * @throws SystemException if a system exception occurred
4696             */
4697            @Override
4698            public List<BookmarksFolder> findByG_P_S(long groupId, long parentFolderId,
4699                    int status, int start, int end) throws SystemException {
4700                    return findByG_P_S(groupId, parentFolderId, status, start, end, null);
4701            }
4702    
4703            /**
4704             * Returns an ordered range of all the bookmarks folders where groupId = &#63; and parentFolderId = &#63; and status = &#63;.
4705             *
4706             * <p>
4707             * 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.
4708             * </p>
4709             *
4710             * @param groupId the group ID
4711             * @param parentFolderId the parent folder ID
4712             * @param status the status
4713             * @param start the lower bound of the range of bookmarks folders
4714             * @param end the upper bound of the range of bookmarks folders (not inclusive)
4715             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4716             * @return the ordered range of matching bookmarks folders
4717             * @throws SystemException if a system exception occurred
4718             */
4719            @Override
4720            public List<BookmarksFolder> findByG_P_S(long groupId, long parentFolderId,
4721                    int status, int start, int end, OrderByComparator orderByComparator)
4722                    throws SystemException {
4723                    boolean pagination = true;
4724                    FinderPath finderPath = null;
4725                    Object[] finderArgs = null;
4726    
4727                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4728                                    (orderByComparator == null)) {
4729                            pagination = false;
4730                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_S;
4731                            finderArgs = new Object[] { groupId, parentFolderId, status };
4732                    }
4733                    else {
4734                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_S;
4735                            finderArgs = new Object[] {
4736                                            groupId, parentFolderId, status,
4737                                            
4738                                            start, end, orderByComparator
4739                                    };
4740                    }
4741    
4742                    List<BookmarksFolder> list = (List<BookmarksFolder>)FinderCacheUtil.getResult(finderPath,
4743                                    finderArgs, this);
4744    
4745                    if ((list != null) && !list.isEmpty()) {
4746                            for (BookmarksFolder bookmarksFolder : list) {
4747                                    if ((groupId != bookmarksFolder.getGroupId()) ||
4748                                                    (parentFolderId != bookmarksFolder.getParentFolderId()) ||
4749                                                    (status != bookmarksFolder.getStatus())) {
4750                                            list = null;
4751    
4752                                            break;
4753                                    }
4754                            }
4755                    }
4756    
4757                    if (list == null) {
4758                            StringBundler query = null;
4759    
4760                            if (orderByComparator != null) {
4761                                    query = new StringBundler(5 +
4762                                                    (orderByComparator.getOrderByFields().length * 3));
4763                            }
4764                            else {
4765                                    query = new StringBundler(5);
4766                            }
4767    
4768                            query.append(_SQL_SELECT_BOOKMARKSFOLDER_WHERE);
4769    
4770                            query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
4771    
4772                            query.append(_FINDER_COLUMN_G_P_S_PARENTFOLDERID_2);
4773    
4774                            query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
4775    
4776                            if (orderByComparator != null) {
4777                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4778                                            orderByComparator);
4779                            }
4780                            else
4781                             if (pagination) {
4782                                    query.append(BookmarksFolderModelImpl.ORDER_BY_JPQL);
4783                            }
4784    
4785                            String sql = query.toString();
4786    
4787                            Session session = null;
4788    
4789                            try {
4790                                    session = openSession();
4791    
4792                                    Query q = session.createQuery(sql);
4793    
4794                                    QueryPos qPos = QueryPos.getInstance(q);
4795    
4796                                    qPos.add(groupId);
4797    
4798                                    qPos.add(parentFolderId);
4799    
4800                                    qPos.add(status);
4801    
4802                                    if (!pagination) {
4803                                            list = (List<BookmarksFolder>)QueryUtil.list(q,
4804                                                            getDialect(), start, end, false);
4805    
4806                                            Collections.sort(list);
4807    
4808                                            list = new UnmodifiableList<BookmarksFolder>(list);
4809                                    }
4810                                    else {
4811                                            list = (List<BookmarksFolder>)QueryUtil.list(q,
4812                                                            getDialect(), start, end);
4813                                    }
4814    
4815                                    cacheResult(list);
4816    
4817                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4818                            }
4819                            catch (Exception e) {
4820                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4821    
4822                                    throw processException(e);
4823                            }
4824                            finally {
4825                                    closeSession(session);
4826                            }
4827                    }
4828    
4829                    return list;
4830            }
4831    
4832            /**
4833             * Returns the first bookmarks folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and status = &#63;.
4834             *
4835             * @param groupId the group ID
4836             * @param parentFolderId the parent folder ID
4837             * @param status the status
4838             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4839             * @return the first matching bookmarks folder
4840             * @throws com.liferay.portlet.bookmarks.NoSuchFolderException if a matching bookmarks folder could not be found
4841             * @throws SystemException if a system exception occurred
4842             */
4843            @Override
4844            public BookmarksFolder findByG_P_S_First(long groupId, long parentFolderId,
4845                    int status, OrderByComparator orderByComparator)
4846                    throws NoSuchFolderException, SystemException {
4847                    BookmarksFolder bookmarksFolder = fetchByG_P_S_First(groupId,
4848                                    parentFolderId, status, orderByComparator);
4849    
4850                    if (bookmarksFolder != null) {
4851                            return bookmarksFolder;
4852                    }
4853    
4854                    StringBundler msg = new StringBundler(8);
4855    
4856                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4857    
4858                    msg.append("groupId=");
4859                    msg.append(groupId);
4860    
4861                    msg.append(", parentFolderId=");
4862                    msg.append(parentFolderId);
4863    
4864                    msg.append(", status=");
4865                    msg.append(status);
4866    
4867                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4868    
4869                    throw new NoSuchFolderException(msg.toString());
4870            }
4871    
4872            /**
4873             * Returns the first bookmarks folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and status = &#63;.
4874             *
4875             * @param groupId the group ID
4876             * @param parentFolderId the parent folder ID
4877             * @param status the status
4878             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4879             * @return the first matching bookmarks folder, or <code>null</code> if a matching bookmarks folder could not be found
4880             * @throws SystemException if a system exception occurred
4881             */
4882            @Override
4883            public BookmarksFolder fetchByG_P_S_First(long groupId,
4884                    long parentFolderId, int status, OrderByComparator orderByComparator)
4885                    throws SystemException {
4886                    List<BookmarksFolder> list = findByG_P_S(groupId, parentFolderId,
4887                                    status, 0, 1, orderByComparator);
4888    
4889                    if (!list.isEmpty()) {
4890                            return list.get(0);
4891                    }
4892    
4893                    return null;
4894            }
4895    
4896            /**
4897             * Returns the last bookmarks folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and status = &#63;.
4898             *
4899             * @param groupId the group 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 findByG_P_S_Last(long groupId, long parentFolderId,
4909                    int status, OrderByComparator orderByComparator)
4910                    throws NoSuchFolderException, SystemException {
4911                    BookmarksFolder bookmarksFolder = fetchByG_P_S_Last(groupId,
4912                                    parentFolderId, status, orderByComparator);
4913    
4914                    if (bookmarksFolder != null) {
4915                            return bookmarksFolder;
4916                    }
4917    
4918                    StringBundler msg = new StringBundler(8);
4919    
4920                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4921    
4922                    msg.append("groupId=");
4923                    msg.append(groupId);
4924    
4925                    msg.append(", parentFolderId=");
4926                    msg.append(parentFolderId);
4927    
4928                    msg.append(", status=");
4929                    msg.append(status);
4930    
4931                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4932    
4933                    throw new NoSuchFolderException(msg.toString());
4934            }
4935    
4936            /**
4937             * Returns the last bookmarks folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and status = &#63;.
4938             *
4939             * @param groupId the group ID
4940             * @param parentFolderId the parent folder ID
4941             * @param status the status
4942             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4943             * @return the last matching bookmarks folder, or <code>null</code> if a matching bookmarks folder could not be found
4944             * @throws SystemException if a system exception occurred
4945             */
4946            @Override
4947            public BookmarksFolder fetchByG_P_S_Last(long groupId, long parentFolderId,
4948                    int status, OrderByComparator orderByComparator)
4949                    throws SystemException {
4950                    int count = countByG_P_S(groupId, parentFolderId, status);
4951    
4952                    if (count == 0) {
4953                            return null;
4954                    }
4955    
4956                    List<BookmarksFolder> list = findByG_P_S(groupId, parentFolderId,
4957                                    status, count - 1, count, orderByComparator);
4958    
4959                    if (!list.isEmpty()) {
4960                            return list.get(0);
4961                    }
4962    
4963                    return null;
4964            }
4965    
4966            /**
4967             * Returns the bookmarks folders before and after the current bookmarks folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and status = &#63;.
4968             *
4969             * @param folderId the primary key of the current bookmarks folder
4970             * @param groupId the group ID
4971             * @param parentFolderId the parent folder ID
4972             * @param status the status
4973             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4974             * @return the previous, current, and next bookmarks folder
4975             * @throws com.liferay.portlet.bookmarks.NoSuchFolderException if a bookmarks folder with the primary key could not be found
4976             * @throws SystemException if a system exception occurred
4977             */
4978            @Override
4979            public BookmarksFolder[] findByG_P_S_PrevAndNext(long folderId,
4980                    long groupId, long parentFolderId, int status,
4981                    OrderByComparator orderByComparator)
4982                    throws NoSuchFolderException, SystemException {
4983                    BookmarksFolder bookmarksFolder = findByPrimaryKey(folderId);
4984    
4985                    Session session = null;
4986    
4987                    try {
4988                            session = openSession();
4989    
4990                            BookmarksFolder[] array = new BookmarksFolderImpl[3];
4991    
4992                            array[0] = getByG_P_S_PrevAndNext(session, bookmarksFolder,
4993                                            groupId, parentFolderId, status, orderByComparator, true);
4994    
4995                            array[1] = bookmarksFolder;
4996    
4997                            array[2] = getByG_P_S_PrevAndNext(session, bookmarksFolder,
4998                                            groupId, parentFolderId, status, orderByComparator, false);
4999    
5000                            return array;
5001                    }
5002                    catch (Exception e) {
5003                            throw processException(e);
5004                    }
5005                    finally {
5006                            closeSession(session);
5007                    }
5008            }
5009    
5010            protected BookmarksFolder getByG_P_S_PrevAndNext(Session session,
5011                    BookmarksFolder bookmarksFolder, long groupId, long parentFolderId,
5012                    int status, OrderByComparator orderByComparator, boolean previous) {
5013                    StringBundler query = null;
5014    
5015                    if (orderByComparator != null) {
5016                            query = new StringBundler(6 +
5017                                            (orderByComparator.getOrderByFields().length * 6));
5018                    }
5019                    else {
5020                            query = new StringBundler(3);
5021                    }
5022    
5023                    query.append(_SQL_SELECT_BOOKMARKSFOLDER_WHERE);
5024    
5025                    query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
5026    
5027                    query.append(_FINDER_COLUMN_G_P_S_PARENTFOLDERID_2);
5028    
5029                    query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
5030    
5031                    if (orderByComparator != null) {
5032                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5033    
5034                            if (orderByConditionFields.length > 0) {
5035                                    query.append(WHERE_AND);
5036                            }
5037    
5038                            for (int i = 0; i < orderByConditionFields.length; i++) {
5039                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5040                                    query.append(orderByConditionFields[i]);
5041    
5042                                    if ((i + 1) < orderByConditionFields.length) {
5043                                            if (orderByComparator.isAscending() ^ previous) {
5044                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5045                                            }
5046                                            else {
5047                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5048                                            }
5049                                    }
5050                                    else {
5051                                            if (orderByComparator.isAscending() ^ previous) {
5052                                                    query.append(WHERE_GREATER_THAN);
5053                                            }
5054                                            else {
5055                                                    query.append(WHERE_LESSER_THAN);
5056                                            }
5057                                    }
5058                            }
5059    
5060                            query.append(ORDER_BY_CLAUSE);
5061    
5062                            String[] orderByFields = orderByComparator.getOrderByFields();
5063    
5064                            for (int i = 0; i < orderByFields.length; i++) {
5065                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5066                                    query.append(orderByFields[i]);
5067    
5068                                    if ((i + 1) < orderByFields.length) {
5069                                            if (orderByComparator.isAscending() ^ previous) {
5070                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5071                                            }
5072                                            else {
5073                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5074                                            }
5075                                    }
5076                                    else {
5077                                            if (orderByComparator.isAscending() ^ previous) {
5078                                                    query.append(ORDER_BY_ASC);
5079                                            }
5080                                            else {
5081                                                    query.append(ORDER_BY_DESC);
5082                                            }
5083                                    }
5084                            }
5085                    }
5086                    else {
5087                            query.append(BookmarksFolderModelImpl.ORDER_BY_JPQL);
5088                    }
5089    
5090                    String sql = query.toString();
5091    
5092                    Query q = session.createQuery(sql);
5093    
5094                    q.setFirstResult(0);
5095                    q.setMaxResults(2);
5096    
5097                    QueryPos qPos = QueryPos.getInstance(q);
5098    
5099                    qPos.add(groupId);
5100    
5101                    qPos.add(parentFolderId);
5102    
5103                    qPos.add(status);
5104    
5105                    if (orderByComparator != null) {
5106                            Object[] values = orderByComparator.getOrderByConditionValues(bookmarksFolder);
5107    
5108                            for (Object value : values) {
5109                                    qPos.add(value);
5110                            }
5111                    }
5112    
5113                    List<BookmarksFolder> list = q.list();
5114    
5115                    if (list.size() == 2) {
5116                            return list.get(1);
5117                    }
5118                    else {
5119                            return null;
5120                    }
5121            }
5122    
5123            /**
5124             * Returns all the bookmarks folders that the user has permission to view where groupId = &#63; and parentFolderId = &#63; and status = &#63;.
5125             *
5126             * @param groupId the group ID
5127             * @param parentFolderId the parent folder ID
5128             * @param status the status
5129             * @return the matching bookmarks folders that the user has permission to view
5130             * @throws SystemException if a system exception occurred
5131             */
5132            @Override
5133            public List<BookmarksFolder> filterFindByG_P_S(long groupId,
5134                    long parentFolderId, int status) throws SystemException {
5135                    return filterFindByG_P_S(groupId, parentFolderId, status,
5136                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5137            }
5138    
5139            /**
5140             * Returns a range of all the bookmarks folders that the user has permission to view where groupId = &#63; and parentFolderId = &#63; and status = &#63;.
5141             *
5142             * <p>
5143             * 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.
5144             * </p>
5145             *
5146             * @param groupId the group ID
5147             * @param parentFolderId the parent folder ID
5148             * @param status the status
5149             * @param start the lower bound of the range of bookmarks folders
5150             * @param end the upper bound of the range of bookmarks folders (not inclusive)
5151             * @return the range of matching bookmarks folders that the user has permission to view
5152             * @throws SystemException if a system exception occurred
5153             */
5154            @Override
5155            public List<BookmarksFolder> filterFindByG_P_S(long groupId,
5156                    long parentFolderId, int status, int start, int end)
5157                    throws SystemException {
5158                    return filterFindByG_P_S(groupId, parentFolderId, status, start, end,
5159                            null);
5160            }
5161    
5162            /**
5163             * 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;.
5164             *
5165             * <p>
5166             * 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.
5167             * </p>
5168             *
5169             * @param groupId the group ID
5170             * @param parentFolderId the parent folder ID
5171             * @param status the status
5172             * @param start the lower bound of the range of bookmarks folders
5173             * @param end the upper bound of the range of bookmarks folders (not inclusive)
5174             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5175             * @return the ordered range of matching bookmarks folders that the user has permission to view
5176             * @throws SystemException if a system exception occurred
5177             */
5178            @Override
5179            public List<BookmarksFolder> filterFindByG_P_S(long groupId,
5180                    long parentFolderId, int status, int start, int end,
5181                    OrderByComparator orderByComparator) throws SystemException {
5182                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5183                            return findByG_P_S(groupId, parentFolderId, status, start, end,
5184                                    orderByComparator);
5185                    }
5186    
5187                    StringBundler query = null;
5188    
5189                    if (orderByComparator != null) {
5190                            query = new StringBundler(5 +
5191                                            (orderByComparator.getOrderByFields().length * 3));
5192                    }
5193                    else {
5194                            query = new StringBundler(5);
5195                    }
5196    
5197                    query.append(_SQL_SELECT_BOOKMARKSFOLDER_WHERE);
5198    
5199                    query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
5200    
5201                    query.append(_FINDER_COLUMN_G_P_S_PARENTFOLDERID_2);
5202    
5203                    query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
5204    
5205                    if (orderByComparator != null) {
5206                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5207                                    orderByComparator);
5208                    }
5209                    else {
5210                            query.append(BookmarksFolderModelImpl.ORDER_BY_JPQL);
5211                    }
5212    
5213                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5214                                    BookmarksFolder.class.getName(),
5215                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN,
5216                                    _FILTER_ENTITY_TABLE_FILTER_USERID_COLUMN, groupId);
5217    
5218                    Session session = null;
5219    
5220                    try {
5221                            session = openSession();
5222    
5223                            Query q = session.createQuery(sql);
5224    
5225                            QueryPos qPos = QueryPos.getInstance(q);
5226    
5227                            qPos.add(groupId);
5228    
5229                            qPos.add(parentFolderId);
5230    
5231                            qPos.add(status);
5232    
5233                            return (List<BookmarksFolder>)QueryUtil.list(q, getDialect(),
5234                                    start, end);
5235                    }
5236                    catch (Exception e) {
5237                            throw processException(e);
5238                    }
5239                    finally {
5240                            closeSession(session);
5241                    }
5242            }
5243    
5244            /**
5245             * 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;.
5246             *
5247             * @param folderId the primary key of the current bookmarks folder
5248             * @param groupId the group ID
5249             * @param parentFolderId the parent folder ID
5250             * @param status the status
5251             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5252             * @return the previous, current, and next bookmarks folder
5253             * @throws com.liferay.portlet.bookmarks.NoSuchFolderException if a bookmarks folder with the primary key could not be found
5254             * @throws SystemException if a system exception occurred
5255             */
5256            @Override
5257            public BookmarksFolder[] filterFindByG_P_S_PrevAndNext(long folderId,
5258                    long groupId, long parentFolderId, int status,
5259                    OrderByComparator orderByComparator)
5260                    throws NoSuchFolderException, SystemException {
5261                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5262                            return findByG_P_S_PrevAndNext(folderId, groupId, parentFolderId,
5263                                    status, orderByComparator);
5264                    }
5265    
5266                    BookmarksFolder bookmarksFolder = findByPrimaryKey(folderId);
5267    
5268                    Session session = null;
5269    
5270                    try {
5271                            session = openSession();
5272    
5273                            BookmarksFolder[] array = new BookmarksFolderImpl[3];
5274    
5275                            array[0] = filterGetByG_P_S_PrevAndNext(session, bookmarksFolder,
5276                                            groupId, parentFolderId, status, orderByComparator, true);
5277    
5278                            array[1] = bookmarksFolder;
5279    
5280                            array[2] = filterGetByG_P_S_PrevAndNext(session, bookmarksFolder,
5281                                            groupId, parentFolderId, status, orderByComparator, false);
5282    
5283                            return array;
5284                    }
5285                    catch (Exception e) {
5286                            throw processException(e);
5287                    }
5288                    finally {
5289                            closeSession(session);
5290                    }
5291            }
5292    
5293            protected BookmarksFolder filterGetByG_P_S_PrevAndNext(Session session,
5294                    BookmarksFolder bookmarksFolder, long groupId, long parentFolderId,
5295                    int status, OrderByComparator orderByComparator, boolean previous) {
5296                    StringBundler query = null;
5297    
5298                    if (orderByComparator != null) {
5299                            query = new StringBundler(6 +
5300                                            (orderByComparator.getOrderByFields().length * 6));
5301                    }
5302                    else {
5303                            query = new StringBundler(3);
5304                    }
5305    
5306                    query.append(_SQL_SELECT_BOOKMARKSFOLDER_WHERE);
5307    
5308                    query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
5309    
5310                    query.append(_FINDER_COLUMN_G_P_S_PARENTFOLDERID_2);
5311    
5312                    query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
5313    
5314                    if (orderByComparator != null) {
5315                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5316    
5317                            if (orderByConditionFields.length > 0) {
5318                                    query.append(WHERE_AND);
5319                            }
5320    
5321                            for (int i = 0; i < orderByConditionFields.length; i++) {
5322                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5323                                    query.append(orderByConditionFields[i]);
5324    
5325                                    if ((i + 1) < orderByConditionFields.length) {
5326                                            if (orderByComparator.isAscending() ^ previous) {
5327                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5328                                            }
5329                                            else {
5330                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5331                                            }
5332                                    }
5333                                    else {
5334                                            if (orderByComparator.isAscending() ^ previous) {
5335                                                    query.append(WHERE_GREATER_THAN);
5336                                            }
5337                                            else {
5338                                                    query.append(WHERE_LESSER_THAN);
5339                                            }
5340                                    }
5341                            }
5342    
5343                            query.append(ORDER_BY_CLAUSE);
5344    
5345                            String[] orderByFields = orderByComparator.getOrderByFields();
5346    
5347                            for (int i = 0; i < orderByFields.length; i++) {
5348                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5349                                    query.append(orderByFields[i]);
5350    
5351                                    if ((i + 1) < orderByFields.length) {
5352                                            if (orderByComparator.isAscending() ^ previous) {
5353                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5354                                            }
5355                                            else {
5356                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5357                                            }
5358                                    }
5359                                    else {
5360                                            if (orderByComparator.isAscending() ^ previous) {
5361                                                    query.append(ORDER_BY_ASC);
5362                                            }
5363                                            else {
5364                                                    query.append(ORDER_BY_DESC);
5365                                            }
5366                                    }
5367                            }
5368                    }
5369                    else {
5370                            query.append(BookmarksFolderModelImpl.ORDER_BY_JPQL);
5371                    }
5372    
5373                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5374                                    BookmarksFolder.class.getName(),
5375                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN,
5376                                    _FILTER_ENTITY_TABLE_FILTER_USERID_COLUMN, groupId);
5377    
5378                    Query q = session.createQuery(sql);
5379    
5380                    q.setFirstResult(0);
5381                    q.setMaxResults(2);
5382    
5383                    QueryPos qPos = QueryPos.getInstance(q);
5384    
5385                    qPos.add(groupId);
5386    
5387                    qPos.add(parentFolderId);
5388    
5389                    qPos.add(status);
5390    
5391                    if (orderByComparator != null) {
5392                            Object[] values = orderByComparator.getOrderByConditionValues(bookmarksFolder);
5393    
5394                            for (Object value : values) {
5395                                    qPos.add(value);
5396                            }
5397                    }
5398    
5399                    List<BookmarksFolder> list = q.list();
5400    
5401                    if (list.size() == 2) {
5402                            return list.get(1);
5403                    }
5404                    else {
5405                            return null;
5406                    }
5407            }
5408    
5409            /**
5410             * Removes all the bookmarks folders where groupId = &#63; and parentFolderId = &#63; and status = &#63; from the database.
5411             *
5412             * @param groupId the group ID
5413             * @param parentFolderId the parent folder ID
5414             * @param status the status
5415             * @throws SystemException if a system exception occurred
5416             */
5417            @Override
5418            public void removeByG_P_S(long groupId, long parentFolderId, int status)
5419                    throws SystemException {
5420                    for (BookmarksFolder bookmarksFolder : findByG_P_S(groupId,
5421                                    parentFolderId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
5422                                    null)) {
5423                            remove(bookmarksFolder);
5424                    }
5425            }
5426    
5427            /**
5428             * Returns the number of bookmarks folders where groupId = &#63; and parentFolderId = &#63; and status = &#63;.
5429             *
5430             * @param groupId the group ID
5431             * @param parentFolderId the parent folder ID
5432             * @param status the status
5433             * @return the number of matching bookmarks folders
5434             * @throws SystemException if a system exception occurred
5435             */
5436            @Override
5437            public int countByG_P_S(long groupId, long parentFolderId, int status)
5438                    throws SystemException {
5439                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_S;
5440    
5441                    Object[] finderArgs = new Object[] { groupId, parentFolderId, status };
5442    
5443                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5444                                    this);
5445    
5446                    if (count == null) {
5447                            StringBundler query = new StringBundler(4);
5448    
5449                            query.append(_SQL_COUNT_BOOKMARKSFOLDER_WHERE);
5450    
5451                            query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
5452    
5453                            query.append(_FINDER_COLUMN_G_P_S_PARENTFOLDERID_2);
5454    
5455                            query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
5456    
5457                            String sql = query.toString();
5458    
5459                            Session session = null;
5460    
5461                            try {
5462                                    session = openSession();
5463    
5464                                    Query q = session.createQuery(sql);
5465    
5466                                    QueryPos qPos = QueryPos.getInstance(q);
5467    
5468                                    qPos.add(groupId);
5469    
5470                                    qPos.add(parentFolderId);
5471    
5472                                    qPos.add(status);
5473    
5474                                    count = (Long)q.uniqueResult();
5475    
5476                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5477                            }
5478                            catch (Exception e) {
5479                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5480    
5481                                    throw processException(e);
5482                            }
5483                            finally {
5484                                    closeSession(session);
5485                            }
5486                    }
5487    
5488                    return count.intValue();
5489            }
5490    
5491            /**
5492             * Returns the number of bookmarks folders that the user has permission to view where groupId = &#63; and parentFolderId = &#63; and status = &#63;.
5493             *
5494             * @param groupId the group ID
5495             * @param parentFolderId the parent folder ID
5496             * @param status the status
5497             * @return the number of matching bookmarks folders that the user has permission to view
5498             * @throws SystemException if a system exception occurred
5499             */
5500            @Override
5501            public int filterCountByG_P_S(long groupId, long parentFolderId, int status)
5502                    throws SystemException {
5503                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5504                            return countByG_P_S(groupId, parentFolderId, status);
5505                    }
5506    
5507                    StringBundler query = new StringBundler(4);
5508    
5509                    query.append(_SQL_COUNT_BOOKMARKSFOLDER_WHERE);
5510    
5511                    query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
5512    
5513                    query.append(_FINDER_COLUMN_G_P_S_PARENTFOLDERID_2);
5514    
5515                    query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
5516    
5517                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5518                                    BookmarksFolder.class.getName(),
5519                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN,
5520                                    _FILTER_ENTITY_TABLE_FILTER_USERID_COLUMN, groupId);
5521    
5522                    Session session = null;
5523    
5524                    try {
5525                            session = openSession();
5526    
5527                            Query q = session.createQuery(sql);
5528    
5529                            QueryPos qPos = QueryPos.getInstance(q);
5530    
5531                            qPos.add(groupId);
5532    
5533                            qPos.add(parentFolderId);
5534    
5535                            qPos.add(status);
5536    
5537                            Long count = (Long)q.uniqueResult();
5538    
5539                            return count.intValue();
5540                    }
5541                    catch (Exception e) {
5542                            throw processException(e);
5543                    }
5544                    finally {
5545                            closeSession(session);
5546                    }
5547            }
5548    
5549            private static final String _FINDER_COLUMN_G_P_S_GROUPID_2 = "bookmarksFolder.groupId = ? AND ";
5550            private static final String _FINDER_COLUMN_G_P_S_PARENTFOLDERID_2 = "bookmarksFolder.parentFolderId = ? AND ";
5551            private static final String _FINDER_COLUMN_G_P_S_STATUS_2 = "bookmarksFolder.status = ?";
5552            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_NOTS = new FinderPath(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
5553                            BookmarksFolderModelImpl.FINDER_CACHE_ENABLED,
5554                            BookmarksFolderImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
5555                            "findByG_P_NotS",
5556                            new String[] {
5557                                    Long.class.getName(), Long.class.getName(),
5558                                    Integer.class.getName(),
5559                                    
5560                            Integer.class.getName(), Integer.class.getName(),
5561                                    OrderByComparator.class.getName()
5562                            });
5563            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P_NOTS =
5564                    new FinderPath(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
5565                            BookmarksFolderModelImpl.FINDER_CACHE_ENABLED, Long.class,
5566                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_P_NotS",
5567                            new String[] {
5568                                    Long.class.getName(), Long.class.getName(),
5569                                    Integer.class.getName()
5570                            });
5571    
5572            /**
5573             * Returns all the bookmarks folders where groupId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
5574             *
5575             * @param groupId the group ID
5576             * @param parentFolderId the parent folder ID
5577             * @param status the status
5578             * @return the matching bookmarks folders
5579             * @throws SystemException if a system exception occurred
5580             */
5581            @Override
5582            public List<BookmarksFolder> findByG_P_NotS(long groupId,
5583                    long parentFolderId, int status) throws SystemException {
5584                    return findByG_P_NotS(groupId, parentFolderId, status,
5585                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5586            }
5587    
5588            /**
5589             * Returns a range of all the bookmarks folders where groupId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
5590             *
5591             * <p>
5592             * 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.
5593             * </p>
5594             *
5595             * @param groupId the group ID
5596             * @param parentFolderId the parent folder ID
5597             * @param status the status
5598             * @param start the lower bound of the range of bookmarks folders
5599             * @param end the upper bound of the range of bookmarks folders (not inclusive)
5600             * @return the range of matching bookmarks folders
5601             * @throws SystemException if a system exception occurred
5602             */
5603            @Override
5604            public List<BookmarksFolder> findByG_P_NotS(long groupId,
5605                    long parentFolderId, int status, int start, int end)
5606                    throws SystemException {
5607                    return findByG_P_NotS(groupId, parentFolderId, status, start, end, null);
5608            }
5609    
5610            /**
5611             * Returns an ordered range of all the bookmarks folders where groupId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
5612             *
5613             * <p>
5614             * 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.
5615             * </p>
5616             *
5617             * @param groupId the group ID
5618             * @param parentFolderId the parent folder ID
5619             * @param status the status
5620             * @param start the lower bound of the range of bookmarks folders
5621             * @param end the upper bound of the range of bookmarks folders (not inclusive)
5622             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5623             * @return the ordered range of matching bookmarks folders
5624             * @throws SystemException if a system exception occurred
5625             */
5626            @Override
5627            public List<BookmarksFolder> findByG_P_NotS(long groupId,
5628                    long parentFolderId, int status, int start, int end,
5629                    OrderByComparator orderByComparator) throws SystemException {
5630                    boolean pagination = true;
5631                    FinderPath finderPath = null;
5632                    Object[] finderArgs = null;
5633    
5634                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_NOTS;
5635                    finderArgs = new Object[] {
5636                                    groupId, parentFolderId, status,
5637                                    
5638                                    start, end, orderByComparator
5639                            };
5640    
5641                    List<BookmarksFolder> list = (List<BookmarksFolder>)FinderCacheUtil.getResult(finderPath,
5642                                    finderArgs, this);
5643    
5644                    if ((list != null) && !list.isEmpty()) {
5645                            for (BookmarksFolder bookmarksFolder : list) {
5646                                    if ((groupId != bookmarksFolder.getGroupId()) ||
5647                                                    (parentFolderId != bookmarksFolder.getParentFolderId()) ||
5648                                                    (status != bookmarksFolder.getStatus())) {
5649                                            list = null;
5650    
5651                                            break;
5652                                    }
5653                            }
5654                    }
5655    
5656                    if (list == null) {
5657                            StringBundler query = null;
5658    
5659                            if (orderByComparator != null) {
5660                                    query = new StringBundler(5 +
5661                                                    (orderByComparator.getOrderByFields().length * 3));
5662                            }
5663                            else {
5664                                    query = new StringBundler(5);
5665                            }
5666    
5667                            query.append(_SQL_SELECT_BOOKMARKSFOLDER_WHERE);
5668    
5669                            query.append(_FINDER_COLUMN_G_P_NOTS_GROUPID_2);
5670    
5671                            query.append(_FINDER_COLUMN_G_P_NOTS_PARENTFOLDERID_2);
5672    
5673                            query.append(_FINDER_COLUMN_G_P_NOTS_STATUS_2);
5674    
5675                            if (orderByComparator != null) {
5676                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5677                                            orderByComparator);
5678                            }
5679                            else
5680                             if (pagination) {
5681                                    query.append(BookmarksFolderModelImpl.ORDER_BY_JPQL);
5682                            }
5683    
5684                            String sql = query.toString();
5685    
5686                            Session session = null;
5687    
5688                            try {
5689                                    session = openSession();
5690    
5691                                    Query q = session.createQuery(sql);
5692    
5693                                    QueryPos qPos = QueryPos.getInstance(q);
5694    
5695                                    qPos.add(groupId);
5696    
5697                                    qPos.add(parentFolderId);
5698    
5699                                    qPos.add(status);
5700    
5701                                    if (!pagination) {
5702                                            list = (List<BookmarksFolder>)QueryUtil.list(q,
5703                                                            getDialect(), start, end, false);
5704    
5705                                            Collections.sort(list);
5706    
5707                                            list = new UnmodifiableList<BookmarksFolder>(list);
5708                                    }
5709                                    else {
5710                                            list = (List<BookmarksFolder>)QueryUtil.list(q,
5711                                                            getDialect(), start, end);
5712                                    }
5713    
5714                                    cacheResult(list);
5715    
5716                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5717                            }
5718                            catch (Exception e) {
5719                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5720    
5721                                    throw processException(e);
5722                            }
5723                            finally {
5724                                    closeSession(session);
5725                            }
5726                    }
5727    
5728                    return list;
5729            }
5730    
5731            /**
5732             * Returns the first bookmarks folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
5733             *
5734             * @param groupId the group ID
5735             * @param parentFolderId the parent folder ID
5736             * @param status the status
5737             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5738             * @return the first matching bookmarks folder
5739             * @throws com.liferay.portlet.bookmarks.NoSuchFolderException if a matching bookmarks folder could not be found
5740             * @throws SystemException if a system exception occurred
5741             */
5742            @Override
5743            public BookmarksFolder findByG_P_NotS_First(long groupId,
5744                    long parentFolderId, int status, OrderByComparator orderByComparator)
5745                    throws NoSuchFolderException, SystemException {
5746                    BookmarksFolder bookmarksFolder = fetchByG_P_NotS_First(groupId,
5747                                    parentFolderId, status, orderByComparator);
5748    
5749                    if (bookmarksFolder != null) {
5750                            return bookmarksFolder;
5751                    }
5752    
5753                    StringBundler msg = new StringBundler(8);
5754    
5755                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5756    
5757                    msg.append("groupId=");
5758                    msg.append(groupId);
5759    
5760                    msg.append(", parentFolderId=");
5761                    msg.append(parentFolderId);
5762    
5763                    msg.append(", status=");
5764                    msg.append(status);
5765    
5766                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5767    
5768                    throw new NoSuchFolderException(msg.toString());
5769            }
5770    
5771            /**
5772             * Returns the first bookmarks folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
5773             *
5774             * @param groupId the group ID
5775             * @param parentFolderId the parent folder ID
5776             * @param status the status
5777             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5778             * @return the first matching bookmarks folder, or <code>null</code> if a matching bookmarks folder could not be found
5779             * @throws SystemException if a system exception occurred
5780             */
5781            @Override
5782            public BookmarksFolder fetchByG_P_NotS_First(long groupId,
5783                    long parentFolderId, int status, OrderByComparator orderByComparator)
5784                    throws SystemException {
5785                    List<BookmarksFolder> list = findByG_P_NotS(groupId, parentFolderId,
5786                                    status, 0, 1, orderByComparator);
5787    
5788                    if (!list.isEmpty()) {
5789                            return list.get(0);
5790                    }
5791    
5792                    return null;
5793            }
5794    
5795            /**
5796             * Returns the last bookmarks folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
5797             *
5798             * @param groupId the group ID
5799             * @param parentFolderId the parent folder ID
5800             * @param status the status
5801             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5802             * @return the last matching bookmarks folder
5803             * @throws com.liferay.portlet.bookmarks.NoSuchFolderException if a matching bookmarks folder could not be found
5804             * @throws SystemException if a system exception occurred
5805             */
5806            @Override
5807            public BookmarksFolder findByG_P_NotS_Last(long groupId,
5808                    long parentFolderId, int status, OrderByComparator orderByComparator)
5809                    throws NoSuchFolderException, SystemException {
5810                    BookmarksFolder bookmarksFolder = fetchByG_P_NotS_Last(groupId,
5811                                    parentFolderId, status, orderByComparator);
5812    
5813                    if (bookmarksFolder != null) {
5814                            return bookmarksFolder;
5815                    }
5816    
5817                    StringBundler msg = new StringBundler(8);
5818    
5819                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5820    
5821                    msg.append("groupId=");
5822                    msg.append(groupId);
5823    
5824                    msg.append(", parentFolderId=");
5825                    msg.append(parentFolderId);
5826    
5827                    msg.append(", status=");
5828                    msg.append(status);
5829    
5830                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5831    
5832                    throw new NoSuchFolderException(msg.toString());
5833            }
5834    
5835            /**
5836             * Returns the last bookmarks folder in the ordered set where groupId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
5837             *
5838             * @param groupId the group ID
5839             * @param parentFolderId the parent folder ID
5840             * @param status the status
5841             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5842             * @return the last matching bookmarks folder, or <code>null</code> if a matching bookmarks folder could not be found
5843             * @throws SystemException if a system exception occurred
5844             */
5845            @Override
5846            public BookmarksFolder fetchByG_P_NotS_Last(long groupId,
5847                    long parentFolderId, int status, OrderByComparator orderByComparator)
5848                    throws SystemException {
5849                    int count = countByG_P_NotS(groupId, parentFolderId, status);
5850    
5851                    if (count == 0) {
5852                            return null;
5853                    }
5854    
5855                    List<BookmarksFolder> list = findByG_P_NotS(groupId, parentFolderId,
5856                                    status, count - 1, count, orderByComparator);
5857    
5858                    if (!list.isEmpty()) {
5859                            return list.get(0);
5860                    }
5861    
5862                    return null;
5863            }
5864    
5865            /**
5866             * 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;.
5867             *
5868             * @param folderId the primary key of the current bookmarks folder
5869             * @param groupId the group ID
5870             * @param parentFolderId the parent folder ID
5871             * @param status the status
5872             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5873             * @return the previous, current, and next bookmarks folder
5874             * @throws com.liferay.portlet.bookmarks.NoSuchFolderException if a bookmarks folder with the primary key could not be found
5875             * @throws SystemException if a system exception occurred
5876             */
5877            @Override
5878            public BookmarksFolder[] findByG_P_NotS_PrevAndNext(long folderId,
5879                    long groupId, long parentFolderId, int status,
5880                    OrderByComparator orderByComparator)
5881                    throws NoSuchFolderException, SystemException {
5882                    BookmarksFolder bookmarksFolder = findByPrimaryKey(folderId);
5883    
5884                    Session session = null;
5885    
5886                    try {
5887                            session = openSession();
5888    
5889                            BookmarksFolder[] array = new BookmarksFolderImpl[3];
5890    
5891                            array[0] = getByG_P_NotS_PrevAndNext(session, bookmarksFolder,
5892                                            groupId, parentFolderId, status, orderByComparator, true);
5893    
5894                            array[1] = bookmarksFolder;
5895    
5896                            array[2] = getByG_P_NotS_PrevAndNext(session, bookmarksFolder,
5897                                            groupId, parentFolderId, status, orderByComparator, false);
5898    
5899                            return array;
5900                    }
5901                    catch (Exception e) {
5902                            throw processException(e);
5903                    }
5904                    finally {
5905                            closeSession(session);
5906                    }
5907            }
5908    
5909            protected BookmarksFolder getByG_P_NotS_PrevAndNext(Session session,
5910                    BookmarksFolder bookmarksFolder, long groupId, long parentFolderId,
5911                    int status, OrderByComparator orderByComparator, boolean previous) {
5912                    StringBundler query = null;
5913    
5914                    if (orderByComparator != null) {
5915                            query = new StringBundler(6 +
5916                                            (orderByComparator.getOrderByFields().length * 6));
5917                    }
5918                    else {
5919                            query = new StringBundler(3);
5920                    }
5921    
5922                    query.append(_SQL_SELECT_BOOKMARKSFOLDER_WHERE);
5923    
5924                    query.append(_FINDER_COLUMN_G_P_NOTS_GROUPID_2);
5925    
5926                    query.append(_FINDER_COLUMN_G_P_NOTS_PARENTFOLDERID_2);
5927    
5928                    query.append(_FINDER_COLUMN_G_P_NOTS_STATUS_2);
5929    
5930                    if (orderByComparator != null) {
5931                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5932    
5933                            if (orderByConditionFields.length > 0) {
5934                                    query.append(WHERE_AND);
5935                            }
5936    
5937                            for (int i = 0; i < orderByConditionFields.length; i++) {
5938                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5939                                    query.append(orderByConditionFields[i]);
5940    
5941                                    if ((i + 1) < orderByConditionFields.length) {
5942                                            if (orderByComparator.isAscending() ^ previous) {
5943                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5944                                            }
5945                                            else {
5946                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5947                                            }
5948                                    }
5949                                    else {
5950                                            if (orderByComparator.isAscending() ^ previous) {
5951                                                    query.append(WHERE_GREATER_THAN);
5952                                            }
5953                                            else {
5954                                                    query.append(WHERE_LESSER_THAN);
5955                                            }
5956                                    }
5957                            }
5958    
5959                            query.append(ORDER_BY_CLAUSE);
5960    
5961                            String[] orderByFields = orderByComparator.getOrderByFields();
5962    
5963                            for (int i = 0; i < orderByFields.length; i++) {
5964                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5965                                    query.append(orderByFields[i]);
5966    
5967                                    if ((i + 1) < orderByFields.length) {
5968                                            if (orderByComparator.isAscending() ^ previous) {
5969                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5970                                            }
5971                                            else {
5972                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5973                                            }
5974                                    }
5975                                    else {
5976                                            if (orderByComparator.isAscending() ^ previous) {
5977                                                    query.append(ORDER_BY_ASC);
5978                                            }
5979                                            else {
5980                                                    query.append(ORDER_BY_DESC);
5981                                            }
5982                                    }
5983                            }
5984                    }
5985                    else {
5986                            query.append(BookmarksFolderModelImpl.ORDER_BY_JPQL);
5987                    }
5988    
5989                    String sql = query.toString();
5990    
5991                    Query q = session.createQuery(sql);
5992    
5993                    q.setFirstResult(0);
5994                    q.setMaxResults(2);
5995    
5996                    QueryPos qPos = QueryPos.getInstance(q);
5997    
5998                    qPos.add(groupId);
5999    
6000                    qPos.add(parentFolderId);
6001    
6002                    qPos.add(status);
6003    
6004                    if (orderByComparator != null) {
6005                            Object[] values = orderByComparator.getOrderByConditionValues(bookmarksFolder);
6006    
6007                            for (Object value : values) {
6008                                    qPos.add(value);
6009                            }
6010                    }
6011    
6012                    List<BookmarksFolder> list = q.list();
6013    
6014                    if (list.size() == 2) {
6015                            return list.get(1);
6016                    }
6017                    else {
6018                            return null;
6019                    }
6020            }
6021    
6022            /**
6023             * Returns all the bookmarks folders that the user has permission to view where groupId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
6024             *
6025             * @param groupId the group ID
6026             * @param parentFolderId the parent folder ID
6027             * @param status the status
6028             * @return the matching bookmarks folders that the user has permission to view
6029             * @throws SystemException if a system exception occurred
6030             */
6031            @Override
6032            public List<BookmarksFolder> filterFindByG_P_NotS(long groupId,
6033                    long parentFolderId, int status) throws SystemException {
6034                    return filterFindByG_P_NotS(groupId, parentFolderId, status,
6035                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6036            }
6037    
6038            /**
6039             * 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;.
6040             *
6041             * <p>
6042             * 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.
6043             * </p>
6044             *
6045             * @param groupId the group ID
6046             * @param parentFolderId the parent folder ID
6047             * @param status the status
6048             * @param start the lower bound of the range of bookmarks folders
6049             * @param end the upper bound of the range of bookmarks folders (not inclusive)
6050             * @return the range of matching bookmarks folders that the user has permission to view
6051             * @throws SystemException if a system exception occurred
6052             */
6053            @Override
6054            public List<BookmarksFolder> filterFindByG_P_NotS(long groupId,
6055                    long parentFolderId, int status, int start, int end)
6056                    throws SystemException {
6057                    return filterFindByG_P_NotS(groupId, parentFolderId, status, start,
6058                            end, null);
6059            }
6060    
6061            /**
6062             * 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;.
6063             *
6064             * <p>
6065             * 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.
6066             * </p>
6067             *
6068             * @param groupId the group ID
6069             * @param parentFolderId the parent folder ID
6070             * @param status the status
6071             * @param start the lower bound of the range of bookmarks folders
6072             * @param end the upper bound of the range of bookmarks folders (not inclusive)
6073             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6074             * @return the ordered range of matching bookmarks folders that the user has permission to view
6075             * @throws SystemException if a system exception occurred
6076             */
6077            @Override
6078            public List<BookmarksFolder> filterFindByG_P_NotS(long groupId,
6079                    long parentFolderId, int status, int start, int end,
6080                    OrderByComparator orderByComparator) throws SystemException {
6081                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6082                            return findByG_P_NotS(groupId, parentFolderId, status, start, end,
6083                                    orderByComparator);
6084                    }
6085    
6086                    StringBundler query = null;
6087    
6088                    if (orderByComparator != null) {
6089                            query = new StringBundler(5 +
6090                                            (orderByComparator.getOrderByFields().length * 3));
6091                    }
6092                    else {
6093                            query = new StringBundler(5);
6094                    }
6095    
6096                    query.append(_SQL_SELECT_BOOKMARKSFOLDER_WHERE);
6097    
6098                    query.append(_FINDER_COLUMN_G_P_NOTS_GROUPID_2);
6099    
6100                    query.append(_FINDER_COLUMN_G_P_NOTS_PARENTFOLDERID_2);
6101    
6102                    query.append(_FINDER_COLUMN_G_P_NOTS_STATUS_2);
6103    
6104                    if (orderByComparator != null) {
6105                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6106                                    orderByComparator);
6107                    }
6108                    else {
6109                            query.append(BookmarksFolderModelImpl.ORDER_BY_JPQL);
6110                    }
6111    
6112                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6113                                    BookmarksFolder.class.getName(),
6114                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN,
6115                                    _FILTER_ENTITY_TABLE_FILTER_USERID_COLUMN, groupId);
6116    
6117                    Session session = null;
6118    
6119                    try {
6120                            session = openSession();
6121    
6122                            Query q = session.createQuery(sql);
6123    
6124                            QueryPos qPos = QueryPos.getInstance(q);
6125    
6126                            qPos.add(groupId);
6127    
6128                            qPos.add(parentFolderId);
6129    
6130                            qPos.add(status);
6131    
6132                            return (List<BookmarksFolder>)QueryUtil.list(q, getDialect(),
6133                                    start, end);
6134                    }
6135                    catch (Exception e) {
6136                            throw processException(e);
6137                    }
6138                    finally {
6139                            closeSession(session);
6140                    }
6141            }
6142    
6143            /**
6144             * 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;.
6145             *
6146             * @param folderId the primary key of the current bookmarks folder
6147             * @param groupId the group ID
6148             * @param parentFolderId the parent folder ID
6149             * @param status the status
6150             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6151             * @return the previous, current, and next bookmarks folder
6152             * @throws com.liferay.portlet.bookmarks.NoSuchFolderException if a bookmarks folder with the primary key could not be found
6153             * @throws SystemException if a system exception occurred
6154             */
6155            @Override
6156            public BookmarksFolder[] filterFindByG_P_NotS_PrevAndNext(long folderId,
6157                    long groupId, long parentFolderId, int status,
6158                    OrderByComparator orderByComparator)
6159                    throws NoSuchFolderException, SystemException {
6160                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6161                            return findByG_P_NotS_PrevAndNext(folderId, groupId,
6162                                    parentFolderId, status, orderByComparator);
6163                    }
6164    
6165                    BookmarksFolder bookmarksFolder = findByPrimaryKey(folderId);
6166    
6167                    Session session = null;
6168    
6169                    try {
6170                            session = openSession();
6171    
6172                            BookmarksFolder[] array = new BookmarksFolderImpl[3];
6173    
6174                            array[0] = filterGetByG_P_NotS_PrevAndNext(session,
6175                                            bookmarksFolder, groupId, parentFolderId, status,
6176                                            orderByComparator, true);
6177    
6178                            array[1] = bookmarksFolder;
6179    
6180                            array[2] = filterGetByG_P_NotS_PrevAndNext(session,
6181                                            bookmarksFolder, groupId, parentFolderId, status,
6182                                            orderByComparator, false);
6183    
6184                            return array;
6185                    }
6186                    catch (Exception e) {
6187                            throw processException(e);
6188                    }
6189                    finally {
6190                            closeSession(session);
6191                    }
6192            }
6193    
6194            protected BookmarksFolder filterGetByG_P_NotS_PrevAndNext(Session session,
6195                    BookmarksFolder bookmarksFolder, long groupId, long parentFolderId,
6196                    int status, OrderByComparator orderByComparator, boolean previous) {
6197                    StringBundler query = null;
6198    
6199                    if (orderByComparator != null) {
6200                            query = new StringBundler(6 +
6201                                            (orderByComparator.getOrderByFields().length * 6));
6202                    }
6203                    else {
6204                            query = new StringBundler(3);
6205                    }
6206    
6207                    query.append(_SQL_SELECT_BOOKMARKSFOLDER_WHERE);
6208    
6209                    query.append(_FINDER_COLUMN_G_P_NOTS_GROUPID_2);
6210    
6211                    query.append(_FINDER_COLUMN_G_P_NOTS_PARENTFOLDERID_2);
6212    
6213                    query.append(_FINDER_COLUMN_G_P_NOTS_STATUS_2);
6214    
6215                    if (orderByComparator != null) {
6216                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6217    
6218                            if (orderByConditionFields.length > 0) {
6219                                    query.append(WHERE_AND);
6220                            }
6221    
6222                            for (int i = 0; i < orderByConditionFields.length; i++) {
6223                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6224                                    query.append(orderByConditionFields[i]);
6225    
6226                                    if ((i + 1) < orderByConditionFields.length) {
6227                                            if (orderByComparator.isAscending() ^ previous) {
6228                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6229                                            }
6230                                            else {
6231                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6232                                            }
6233                                    }
6234                                    else {
6235                                            if (orderByComparator.isAscending() ^ previous) {
6236                                                    query.append(WHERE_GREATER_THAN);
6237                                            }
6238                                            else {
6239                                                    query.append(WHERE_LESSER_THAN);
6240                                            }
6241                                    }
6242                            }
6243    
6244                            query.append(ORDER_BY_CLAUSE);
6245    
6246                            String[] orderByFields = orderByComparator.getOrderByFields();
6247    
6248                            for (int i = 0; i < orderByFields.length; i++) {
6249                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6250                                    query.append(orderByFields[i]);
6251    
6252                                    if ((i + 1) < orderByFields.length) {
6253                                            if (orderByComparator.isAscending() ^ previous) {
6254                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6255                                            }
6256                                            else {
6257                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6258                                            }
6259                                    }
6260                                    else {
6261                                            if (orderByComparator.isAscending() ^ previous) {
6262                                                    query.append(ORDER_BY_ASC);
6263                                            }
6264                                            else {
6265                                                    query.append(ORDER_BY_DESC);
6266                                            }
6267                                    }
6268                            }
6269                    }
6270                    else {
6271                            query.append(BookmarksFolderModelImpl.ORDER_BY_JPQL);
6272                    }
6273    
6274                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6275                                    BookmarksFolder.class.getName(),
6276                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN,
6277                                    _FILTER_ENTITY_TABLE_FILTER_USERID_COLUMN, groupId);
6278    
6279                    Query q = session.createQuery(sql);
6280    
6281                    q.setFirstResult(0);
6282                    q.setMaxResults(2);
6283    
6284                    QueryPos qPos = QueryPos.getInstance(q);
6285    
6286                    qPos.add(groupId);
6287    
6288                    qPos.add(parentFolderId);
6289    
6290                    qPos.add(status);
6291    
6292                    if (orderByComparator != null) {
6293                            Object[] values = orderByComparator.getOrderByConditionValues(bookmarksFolder);
6294    
6295                            for (Object value : values) {
6296                                    qPos.add(value);
6297                            }
6298                    }
6299    
6300                    List<BookmarksFolder> list = q.list();
6301    
6302                    if (list.size() == 2) {
6303                            return list.get(1);
6304                    }
6305                    else {
6306                            return null;
6307                    }
6308            }
6309    
6310            /**
6311             * Removes all the bookmarks folders where groupId = &#63; and parentFolderId = &#63; and status &ne; &#63; from the database.
6312             *
6313             * @param groupId the group ID
6314             * @param parentFolderId the parent folder ID
6315             * @param status the status
6316             * @throws SystemException if a system exception occurred
6317             */
6318            @Override
6319            public void removeByG_P_NotS(long groupId, long parentFolderId, int status)
6320                    throws SystemException {
6321                    for (BookmarksFolder bookmarksFolder : findByG_P_NotS(groupId,
6322                                    parentFolderId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
6323                                    null)) {
6324                            remove(bookmarksFolder);
6325                    }
6326            }
6327    
6328            /**
6329             * Returns the number of bookmarks folders where groupId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
6330             *
6331             * @param groupId the group ID
6332             * @param parentFolderId the parent folder ID
6333             * @param status the status
6334             * @return the number of matching bookmarks folders
6335             * @throws SystemException if a system exception occurred
6336             */
6337            @Override
6338            public int countByG_P_NotS(long groupId, long parentFolderId, int status)
6339                    throws SystemException {
6340                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P_NOTS;
6341    
6342                    Object[] finderArgs = new Object[] { groupId, parentFolderId, status };
6343    
6344                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6345                                    this);
6346    
6347                    if (count == null) {
6348                            StringBundler query = new StringBundler(4);
6349    
6350                            query.append(_SQL_COUNT_BOOKMARKSFOLDER_WHERE);
6351    
6352                            query.append(_FINDER_COLUMN_G_P_NOTS_GROUPID_2);
6353    
6354                            query.append(_FINDER_COLUMN_G_P_NOTS_PARENTFOLDERID_2);
6355    
6356                            query.append(_FINDER_COLUMN_G_P_NOTS_STATUS_2);
6357    
6358                            String sql = query.toString();
6359    
6360                            Session session = null;
6361    
6362                            try {
6363                                    session = openSession();
6364    
6365                                    Query q = session.createQuery(sql);
6366    
6367                                    QueryPos qPos = QueryPos.getInstance(q);
6368    
6369                                    qPos.add(groupId);
6370    
6371                                    qPos.add(parentFolderId);
6372    
6373                                    qPos.add(status);
6374    
6375                                    count = (Long)q.uniqueResult();
6376    
6377                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
6378                            }
6379                            catch (Exception e) {
6380                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6381    
6382                                    throw processException(e);
6383                            }
6384                            finally {
6385                                    closeSession(session);
6386                            }
6387                    }
6388    
6389                    return count.intValue();
6390            }
6391    
6392            /**
6393             * Returns the number of bookmarks folders that the user has permission to view where groupId = &#63; and parentFolderId = &#63; and status &ne; &#63;.
6394             *
6395             * @param groupId the group ID
6396             * @param parentFolderId the parent folder ID
6397             * @param status the status
6398             * @return the number of matching bookmarks folders that the user has permission to view
6399             * @throws SystemException if a system exception occurred
6400             */
6401            @Override
6402            public int filterCountByG_P_NotS(long groupId, long parentFolderId,
6403                    int status) throws SystemException {
6404                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6405                            return countByG_P_NotS(groupId, parentFolderId, status);
6406                    }
6407    
6408                    StringBundler query = new StringBundler(4);
6409    
6410                    query.append(_SQL_COUNT_BOOKMARKSFOLDER_WHERE);
6411    
6412                    query.append(_FINDER_COLUMN_G_P_NOTS_GROUPID_2);
6413    
6414                    query.append(_FINDER_COLUMN_G_P_NOTS_PARENTFOLDERID_2);
6415    
6416                    query.append(_FINDER_COLUMN_G_P_NOTS_STATUS_2);
6417    
6418                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6419                                    BookmarksFolder.class.getName(),
6420                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN,
6421                                    _FILTER_ENTITY_TABLE_FILTER_USERID_COLUMN, groupId);
6422    
6423                    Session session = null;
6424    
6425                    try {
6426                            session = openSession();
6427    
6428                            Query q = session.createQuery(sql);
6429    
6430                            QueryPos qPos = QueryPos.getInstance(q);
6431    
6432                            qPos.add(groupId);
6433    
6434                            qPos.add(parentFolderId);
6435    
6436                            qPos.add(status);
6437    
6438                            Long count = (Long)q.uniqueResult();
6439    
6440                            return count.intValue();
6441                    }
6442                    catch (Exception e) {
6443                            throw processException(e);
6444                    }
6445                    finally {
6446                            closeSession(session);
6447                    }
6448            }
6449    
6450            private static final String _FINDER_COLUMN_G_P_NOTS_GROUPID_2 = "bookmarksFolder.groupId = ? AND ";
6451            private static final String _FINDER_COLUMN_G_P_NOTS_PARENTFOLDERID_2 = "bookmarksFolder.parentFolderId = ? AND ";
6452            private static final String _FINDER_COLUMN_G_P_NOTS_STATUS_2 = "bookmarksFolder.status != ?";
6453    
6454            public BookmarksFolderPersistenceImpl() {
6455                    setModelClass(BookmarksFolder.class);
6456            }
6457    
6458            /**
6459             * Caches the bookmarks folder in the entity cache if it is enabled.
6460             *
6461             * @param bookmarksFolder the bookmarks folder
6462             */
6463            @Override
6464            public void cacheResult(BookmarksFolder bookmarksFolder) {
6465                    EntityCacheUtil.putResult(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
6466                            BookmarksFolderImpl.class, bookmarksFolder.getPrimaryKey(),
6467                            bookmarksFolder);
6468    
6469                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
6470                            new Object[] { bookmarksFolder.getUuid(), bookmarksFolder.getGroupId() },
6471                            bookmarksFolder);
6472    
6473                    bookmarksFolder.resetOriginalValues();
6474            }
6475    
6476            /**
6477             * Caches the bookmarks folders in the entity cache if it is enabled.
6478             *
6479             * @param bookmarksFolders the bookmarks folders
6480             */
6481            @Override
6482            public void cacheResult(List<BookmarksFolder> bookmarksFolders) {
6483                    for (BookmarksFolder bookmarksFolder : bookmarksFolders) {
6484                            if (EntityCacheUtil.getResult(
6485                                                    BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
6486                                                    BookmarksFolderImpl.class,
6487                                                    bookmarksFolder.getPrimaryKey()) == null) {
6488                                    cacheResult(bookmarksFolder);
6489                            }
6490                            else {
6491                                    bookmarksFolder.resetOriginalValues();
6492                            }
6493                    }
6494            }
6495    
6496            /**
6497             * Clears the cache for all bookmarks folders.
6498             *
6499             * <p>
6500             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
6501             * </p>
6502             */
6503            @Override
6504            public void clearCache() {
6505                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
6506                            CacheRegistryUtil.clear(BookmarksFolderImpl.class.getName());
6507                    }
6508    
6509                    EntityCacheUtil.clearCache(BookmarksFolderImpl.class.getName());
6510    
6511                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
6512                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6513                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6514            }
6515    
6516            /**
6517             * Clears the cache for the bookmarks folder.
6518             *
6519             * <p>
6520             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
6521             * </p>
6522             */
6523            @Override
6524            public void clearCache(BookmarksFolder bookmarksFolder) {
6525                    EntityCacheUtil.removeResult(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
6526                            BookmarksFolderImpl.class, bookmarksFolder.getPrimaryKey());
6527    
6528                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6529                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6530    
6531                    clearUniqueFindersCache(bookmarksFolder);
6532            }
6533    
6534            @Override
6535            public void clearCache(List<BookmarksFolder> bookmarksFolders) {
6536                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6537                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6538    
6539                    for (BookmarksFolder bookmarksFolder : bookmarksFolders) {
6540                            EntityCacheUtil.removeResult(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
6541                                    BookmarksFolderImpl.class, bookmarksFolder.getPrimaryKey());
6542    
6543                            clearUniqueFindersCache(bookmarksFolder);
6544                    }
6545            }
6546    
6547            protected void cacheUniqueFindersCache(BookmarksFolder bookmarksFolder) {
6548                    if (bookmarksFolder.isNew()) {
6549                            Object[] args = new Object[] {
6550                                            bookmarksFolder.getUuid(), bookmarksFolder.getGroupId()
6551                                    };
6552    
6553                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
6554                                    Long.valueOf(1));
6555                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
6556                                    bookmarksFolder);
6557                    }
6558                    else {
6559                            BookmarksFolderModelImpl bookmarksFolderModelImpl = (BookmarksFolderModelImpl)bookmarksFolder;
6560    
6561                            if ((bookmarksFolderModelImpl.getColumnBitmask() &
6562                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
6563                                    Object[] args = new Object[] {
6564                                                    bookmarksFolder.getUuid(), bookmarksFolder.getGroupId()
6565                                            };
6566    
6567                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
6568                                            Long.valueOf(1));
6569                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
6570                                            bookmarksFolder);
6571                            }
6572                    }
6573            }
6574    
6575            protected void clearUniqueFindersCache(BookmarksFolder bookmarksFolder) {
6576                    BookmarksFolderModelImpl bookmarksFolderModelImpl = (BookmarksFolderModelImpl)bookmarksFolder;
6577    
6578                    Object[] args = new Object[] {
6579                                    bookmarksFolder.getUuid(), bookmarksFolder.getGroupId()
6580                            };
6581    
6582                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
6583                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
6584    
6585                    if ((bookmarksFolderModelImpl.getColumnBitmask() &
6586                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
6587                            args = new Object[] {
6588                                            bookmarksFolderModelImpl.getOriginalUuid(),
6589                                            bookmarksFolderModelImpl.getOriginalGroupId()
6590                                    };
6591    
6592                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
6593                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
6594                    }
6595            }
6596    
6597            /**
6598             * Creates a new bookmarks folder with the primary key. Does not add the bookmarks folder to the database.
6599             *
6600             * @param folderId the primary key for the new bookmarks folder
6601             * @return the new bookmarks folder
6602             */
6603            @Override
6604            public BookmarksFolder create(long folderId) {
6605                    BookmarksFolder bookmarksFolder = new BookmarksFolderImpl();
6606    
6607                    bookmarksFolder.setNew(true);
6608                    bookmarksFolder.setPrimaryKey(folderId);
6609    
6610                    String uuid = PortalUUIDUtil.generate();
6611    
6612                    bookmarksFolder.setUuid(uuid);
6613    
6614                    return bookmarksFolder;
6615            }
6616    
6617            /**
6618             * Removes the bookmarks folder with the primary key from the database. Also notifies the appropriate model listeners.
6619             *
6620             * @param folderId the primary key of the bookmarks folder
6621             * @return the bookmarks folder that was removed
6622             * @throws com.liferay.portlet.bookmarks.NoSuchFolderException if a bookmarks folder with the primary key could not be found
6623             * @throws SystemException if a system exception occurred
6624             */
6625            @Override
6626            public BookmarksFolder remove(long folderId)
6627                    throws NoSuchFolderException, SystemException {
6628                    return remove((Serializable)folderId);
6629            }
6630    
6631            /**
6632             * Removes the bookmarks folder with the primary key from the database. Also notifies the appropriate model listeners.
6633             *
6634             * @param primaryKey the primary key of the bookmarks folder
6635             * @return the bookmarks folder that was removed
6636             * @throws com.liferay.portlet.bookmarks.NoSuchFolderException if a bookmarks folder with the primary key could not be found
6637             * @throws SystemException if a system exception occurred
6638             */
6639            @Override
6640            public BookmarksFolder remove(Serializable primaryKey)
6641                    throws NoSuchFolderException, SystemException {
6642                    Session session = null;
6643    
6644                    try {
6645                            session = openSession();
6646    
6647                            BookmarksFolder bookmarksFolder = (BookmarksFolder)session.get(BookmarksFolderImpl.class,
6648                                            primaryKey);
6649    
6650                            if (bookmarksFolder == null) {
6651                                    if (_log.isWarnEnabled()) {
6652                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
6653                                    }
6654    
6655                                    throw new NoSuchFolderException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
6656                                            primaryKey);
6657                            }
6658    
6659                            return remove(bookmarksFolder);
6660                    }
6661                    catch (NoSuchFolderException nsee) {
6662                            throw nsee;
6663                    }
6664                    catch (Exception e) {
6665                            throw processException(e);
6666                    }
6667                    finally {
6668                            closeSession(session);
6669                    }
6670            }
6671    
6672            @Override
6673            protected BookmarksFolder removeImpl(BookmarksFolder bookmarksFolder)
6674                    throws SystemException {
6675                    bookmarksFolder = toUnwrappedModel(bookmarksFolder);
6676    
6677                    Session session = null;
6678    
6679                    try {
6680                            session = openSession();
6681    
6682                            if (!session.contains(bookmarksFolder)) {
6683                                    bookmarksFolder = (BookmarksFolder)session.get(BookmarksFolderImpl.class,
6684                                                    bookmarksFolder.getPrimaryKeyObj());
6685                            }
6686    
6687                            if (bookmarksFolder != null) {
6688                                    session.delete(bookmarksFolder);
6689                            }
6690                    }
6691                    catch (Exception e) {
6692                            throw processException(e);
6693                    }
6694                    finally {
6695                            closeSession(session);
6696                    }
6697    
6698                    if (bookmarksFolder != null) {
6699                            clearCache(bookmarksFolder);
6700                    }
6701    
6702                    return bookmarksFolder;
6703            }
6704    
6705            @Override
6706            public BookmarksFolder updateImpl(
6707                    com.liferay.portlet.bookmarks.model.BookmarksFolder bookmarksFolder)
6708                    throws SystemException {
6709                    bookmarksFolder = toUnwrappedModel(bookmarksFolder);
6710    
6711                    boolean isNew = bookmarksFolder.isNew();
6712    
6713                    BookmarksFolderModelImpl bookmarksFolderModelImpl = (BookmarksFolderModelImpl)bookmarksFolder;
6714    
6715                    if (Validator.isNull(bookmarksFolder.getUuid())) {
6716                            String uuid = PortalUUIDUtil.generate();
6717    
6718                            bookmarksFolder.setUuid(uuid);
6719                    }
6720    
6721                    Session session = null;
6722    
6723                    try {
6724                            session = openSession();
6725    
6726                            if (bookmarksFolder.isNew()) {
6727                                    session.save(bookmarksFolder);
6728    
6729                                    bookmarksFolder.setNew(false);
6730                            }
6731                            else {
6732                                    session.merge(bookmarksFolder);
6733                            }
6734                    }
6735                    catch (Exception e) {
6736                            throw processException(e);
6737                    }
6738                    finally {
6739                            closeSession(session);
6740                    }
6741    
6742                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6743    
6744                    if (isNew || !BookmarksFolderModelImpl.COLUMN_BITMASK_ENABLED) {
6745                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6746                    }
6747    
6748                    else {
6749                            if ((bookmarksFolderModelImpl.getColumnBitmask() &
6750                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEBLOCKID.getColumnBitmask()) != 0) {
6751                                    Object[] args = new Object[] {
6752                                                    bookmarksFolderModelImpl.getOriginalResourceBlockId()
6753                                            };
6754    
6755                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RESOURCEBLOCKID,
6756                                            args);
6757                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEBLOCKID,
6758                                            args);
6759    
6760                                    args = new Object[] {
6761                                                    bookmarksFolderModelImpl.getResourceBlockId()
6762                                            };
6763    
6764                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RESOURCEBLOCKID,
6765                                            args);
6766                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEBLOCKID,
6767                                            args);
6768                            }
6769    
6770                            if ((bookmarksFolderModelImpl.getColumnBitmask() &
6771                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
6772                                    Object[] args = new Object[] {
6773                                                    bookmarksFolderModelImpl.getOriginalUuid()
6774                                            };
6775    
6776                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
6777                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
6778                                            args);
6779    
6780                                    args = new Object[] { bookmarksFolderModelImpl.getUuid() };
6781    
6782                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
6783                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
6784                                            args);
6785                            }
6786    
6787                            if ((bookmarksFolderModelImpl.getColumnBitmask() &
6788                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
6789                                    Object[] args = new Object[] {
6790                                                    bookmarksFolderModelImpl.getOriginalUuid(),
6791                                                    bookmarksFolderModelImpl.getOriginalCompanyId()
6792                                            };
6793    
6794                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
6795                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
6796                                            args);
6797    
6798                                    args = new Object[] {
6799                                                    bookmarksFolderModelImpl.getUuid(),
6800                                                    bookmarksFolderModelImpl.getCompanyId()
6801                                            };
6802    
6803                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
6804                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
6805                                            args);
6806                            }
6807    
6808                            if ((bookmarksFolderModelImpl.getColumnBitmask() &
6809                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
6810                                    Object[] args = new Object[] {
6811                                                    bookmarksFolderModelImpl.getOriginalGroupId()
6812                                            };
6813    
6814                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
6815                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
6816                                            args);
6817    
6818                                    args = new Object[] { bookmarksFolderModelImpl.getGroupId() };
6819    
6820                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
6821                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
6822                                            args);
6823                            }
6824    
6825                            if ((bookmarksFolderModelImpl.getColumnBitmask() &
6826                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
6827                                    Object[] args = new Object[] {
6828                                                    bookmarksFolderModelImpl.getOriginalCompanyId()
6829                                            };
6830    
6831                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
6832                                            args);
6833                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
6834                                            args);
6835    
6836                                    args = new Object[] { bookmarksFolderModelImpl.getCompanyId() };
6837    
6838                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
6839                                            args);
6840                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
6841                                            args);
6842                            }
6843    
6844                            if ((bookmarksFolderModelImpl.getColumnBitmask() &
6845                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P.getColumnBitmask()) != 0) {
6846                                    Object[] args = new Object[] {
6847                                                    bookmarksFolderModelImpl.getOriginalGroupId(),
6848                                                    bookmarksFolderModelImpl.getOriginalParentFolderId()
6849                                            };
6850    
6851                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
6852                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
6853                                            args);
6854    
6855                                    args = new Object[] {
6856                                                    bookmarksFolderModelImpl.getGroupId(),
6857                                                    bookmarksFolderModelImpl.getParentFolderId()
6858                                            };
6859    
6860                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
6861                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
6862                                            args);
6863                            }
6864    
6865                            if ((bookmarksFolderModelImpl.getColumnBitmask() &
6866                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_S.getColumnBitmask()) != 0) {
6867                                    Object[] args = new Object[] {
6868                                                    bookmarksFolderModelImpl.getOriginalGroupId(),
6869                                                    bookmarksFolderModelImpl.getOriginalParentFolderId(),
6870                                                    bookmarksFolderModelImpl.getOriginalStatus()
6871                                            };
6872    
6873                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_S, args);
6874                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_S,
6875                                            args);
6876    
6877                                    args = new Object[] {
6878                                                    bookmarksFolderModelImpl.getGroupId(),
6879                                                    bookmarksFolderModelImpl.getParentFolderId(),
6880                                                    bookmarksFolderModelImpl.getStatus()
6881                                            };
6882    
6883                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_S, args);
6884                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_S,
6885                                            args);
6886                            }
6887                    }
6888    
6889                    EntityCacheUtil.putResult(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
6890                            BookmarksFolderImpl.class, bookmarksFolder.getPrimaryKey(),
6891                            bookmarksFolder);
6892    
6893                    clearUniqueFindersCache(bookmarksFolder);
6894                    cacheUniqueFindersCache(bookmarksFolder);
6895    
6896                    return bookmarksFolder;
6897            }
6898    
6899            protected BookmarksFolder toUnwrappedModel(BookmarksFolder bookmarksFolder) {
6900                    if (bookmarksFolder instanceof BookmarksFolderImpl) {
6901                            return bookmarksFolder;
6902                    }
6903    
6904                    BookmarksFolderImpl bookmarksFolderImpl = new BookmarksFolderImpl();
6905    
6906                    bookmarksFolderImpl.setNew(bookmarksFolder.isNew());
6907                    bookmarksFolderImpl.setPrimaryKey(bookmarksFolder.getPrimaryKey());
6908    
6909                    bookmarksFolderImpl.setUuid(bookmarksFolder.getUuid());
6910                    bookmarksFolderImpl.setFolderId(bookmarksFolder.getFolderId());
6911                    bookmarksFolderImpl.setGroupId(bookmarksFolder.getGroupId());
6912                    bookmarksFolderImpl.setCompanyId(bookmarksFolder.getCompanyId());
6913                    bookmarksFolderImpl.setUserId(bookmarksFolder.getUserId());
6914                    bookmarksFolderImpl.setUserName(bookmarksFolder.getUserName());
6915                    bookmarksFolderImpl.setCreateDate(bookmarksFolder.getCreateDate());
6916                    bookmarksFolderImpl.setModifiedDate(bookmarksFolder.getModifiedDate());
6917                    bookmarksFolderImpl.setResourceBlockId(bookmarksFolder.getResourceBlockId());
6918                    bookmarksFolderImpl.setParentFolderId(bookmarksFolder.getParentFolderId());
6919                    bookmarksFolderImpl.setTreePath(bookmarksFolder.getTreePath());
6920                    bookmarksFolderImpl.setName(bookmarksFolder.getName());
6921                    bookmarksFolderImpl.setDescription(bookmarksFolder.getDescription());
6922                    bookmarksFolderImpl.setStatus(bookmarksFolder.getStatus());
6923                    bookmarksFolderImpl.setStatusByUserId(bookmarksFolder.getStatusByUserId());
6924                    bookmarksFolderImpl.setStatusByUserName(bookmarksFolder.getStatusByUserName());
6925                    bookmarksFolderImpl.setStatusDate(bookmarksFolder.getStatusDate());
6926    
6927                    return bookmarksFolderImpl;
6928            }
6929    
6930            /**
6931             * Returns the bookmarks folder with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
6932             *
6933             * @param primaryKey the primary key of the bookmarks folder
6934             * @return the bookmarks folder
6935             * @throws com.liferay.portlet.bookmarks.NoSuchFolderException if a bookmarks folder with the primary key could not be found
6936             * @throws SystemException if a system exception occurred
6937             */
6938            @Override
6939            public BookmarksFolder findByPrimaryKey(Serializable primaryKey)
6940                    throws NoSuchFolderException, SystemException {
6941                    BookmarksFolder bookmarksFolder = fetchByPrimaryKey(primaryKey);
6942    
6943                    if (bookmarksFolder == null) {
6944                            if (_log.isWarnEnabled()) {
6945                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
6946                            }
6947    
6948                            throw new NoSuchFolderException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
6949                                    primaryKey);
6950                    }
6951    
6952                    return bookmarksFolder;
6953            }
6954    
6955            /**
6956             * Returns the bookmarks folder with the primary key or throws a {@link com.liferay.portlet.bookmarks.NoSuchFolderException} if it could not be found.
6957             *
6958             * @param folderId the primary key of the bookmarks folder
6959             * @return the bookmarks folder
6960             * @throws com.liferay.portlet.bookmarks.NoSuchFolderException if a bookmarks folder with the primary key could not be found
6961             * @throws SystemException if a system exception occurred
6962             */
6963            @Override
6964            public BookmarksFolder findByPrimaryKey(long folderId)
6965                    throws NoSuchFolderException, SystemException {
6966                    return findByPrimaryKey((Serializable)folderId);
6967            }
6968    
6969            /**
6970             * Returns the bookmarks folder with the primary key or returns <code>null</code> if it could not be found.
6971             *
6972             * @param primaryKey the primary key of the bookmarks folder
6973             * @return the bookmarks folder, or <code>null</code> if a bookmarks folder with the primary key could not be found
6974             * @throws SystemException if a system exception occurred
6975             */
6976            @Override
6977            public BookmarksFolder fetchByPrimaryKey(Serializable primaryKey)
6978                    throws SystemException {
6979                    BookmarksFolder bookmarksFolder = (BookmarksFolder)EntityCacheUtil.getResult(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
6980                                    BookmarksFolderImpl.class, primaryKey);
6981    
6982                    if (bookmarksFolder == _nullBookmarksFolder) {
6983                            return null;
6984                    }
6985    
6986                    if (bookmarksFolder == null) {
6987                            Session session = null;
6988    
6989                            try {
6990                                    session = openSession();
6991    
6992                                    bookmarksFolder = (BookmarksFolder)session.get(BookmarksFolderImpl.class,
6993                                                    primaryKey);
6994    
6995                                    if (bookmarksFolder != null) {
6996                                            cacheResult(bookmarksFolder);
6997                                    }
6998                                    else {
6999                                            EntityCacheUtil.putResult(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
7000                                                    BookmarksFolderImpl.class, primaryKey,
7001                                                    _nullBookmarksFolder);
7002                                    }
7003                            }
7004                            catch (Exception e) {
7005                                    EntityCacheUtil.removeResult(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
7006                                            BookmarksFolderImpl.class, primaryKey);
7007    
7008                                    throw processException(e);
7009                            }
7010                            finally {
7011                                    closeSession(session);
7012                            }
7013                    }
7014    
7015                    return bookmarksFolder;
7016            }
7017    
7018            /**
7019             * Returns the bookmarks folder with the primary key or returns <code>null</code> if it could not be found.
7020             *
7021             * @param folderId the primary key of the bookmarks folder
7022             * @return the bookmarks folder, or <code>null</code> if a bookmarks folder with the primary key could not be found
7023             * @throws SystemException if a system exception occurred
7024             */
7025            @Override
7026            public BookmarksFolder fetchByPrimaryKey(long folderId)
7027                    throws SystemException {
7028                    return fetchByPrimaryKey((Serializable)folderId);
7029            }
7030    
7031            /**
7032             * Returns all the bookmarks folders.
7033             *
7034             * @return the bookmarks folders
7035             * @throws SystemException if a system exception occurred
7036             */
7037            @Override
7038            public List<BookmarksFolder> findAll() throws SystemException {
7039                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7040            }
7041    
7042            /**
7043             * Returns a range of all the bookmarks folders.
7044             *
7045             * <p>
7046             * 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.
7047             * </p>
7048             *
7049             * @param start the lower bound of the range of bookmarks folders
7050             * @param end the upper bound of the range of bookmarks folders (not inclusive)
7051             * @return the range of bookmarks folders
7052             * @throws SystemException if a system exception occurred
7053             */
7054            @Override
7055            public List<BookmarksFolder> findAll(int start, int end)
7056                    throws SystemException {
7057                    return findAll(start, end, null);
7058            }
7059    
7060            /**
7061             * Returns an ordered range of all the bookmarks folders.
7062             *
7063             * <p>
7064             * 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.
7065             * </p>
7066             *
7067             * @param start the lower bound of the range of bookmarks folders
7068             * @param end the upper bound of the range of bookmarks folders (not inclusive)
7069             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7070             * @return the ordered range of bookmarks folders
7071             * @throws SystemException if a system exception occurred
7072             */
7073            @Override
7074            public List<BookmarksFolder> findAll(int start, int end,
7075                    OrderByComparator orderByComparator) throws SystemException {
7076                    boolean pagination = true;
7077                    FinderPath finderPath = null;
7078                    Object[] finderArgs = null;
7079    
7080                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7081                                    (orderByComparator == null)) {
7082                            pagination = false;
7083                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
7084                            finderArgs = FINDER_ARGS_EMPTY;
7085                    }
7086                    else {
7087                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
7088                            finderArgs = new Object[] { start, end, orderByComparator };
7089                    }
7090    
7091                    List<BookmarksFolder> list = (List<BookmarksFolder>)FinderCacheUtil.getResult(finderPath,
7092                                    finderArgs, this);
7093    
7094                    if (list == null) {
7095                            StringBundler query = null;
7096                            String sql = null;
7097    
7098                            if (orderByComparator != null) {
7099                                    query = new StringBundler(2 +
7100                                                    (orderByComparator.getOrderByFields().length * 3));
7101    
7102                                    query.append(_SQL_SELECT_BOOKMARKSFOLDER);
7103    
7104                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7105                                            orderByComparator);
7106    
7107                                    sql = query.toString();
7108                            }
7109                            else {
7110                                    sql = _SQL_SELECT_BOOKMARKSFOLDER;
7111    
7112                                    if (pagination) {
7113                                            sql = sql.concat(BookmarksFolderModelImpl.ORDER_BY_JPQL);
7114                                    }
7115                            }
7116    
7117                            Session session = null;
7118    
7119                            try {
7120                                    session = openSession();
7121    
7122                                    Query q = session.createQuery(sql);
7123    
7124                                    if (!pagination) {
7125                                            list = (List<BookmarksFolder>)QueryUtil.list(q,
7126                                                            getDialect(), start, end, false);
7127    
7128                                            Collections.sort(list);
7129    
7130                                            list = new UnmodifiableList<BookmarksFolder>(list);
7131                                    }
7132                                    else {
7133                                            list = (List<BookmarksFolder>)QueryUtil.list(q,
7134                                                            getDialect(), start, end);
7135                                    }
7136    
7137                                    cacheResult(list);
7138    
7139                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
7140                            }
7141                            catch (Exception e) {
7142                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7143    
7144                                    throw processException(e);
7145                            }
7146                            finally {
7147                                    closeSession(session);
7148                            }
7149                    }
7150    
7151                    return list;
7152            }
7153    
7154            /**
7155             * Removes all the bookmarks folders from the database.
7156             *
7157             * @throws SystemException if a system exception occurred
7158             */
7159            @Override
7160            public void removeAll() throws SystemException {
7161                    for (BookmarksFolder bookmarksFolder : findAll()) {
7162                            remove(bookmarksFolder);
7163                    }
7164            }
7165    
7166            /**
7167             * Returns the number of bookmarks folders.
7168             *
7169             * @return the number of bookmarks folders
7170             * @throws SystemException if a system exception occurred
7171             */
7172            @Override
7173            public int countAll() throws SystemException {
7174                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
7175                                    FINDER_ARGS_EMPTY, this);
7176    
7177                    if (count == null) {
7178                            Session session = null;
7179    
7180                            try {
7181                                    session = openSession();
7182    
7183                                    Query q = session.createQuery(_SQL_COUNT_BOOKMARKSFOLDER);
7184    
7185                                    count = (Long)q.uniqueResult();
7186    
7187                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
7188                                            FINDER_ARGS_EMPTY, count);
7189                            }
7190                            catch (Exception e) {
7191                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
7192                                            FINDER_ARGS_EMPTY);
7193    
7194                                    throw processException(e);
7195                            }
7196                            finally {
7197                                    closeSession(session);
7198                            }
7199                    }
7200    
7201                    return count.intValue();
7202            }
7203    
7204            @Override
7205            protected Set<String> getBadColumnNames() {
7206                    return _badColumnNames;
7207            }
7208    
7209            /**
7210             * Initializes the bookmarks folder persistence.
7211             */
7212            public void afterPropertiesSet() {
7213                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
7214                                            com.liferay.portal.util.PropsUtil.get(
7215                                                    "value.object.listener.com.liferay.portlet.bookmarks.model.BookmarksFolder")));
7216    
7217                    if (listenerClassNames.length > 0) {
7218                            try {
7219                                    List<ModelListener<BookmarksFolder>> listenersList = new ArrayList<ModelListener<BookmarksFolder>>();
7220    
7221                                    for (String listenerClassName : listenerClassNames) {
7222                                            listenersList.add((ModelListener<BookmarksFolder>)InstanceFactory.newInstance(
7223                                                            getClassLoader(), listenerClassName));
7224                                    }
7225    
7226                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
7227                            }
7228                            catch (Exception e) {
7229                                    _log.error(e);
7230                            }
7231                    }
7232            }
7233    
7234            public void destroy() {
7235                    EntityCacheUtil.removeCache(BookmarksFolderImpl.class.getName());
7236                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
7237                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7238                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7239            }
7240    
7241            private static final String _SQL_SELECT_BOOKMARKSFOLDER = "SELECT bookmarksFolder FROM BookmarksFolder bookmarksFolder";
7242            private static final String _SQL_SELECT_BOOKMARKSFOLDER_WHERE = "SELECT bookmarksFolder FROM BookmarksFolder bookmarksFolder WHERE ";
7243            private static final String _SQL_COUNT_BOOKMARKSFOLDER = "SELECT COUNT(bookmarksFolder) FROM BookmarksFolder bookmarksFolder";
7244            private static final String _SQL_COUNT_BOOKMARKSFOLDER_WHERE = "SELECT COUNT(bookmarksFolder) FROM BookmarksFolder bookmarksFolder WHERE ";
7245            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "bookmarksFolder.folderId";
7246            private static final String _FILTER_ENTITY_TABLE_FILTER_USERID_COLUMN = "bookmarksFolder.userId";
7247            private static final String _ORDER_BY_ENTITY_ALIAS = "bookmarksFolder.";
7248            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No BookmarksFolder exists with the primary key ";
7249            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No BookmarksFolder exists with the key {";
7250            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
7251            private static Log _log = LogFactoryUtil.getLog(BookmarksFolderPersistenceImpl.class);
7252            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
7253                                    "uuid"
7254                            });
7255            private static BookmarksFolder _nullBookmarksFolder = new BookmarksFolderImpl() {
7256                            @Override
7257                            public Object clone() {
7258                                    return this;
7259                            }
7260    
7261                            @Override
7262                            public CacheModel<BookmarksFolder> toCacheModel() {
7263                                    return _nullBookmarksFolderCacheModel;
7264                            }
7265                    };
7266    
7267            private static CacheModel<BookmarksFolder> _nullBookmarksFolderCacheModel = new CacheModel<BookmarksFolder>() {
7268                            @Override
7269                            public BookmarksFolder toEntityModel() {
7270                                    return _nullBookmarksFolder;
7271                            }
7272                    };
7273    }