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