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