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