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