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