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