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