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