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