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