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