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