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