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