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