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