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