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