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