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