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