001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.bookmarks.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.annotation.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.SQLQuery;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.kernel.util.Validator;
038    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
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     * 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.
064     * </p>
065     *
066     * <p>
067     * Caching information and settings can be found in <code>portal.properties</code>
068     * </p>
069     *
070     * @author Brian Wing Shun Chan
071     * @see BookmarksFolderPersistence
072     * @see BookmarksFolderUtil
073     * @generated
074     */
075    public class BookmarksFolderPersistenceImpl extends BasePersistenceImpl<BookmarksFolder>
076            implements BookmarksFolderPersistence {
077            public static final String FINDER_CLASS_NAME_ENTITY = BookmarksFolderImpl.class.getName();
078            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
079                    ".List";
080            public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
081                            BookmarksFolderModelImpl.FINDER_CACHE_ENABLED,
082                            FINDER_CLASS_NAME_LIST, "findByUuid",
083                            new String[] {
084                                    String.class.getName(),
085                                    
086                            "java.lang.Integer", "java.lang.Integer",
087                                    "com.liferay.portal.kernel.util.OrderByComparator"
088                            });
089            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
090                            BookmarksFolderModelImpl.FINDER_CACHE_ENABLED,
091                            FINDER_CLASS_NAME_LIST, "countByUuid",
092                            new String[] { String.class.getName() });
093            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
094                            BookmarksFolderModelImpl.FINDER_CACHE_ENABLED,
095                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
096                            new String[] { String.class.getName(), Long.class.getName() });
097            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
098                            BookmarksFolderModelImpl.FINDER_CACHE_ENABLED,
099                            FINDER_CLASS_NAME_LIST, "countByUUID_G",
100                            new String[] { String.class.getName(), Long.class.getName() });
101            public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
102                            BookmarksFolderModelImpl.FINDER_CACHE_ENABLED,
103                            FINDER_CLASS_NAME_LIST, "findByGroupId",
104                            new String[] {
105                                    Long.class.getName(),
106                                    
107                            "java.lang.Integer", "java.lang.Integer",
108                                    "com.liferay.portal.kernel.util.OrderByComparator"
109                            });
110            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
111                            BookmarksFolderModelImpl.FINDER_CACHE_ENABLED,
112                            FINDER_CLASS_NAME_LIST, "countByGroupId",
113                            new String[] { Long.class.getName() });
114            public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
115                            BookmarksFolderModelImpl.FINDER_CACHE_ENABLED,
116                            FINDER_CLASS_NAME_LIST, "findByCompanyId",
117                            new String[] {
118                                    Long.class.getName(),
119                                    
120                            "java.lang.Integer", "java.lang.Integer",
121                                    "com.liferay.portal.kernel.util.OrderByComparator"
122                            });
123            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
124                            BookmarksFolderModelImpl.FINDER_CACHE_ENABLED,
125                            FINDER_CLASS_NAME_LIST, "countByCompanyId",
126                            new String[] { Long.class.getName() });
127            public static final FinderPath FINDER_PATH_FIND_BY_G_P = new FinderPath(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
128                            BookmarksFolderModelImpl.FINDER_CACHE_ENABLED,
129                            FINDER_CLASS_NAME_LIST, "findByG_P",
130                            new String[] {
131                                    Long.class.getName(), Long.class.getName(),
132                                    
133                            "java.lang.Integer", "java.lang.Integer",
134                                    "com.liferay.portal.kernel.util.OrderByComparator"
135                            });
136            public static final FinderPath FINDER_PATH_COUNT_BY_G_P = new FinderPath(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
137                            BookmarksFolderModelImpl.FINDER_CACHE_ENABLED,
138                            FINDER_CLASS_NAME_LIST, "countByG_P",
139                            new String[] { Long.class.getName(), Long.class.getName() });
140            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
141                            BookmarksFolderModelImpl.FINDER_CACHE_ENABLED,
142                            FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
143            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
144                            BookmarksFolderModelImpl.FINDER_CACHE_ENABLED,
145                            FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
146    
147            /**
148             * Caches the bookmarks folder in the entity cache if it is enabled.
149             *
150             * @param bookmarksFolder the bookmarks folder to cache
151             */
152            public void cacheResult(BookmarksFolder bookmarksFolder) {
153                    EntityCacheUtil.putResult(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
154                            BookmarksFolderImpl.class, bookmarksFolder.getPrimaryKey(),
155                            bookmarksFolder);
156    
157                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
158                            new Object[] {
159                                    bookmarksFolder.getUuid(),
160                                    new Long(bookmarksFolder.getGroupId())
161                            }, bookmarksFolder);
162            }
163    
164            /**
165             * Caches the bookmarks folders in the entity cache if it is enabled.
166             *
167             * @param bookmarksFolders the bookmarks folders to cache
168             */
169            public void cacheResult(List<BookmarksFolder> bookmarksFolders) {
170                    for (BookmarksFolder bookmarksFolder : bookmarksFolders) {
171                            if (EntityCacheUtil.getResult(
172                                                    BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
173                                                    BookmarksFolderImpl.class,
174                                                    bookmarksFolder.getPrimaryKey(), this) == null) {
175                                    cacheResult(bookmarksFolder);
176                            }
177                    }
178            }
179    
180            /**
181             * Clears the cache for all bookmarks folders.
182             *
183             * <p>
184             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
185             * </p>
186             */
187            public void clearCache() {
188                    CacheRegistryUtil.clear(BookmarksFolderImpl.class.getName());
189                    EntityCacheUtil.clearCache(BookmarksFolderImpl.class.getName());
190                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
191                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
192            }
193    
194            /**
195             * Clears the cache for the bookmarks folder.
196             *
197             * <p>
198             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
199             * </p>
200             */
201            public void clearCache(BookmarksFolder bookmarksFolder) {
202                    EntityCacheUtil.removeResult(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
203                            BookmarksFolderImpl.class, bookmarksFolder.getPrimaryKey());
204    
205                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
206                            new Object[] {
207                                    bookmarksFolder.getUuid(),
208                                    new Long(bookmarksFolder.getGroupId())
209                            });
210            }
211    
212            /**
213             * Creates a new bookmarks folder with the primary key. Does not add the bookmarks folder to the database.
214             *
215             * @param folderId the primary key for the new bookmarks folder
216             * @return the new bookmarks folder
217             */
218            public BookmarksFolder create(long folderId) {
219                    BookmarksFolder bookmarksFolder = new BookmarksFolderImpl();
220    
221                    bookmarksFolder.setNew(true);
222                    bookmarksFolder.setPrimaryKey(folderId);
223    
224                    String uuid = PortalUUIDUtil.generate();
225    
226                    bookmarksFolder.setUuid(uuid);
227    
228                    return bookmarksFolder;
229            }
230    
231            /**
232             * Removes the bookmarks folder with the primary key from the database. Also notifies the appropriate model listeners.
233             *
234             * @param primaryKey the primary key of the bookmarks folder to remove
235             * @return the bookmarks folder that was removed
236             * @throws com.liferay.portal.NoSuchModelException if a bookmarks folder with the primary key could not be found
237             * @throws SystemException if a system exception occurred
238             */
239            public BookmarksFolder remove(Serializable primaryKey)
240                    throws NoSuchModelException, SystemException {
241                    return remove(((Long)primaryKey).longValue());
242            }
243    
244            /**
245             * Removes the bookmarks folder with the primary key from the database. Also notifies the appropriate model listeners.
246             *
247             * @param folderId the primary key of the bookmarks folder to remove
248             * @return the bookmarks folder that was removed
249             * @throws com.liferay.portlet.bookmarks.NoSuchFolderException if a bookmarks folder with the primary key could not be found
250             * @throws SystemException if a system exception occurred
251             */
252            public BookmarksFolder remove(long folderId)
253                    throws NoSuchFolderException, SystemException {
254                    Session session = null;
255    
256                    try {
257                            session = openSession();
258    
259                            BookmarksFolder bookmarksFolder = (BookmarksFolder)session.get(BookmarksFolderImpl.class,
260                                            new Long(folderId));
261    
262                            if (bookmarksFolder == null) {
263                                    if (_log.isWarnEnabled()) {
264                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + folderId);
265                                    }
266    
267                                    throw new NoSuchFolderException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
268                                            folderId);
269                            }
270    
271                            return remove(bookmarksFolder);
272                    }
273                    catch (NoSuchFolderException nsee) {
274                            throw nsee;
275                    }
276                    catch (Exception e) {
277                            throw processException(e);
278                    }
279                    finally {
280                            closeSession(session);
281                    }
282            }
283    
284            protected BookmarksFolder removeImpl(BookmarksFolder bookmarksFolder)
285                    throws SystemException {
286                    bookmarksFolder = toUnwrappedModel(bookmarksFolder);
287    
288                    Session session = null;
289    
290                    try {
291                            session = openSession();
292    
293                            BatchSessionUtil.delete(session, bookmarksFolder);
294                    }
295                    catch (Exception e) {
296                            throw processException(e);
297                    }
298                    finally {
299                            closeSession(session);
300                    }
301    
302                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
303    
304                    BookmarksFolderModelImpl bookmarksFolderModelImpl = (BookmarksFolderModelImpl)bookmarksFolder;
305    
306                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
307                            new Object[] {
308                                    bookmarksFolderModelImpl.getOriginalUuid(),
309                                    new Long(bookmarksFolderModelImpl.getOriginalGroupId())
310                            });
311    
312                    EntityCacheUtil.removeResult(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
313                            BookmarksFolderImpl.class, bookmarksFolder.getPrimaryKey());
314    
315                    return bookmarksFolder;
316            }
317    
318            public BookmarksFolder updateImpl(
319                    com.liferay.portlet.bookmarks.model.BookmarksFolder bookmarksFolder,
320                    boolean merge) throws SystemException {
321                    bookmarksFolder = toUnwrappedModel(bookmarksFolder);
322    
323                    boolean isNew = bookmarksFolder.isNew();
324    
325                    BookmarksFolderModelImpl bookmarksFolderModelImpl = (BookmarksFolderModelImpl)bookmarksFolder;
326    
327                    if (Validator.isNull(bookmarksFolder.getUuid())) {
328                            String uuid = PortalUUIDUtil.generate();
329    
330                            bookmarksFolder.setUuid(uuid);
331                    }
332    
333                    Session session = null;
334    
335                    try {
336                            session = openSession();
337    
338                            BatchSessionUtil.update(session, bookmarksFolder, merge);
339    
340                            bookmarksFolder.setNew(false);
341                    }
342                    catch (Exception e) {
343                            throw processException(e);
344                    }
345                    finally {
346                            closeSession(session);
347                    }
348    
349                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
350    
351                    EntityCacheUtil.putResult(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
352                            BookmarksFolderImpl.class, bookmarksFolder.getPrimaryKey(),
353                            bookmarksFolder);
354    
355                    if (!isNew &&
356                                    (!Validator.equals(bookmarksFolder.getUuid(),
357                                            bookmarksFolderModelImpl.getOriginalUuid()) ||
358                                    (bookmarksFolder.getGroupId() != bookmarksFolderModelImpl.getOriginalGroupId()))) {
359                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
360                                    new Object[] {
361                                            bookmarksFolderModelImpl.getOriginalUuid(),
362                                            new Long(bookmarksFolderModelImpl.getOriginalGroupId())
363                                    });
364                    }
365    
366                    if (isNew ||
367                                    (!Validator.equals(bookmarksFolder.getUuid(),
368                                            bookmarksFolderModelImpl.getOriginalUuid()) ||
369                                    (bookmarksFolder.getGroupId() != bookmarksFolderModelImpl.getOriginalGroupId()))) {
370                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
371                                    new Object[] {
372                                            bookmarksFolder.getUuid(),
373                                            new Long(bookmarksFolder.getGroupId())
374                                    }, bookmarksFolder);
375                    }
376    
377                    return bookmarksFolder;
378            }
379    
380            protected BookmarksFolder toUnwrappedModel(BookmarksFolder bookmarksFolder) {
381                    if (bookmarksFolder instanceof BookmarksFolderImpl) {
382                            return bookmarksFolder;
383                    }
384    
385                    BookmarksFolderImpl bookmarksFolderImpl = new BookmarksFolderImpl();
386    
387                    bookmarksFolderImpl.setNew(bookmarksFolder.isNew());
388                    bookmarksFolderImpl.setPrimaryKey(bookmarksFolder.getPrimaryKey());
389    
390                    bookmarksFolderImpl.setUuid(bookmarksFolder.getUuid());
391                    bookmarksFolderImpl.setFolderId(bookmarksFolder.getFolderId());
392                    bookmarksFolderImpl.setGroupId(bookmarksFolder.getGroupId());
393                    bookmarksFolderImpl.setCompanyId(bookmarksFolder.getCompanyId());
394                    bookmarksFolderImpl.setUserId(bookmarksFolder.getUserId());
395                    bookmarksFolderImpl.setCreateDate(bookmarksFolder.getCreateDate());
396                    bookmarksFolderImpl.setModifiedDate(bookmarksFolder.getModifiedDate());
397                    bookmarksFolderImpl.setParentFolderId(bookmarksFolder.getParentFolderId());
398                    bookmarksFolderImpl.setName(bookmarksFolder.getName());
399                    bookmarksFolderImpl.setDescription(bookmarksFolder.getDescription());
400    
401                    return bookmarksFolderImpl;
402            }
403    
404            /**
405             * Finds the bookmarks folder with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
406             *
407             * @param primaryKey the primary key of the bookmarks folder to find
408             * @return the bookmarks folder
409             * @throws com.liferay.portal.NoSuchModelException if a bookmarks folder with the primary key could not be found
410             * @throws SystemException if a system exception occurred
411             */
412            public BookmarksFolder findByPrimaryKey(Serializable primaryKey)
413                    throws NoSuchModelException, SystemException {
414                    return findByPrimaryKey(((Long)primaryKey).longValue());
415            }
416    
417            /**
418             * Finds the bookmarks folder with the primary key or throws a {@link com.liferay.portlet.bookmarks.NoSuchFolderException} if it could not be found.
419             *
420             * @param folderId the primary key of the bookmarks folder to find
421             * @return the bookmarks folder
422             * @throws com.liferay.portlet.bookmarks.NoSuchFolderException if a bookmarks folder with the primary key could not be found
423             * @throws SystemException if a system exception occurred
424             */
425            public BookmarksFolder findByPrimaryKey(long folderId)
426                    throws NoSuchFolderException, SystemException {
427                    BookmarksFolder bookmarksFolder = fetchByPrimaryKey(folderId);
428    
429                    if (bookmarksFolder == null) {
430                            if (_log.isWarnEnabled()) {
431                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + folderId);
432                            }
433    
434                            throw new NoSuchFolderException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
435                                    folderId);
436                    }
437    
438                    return bookmarksFolder;
439            }
440    
441            /**
442             * Finds the bookmarks folder with the primary key or returns <code>null</code> if it could not be found.
443             *
444             * @param primaryKey the primary key of the bookmarks folder to find
445             * @return the bookmarks folder, or <code>null</code> if a bookmarks folder with the primary key could not be found
446             * @throws SystemException if a system exception occurred
447             */
448            public BookmarksFolder fetchByPrimaryKey(Serializable primaryKey)
449                    throws SystemException {
450                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
451            }
452    
453            /**
454             * Finds the bookmarks folder with the primary key or returns <code>null</code> if it could not be found.
455             *
456             * @param folderId the primary key of the bookmarks folder to find
457             * @return the bookmarks folder, or <code>null</code> if a bookmarks folder with the primary key could not be found
458             * @throws SystemException if a system exception occurred
459             */
460            public BookmarksFolder fetchByPrimaryKey(long folderId)
461                    throws SystemException {
462                    BookmarksFolder bookmarksFolder = (BookmarksFolder)EntityCacheUtil.getResult(BookmarksFolderModelImpl.ENTITY_CACHE_ENABLED,
463                                    BookmarksFolderImpl.class, folderId, this);
464    
465                    if (bookmarksFolder == null) {
466                            Session session = null;
467    
468                            try {
469                                    session = openSession();
470    
471                                    bookmarksFolder = (BookmarksFolder)session.get(BookmarksFolderImpl.class,
472                                                    new Long(folderId));
473                            }
474                            catch (Exception e) {
475                                    throw processException(e);
476                            }
477                            finally {
478                                    if (bookmarksFolder != null) {
479                                            cacheResult(bookmarksFolder);
480                                    }
481    
482                                    closeSession(session);
483                            }
484                    }
485    
486                    return bookmarksFolder;
487            }
488    
489            /**
490             * Finds all the bookmarks folders where uuid = &#63;.
491             *
492             * @param uuid the uuid to search with
493             * @return the matching bookmarks folders
494             * @throws SystemException if a system exception occurred
495             */
496            public List<BookmarksFolder> findByUuid(String uuid)
497                    throws SystemException {
498                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
499            }
500    
501            /**
502             * Finds a range of all the bookmarks folders where uuid = &#63;.
503             *
504             * <p>
505             * 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.
506             * </p>
507             *
508             * @param uuid the uuid to search with
509             * @param start the lower bound of the range of bookmarks folders to return
510             * @param end the upper bound of the range of bookmarks folders to return (not inclusive)
511             * @return the range of matching bookmarks folders
512             * @throws SystemException if a system exception occurred
513             */
514            public List<BookmarksFolder> findByUuid(String uuid, int start, int end)
515                    throws SystemException {
516                    return findByUuid(uuid, start, end, null);
517            }
518    
519            /**
520             * Finds an ordered range of all the bookmarks folders where uuid = &#63;.
521             *
522             * <p>
523             * 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.
524             * </p>
525             *
526             * @param uuid the uuid to search with
527             * @param start the lower bound of the range of bookmarks folders to return
528             * @param end the upper bound of the range of bookmarks folders to return (not inclusive)
529             * @param orderByComparator the comparator to order the results by
530             * @return the ordered range of matching bookmarks folders
531             * @throws SystemException if a system exception occurred
532             */
533            public List<BookmarksFolder> findByUuid(String uuid, int start, int end,
534                    OrderByComparator orderByComparator) throws SystemException {
535                    Object[] finderArgs = new Object[] {
536                                    uuid,
537                                    
538                                    String.valueOf(start), String.valueOf(end),
539                                    String.valueOf(orderByComparator)
540                            };
541    
542                    List<BookmarksFolder> list = (List<BookmarksFolder>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
543                                    finderArgs, this);
544    
545                    if (list == null) {
546                            Session session = null;
547    
548                            try {
549                                    session = openSession();
550    
551                                    StringBundler query = null;
552    
553                                    if (orderByComparator != null) {
554                                            query = new StringBundler(3 +
555                                                            (orderByComparator.getOrderByFields().length * 3));
556                                    }
557                                    else {
558                                            query = new StringBundler(3);
559                                    }
560    
561                                    query.append(_SQL_SELECT_BOOKMARKSFOLDER_WHERE);
562    
563                                    if (uuid == null) {
564                                            query.append(_FINDER_COLUMN_UUID_UUID_1);
565                                    }
566                                    else {
567                                            if (uuid.equals(StringPool.BLANK)) {
568                                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
569                                            }
570                                            else {
571                                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
572                                            }
573                                    }
574    
575                                    if (orderByComparator != null) {
576                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
577                                                    orderByComparator);
578                                    }
579    
580                                    else {
581                                            query.append(BookmarksFolderModelImpl.ORDER_BY_JPQL);
582                                    }
583    
584                                    String sql = query.toString();
585    
586                                    Query q = session.createQuery(sql);
587    
588                                    QueryPos qPos = QueryPos.getInstance(q);
589    
590                                    if (uuid != null) {
591                                            qPos.add(uuid);
592                                    }
593    
594                                    list = (List<BookmarksFolder>)QueryUtil.list(q, getDialect(),
595                                                    start, end);
596                            }
597                            catch (Exception e) {
598                                    throw processException(e);
599                            }
600                            finally {
601                                    if (list == null) {
602                                            list = new ArrayList<BookmarksFolder>();
603                                    }
604    
605                                    cacheResult(list);
606    
607                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
608                                            list);
609    
610                                    closeSession(session);
611                            }
612                    }
613    
614                    return list;
615            }
616    
617            /**
618             * Finds the first bookmarks folder in the ordered set where uuid = &#63;.
619             *
620             * <p>
621             * 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.
622             * </p>
623             *
624             * @param uuid the uuid to search with
625             * @param orderByComparator the comparator to order the set by
626             * @return the first matching bookmarks folder
627             * @throws com.liferay.portlet.bookmarks.NoSuchFolderException if a matching bookmarks folder could not be found
628             * @throws SystemException if a system exception occurred
629             */
630            public BookmarksFolder findByUuid_First(String uuid,
631                    OrderByComparator orderByComparator)
632                    throws NoSuchFolderException, SystemException {
633                    List<BookmarksFolder> list = findByUuid(uuid, 0, 1, orderByComparator);
634    
635                    if (list.isEmpty()) {
636                            StringBundler msg = new StringBundler(4);
637    
638                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
639    
640                            msg.append("uuid=");
641                            msg.append(uuid);
642    
643                            msg.append(StringPool.CLOSE_CURLY_BRACE);
644    
645                            throw new NoSuchFolderException(msg.toString());
646                    }
647                    else {
648                            return list.get(0);
649                    }
650            }
651    
652            /**
653             * Finds the last bookmarks folder in the ordered set where uuid = &#63;.
654             *
655             * <p>
656             * 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.
657             * </p>
658             *
659             * @param uuid the uuid to search with
660             * @param orderByComparator the comparator to order the set by
661             * @return the last matching bookmarks folder
662             * @throws com.liferay.portlet.bookmarks.NoSuchFolderException if a matching bookmarks folder could not be found
663             * @throws SystemException if a system exception occurred
664             */
665            public BookmarksFolder findByUuid_Last(String uuid,
666                    OrderByComparator orderByComparator)
667                    throws NoSuchFolderException, SystemException {
668                    int count = countByUuid(uuid);
669    
670                    List<BookmarksFolder> list = findByUuid(uuid, count - 1, count,
671                                    orderByComparator);
672    
673                    if (list.isEmpty()) {
674                            StringBundler msg = new StringBundler(4);
675    
676                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
677    
678                            msg.append("uuid=");
679                            msg.append(uuid);
680    
681                            msg.append(StringPool.CLOSE_CURLY_BRACE);
682    
683                            throw new NoSuchFolderException(msg.toString());
684                    }
685                    else {
686                            return list.get(0);
687                    }
688            }
689    
690            /**
691             * Finds the bookmarks folders before and after the current bookmarks folder in the ordered set where uuid = &#63;.
692             *
693             * <p>
694             * 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.
695             * </p>
696             *
697             * @param folderId the primary key of the current bookmarks folder
698             * @param uuid the uuid to search with
699             * @param orderByComparator the comparator to order the set by
700             * @return the previous, current, and next bookmarks folder
701             * @throws com.liferay.portlet.bookmarks.NoSuchFolderException if a bookmarks folder with the primary key could not be found
702             * @throws SystemException if a system exception occurred
703             */
704            public BookmarksFolder[] findByUuid_PrevAndNext(long folderId, String uuid,
705                    OrderByComparator orderByComparator)
706                    throws NoSuchFolderException, SystemException {
707                    BookmarksFolder bookmarksFolder = findByPrimaryKey(folderId);
708    
709                    Session session = null;
710    
711                    try {
712                            session = openSession();
713    
714                            BookmarksFolder[] array = new BookmarksFolderImpl[3];
715    
716                            array[0] = getByUuid_PrevAndNext(session, bookmarksFolder, uuid,
717                                            orderByComparator, true);
718    
719                            array[1] = bookmarksFolder;
720    
721                            array[2] = getByUuid_PrevAndNext(session, bookmarksFolder, uuid,
722                                            orderByComparator, false);
723    
724                            return array;
725                    }
726                    catch (Exception e) {
727                            throw processException(e);
728                    }
729                    finally {
730                            closeSession(session);
731                    }
732            }
733    
734            protected BookmarksFolder getByUuid_PrevAndNext(Session session,
735                    BookmarksFolder bookmarksFolder, String uuid,
736                    OrderByComparator orderByComparator, boolean previous) {
737                    StringBundler query = null;
738    
739                    if (orderByComparator != null) {
740                            query = new StringBundler(6 +
741                                            (orderByComparator.getOrderByFields().length * 6));
742                    }
743                    else {
744                            query = new StringBundler(3);
745                    }
746    
747                    query.append(_SQL_SELECT_BOOKMARKSFOLDER_WHERE);
748    
749                    if (uuid == null) {
750                            query.append(_FINDER_COLUMN_UUID_UUID_1);
751                    }
752                    else {
753                            if (uuid.equals(StringPool.BLANK)) {
754                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
755                            }
756                            else {
757                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
758                            }
759                    }
760    
761                    if (orderByComparator != null) {
762                            String[] orderByFields = orderByComparator.getOrderByFields();
763    
764                            if (orderByFields.length > 0) {
765                                    query.append(WHERE_AND);
766                            }
767    
768                            for (int i = 0; i < orderByFields.length; i++) {
769                                    query.append(_ORDER_BY_ENTITY_ALIAS);
770                                    query.append(orderByFields[i]);
771    
772                                    if ((i + 1) < orderByFields.length) {
773                                            if (orderByComparator.isAscending() ^ previous) {
774                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
775                                            }
776                                            else {
777                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
778                                            }
779                                    }
780                                    else {
781                                            if (orderByComparator.isAscending() ^ previous) {
782                                                    query.append(WHERE_GREATER_THAN);
783                                            }
784                                            else {
785                                                    query.append(WHERE_LESSER_THAN);
786                                            }
787                                    }
788                            }
789    
790                            query.append(ORDER_BY_CLAUSE);
791    
792                            for (int i = 0; i < orderByFields.length; i++) {
793                                    query.append(_ORDER_BY_ENTITY_ALIAS);
794                                    query.append(orderByFields[i]);
795    
796                                    if ((i + 1) < orderByFields.length) {
797                                            if (orderByComparator.isAscending() ^ previous) {
798                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
799                                            }
800                                            else {
801                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
802                                            }
803                                    }
804                                    else {
805                                            if (orderByComparator.isAscending() ^ previous) {
806                                                    query.append(ORDER_BY_ASC);
807                                            }
808                                            else {
809                                                    query.append(ORDER_BY_DESC);
810                                            }
811                                    }
812                            }
813                    }
814    
815                    else {
816                            query.append(BookmarksFolderModelImpl.ORDER_BY_JPQL);
817                    }
818    
819                    String sql = query.toString();
820    
821                    Query q = session.createQuery(sql);
822    
823                    q.setFirstResult(0);
824                    q.setMaxResults(2);
825    
826                    QueryPos qPos = QueryPos.getInstance(q);
827    
828                    if (uuid != null) {
829                            qPos.add(uuid);
830                    }
831    
832                    if (orderByComparator != null) {
833                            Object[] values = orderByComparator.getOrderByValues(bookmarksFolder);
834    
835                            for (Object value : values) {
836                                    qPos.add(value);
837                            }
838                    }
839    
840                    List<BookmarksFolder> list = q.list();
841    
842                    if (list.size() == 2) {
843                            return list.get(1);
844                    }
845                    else {
846                            return null;
847                    }
848            }
849    
850            /**
851             * Finds the bookmarks folder where uuid = &#63; and groupId = &#63; or throws a {@link com.liferay.portlet.bookmarks.NoSuchFolderException} if it could not be found.
852             *
853             * @param uuid the uuid to search with
854             * @param groupId the group id to search with
855             * @return the matching bookmarks folder
856             * @throws com.liferay.portlet.bookmarks.NoSuchFolderException if a matching bookmarks folder could not be found
857             * @throws SystemException if a system exception occurred
858             */
859            public BookmarksFolder findByUUID_G(String uuid, long groupId)
860                    throws NoSuchFolderException, SystemException {
861                    BookmarksFolder bookmarksFolder = fetchByUUID_G(uuid, groupId);
862    
863                    if (bookmarksFolder == null) {
864                            StringBundler msg = new StringBundler(6);
865    
866                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
867    
868                            msg.append("uuid=");
869                            msg.append(uuid);
870    
871                            msg.append(", groupId=");
872                            msg.append(groupId);
873    
874                            msg.append(StringPool.CLOSE_CURLY_BRACE);
875    
876                            if (_log.isWarnEnabled()) {
877                                    _log.warn(msg.toString());
878                            }
879    
880                            throw new NoSuchFolderException(msg.toString());
881                    }
882    
883                    return bookmarksFolder;
884            }
885    
886            /**
887             * Finds the bookmarks folder where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
888             *
889             * @param uuid the uuid to search with
890             * @param groupId the group id to search with
891             * @return the matching bookmarks folder, or <code>null</code> if a matching bookmarks folder could not be found
892             * @throws SystemException if a system exception occurred
893             */
894            public BookmarksFolder fetchByUUID_G(String uuid, long groupId)
895                    throws SystemException {
896                    return fetchByUUID_G(uuid, groupId, true);
897            }
898    
899            /**
900             * Finds 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.
901             *
902             * @param uuid the uuid to search with
903             * @param groupId the group id to search with
904             * @return the matching bookmarks folder, or <code>null</code> if a matching bookmarks folder could not be found
905             * @throws SystemException if a system exception occurred
906             */
907            public BookmarksFolder fetchByUUID_G(String uuid, long groupId,
908                    boolean retrieveFromCache) throws SystemException {
909                    Object[] finderArgs = new Object[] { uuid, groupId };
910    
911                    Object result = null;
912    
913                    if (retrieveFromCache) {
914                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
915                                            finderArgs, this);
916                    }
917    
918                    if (result == null) {
919                            Session session = null;
920    
921                            try {
922                                    session = openSession();
923    
924                                    StringBundler query = new StringBundler(4);
925    
926                                    query.append(_SQL_SELECT_BOOKMARKSFOLDER_WHERE);
927    
928                                    if (uuid == null) {
929                                            query.append(_FINDER_COLUMN_UUID_G_UUID_1);
930                                    }
931                                    else {
932                                            if (uuid.equals(StringPool.BLANK)) {
933                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
934                                            }
935                                            else {
936                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
937                                            }
938                                    }
939    
940                                    query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
941    
942                                    query.append(BookmarksFolderModelImpl.ORDER_BY_JPQL);
943    
944                                    String sql = query.toString();
945    
946                                    Query q = session.createQuery(sql);
947    
948                                    QueryPos qPos = QueryPos.getInstance(q);
949    
950                                    if (uuid != null) {
951                                            qPos.add(uuid);
952                                    }
953    
954                                    qPos.add(groupId);
955    
956                                    List<BookmarksFolder> list = q.list();
957    
958                                    result = list;
959    
960                                    BookmarksFolder bookmarksFolder = null;
961    
962                                    if (list.isEmpty()) {
963                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
964                                                    finderArgs, list);
965                                    }
966                                    else {
967                                            bookmarksFolder = list.get(0);
968    
969                                            cacheResult(bookmarksFolder);
970    
971                                            if ((bookmarksFolder.getUuid() == null) ||
972                                                            !bookmarksFolder.getUuid().equals(uuid) ||
973                                                            (bookmarksFolder.getGroupId() != groupId)) {
974                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
975                                                            finderArgs, bookmarksFolder);
976                                            }
977                                    }
978    
979                                    return bookmarksFolder;
980                            }
981                            catch (Exception e) {
982                                    throw processException(e);
983                            }
984                            finally {
985                                    if (result == null) {
986                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
987                                                    finderArgs, new ArrayList<BookmarksFolder>());
988                                    }
989    
990                                    closeSession(session);
991                            }
992                    }
993                    else {
994                            if (result instanceof List<?>) {
995                                    return null;
996                            }
997                            else {
998                                    return (BookmarksFolder)result;
999                            }
1000                    }
1001            }
1002    
1003            /**
1004             * Finds all the bookmarks folders where groupId = &#63;.
1005             *
1006             * @param groupId the group id to search with
1007             * @return the matching bookmarks folders
1008             * @throws SystemException if a system exception occurred
1009             */
1010            public List<BookmarksFolder> findByGroupId(long groupId)
1011                    throws SystemException {
1012                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1013            }
1014    
1015            /**
1016             * Finds a range of all the bookmarks folders where groupId = &#63;.
1017             *
1018             * <p>
1019             * 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.
1020             * </p>
1021             *
1022             * @param groupId the group id to search with
1023             * @param start the lower bound of the range of bookmarks folders to return
1024             * @param end the upper bound of the range of bookmarks folders to return (not inclusive)
1025             * @return the range of matching bookmarks folders
1026             * @throws SystemException if a system exception occurred
1027             */
1028            public List<BookmarksFolder> findByGroupId(long groupId, int start, int end)
1029                    throws SystemException {
1030                    return findByGroupId(groupId, start, end, null);
1031            }
1032    
1033            /**
1034             * Finds an ordered range of all the bookmarks folders where groupId = &#63;.
1035             *
1036             * <p>
1037             * 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.
1038             * </p>
1039             *
1040             * @param groupId the group id to search with
1041             * @param start the lower bound of the range of bookmarks folders to return
1042             * @param end the upper bound of the range of bookmarks folders to return (not inclusive)
1043             * @param orderByComparator the comparator to order the results by
1044             * @return the ordered range of matching bookmarks folders
1045             * @throws SystemException if a system exception occurred
1046             */
1047            public List<BookmarksFolder> findByGroupId(long groupId, int start,
1048                    int end, OrderByComparator orderByComparator) throws SystemException {
1049                    Object[] finderArgs = new Object[] {
1050                                    groupId,
1051                                    
1052                                    String.valueOf(start), String.valueOf(end),
1053                                    String.valueOf(orderByComparator)
1054                            };
1055    
1056                    List<BookmarksFolder> list = (List<BookmarksFolder>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
1057                                    finderArgs, this);
1058    
1059                    if (list == null) {
1060                            Session session = null;
1061    
1062                            try {
1063                                    session = openSession();
1064    
1065                                    StringBundler query = null;
1066    
1067                                    if (orderByComparator != null) {
1068                                            query = new StringBundler(3 +
1069                                                            (orderByComparator.getOrderByFields().length * 3));
1070                                    }
1071                                    else {
1072                                            query = new StringBundler(3);
1073                                    }
1074    
1075                                    query.append(_SQL_SELECT_BOOKMARKSFOLDER_WHERE);
1076    
1077                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1078    
1079                                    if (orderByComparator != null) {
1080                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1081                                                    orderByComparator);
1082                                    }
1083    
1084                                    else {
1085                                            query.append(BookmarksFolderModelImpl.ORDER_BY_JPQL);
1086                                    }
1087    
1088                                    String sql = query.toString();
1089    
1090                                    Query q = session.createQuery(sql);
1091    
1092                                    QueryPos qPos = QueryPos.getInstance(q);
1093    
1094                                    qPos.add(groupId);
1095    
1096                                    list = (List<BookmarksFolder>)QueryUtil.list(q, getDialect(),
1097                                                    start, end);
1098                            }
1099                            catch (Exception e) {
1100                                    throw processException(e);
1101                            }
1102                            finally {
1103                                    if (list == null) {
1104                                            list = new ArrayList<BookmarksFolder>();
1105                                    }
1106    
1107                                    cacheResult(list);
1108    
1109                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
1110                                            finderArgs, list);
1111    
1112                                    closeSession(session);
1113                            }
1114                    }
1115    
1116                    return list;
1117            }
1118    
1119            /**
1120             * Finds the first bookmarks folder in the ordered set where groupId = &#63;.
1121             *
1122             * <p>
1123             * 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.
1124             * </p>
1125             *
1126             * @param groupId the group id to search with
1127             * @param orderByComparator the comparator to order the set by
1128             * @return the first matching bookmarks folder
1129             * @throws com.liferay.portlet.bookmarks.NoSuchFolderException if a matching bookmarks folder could not be found
1130             * @throws SystemException if a system exception occurred
1131             */
1132            public BookmarksFolder findByGroupId_First(long groupId,
1133                    OrderByComparator orderByComparator)
1134                    throws NoSuchFolderException, SystemException {
1135                    List<BookmarksFolder> list = findByGroupId(groupId, 0, 1,
1136                                    orderByComparator);
1137    
1138                    if (list.isEmpty()) {
1139                            StringBundler msg = new StringBundler(4);
1140    
1141                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1142    
1143                            msg.append("groupId=");
1144                            msg.append(groupId);
1145    
1146                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1147    
1148                            throw new NoSuchFolderException(msg.toString());
1149                    }
1150                    else {
1151                            return list.get(0);
1152                    }
1153            }
1154    
1155            /**
1156             * Finds the last bookmarks folder in the ordered set where groupId = &#63;.
1157             *
1158             * <p>
1159             * 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.
1160             * </p>
1161             *
1162             * @param groupId the group id to search with
1163             * @param orderByComparator the comparator to order the set by
1164             * @return the last matching bookmarks folder
1165             * @throws com.liferay.portlet.bookmarks.NoSuchFolderException if a matching bookmarks folder could not be found
1166             * @throws SystemException if a system exception occurred
1167             */
1168            public BookmarksFolder findByGroupId_Last(long groupId,
1169                    OrderByComparator orderByComparator)
1170                    throws NoSuchFolderException, SystemException {
1171                    int count = countByGroupId(groupId);
1172    
1173                    List<BookmarksFolder> list = findByGroupId(groupId, count - 1, count,
1174                                    orderByComparator);
1175    
1176                    if (list.isEmpty()) {
1177                            StringBundler msg = new StringBundler(4);
1178    
1179                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1180    
1181                            msg.append("groupId=");
1182                            msg.append(groupId);
1183    
1184                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1185    
1186                            throw new NoSuchFolderException(msg.toString());
1187                    }
1188                    else {
1189                            return list.get(0);
1190                    }
1191            }
1192    
1193            /**
1194             * Finds the bookmarks folders before and after the current bookmarks folder in the ordered set where groupId = &#63;.
1195             *
1196             * <p>
1197             * 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.
1198             * </p>
1199             *
1200             * @param folderId the primary key of the current bookmarks folder
1201             * @param groupId the group id to search with
1202             * @param orderByComparator the comparator to order the set by
1203             * @return the previous, current, and next bookmarks folder
1204             * @throws com.liferay.portlet.bookmarks.NoSuchFolderException if a bookmarks folder with the primary key could not be found
1205             * @throws SystemException if a system exception occurred
1206             */
1207            public BookmarksFolder[] findByGroupId_PrevAndNext(long folderId,
1208                    long groupId, OrderByComparator orderByComparator)
1209                    throws NoSuchFolderException, SystemException {
1210                    BookmarksFolder bookmarksFolder = findByPrimaryKey(folderId);
1211    
1212                    Session session = null;
1213    
1214                    try {
1215                            session = openSession();
1216    
1217                            BookmarksFolder[] array = new BookmarksFolderImpl[3];
1218    
1219                            array[0] = getByGroupId_PrevAndNext(session, bookmarksFolder,
1220                                            groupId, orderByComparator, true);
1221    
1222                            array[1] = bookmarksFolder;
1223    
1224                            array[2] = getByGroupId_PrevAndNext(session, bookmarksFolder,
1225                                            groupId, orderByComparator, false);
1226    
1227                            return array;
1228                    }
1229                    catch (Exception e) {
1230                            throw processException(e);
1231                    }
1232                    finally {
1233                            closeSession(session);
1234                    }
1235            }
1236    
1237            protected BookmarksFolder getByGroupId_PrevAndNext(Session session,
1238                    BookmarksFolder bookmarksFolder, long groupId,
1239                    OrderByComparator orderByComparator, boolean previous) {
1240                    StringBundler query = null;
1241    
1242                    if (orderByComparator != null) {
1243                            query = new StringBundler(6 +
1244                                            (orderByComparator.getOrderByFields().length * 6));
1245                    }
1246                    else {
1247                            query = new StringBundler(3);
1248                    }
1249    
1250                    query.append(_SQL_SELECT_BOOKMARKSFOLDER_WHERE);
1251    
1252                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1253    
1254                    if (orderByComparator != null) {
1255                            String[] orderByFields = orderByComparator.getOrderByFields();
1256    
1257                            if (orderByFields.length > 0) {
1258                                    query.append(WHERE_AND);
1259                            }
1260    
1261                            for (int i = 0; i < orderByFields.length; i++) {
1262                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1263                                    query.append(orderByFields[i]);
1264    
1265                                    if ((i + 1) < orderByFields.length) {
1266                                            if (orderByComparator.isAscending() ^ previous) {
1267                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1268                                            }
1269                                            else {
1270                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1271                                            }
1272                                    }
1273                                    else {
1274                                            if (orderByComparator.isAscending() ^ previous) {
1275                                                    query.append(WHERE_GREATER_THAN);
1276                                            }
1277                                            else {
1278                                                    query.append(WHERE_LESSER_THAN);
1279                                            }
1280                                    }
1281                            }
1282    
1283                            query.append(ORDER_BY_CLAUSE);
1284    
1285                            for (int i = 0; i < orderByFields.length; i++) {
1286                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1287                                    query.append(orderByFields[i]);
1288    
1289                                    if ((i + 1) < orderByFields.length) {
1290                                            if (orderByComparator.isAscending() ^ previous) {
1291                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1292                                            }
1293                                            else {
1294                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1295                                            }
1296                                    }
1297                                    else {
1298                                            if (orderByComparator.isAscending() ^ previous) {
1299                                                    query.append(ORDER_BY_ASC);
1300                                            }
1301                                            else {
1302                                                    query.append(ORDER_BY_DESC);
1303                                            }
1304                                    }
1305                            }
1306                    }
1307    
1308                    else {
1309                            query.append(BookmarksFolderModelImpl.ORDER_BY_JPQL);
1310                    }
1311    
1312                    String sql = query.toString();
1313    
1314                    Query q = session.createQuery(sql);
1315    
1316                    q.setFirstResult(0);
1317                    q.setMaxResults(2);
1318    
1319                    QueryPos qPos = QueryPos.getInstance(q);
1320    
1321                    qPos.add(groupId);
1322    
1323                    if (orderByComparator != null) {
1324                            Object[] values = orderByComparator.getOrderByValues(bookmarksFolder);
1325    
1326                            for (Object value : values) {
1327                                    qPos.add(value);
1328                            }
1329                    }
1330    
1331                    List<BookmarksFolder> list = q.list();
1332    
1333                    if (list.size() == 2) {
1334                            return list.get(1);
1335                    }
1336                    else {
1337                            return null;
1338                    }
1339            }
1340    
1341            /**
1342             * Filters by the user's permissions and finds all the bookmarks folders where groupId = &#63;.
1343             *
1344             * @param groupId the group id to search with
1345             * @return the matching bookmarks folders that the user has permission to view
1346             * @throws SystemException if a system exception occurred
1347             */
1348            public List<BookmarksFolder> filterFindByGroupId(long groupId)
1349                    throws SystemException {
1350                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1351                            QueryUtil.ALL_POS, null);
1352            }
1353    
1354            /**
1355             * Filters by the user's permissions and finds a range of all the bookmarks folders where groupId = &#63;.
1356             *
1357             * <p>
1358             * 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.
1359             * </p>
1360             *
1361             * @param groupId the group id to search with
1362             * @param start the lower bound of the range of bookmarks folders to return
1363             * @param end the upper bound of the range of bookmarks folders to return (not inclusive)
1364             * @return the range of matching bookmarks folders that the user has permission to view
1365             * @throws SystemException if a system exception occurred
1366             */
1367            public List<BookmarksFolder> filterFindByGroupId(long groupId, int start,
1368                    int end) throws SystemException {
1369                    return filterFindByGroupId(groupId, start, end, null);
1370            }
1371    
1372            /**
1373             * Filters by the user's permissions and finds an ordered range of all the bookmarks folders where groupId = &#63;.
1374             *
1375             * <p>
1376             * 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.
1377             * </p>
1378             *
1379             * @param groupId the group id to search with
1380             * @param start the lower bound of the range of bookmarks folders to return
1381             * @param end the upper bound of the range of bookmarks folders to return (not inclusive)
1382             * @param orderByComparator the comparator to order the results by
1383             * @return the ordered range of matching bookmarks folders that the user has permission to view
1384             * @throws SystemException if a system exception occurred
1385             */
1386            public List<BookmarksFolder> filterFindByGroupId(long groupId, int start,
1387                    int end, OrderByComparator orderByComparator) throws SystemException {
1388                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1389                            return findByGroupId(groupId, start, end, orderByComparator);
1390                    }
1391    
1392                    Session session = null;
1393    
1394                    try {
1395                            session = openSession();
1396    
1397                            StringBundler query = null;
1398    
1399                            if (orderByComparator != null) {
1400                                    query = new StringBundler(3 +
1401                                                    (orderByComparator.getOrderByFields().length * 3));
1402                            }
1403                            else {
1404                                    query = new StringBundler(3);
1405                            }
1406    
1407                            if (getDB().isSupportsInlineDistinct()) {
1408                                    query.append(_FILTER_SQL_SELECT_BOOKMARKSFOLDER_WHERE);
1409                            }
1410                            else {
1411                                    query.append(_FILTER_SQL_SELECT_BOOKMARKSFOLDER_NO_INLINE_DISTINCT_WHERE);
1412                            }
1413    
1414                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1415    
1416                            if (orderByComparator != null) {
1417                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1418                                            orderByComparator);
1419                            }
1420    
1421                            else {
1422                                    query.append(BookmarksFolderModelImpl.ORDER_BY_JPQL);
1423                            }
1424    
1425                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1426                                            BookmarksFolder.class.getName(), _FILTER_COLUMN_PK,
1427                                            _FILTER_COLUMN_USERID, groupId);
1428    
1429                            SQLQuery q = session.createSQLQuery(sql);
1430    
1431                            q.addEntity(_FILTER_ENTITY_ALIAS, BookmarksFolderImpl.class);
1432    
1433                            QueryPos qPos = QueryPos.getInstance(q);
1434    
1435                            qPos.add(groupId);
1436    
1437                            return (List<BookmarksFolder>)QueryUtil.list(q, getDialect(),
1438                                    start, end);
1439                    }
1440                    catch (Exception e) {
1441                            throw processException(e);
1442                    }
1443                    finally {
1444                            closeSession(session);
1445                    }
1446            }
1447    
1448            /**
1449             * Finds all the bookmarks folders where companyId = &#63;.
1450             *
1451             * @param companyId the company id to search with
1452             * @return the matching bookmarks folders
1453             * @throws SystemException if a system exception occurred
1454             */
1455            public List<BookmarksFolder> findByCompanyId(long companyId)
1456                    throws SystemException {
1457                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1458                            null);
1459            }
1460    
1461            /**
1462             * Finds a range of all the bookmarks folders where companyId = &#63;.
1463             *
1464             * <p>
1465             * 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.
1466             * </p>
1467             *
1468             * @param companyId the company id to search with
1469             * @param start the lower bound of the range of bookmarks folders to return
1470             * @param end the upper bound of the range of bookmarks folders to return (not inclusive)
1471             * @return the range of matching bookmarks folders
1472             * @throws SystemException if a system exception occurred
1473             */
1474            public List<BookmarksFolder> findByCompanyId(long companyId, int start,
1475                    int end) throws SystemException {
1476                    return findByCompanyId(companyId, start, end, null);
1477            }
1478    
1479            /**
1480             * Finds an ordered range of all the bookmarks folders where companyId = &#63;.
1481             *
1482             * <p>
1483             * 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.
1484             * </p>
1485             *
1486             * @param companyId the company id to search with
1487             * @param start the lower bound of the range of bookmarks folders to return
1488             * @param end the upper bound of the range of bookmarks folders to return (not inclusive)
1489             * @param orderByComparator the comparator to order the results by
1490             * @return the ordered range of matching bookmarks folders
1491             * @throws SystemException if a system exception occurred
1492             */
1493            public List<BookmarksFolder> findByCompanyId(long companyId, int start,
1494                    int end, OrderByComparator orderByComparator) throws SystemException {
1495                    Object[] finderArgs = new Object[] {
1496                                    companyId,
1497                                    
1498                                    String.valueOf(start), String.valueOf(end),
1499                                    String.valueOf(orderByComparator)
1500                            };
1501    
1502                    List<BookmarksFolder> list = (List<BookmarksFolder>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
1503                                    finderArgs, this);
1504    
1505                    if (list == null) {
1506                            Session session = null;
1507    
1508                            try {
1509                                    session = openSession();
1510    
1511                                    StringBundler query = null;
1512    
1513                                    if (orderByComparator != null) {
1514                                            query = new StringBundler(3 +
1515                                                            (orderByComparator.getOrderByFields().length * 3));
1516                                    }
1517                                    else {
1518                                            query = new StringBundler(3);
1519                                    }
1520    
1521                                    query.append(_SQL_SELECT_BOOKMARKSFOLDER_WHERE);
1522    
1523                                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1524    
1525                                    if (orderByComparator != null) {
1526                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1527                                                    orderByComparator);
1528                                    }
1529    
1530                                    else {
1531                                            query.append(BookmarksFolderModelImpl.ORDER_BY_JPQL);
1532                                    }
1533    
1534                                    String sql = query.toString();
1535    
1536                                    Query q = session.createQuery(sql);
1537    
1538                                    QueryPos qPos = QueryPos.getInstance(q);
1539    
1540                                    qPos.add(companyId);
1541    
1542                                    list = (List<BookmarksFolder>)QueryUtil.list(q, getDialect(),
1543                                                    start, end);
1544                            }
1545                            catch (Exception e) {
1546                                    throw processException(e);
1547                            }
1548                            finally {
1549                                    if (list == null) {
1550                                            list = new ArrayList<BookmarksFolder>();
1551                                    }
1552    
1553                                    cacheResult(list);
1554    
1555                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
1556                                            finderArgs, list);
1557    
1558                                    closeSession(session);
1559                            }
1560                    }
1561    
1562                    return list;
1563            }
1564    
1565            /**
1566             * Finds the first bookmarks folder in the ordered set where companyId = &#63;.
1567             *
1568             * <p>
1569             * 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.
1570             * </p>
1571             *
1572             * @param companyId the company id to search with
1573             * @param orderByComparator the comparator to order the set by
1574             * @return the first matching bookmarks folder
1575             * @throws com.liferay.portlet.bookmarks.NoSuchFolderException if a matching bookmarks folder could not be found
1576             * @throws SystemException if a system exception occurred
1577             */
1578            public BookmarksFolder findByCompanyId_First(long companyId,
1579                    OrderByComparator orderByComparator)
1580                    throws NoSuchFolderException, SystemException {
1581                    List<BookmarksFolder> list = findByCompanyId(companyId, 0, 1,
1582                                    orderByComparator);
1583    
1584                    if (list.isEmpty()) {
1585                            StringBundler msg = new StringBundler(4);
1586    
1587                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1588    
1589                            msg.append("companyId=");
1590                            msg.append(companyId);
1591    
1592                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1593    
1594                            throw new NoSuchFolderException(msg.toString());
1595                    }
1596                    else {
1597                            return list.get(0);
1598                    }
1599            }
1600    
1601            /**
1602             * Finds the last bookmarks folder in the ordered set where companyId = &#63;.
1603             *
1604             * <p>
1605             * 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.
1606             * </p>
1607             *
1608             * @param companyId the company id to search with
1609             * @param orderByComparator the comparator to order the set by
1610             * @return the last matching bookmarks folder
1611             * @throws com.liferay.portlet.bookmarks.NoSuchFolderException if a matching bookmarks folder could not be found
1612             * @throws SystemException if a system exception occurred
1613             */
1614            public BookmarksFolder findByCompanyId_Last(long companyId,
1615                    OrderByComparator orderByComparator)
1616                    throws NoSuchFolderException, SystemException {
1617                    int count = countByCompanyId(companyId);
1618    
1619                    List<BookmarksFolder> list = findByCompanyId(companyId, count - 1,
1620                                    count, orderByComparator);
1621    
1622                    if (list.isEmpty()) {
1623                            StringBundler msg = new StringBundler(4);
1624    
1625                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1626    
1627                            msg.append("companyId=");
1628                            msg.append(companyId);
1629    
1630                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1631    
1632                            throw new NoSuchFolderException(msg.toString());
1633                    }
1634                    else {
1635                            return list.get(0);
1636                    }
1637            }
1638    
1639            /**
1640             * Finds the bookmarks folders before and after the current bookmarks folder in the ordered set where companyId = &#63;.
1641             *
1642             * <p>
1643             * 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.
1644             * </p>
1645             *
1646             * @param folderId the primary key of the current bookmarks folder
1647             * @param companyId the company id to search with
1648             * @param orderByComparator the comparator to order the set by
1649             * @return the previous, current, and next bookmarks folder
1650             * @throws com.liferay.portlet.bookmarks.NoSuchFolderException if a bookmarks folder with the primary key could not be found
1651             * @throws SystemException if a system exception occurred
1652             */
1653            public BookmarksFolder[] findByCompanyId_PrevAndNext(long folderId,
1654                    long companyId, OrderByComparator orderByComparator)
1655                    throws NoSuchFolderException, SystemException {
1656                    BookmarksFolder bookmarksFolder = findByPrimaryKey(folderId);
1657    
1658                    Session session = null;
1659    
1660                    try {
1661                            session = openSession();
1662    
1663                            BookmarksFolder[] array = new BookmarksFolderImpl[3];
1664    
1665                            array[0] = getByCompanyId_PrevAndNext(session, bookmarksFolder,
1666                                            companyId, orderByComparator, true);
1667    
1668                            array[1] = bookmarksFolder;
1669    
1670                            array[2] = getByCompanyId_PrevAndNext(session, bookmarksFolder,
1671                                            companyId, orderByComparator, false);
1672    
1673                            return array;
1674                    }
1675                    catch (Exception e) {
1676                            throw processException(e);
1677                    }
1678                    finally {
1679                            closeSession(session);
1680                    }
1681            }
1682    
1683            protected BookmarksFolder getByCompanyId_PrevAndNext(Session session,
1684                    BookmarksFolder bookmarksFolder, long companyId,
1685                    OrderByComparator orderByComparator, boolean previous) {
1686                    StringBundler query = null;
1687    
1688                    if (orderByComparator != null) {
1689                            query = new StringBundler(6 +
1690                                            (orderByComparator.getOrderByFields().length * 6));
1691                    }
1692                    else {
1693                            query = new StringBundler(3);
1694                    }
1695    
1696                    query.append(_SQL_SELECT_BOOKMARKSFOLDER_WHERE);
1697    
1698                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1699    
1700                    if (orderByComparator != null) {
1701                            String[] orderByFields = orderByComparator.getOrderByFields();
1702    
1703                            if (orderByFields.length > 0) {
1704                                    query.append(WHERE_AND);
1705                            }
1706    
1707                            for (int i = 0; i < orderByFields.length; i++) {
1708                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1709                                    query.append(orderByFields[i]);
1710    
1711                                    if ((i + 1) < orderByFields.length) {
1712                                            if (orderByComparator.isAscending() ^ previous) {
1713                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1714                                            }
1715                                            else {
1716                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1717                                            }
1718                                    }
1719                                    else {
1720                                            if (orderByComparator.isAscending() ^ previous) {
1721                                                    query.append(WHERE_GREATER_THAN);
1722                                            }
1723                                            else {
1724                                                    query.append(WHERE_LESSER_THAN);
1725                                            }
1726                                    }
1727                            }
1728    
1729                            query.append(ORDER_BY_CLAUSE);
1730    
1731                            for (int i = 0; i < orderByFields.length; i++) {
1732                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1733                                    query.append(orderByFields[i]);
1734    
1735                                    if ((i + 1) < orderByFields.length) {
1736                                            if (orderByComparator.isAscending() ^ previous) {
1737                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1738                                            }
1739                                            else {
1740                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1741                                            }
1742                                    }
1743                                    else {
1744                                            if (orderByComparator.isAscending() ^ previous) {
1745                                                    query.append(ORDER_BY_ASC);
1746                                            }
1747                                            else {
1748                                                    query.append(ORDER_BY_DESC);
1749                                            }
1750                                    }
1751                            }
1752                    }
1753    
1754                    else {
1755                            query.append(BookmarksFolderModelImpl.ORDER_BY_JPQL);
1756                    }
1757    
1758                    String sql = query.toString();
1759    
1760                    Query q = session.createQuery(sql);
1761    
1762                    q.setFirstResult(0);
1763                    q.setMaxResults(2);
1764    
1765                    QueryPos qPos = QueryPos.getInstance(q);
1766    
1767                    qPos.add(companyId);
1768    
1769                    if (orderByComparator != null) {
1770                            Object[] values = orderByComparator.getOrderByValues(bookmarksFolder);
1771    
1772                            for (Object value : values) {
1773                                    qPos.add(value);
1774                            }
1775                    }
1776    
1777                    List<BookmarksFolder> list = q.list();
1778    
1779                    if (list.size() == 2) {
1780                            return list.get(1);
1781                    }
1782                    else {
1783                            return null;
1784                    }
1785            }
1786    
1787            /**
1788             * Finds all the bookmarks folders where groupId = &#63; and parentFolderId = &#63;.
1789             *
1790             * @param groupId the group id to search with
1791             * @param parentFolderId the parent folder id to search with
1792             * @return the matching bookmarks folders
1793             * @throws SystemException if a system exception occurred
1794             */
1795            public List<BookmarksFolder> findByG_P(long groupId, long parentFolderId)
1796                    throws SystemException {
1797                    return findByG_P(groupId, parentFolderId, QueryUtil.ALL_POS,
1798                            QueryUtil.ALL_POS, null);
1799            }
1800    
1801            /**
1802             * Finds a range of all the bookmarks folders where groupId = &#63; and parentFolderId = &#63;.
1803             *
1804             * <p>
1805             * 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.
1806             * </p>
1807             *
1808             * @param groupId the group id to search with
1809             * @param parentFolderId the parent folder id to search with
1810             * @param start the lower bound of the range of bookmarks folders to return
1811             * @param end the upper bound of the range of bookmarks folders to return (not inclusive)
1812             * @return the range of matching bookmarks folders
1813             * @throws SystemException if a system exception occurred
1814             */
1815            public List<BookmarksFolder> findByG_P(long groupId, long parentFolderId,
1816                    int start, int end) throws SystemException {
1817                    return findByG_P(groupId, parentFolderId, start, end, null);
1818            }
1819    
1820            /**
1821             * Finds an ordered range of all the bookmarks folders where groupId = &#63; and parentFolderId = &#63;.
1822             *
1823             * <p>
1824             * 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.
1825             * </p>
1826             *
1827             * @param groupId the group id to search with
1828             * @param parentFolderId the parent folder id to search with
1829             * @param start the lower bound of the range of bookmarks folders to return
1830             * @param end the upper bound of the range of bookmarks folders to return (not inclusive)
1831             * @param orderByComparator the comparator to order the results by
1832             * @return the ordered range of matching bookmarks folders
1833             * @throws SystemException if a system exception occurred
1834             */
1835            public List<BookmarksFolder> findByG_P(long groupId, long parentFolderId,
1836                    int start, int end, OrderByComparator orderByComparator)
1837                    throws SystemException {
1838                    Object[] finderArgs = new Object[] {
1839                                    groupId, parentFolderId,
1840                                    
1841                                    String.valueOf(start), String.valueOf(end),
1842                                    String.valueOf(orderByComparator)
1843                            };
1844    
1845                    List<BookmarksFolder> list = (List<BookmarksFolder>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_P,
1846                                    finderArgs, this);
1847    
1848                    if (list == null) {
1849                            Session session = null;
1850    
1851                            try {
1852                                    session = openSession();
1853    
1854                                    StringBundler query = null;
1855    
1856                                    if (orderByComparator != null) {
1857                                            query = new StringBundler(4 +
1858                                                            (orderByComparator.getOrderByFields().length * 3));
1859                                    }
1860                                    else {
1861                                            query = new StringBundler(4);
1862                                    }
1863    
1864                                    query.append(_SQL_SELECT_BOOKMARKSFOLDER_WHERE);
1865    
1866                                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1867    
1868                                    query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
1869    
1870                                    if (orderByComparator != null) {
1871                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1872                                                    orderByComparator);
1873                                    }
1874    
1875                                    else {
1876                                            query.append(BookmarksFolderModelImpl.ORDER_BY_JPQL);
1877                                    }
1878    
1879                                    String sql = query.toString();
1880    
1881                                    Query q = session.createQuery(sql);
1882    
1883                                    QueryPos qPos = QueryPos.getInstance(q);
1884    
1885                                    qPos.add(groupId);
1886    
1887                                    qPos.add(parentFolderId);
1888    
1889                                    list = (List<BookmarksFolder>)QueryUtil.list(q, getDialect(),
1890                                                    start, end);
1891                            }
1892                            catch (Exception e) {
1893                                    throw processException(e);
1894                            }
1895                            finally {
1896                                    if (list == null) {
1897                                            list = new ArrayList<BookmarksFolder>();
1898                                    }
1899    
1900                                    cacheResult(list);
1901    
1902                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_P, finderArgs,
1903                                            list);
1904    
1905                                    closeSession(session);
1906                            }
1907                    }
1908    
1909                    return list;
1910            }
1911    
1912            /**
1913             * Finds the first bookmarks folder in the ordered set where groupId = &#63; and parentFolderId = &#63;.
1914             *
1915             * <p>
1916             * 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.
1917             * </p>
1918             *
1919             * @param groupId the group id to search with
1920             * @param parentFolderId the parent folder id to search with
1921             * @param orderByComparator the comparator to order the set by
1922             * @return the first matching bookmarks folder
1923             * @throws com.liferay.portlet.bookmarks.NoSuchFolderException if a matching bookmarks folder could not be found
1924             * @throws SystemException if a system exception occurred
1925             */
1926            public BookmarksFolder findByG_P_First(long groupId, long parentFolderId,
1927                    OrderByComparator orderByComparator)
1928                    throws NoSuchFolderException, SystemException {
1929                    List<BookmarksFolder> list = findByG_P(groupId, parentFolderId, 0, 1,
1930                                    orderByComparator);
1931    
1932                    if (list.isEmpty()) {
1933                            StringBundler msg = new StringBundler(6);
1934    
1935                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1936    
1937                            msg.append("groupId=");
1938                            msg.append(groupId);
1939    
1940                            msg.append(", parentFolderId=");
1941                            msg.append(parentFolderId);
1942    
1943                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1944    
1945                            throw new NoSuchFolderException(msg.toString());
1946                    }
1947                    else {
1948                            return list.get(0);
1949                    }
1950            }
1951    
1952            /**
1953             * Finds the last bookmarks folder in the ordered set where groupId = &#63; and parentFolderId = &#63;.
1954             *
1955             * <p>
1956             * 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.
1957             * </p>
1958             *
1959             * @param groupId the group id to search with
1960             * @param parentFolderId the parent folder id to search with
1961             * @param orderByComparator the comparator to order the set by
1962             * @return the last matching bookmarks folder
1963             * @throws com.liferay.portlet.bookmarks.NoSuchFolderException if a matching bookmarks folder could not be found
1964             * @throws SystemException if a system exception occurred
1965             */
1966            public BookmarksFolder findByG_P_Last(long groupId, long parentFolderId,
1967                    OrderByComparator orderByComparator)
1968                    throws NoSuchFolderException, SystemException {
1969                    int count = countByG_P(groupId, parentFolderId);
1970    
1971                    List<BookmarksFolder> list = findByG_P(groupId, parentFolderId,
1972                                    count - 1, count, orderByComparator);
1973    
1974                    if (list.isEmpty()) {
1975                            StringBundler msg = new StringBundler(6);
1976    
1977                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1978    
1979                            msg.append("groupId=");
1980                            msg.append(groupId);
1981    
1982                            msg.append(", parentFolderId=");
1983                            msg.append(parentFolderId);
1984    
1985                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1986    
1987                            throw new NoSuchFolderException(msg.toString());
1988                    }
1989                    else {
1990                            return list.get(0);
1991                    }
1992            }
1993    
1994            /**
1995             * Finds the bookmarks folders before and after the current bookmarks folder in the ordered set where groupId = &#63; and parentFolderId = &#63;.
1996             *
1997             * <p>
1998             * 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.
1999             * </p>
2000             *
2001             * @param folderId the primary key of the current bookmarks folder
2002             * @param groupId the group id to search with
2003             * @param parentFolderId the parent folder id to search with
2004             * @param orderByComparator the comparator to order the set by
2005             * @return the previous, current, and next bookmarks folder
2006             * @throws com.liferay.portlet.bookmarks.NoSuchFolderException if a bookmarks folder with the primary key could not be found
2007             * @throws SystemException if a system exception occurred
2008             */
2009            public BookmarksFolder[] findByG_P_PrevAndNext(long folderId, long groupId,
2010                    long parentFolderId, OrderByComparator orderByComparator)
2011                    throws NoSuchFolderException, SystemException {
2012                    BookmarksFolder bookmarksFolder = findByPrimaryKey(folderId);
2013    
2014                    Session session = null;
2015    
2016                    try {
2017                            session = openSession();
2018    
2019                            BookmarksFolder[] array = new BookmarksFolderImpl[3];
2020    
2021                            array[0] = getByG_P_PrevAndNext(session, bookmarksFolder, groupId,
2022                                            parentFolderId, orderByComparator, true);
2023    
2024                            array[1] = bookmarksFolder;
2025    
2026                            array[2] = getByG_P_PrevAndNext(session, bookmarksFolder, groupId,
2027                                            parentFolderId, orderByComparator, false);
2028    
2029                            return array;
2030                    }
2031                    catch (Exception e) {
2032                            throw processException(e);
2033                    }
2034                    finally {
2035                            closeSession(session);
2036                    }
2037            }
2038    
2039            protected BookmarksFolder getByG_P_PrevAndNext(Session session,
2040                    BookmarksFolder bookmarksFolder, long groupId, long parentFolderId,
2041                    OrderByComparator orderByComparator, boolean previous) {
2042                    StringBundler query = null;
2043    
2044                    if (orderByComparator != null) {
2045                            query = new StringBundler(6 +
2046                                            (orderByComparator.getOrderByFields().length * 6));
2047                    }
2048                    else {
2049                            query = new StringBundler(3);
2050                    }
2051    
2052                    query.append(_SQL_SELECT_BOOKMARKSFOLDER_WHERE);
2053    
2054                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
2055    
2056                    query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
2057    
2058                    if (orderByComparator != null) {
2059                            String[] orderByFields = orderByComparator.getOrderByFields();
2060    
2061                            if (orderByFields.length > 0) {
2062                                    query.append(WHERE_AND);
2063                            }
2064    
2065                            for (int i = 0; i < orderByFields.length; i++) {
2066                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2067                                    query.append(orderByFields[i]);
2068    
2069                                    if ((i + 1) < orderByFields.length) {
2070                                            if (orderByComparator.isAscending() ^ previous) {
2071                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2072                                            }
2073                                            else {
2074                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2075                                            }
2076                                    }
2077                                    else {
2078                                            if (orderByComparator.isAscending() ^ previous) {
2079                                                    query.append(WHERE_GREATER_THAN);
2080                                            }
2081                                            else {
2082                                                    query.append(WHERE_LESSER_THAN);
2083                                            }
2084                                    }
2085                            }
2086    
2087                            query.append(ORDER_BY_CLAUSE);
2088    
2089                            for (int i = 0; i < orderByFields.length; i++) {
2090                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2091                                    query.append(orderByFields[i]);
2092    
2093                                    if ((i + 1) < orderByFields.length) {
2094                                            if (orderByComparator.isAscending() ^ previous) {
2095                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2096                                            }
2097                                            else {
2098                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2099                                            }
2100                                    }
2101                                    else {
2102                                            if (orderByComparator.isAscending() ^ previous) {
2103                                                    query.append(ORDER_BY_ASC);
2104                                            }
2105                                            else {
2106                                                    query.append(ORDER_BY_DESC);
2107                                            }
2108                                    }
2109                            }
2110                    }
2111    
2112                    else {
2113                            query.append(BookmarksFolderModelImpl.ORDER_BY_JPQL);
2114                    }
2115    
2116                    String sql = query.toString();
2117    
2118                    Query q = session.createQuery(sql);
2119    
2120                    q.setFirstResult(0);
2121                    q.setMaxResults(2);
2122    
2123                    QueryPos qPos = QueryPos.getInstance(q);
2124    
2125                    qPos.add(groupId);
2126    
2127                    qPos.add(parentFolderId);
2128    
2129                    if (orderByComparator != null) {
2130                            Object[] values = orderByComparator.getOrderByValues(bookmarksFolder);
2131    
2132                            for (Object value : values) {
2133                                    qPos.add(value);
2134                            }
2135                    }
2136    
2137                    List<BookmarksFolder> list = q.list();
2138    
2139                    if (list.size() == 2) {
2140                            return list.get(1);
2141                    }
2142                    else {
2143                            return null;
2144                    }
2145            }
2146    
2147            /**
2148             * Filters by the user's permissions and finds all the bookmarks folders where groupId = &#63; and parentFolderId = &#63;.
2149             *
2150             * @param groupId the group id to search with
2151             * @param parentFolderId the parent folder id to search with
2152             * @return the matching bookmarks folders that the user has permission to view
2153             * @throws SystemException if a system exception occurred
2154             */
2155            public List<BookmarksFolder> filterFindByG_P(long groupId,
2156                    long parentFolderId) throws SystemException {
2157                    return filterFindByG_P(groupId, parentFolderId, QueryUtil.ALL_POS,
2158                            QueryUtil.ALL_POS, null);
2159            }
2160    
2161            /**
2162             * Filters by the user's permissions and finds a range of all the bookmarks folders where groupId = &#63; and parentFolderId = &#63;.
2163             *
2164             * <p>
2165             * 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.
2166             * </p>
2167             *
2168             * @param groupId the group id to search with
2169             * @param parentFolderId the parent folder id to search with
2170             * @param start the lower bound of the range of bookmarks folders to return
2171             * @param end the upper bound of the range of bookmarks folders to return (not inclusive)
2172             * @return the range of matching bookmarks folders that the user has permission to view
2173             * @throws SystemException if a system exception occurred
2174             */
2175            public List<BookmarksFolder> filterFindByG_P(long groupId,
2176                    long parentFolderId, int start, int end) throws SystemException {
2177                    return filterFindByG_P(groupId, parentFolderId, start, end, null);
2178            }
2179    
2180            /**
2181             * Filters by the user's permissions and finds an ordered range of all the bookmarks folders where groupId = &#63; and parentFolderId = &#63;.
2182             *
2183             * <p>
2184             * 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.
2185             * </p>
2186             *
2187             * @param groupId the group id to search with
2188             * @param parentFolderId the parent folder id to search with
2189             * @param start the lower bound of the range of bookmarks folders to return
2190             * @param end the upper bound of the range of bookmarks folders to return (not inclusive)
2191             * @param orderByComparator the comparator to order the results by
2192             * @return the ordered range of matching bookmarks folders that the user has permission to view
2193             * @throws SystemException if a system exception occurred
2194             */
2195            public List<BookmarksFolder> filterFindByG_P(long groupId,
2196                    long parentFolderId, int start, int end,
2197                    OrderByComparator orderByComparator) throws SystemException {
2198                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2199                            return findByG_P(groupId, parentFolderId, start, end,
2200                                    orderByComparator);
2201                    }
2202    
2203                    Session session = null;
2204    
2205                    try {
2206                            session = openSession();
2207    
2208                            StringBundler query = null;
2209    
2210                            if (orderByComparator != null) {
2211                                    query = new StringBundler(4 +
2212                                                    (orderByComparator.getOrderByFields().length * 3));
2213                            }
2214                            else {
2215                                    query = new StringBundler(4);
2216                            }
2217    
2218                            if (getDB().isSupportsInlineDistinct()) {
2219                                    query.append(_FILTER_SQL_SELECT_BOOKMARKSFOLDER_WHERE);
2220                            }
2221                            else {
2222                                    query.append(_FILTER_SQL_SELECT_BOOKMARKSFOLDER_NO_INLINE_DISTINCT_WHERE);
2223                            }
2224    
2225                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
2226    
2227                            query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
2228    
2229                            if (orderByComparator != null) {
2230                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2231                                            orderByComparator);
2232                            }
2233    
2234                            else {
2235                                    query.append(BookmarksFolderModelImpl.ORDER_BY_JPQL);
2236                            }
2237    
2238                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2239                                            BookmarksFolder.class.getName(), _FILTER_COLUMN_PK,
2240                                            _FILTER_COLUMN_USERID, groupId);
2241    
2242                            SQLQuery q = session.createSQLQuery(sql);
2243    
2244                            q.addEntity(_FILTER_ENTITY_ALIAS, BookmarksFolderImpl.class);
2245    
2246                            QueryPos qPos = QueryPos.getInstance(q);
2247    
2248                            qPos.add(groupId);
2249    
2250                            qPos.add(parentFolderId);
2251    
2252                            return (List<BookmarksFolder>)QueryUtil.list(q, getDialect(),
2253                                    start, end);
2254                    }
2255                    catch (Exception e) {
2256                            throw processException(e);
2257                    }
2258                    finally {
2259                            closeSession(session);
2260                    }
2261            }
2262    
2263            /**
2264             * Finds all the bookmarks folders.
2265             *
2266             * @return the bookmarks folders
2267             * @throws SystemException if a system exception occurred
2268             */
2269            public List<BookmarksFolder> findAll() throws SystemException {
2270                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2271            }
2272    
2273            /**
2274             * Finds a range of all the bookmarks folders.
2275             *
2276             * <p>
2277             * 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.
2278             * </p>
2279             *
2280             * @param start the lower bound of the range of bookmarks folders to return
2281             * @param end the upper bound of the range of bookmarks folders to return (not inclusive)
2282             * @return the range of bookmarks folders
2283             * @throws SystemException if a system exception occurred
2284             */
2285            public List<BookmarksFolder> findAll(int start, int end)
2286                    throws SystemException {
2287                    return findAll(start, end, null);
2288            }
2289    
2290            /**
2291             * Finds an ordered range of all the bookmarks folders.
2292             *
2293             * <p>
2294             * 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.
2295             * </p>
2296             *
2297             * @param start the lower bound of the range of bookmarks folders to return
2298             * @param end the upper bound of the range of bookmarks folders to return (not inclusive)
2299             * @param orderByComparator the comparator to order the results by
2300             * @return the ordered range of bookmarks folders
2301             * @throws SystemException if a system exception occurred
2302             */
2303            public List<BookmarksFolder> findAll(int start, int end,
2304                    OrderByComparator orderByComparator) throws SystemException {
2305                    Object[] finderArgs = new Object[] {
2306                                    String.valueOf(start), String.valueOf(end),
2307                                    String.valueOf(orderByComparator)
2308                            };
2309    
2310                    List<BookmarksFolder> list = (List<BookmarksFolder>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
2311                                    finderArgs, this);
2312    
2313                    if (list == null) {
2314                            Session session = null;
2315    
2316                            try {
2317                                    session = openSession();
2318    
2319                                    StringBundler query = null;
2320                                    String sql = null;
2321    
2322                                    if (orderByComparator != null) {
2323                                            query = new StringBundler(2 +
2324                                                            (orderByComparator.getOrderByFields().length * 3));
2325    
2326                                            query.append(_SQL_SELECT_BOOKMARKSFOLDER);
2327    
2328                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2329                                                    orderByComparator);
2330    
2331                                            sql = query.toString();
2332                                    }
2333                                    else {
2334                                            sql = _SQL_SELECT_BOOKMARKSFOLDER.concat(BookmarksFolderModelImpl.ORDER_BY_JPQL);
2335                                    }
2336    
2337                                    Query q = session.createQuery(sql);
2338    
2339                                    if (orderByComparator == null) {
2340                                            list = (List<BookmarksFolder>)QueryUtil.list(q,
2341                                                            getDialect(), start, end, false);
2342    
2343                                            Collections.sort(list);
2344                                    }
2345                                    else {
2346                                            list = (List<BookmarksFolder>)QueryUtil.list(q,
2347                                                            getDialect(), start, end);
2348                                    }
2349                            }
2350                            catch (Exception e) {
2351                                    throw processException(e);
2352                            }
2353                            finally {
2354                                    if (list == null) {
2355                                            list = new ArrayList<BookmarksFolder>();
2356                                    }
2357    
2358                                    cacheResult(list);
2359    
2360                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
2361    
2362                                    closeSession(session);
2363                            }
2364                    }
2365    
2366                    return list;
2367            }
2368    
2369            /**
2370             * Removes all the bookmarks folders where uuid = &#63; from the database.
2371             *
2372             * @param uuid the uuid to search with
2373             * @throws SystemException if a system exception occurred
2374             */
2375            public void removeByUuid(String uuid) throws SystemException {
2376                    for (BookmarksFolder bookmarksFolder : findByUuid(uuid)) {
2377                            remove(bookmarksFolder);
2378                    }
2379            }
2380    
2381            /**
2382             * Removes the bookmarks folder where uuid = &#63; and groupId = &#63; from the database.
2383             *
2384             * @param uuid the uuid to search with
2385             * @param groupId the group id to search with
2386             * @throws SystemException if a system exception occurred
2387             */
2388            public void removeByUUID_G(String uuid, long groupId)
2389                    throws NoSuchFolderException, SystemException {
2390                    BookmarksFolder bookmarksFolder = findByUUID_G(uuid, groupId);
2391    
2392                    remove(bookmarksFolder);
2393            }
2394    
2395            /**
2396             * Removes all the bookmarks folders where groupId = &#63; from the database.
2397             *
2398             * @param groupId the group id to search with
2399             * @throws SystemException if a system exception occurred
2400             */
2401            public void removeByGroupId(long groupId) throws SystemException {
2402                    for (BookmarksFolder bookmarksFolder : findByGroupId(groupId)) {
2403                            remove(bookmarksFolder);
2404                    }
2405            }
2406    
2407            /**
2408             * Removes all the bookmarks folders where companyId = &#63; from the database.
2409             *
2410             * @param companyId the company id to search with
2411             * @throws SystemException if a system exception occurred
2412             */
2413            public void removeByCompanyId(long companyId) throws SystemException {
2414                    for (BookmarksFolder bookmarksFolder : findByCompanyId(companyId)) {
2415                            remove(bookmarksFolder);
2416                    }
2417            }
2418    
2419            /**
2420             * Removes all the bookmarks folders where groupId = &#63; and parentFolderId = &#63; from the database.
2421             *
2422             * @param groupId the group id to search with
2423             * @param parentFolderId the parent folder id to search with
2424             * @throws SystemException if a system exception occurred
2425             */
2426            public void removeByG_P(long groupId, long parentFolderId)
2427                    throws SystemException {
2428                    for (BookmarksFolder bookmarksFolder : findByG_P(groupId, parentFolderId)) {
2429                            remove(bookmarksFolder);
2430                    }
2431            }
2432    
2433            /**
2434             * Removes all the bookmarks folders from the database.
2435             *
2436             * @throws SystemException if a system exception occurred
2437             */
2438            public void removeAll() throws SystemException {
2439                    for (BookmarksFolder bookmarksFolder : findAll()) {
2440                            remove(bookmarksFolder);
2441                    }
2442            }
2443    
2444            /**
2445             * Counts all the bookmarks folders where uuid = &#63;.
2446             *
2447             * @param uuid the uuid to search with
2448             * @return the number of matching bookmarks folders
2449             * @throws SystemException if a system exception occurred
2450             */
2451            public int countByUuid(String uuid) throws SystemException {
2452                    Object[] finderArgs = new Object[] { uuid };
2453    
2454                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
2455                                    finderArgs, this);
2456    
2457                    if (count == null) {
2458                            Session session = null;
2459    
2460                            try {
2461                                    session = openSession();
2462    
2463                                    StringBundler query = new StringBundler(2);
2464    
2465                                    query.append(_SQL_COUNT_BOOKMARKSFOLDER_WHERE);
2466    
2467                                    if (uuid == null) {
2468                                            query.append(_FINDER_COLUMN_UUID_UUID_1);
2469                                    }
2470                                    else {
2471                                            if (uuid.equals(StringPool.BLANK)) {
2472                                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
2473                                            }
2474                                            else {
2475                                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
2476                                            }
2477                                    }
2478    
2479                                    String sql = query.toString();
2480    
2481                                    Query q = session.createQuery(sql);
2482    
2483                                    QueryPos qPos = QueryPos.getInstance(q);
2484    
2485                                    if (uuid != null) {
2486                                            qPos.add(uuid);
2487                                    }
2488    
2489                                    count = (Long)q.uniqueResult();
2490                            }
2491                            catch (Exception e) {
2492                                    throw processException(e);
2493                            }
2494                            finally {
2495                                    if (count == null) {
2496                                            count = Long.valueOf(0);
2497                                    }
2498    
2499                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
2500                                            finderArgs, count);
2501    
2502                                    closeSession(session);
2503                            }
2504                    }
2505    
2506                    return count.intValue();
2507            }
2508    
2509            /**
2510             * Counts all the bookmarks folders where uuid = &#63; and groupId = &#63;.
2511             *
2512             * @param uuid the uuid to search with
2513             * @param groupId the group id to search with
2514             * @return the number of matching bookmarks folders
2515             * @throws SystemException if a system exception occurred
2516             */
2517            public int countByUUID_G(String uuid, long groupId)
2518                    throws SystemException {
2519                    Object[] finderArgs = new Object[] { uuid, groupId };
2520    
2521                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
2522                                    finderArgs, this);
2523    
2524                    if (count == null) {
2525                            Session session = null;
2526    
2527                            try {
2528                                    session = openSession();
2529    
2530                                    StringBundler query = new StringBundler(3);
2531    
2532                                    query.append(_SQL_COUNT_BOOKMARKSFOLDER_WHERE);
2533    
2534                                    if (uuid == null) {
2535                                            query.append(_FINDER_COLUMN_UUID_G_UUID_1);
2536                                    }
2537                                    else {
2538                                            if (uuid.equals(StringPool.BLANK)) {
2539                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
2540                                            }
2541                                            else {
2542                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
2543                                            }
2544                                    }
2545    
2546                                    query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
2547    
2548                                    String sql = query.toString();
2549    
2550                                    Query q = session.createQuery(sql);
2551    
2552                                    QueryPos qPos = QueryPos.getInstance(q);
2553    
2554                                    if (uuid != null) {
2555                                            qPos.add(uuid);
2556                                    }
2557    
2558                                    qPos.add(groupId);
2559    
2560                                    count = (Long)q.uniqueResult();
2561                            }
2562                            catch (Exception e) {
2563                                    throw processException(e);
2564                            }
2565                            finally {
2566                                    if (count == null) {
2567                                            count = Long.valueOf(0);
2568                                    }
2569    
2570                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
2571                                            finderArgs, count);
2572    
2573                                    closeSession(session);
2574                            }
2575                    }
2576    
2577                    return count.intValue();
2578            }
2579    
2580            /**
2581             * Counts all the bookmarks folders where groupId = &#63;.
2582             *
2583             * @param groupId the group id to search with
2584             * @return the number of matching bookmarks folders
2585             * @throws SystemException if a system exception occurred
2586             */
2587            public int countByGroupId(long groupId) throws SystemException {
2588                    Object[] finderArgs = new Object[] { groupId };
2589    
2590                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
2591                                    finderArgs, this);
2592    
2593                    if (count == null) {
2594                            Session session = null;
2595    
2596                            try {
2597                                    session = openSession();
2598    
2599                                    StringBundler query = new StringBundler(2);
2600    
2601                                    query.append(_SQL_COUNT_BOOKMARKSFOLDER_WHERE);
2602    
2603                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2604    
2605                                    String sql = query.toString();
2606    
2607                                    Query q = session.createQuery(sql);
2608    
2609                                    QueryPos qPos = QueryPos.getInstance(q);
2610    
2611                                    qPos.add(groupId);
2612    
2613                                    count = (Long)q.uniqueResult();
2614                            }
2615                            catch (Exception e) {
2616                                    throw processException(e);
2617                            }
2618                            finally {
2619                                    if (count == null) {
2620                                            count = Long.valueOf(0);
2621                                    }
2622    
2623                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
2624                                            finderArgs, count);
2625    
2626                                    closeSession(session);
2627                            }
2628                    }
2629    
2630                    return count.intValue();
2631            }
2632    
2633            /**
2634             * Filters by the user's permissions and counts all the bookmarks folders where groupId = &#63;.
2635             *
2636             * @param groupId the group id to search with
2637             * @return the number of matching bookmarks folders that the user has permission to view
2638             * @throws SystemException if a system exception occurred
2639             */
2640            public int filterCountByGroupId(long groupId) throws SystemException {
2641                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2642                            return countByGroupId(groupId);
2643                    }
2644    
2645                    Session session = null;
2646    
2647                    try {
2648                            session = openSession();
2649    
2650                            StringBundler query = new StringBundler(2);
2651    
2652                            query.append(_FILTER_SQL_COUNT_BOOKMARKSFOLDER_WHERE);
2653    
2654                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2655    
2656                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2657                                            BookmarksFolder.class.getName(), _FILTER_COLUMN_PK,
2658                                            _FILTER_COLUMN_USERID, groupId);
2659    
2660                            SQLQuery q = session.createSQLQuery(sql);
2661    
2662                            q.addScalar(COUNT_COLUMN_NAME,
2663                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2664    
2665                            QueryPos qPos = QueryPos.getInstance(q);
2666    
2667                            qPos.add(groupId);
2668    
2669                            Long count = (Long)q.uniqueResult();
2670    
2671                            return count.intValue();
2672                    }
2673                    catch (Exception e) {
2674                            throw processException(e);
2675                    }
2676                    finally {
2677                            closeSession(session);
2678                    }
2679            }
2680    
2681            /**
2682             * Counts all the bookmarks folders where companyId = &#63;.
2683             *
2684             * @param companyId the company id to search with
2685             * @return the number of matching bookmarks folders
2686             * @throws SystemException if a system exception occurred
2687             */
2688            public int countByCompanyId(long companyId) throws SystemException {
2689                    Object[] finderArgs = new Object[] { companyId };
2690    
2691                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
2692                                    finderArgs, this);
2693    
2694                    if (count == null) {
2695                            Session session = null;
2696    
2697                            try {
2698                                    session = openSession();
2699    
2700                                    StringBundler query = new StringBundler(2);
2701    
2702                                    query.append(_SQL_COUNT_BOOKMARKSFOLDER_WHERE);
2703    
2704                                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2705    
2706                                    String sql = query.toString();
2707    
2708                                    Query q = session.createQuery(sql);
2709    
2710                                    QueryPos qPos = QueryPos.getInstance(q);
2711    
2712                                    qPos.add(companyId);
2713    
2714                                    count = (Long)q.uniqueResult();
2715                            }
2716                            catch (Exception e) {
2717                                    throw processException(e);
2718                            }
2719                            finally {
2720                                    if (count == null) {
2721                                            count = Long.valueOf(0);
2722                                    }
2723    
2724                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
2725                                            finderArgs, count);
2726    
2727                                    closeSession(session);
2728                            }
2729                    }
2730    
2731                    return count.intValue();
2732            }
2733    
2734            /**
2735             * Counts all the bookmarks folders where groupId = &#63; and parentFolderId = &#63;.
2736             *
2737             * @param groupId the group id to search with
2738             * @param parentFolderId the parent folder id to search with
2739             * @return the number of matching bookmarks folders
2740             * @throws SystemException if a system exception occurred
2741             */
2742            public int countByG_P(long groupId, long parentFolderId)
2743                    throws SystemException {
2744                    Object[] finderArgs = new Object[] { groupId, parentFolderId };
2745    
2746                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P,
2747                                    finderArgs, this);
2748    
2749                    if (count == null) {
2750                            Session session = null;
2751    
2752                            try {
2753                                    session = openSession();
2754    
2755                                    StringBundler query = new StringBundler(3);
2756    
2757                                    query.append(_SQL_COUNT_BOOKMARKSFOLDER_WHERE);
2758    
2759                                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
2760    
2761                                    query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
2762    
2763                                    String sql = query.toString();
2764    
2765                                    Query q = session.createQuery(sql);
2766    
2767                                    QueryPos qPos = QueryPos.getInstance(q);
2768    
2769                                    qPos.add(groupId);
2770    
2771                                    qPos.add(parentFolderId);
2772    
2773                                    count = (Long)q.uniqueResult();
2774                            }
2775                            catch (Exception e) {
2776                                    throw processException(e);
2777                            }
2778                            finally {
2779                                    if (count == null) {
2780                                            count = Long.valueOf(0);
2781                                    }
2782    
2783                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P, finderArgs,
2784                                            count);
2785    
2786                                    closeSession(session);
2787                            }
2788                    }
2789    
2790                    return count.intValue();
2791            }
2792    
2793            /**
2794             * Filters by the user's permissions and counts all the bookmarks folders where groupId = &#63; and parentFolderId = &#63;.
2795             *
2796             * @param groupId the group id to search with
2797             * @param parentFolderId the parent folder id to search with
2798             * @return the number of matching bookmarks folders that the user has permission to view
2799             * @throws SystemException if a system exception occurred
2800             */
2801            public int filterCountByG_P(long groupId, long parentFolderId)
2802                    throws SystemException {
2803                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2804                            return countByG_P(groupId, parentFolderId);
2805                    }
2806    
2807                    Session session = null;
2808    
2809                    try {
2810                            session = openSession();
2811    
2812                            StringBundler query = new StringBundler(3);
2813    
2814                            query.append(_FILTER_SQL_COUNT_BOOKMARKSFOLDER_WHERE);
2815    
2816                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
2817    
2818                            query.append(_FINDER_COLUMN_G_P_PARENTFOLDERID_2);
2819    
2820                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2821                                            BookmarksFolder.class.getName(), _FILTER_COLUMN_PK,
2822                                            _FILTER_COLUMN_USERID, groupId);
2823    
2824                            SQLQuery q = session.createSQLQuery(sql);
2825    
2826                            q.addScalar(COUNT_COLUMN_NAME,
2827                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2828    
2829                            QueryPos qPos = QueryPos.getInstance(q);
2830    
2831                            qPos.add(groupId);
2832    
2833                            qPos.add(parentFolderId);
2834    
2835                            Long count = (Long)q.uniqueResult();
2836    
2837                            return count.intValue();
2838                    }
2839                    catch (Exception e) {
2840                            throw processException(e);
2841                    }
2842                    finally {
2843                            closeSession(session);
2844                    }
2845            }
2846    
2847            /**
2848             * Counts all the bookmarks folders.
2849             *
2850             * @return the number of bookmarks folders
2851             * @throws SystemException if a system exception occurred
2852             */
2853            public int countAll() throws SystemException {
2854                    Object[] finderArgs = new Object[0];
2855    
2856                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2857                                    finderArgs, this);
2858    
2859                    if (count == null) {
2860                            Session session = null;
2861    
2862                            try {
2863                                    session = openSession();
2864    
2865                                    Query q = session.createQuery(_SQL_COUNT_BOOKMARKSFOLDER);
2866    
2867                                    count = (Long)q.uniqueResult();
2868                            }
2869                            catch (Exception e) {
2870                                    throw processException(e);
2871                            }
2872                            finally {
2873                                    if (count == null) {
2874                                            count = Long.valueOf(0);
2875                                    }
2876    
2877                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
2878                                            count);
2879    
2880                                    closeSession(session);
2881                            }
2882                    }
2883    
2884                    return count.intValue();
2885            }
2886    
2887            /**
2888             * Initializes the bookmarks folder persistence.
2889             */
2890            public void afterPropertiesSet() {
2891                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2892                                            com.liferay.portal.util.PropsUtil.get(
2893                                                    "value.object.listener.com.liferay.portlet.bookmarks.model.BookmarksFolder")));
2894    
2895                    if (listenerClassNames.length > 0) {
2896                            try {
2897                                    List<ModelListener<BookmarksFolder>> listenersList = new ArrayList<ModelListener<BookmarksFolder>>();
2898    
2899                                    for (String listenerClassName : listenerClassNames) {
2900                                            listenersList.add((ModelListener<BookmarksFolder>)InstanceFactory.newInstance(
2901                                                            listenerClassName));
2902                                    }
2903    
2904                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2905                            }
2906                            catch (Exception e) {
2907                                    _log.error(e);
2908                            }
2909                    }
2910            }
2911    
2912            public void destroy() {
2913                    EntityCacheUtil.removeCache(BookmarksFolderImpl.class.getName());
2914                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2915                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
2916            }
2917    
2918            @BeanReference(type = BookmarksEntryPersistence.class)
2919            protected BookmarksEntryPersistence bookmarksEntryPersistence;
2920            @BeanReference(type = BookmarksFolderPersistence.class)
2921            protected BookmarksFolderPersistence bookmarksFolderPersistence;
2922            @BeanReference(type = GroupPersistence.class)
2923            protected GroupPersistence groupPersistence;
2924            @BeanReference(type = ResourcePersistence.class)
2925            protected ResourcePersistence resourcePersistence;
2926            @BeanReference(type = UserPersistence.class)
2927            protected UserPersistence userPersistence;
2928            @BeanReference(type = ExpandoValuePersistence.class)
2929            protected ExpandoValuePersistence expandoValuePersistence;
2930            private static final String _SQL_SELECT_BOOKMARKSFOLDER = "SELECT bookmarksFolder FROM BookmarksFolder bookmarksFolder";
2931            private static final String _SQL_SELECT_BOOKMARKSFOLDER_WHERE = "SELECT bookmarksFolder FROM BookmarksFolder bookmarksFolder WHERE ";
2932            private static final String _SQL_COUNT_BOOKMARKSFOLDER = "SELECT COUNT(bookmarksFolder) FROM BookmarksFolder bookmarksFolder";
2933            private static final String _SQL_COUNT_BOOKMARKSFOLDER_WHERE = "SELECT COUNT(bookmarksFolder) FROM BookmarksFolder bookmarksFolder WHERE ";
2934            private static final String _FINDER_COLUMN_UUID_UUID_1 = "bookmarksFolder.uuid IS NULL";
2935            private static final String _FINDER_COLUMN_UUID_UUID_2 = "bookmarksFolder.uuid = ?";
2936            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(bookmarksFolder.uuid IS NULL OR bookmarksFolder.uuid = ?)";
2937            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "bookmarksFolder.uuid IS NULL AND ";
2938            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "bookmarksFolder.uuid = ? AND ";
2939            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(bookmarksFolder.uuid IS NULL OR bookmarksFolder.uuid = ?) AND ";
2940            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "bookmarksFolder.groupId = ?";
2941            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "bookmarksFolder.groupId = ?";
2942            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "bookmarksFolder.companyId = ?";
2943            private static final String _FINDER_COLUMN_G_P_GROUPID_2 = "bookmarksFolder.groupId = ? AND ";
2944            private static final String _FINDER_COLUMN_G_P_PARENTFOLDERID_2 = "bookmarksFolder.parentFolderId = ?";
2945            private static final String _FILTER_SQL_SELECT_BOOKMARKSFOLDER_WHERE = "SELECT DISTINCT {bookmarksFolder.*} FROM BookmarksFolder bookmarksFolder WHERE ";
2946            private static final String _FILTER_SQL_SELECT_BOOKMARKSFOLDER_NO_INLINE_DISTINCT_WHERE =
2947                    "SELECT {bookmarksFolder.*} FROM (SELECT DISTINCT folderId FROM BookmarksFolder) bookmarksFolder2 INNER JOIN BookmarksFolder bookmarksFolder ON (bookmarksFolder2.folderId = bookmarksFolder.folderId) WHERE ";
2948            private static final String _FILTER_SQL_COUNT_BOOKMARKSFOLDER_WHERE = "SELECT COUNT(DISTINCT bookmarksFolder.folderId) AS COUNT_VALUE FROM BookmarksFolder bookmarksFolder WHERE ";
2949            private static final String _FILTER_COLUMN_PK = "bookmarksFolder.folderId";
2950            private static final String _FILTER_COLUMN_USERID = "bookmarksFolder.userId";
2951            private static final String _FILTER_ENTITY_ALIAS = "bookmarksFolder";
2952            private static final String _ORDER_BY_ENTITY_ALIAS = "bookmarksFolder.";
2953            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No BookmarksFolder exists with the primary key ";
2954            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No BookmarksFolder exists with the key {";
2955            private static Log _log = LogFactoryUtil.getLog(BookmarksFolderPersistenceImpl.class);
2956    }