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