1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.journal.service.persistence;
16  
17  import com.liferay.portal.NoSuchModelException;
18  import com.liferay.portal.kernel.annotation.BeanReference;
19  import com.liferay.portal.kernel.cache.CacheRegistry;
20  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
21  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
22  import com.liferay.portal.kernel.dao.orm.FinderPath;
23  import com.liferay.portal.kernel.dao.orm.Query;
24  import com.liferay.portal.kernel.dao.orm.QueryPos;
25  import com.liferay.portal.kernel.dao.orm.QueryUtil;
26  import com.liferay.portal.kernel.dao.orm.SQLQuery;
27  import com.liferay.portal.kernel.dao.orm.Session;
28  import com.liferay.portal.kernel.dao.orm.Type;
29  import com.liferay.portal.kernel.exception.SystemException;
30  import com.liferay.portal.kernel.log.Log;
31  import com.liferay.portal.kernel.log.LogFactoryUtil;
32  import com.liferay.portal.kernel.util.GetterUtil;
33  import com.liferay.portal.kernel.util.InstanceFactory;
34  import com.liferay.portal.kernel.util.OrderByComparator;
35  import com.liferay.portal.kernel.util.StringBundler;
36  import com.liferay.portal.kernel.util.StringPool;
37  import com.liferay.portal.kernel.util.StringUtil;
38  import com.liferay.portal.kernel.util.Validator;
39  import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
40  import com.liferay.portal.model.ModelListener;
41  import com.liferay.portal.security.permission.InlineSQLHelperUtil;
42  import com.liferay.portal.service.persistence.BatchSessionUtil;
43  import com.liferay.portal.service.persistence.ResourcePersistence;
44  import com.liferay.portal.service.persistence.UserPersistence;
45  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
46  
47  import com.liferay.portlet.expando.service.persistence.ExpandoValuePersistence;
48  import com.liferay.portlet.journal.NoSuchFeedException;
49  import com.liferay.portlet.journal.model.JournalFeed;
50  import com.liferay.portlet.journal.model.impl.JournalFeedImpl;
51  import com.liferay.portlet.journal.model.impl.JournalFeedModelImpl;
52  
53  import java.io.Serializable;
54  
55  import java.util.ArrayList;
56  import java.util.Collections;
57  import java.util.List;
58  
59  /**
60   * <a href="JournalFeedPersistenceImpl.java.html"><b><i>View Source</i></b></a>
61   *
62   * <p>
63   * ServiceBuilder generated this class. Modifications in this class will be
64   * overwritten the next time is generated.
65   * </p>
66   *
67   * @author    Brian Wing Shun Chan
68   * @see       JournalFeedPersistence
69   * @see       JournalFeedUtil
70   * @generated
71   */
72  public class JournalFeedPersistenceImpl extends BasePersistenceImpl<JournalFeed>
73      implements JournalFeedPersistence {
74      public static final String FINDER_CLASS_NAME_ENTITY = JournalFeedImpl.class.getName();
75      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
76          ".List";
77      public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
78              JournalFeedModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
79              "findByUuid",
80              new String[] {
81                  String.class.getName(),
82                  
83              "java.lang.Integer", "java.lang.Integer",
84                  "com.liferay.portal.kernel.util.OrderByComparator"
85              });
86      public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
87              JournalFeedModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
88              "countByUuid", new String[] { String.class.getName() });
89      public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
90              JournalFeedModelImpl.FINDER_CACHE_ENABLED,
91              FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
92              new String[] { String.class.getName(), Long.class.getName() });
93      public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
94              JournalFeedModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
95              "countByUUID_G",
96              new String[] { String.class.getName(), Long.class.getName() });
97      public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
98              JournalFeedModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
99              "findByGroupId",
100             new String[] {
101                 Long.class.getName(),
102                 
103             "java.lang.Integer", "java.lang.Integer",
104                 "com.liferay.portal.kernel.util.OrderByComparator"
105             });
106     public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
107             JournalFeedModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
108             "countByGroupId", new String[] { Long.class.getName() });
109     public static final FinderPath FINDER_PATH_FETCH_BY_G_F = new FinderPath(JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
110             JournalFeedModelImpl.FINDER_CACHE_ENABLED,
111             FINDER_CLASS_NAME_ENTITY, "fetchByG_F",
112             new String[] { Long.class.getName(), String.class.getName() });
113     public static final FinderPath FINDER_PATH_COUNT_BY_G_F = new FinderPath(JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
114             JournalFeedModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
115             "countByG_F",
116             new String[] { Long.class.getName(), String.class.getName() });
117     public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
118             JournalFeedModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
119             "findAll", new String[0]);
120     public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
121             JournalFeedModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
122             "countAll", new String[0]);
123 
124     public void cacheResult(JournalFeed journalFeed) {
125         EntityCacheUtil.putResult(JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
126             JournalFeedImpl.class, journalFeed.getPrimaryKey(), journalFeed);
127 
128         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
129             new Object[] {
130                 journalFeed.getUuid(), new Long(journalFeed.getGroupId())
131             }, journalFeed);
132 
133         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_F,
134             new Object[] {
135                 new Long(journalFeed.getGroupId()),
136                 
137             journalFeed.getFeedId()
138             }, journalFeed);
139     }
140 
141     public void cacheResult(List<JournalFeed> journalFeeds) {
142         for (JournalFeed journalFeed : journalFeeds) {
143             if (EntityCacheUtil.getResult(
144                         JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
145                         JournalFeedImpl.class, journalFeed.getPrimaryKey(), this) == null) {
146                 cacheResult(journalFeed);
147             }
148         }
149     }
150 
151     public void clearCache() {
152         CacheRegistry.clear(JournalFeedImpl.class.getName());
153         EntityCacheUtil.clearCache(JournalFeedImpl.class.getName());
154         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
155         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
156     }
157 
158     public void clearCache(JournalFeed journalFeed) {
159         EntityCacheUtil.removeResult(JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
160             JournalFeedImpl.class, journalFeed.getPrimaryKey());
161 
162         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
163             new Object[] {
164                 journalFeed.getUuid(), new Long(journalFeed.getGroupId())
165             });
166 
167         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_F,
168             new Object[] {
169                 new Long(journalFeed.getGroupId()),
170                 
171             journalFeed.getFeedId()
172             });
173     }
174 
175     public JournalFeed create(long id) {
176         JournalFeed journalFeed = new JournalFeedImpl();
177 
178         journalFeed.setNew(true);
179         journalFeed.setPrimaryKey(id);
180 
181         String uuid = PortalUUIDUtil.generate();
182 
183         journalFeed.setUuid(uuid);
184 
185         return journalFeed;
186     }
187 
188     public JournalFeed remove(Serializable primaryKey)
189         throws NoSuchModelException, SystemException {
190         return remove(((Long)primaryKey).longValue());
191     }
192 
193     public JournalFeed remove(long id)
194         throws NoSuchFeedException, SystemException {
195         Session session = null;
196 
197         try {
198             session = openSession();
199 
200             JournalFeed journalFeed = (JournalFeed)session.get(JournalFeedImpl.class,
201                     new Long(id));
202 
203             if (journalFeed == null) {
204                 if (_log.isWarnEnabled()) {
205                     _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + id);
206                 }
207 
208                 throw new NoSuchFeedException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
209                     id);
210             }
211 
212             return remove(journalFeed);
213         }
214         catch (NoSuchFeedException nsee) {
215             throw nsee;
216         }
217         catch (Exception e) {
218             throw processException(e);
219         }
220         finally {
221             closeSession(session);
222         }
223     }
224 
225     public JournalFeed remove(JournalFeed journalFeed)
226         throws SystemException {
227         for (ModelListener<JournalFeed> listener : listeners) {
228             listener.onBeforeRemove(journalFeed);
229         }
230 
231         journalFeed = removeImpl(journalFeed);
232 
233         for (ModelListener<JournalFeed> listener : listeners) {
234             listener.onAfterRemove(journalFeed);
235         }
236 
237         return journalFeed;
238     }
239 
240     protected JournalFeed removeImpl(JournalFeed journalFeed)
241         throws SystemException {
242         journalFeed = toUnwrappedModel(journalFeed);
243 
244         Session session = null;
245 
246         try {
247             session = openSession();
248 
249             if (journalFeed.isCachedModel() || BatchSessionUtil.isEnabled()) {
250                 Object staleObject = session.get(JournalFeedImpl.class,
251                         journalFeed.getPrimaryKeyObj());
252 
253                 if (staleObject != null) {
254                     session.evict(staleObject);
255                 }
256             }
257 
258             session.delete(journalFeed);
259 
260             session.flush();
261         }
262         catch (Exception e) {
263             throw processException(e);
264         }
265         finally {
266             closeSession(session);
267         }
268 
269         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
270 
271         JournalFeedModelImpl journalFeedModelImpl = (JournalFeedModelImpl)journalFeed;
272 
273         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
274             new Object[] {
275                 journalFeedModelImpl.getOriginalUuid(),
276                 new Long(journalFeedModelImpl.getOriginalGroupId())
277             });
278 
279         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_F,
280             new Object[] {
281                 new Long(journalFeedModelImpl.getOriginalGroupId()),
282                 
283             journalFeedModelImpl.getOriginalFeedId()
284             });
285 
286         EntityCacheUtil.removeResult(JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
287             JournalFeedImpl.class, journalFeed.getPrimaryKey());
288 
289         return journalFeed;
290     }
291 
292     public JournalFeed updateImpl(
293         com.liferay.portlet.journal.model.JournalFeed journalFeed, boolean merge)
294         throws SystemException {
295         journalFeed = toUnwrappedModel(journalFeed);
296 
297         boolean isNew = journalFeed.isNew();
298 
299         JournalFeedModelImpl journalFeedModelImpl = (JournalFeedModelImpl)journalFeed;
300 
301         if (Validator.isNull(journalFeed.getUuid())) {
302             String uuid = PortalUUIDUtil.generate();
303 
304             journalFeed.setUuid(uuid);
305         }
306 
307         Session session = null;
308 
309         try {
310             session = openSession();
311 
312             BatchSessionUtil.update(session, journalFeed, merge);
313 
314             journalFeed.setNew(false);
315         }
316         catch (Exception e) {
317             throw processException(e);
318         }
319         finally {
320             closeSession(session);
321         }
322 
323         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
324 
325         EntityCacheUtil.putResult(JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
326             JournalFeedImpl.class, journalFeed.getPrimaryKey(), journalFeed);
327 
328         if (!isNew &&
329                 (!Validator.equals(journalFeed.getUuid(),
330                     journalFeedModelImpl.getOriginalUuid()) ||
331                 (journalFeed.getGroupId() != journalFeedModelImpl.getOriginalGroupId()))) {
332             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
333                 new Object[] {
334                     journalFeedModelImpl.getOriginalUuid(),
335                     new Long(journalFeedModelImpl.getOriginalGroupId())
336                 });
337         }
338 
339         if (isNew ||
340                 (!Validator.equals(journalFeed.getUuid(),
341                     journalFeedModelImpl.getOriginalUuid()) ||
342                 (journalFeed.getGroupId() != journalFeedModelImpl.getOriginalGroupId()))) {
343             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
344                 new Object[] {
345                     journalFeed.getUuid(), new Long(journalFeed.getGroupId())
346                 }, journalFeed);
347         }
348 
349         if (!isNew &&
350                 ((journalFeed.getGroupId() != journalFeedModelImpl.getOriginalGroupId()) ||
351                 !Validator.equals(journalFeed.getFeedId(),
352                     journalFeedModelImpl.getOriginalFeedId()))) {
353             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_F,
354                 new Object[] {
355                     new Long(journalFeedModelImpl.getOriginalGroupId()),
356                     
357                 journalFeedModelImpl.getOriginalFeedId()
358                 });
359         }
360 
361         if (isNew ||
362                 ((journalFeed.getGroupId() != journalFeedModelImpl.getOriginalGroupId()) ||
363                 !Validator.equals(journalFeed.getFeedId(),
364                     journalFeedModelImpl.getOriginalFeedId()))) {
365             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_F,
366                 new Object[] {
367                     new Long(journalFeed.getGroupId()),
368                     
369                 journalFeed.getFeedId()
370                 }, journalFeed);
371         }
372 
373         return journalFeed;
374     }
375 
376     protected JournalFeed toUnwrappedModel(JournalFeed journalFeed) {
377         if (journalFeed instanceof JournalFeedImpl) {
378             return journalFeed;
379         }
380 
381         JournalFeedImpl journalFeedImpl = new JournalFeedImpl();
382 
383         journalFeedImpl.setNew(journalFeed.isNew());
384         journalFeedImpl.setPrimaryKey(journalFeed.getPrimaryKey());
385 
386         journalFeedImpl.setUuid(journalFeed.getUuid());
387         journalFeedImpl.setId(journalFeed.getId());
388         journalFeedImpl.setGroupId(journalFeed.getGroupId());
389         journalFeedImpl.setCompanyId(journalFeed.getCompanyId());
390         journalFeedImpl.setUserId(journalFeed.getUserId());
391         journalFeedImpl.setUserName(journalFeed.getUserName());
392         journalFeedImpl.setCreateDate(journalFeed.getCreateDate());
393         journalFeedImpl.setModifiedDate(journalFeed.getModifiedDate());
394         journalFeedImpl.setFeedId(journalFeed.getFeedId());
395         journalFeedImpl.setName(journalFeed.getName());
396         journalFeedImpl.setDescription(journalFeed.getDescription());
397         journalFeedImpl.setType(journalFeed.getType());
398         journalFeedImpl.setStructureId(journalFeed.getStructureId());
399         journalFeedImpl.setTemplateId(journalFeed.getTemplateId());
400         journalFeedImpl.setRendererTemplateId(journalFeed.getRendererTemplateId());
401         journalFeedImpl.setDelta(journalFeed.getDelta());
402         journalFeedImpl.setOrderByCol(journalFeed.getOrderByCol());
403         journalFeedImpl.setOrderByType(journalFeed.getOrderByType());
404         journalFeedImpl.setTargetLayoutFriendlyUrl(journalFeed.getTargetLayoutFriendlyUrl());
405         journalFeedImpl.setTargetPortletId(journalFeed.getTargetPortletId());
406         journalFeedImpl.setContentField(journalFeed.getContentField());
407         journalFeedImpl.setFeedType(journalFeed.getFeedType());
408         journalFeedImpl.setFeedVersion(journalFeed.getFeedVersion());
409 
410         return journalFeedImpl;
411     }
412 
413     public JournalFeed findByPrimaryKey(Serializable primaryKey)
414         throws NoSuchModelException, SystemException {
415         return findByPrimaryKey(((Long)primaryKey).longValue());
416     }
417 
418     public JournalFeed findByPrimaryKey(long id)
419         throws NoSuchFeedException, SystemException {
420         JournalFeed journalFeed = fetchByPrimaryKey(id);
421 
422         if (journalFeed == null) {
423             if (_log.isWarnEnabled()) {
424                 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + id);
425             }
426 
427             throw new NoSuchFeedException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
428                 id);
429         }
430 
431         return journalFeed;
432     }
433 
434     public JournalFeed fetchByPrimaryKey(Serializable primaryKey)
435         throws SystemException {
436         return fetchByPrimaryKey(((Long)primaryKey).longValue());
437     }
438 
439     public JournalFeed fetchByPrimaryKey(long id) throws SystemException {
440         JournalFeed journalFeed = (JournalFeed)EntityCacheUtil.getResult(JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
441                 JournalFeedImpl.class, id, this);
442 
443         if (journalFeed == null) {
444             Session session = null;
445 
446             try {
447                 session = openSession();
448 
449                 journalFeed = (JournalFeed)session.get(JournalFeedImpl.class,
450                         new Long(id));
451             }
452             catch (Exception e) {
453                 throw processException(e);
454             }
455             finally {
456                 if (journalFeed != null) {
457                     cacheResult(journalFeed);
458                 }
459 
460                 closeSession(session);
461             }
462         }
463 
464         return journalFeed;
465     }
466 
467     public List<JournalFeed> findByUuid(String uuid) throws SystemException {
468         return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
469     }
470 
471     public List<JournalFeed> findByUuid(String uuid, int start, int end)
472         throws SystemException {
473         return findByUuid(uuid, start, end, null);
474     }
475 
476     public List<JournalFeed> findByUuid(String uuid, int start, int end,
477         OrderByComparator orderByComparator) throws SystemException {
478         Object[] finderArgs = new Object[] {
479                 uuid,
480                 
481                 String.valueOf(start), String.valueOf(end),
482                 String.valueOf(orderByComparator)
483             };
484 
485         List<JournalFeed> list = (List<JournalFeed>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
486                 finderArgs, this);
487 
488         if (list == null) {
489             Session session = null;
490 
491             try {
492                 session = openSession();
493 
494                 StringBundler query = null;
495 
496                 if (orderByComparator != null) {
497                     query = new StringBundler(3 +
498                             (orderByComparator.getOrderByFields().length * 3));
499                 }
500                 else {
501                     query = new StringBundler(3);
502                 }
503 
504                 query.append(_SQL_SELECT_JOURNALFEED_WHERE);
505 
506                 if (uuid == null) {
507                     query.append(_FINDER_COLUMN_UUID_UUID_1);
508                 }
509                 else {
510                     if (uuid.equals(StringPool.BLANK)) {
511                         query.append(_FINDER_COLUMN_UUID_UUID_3);
512                     }
513                     else {
514                         query.append(_FINDER_COLUMN_UUID_UUID_2);
515                     }
516                 }
517 
518                 if (orderByComparator != null) {
519                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
520                         orderByComparator);
521                 }
522 
523                 else {
524                     query.append(JournalFeedModelImpl.ORDER_BY_JPQL);
525                 }
526 
527                 String sql = query.toString();
528 
529                 Query q = session.createQuery(sql);
530 
531                 QueryPos qPos = QueryPos.getInstance(q);
532 
533                 if (uuid != null) {
534                     qPos.add(uuid);
535                 }
536 
537                 list = (List<JournalFeed>)QueryUtil.list(q, getDialect(),
538                         start, end);
539             }
540             catch (Exception e) {
541                 throw processException(e);
542             }
543             finally {
544                 if (list == null) {
545                     list = new ArrayList<JournalFeed>();
546                 }
547 
548                 cacheResult(list);
549 
550                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
551                     list);
552 
553                 closeSession(session);
554             }
555         }
556 
557         return list;
558     }
559 
560     public JournalFeed findByUuid_First(String uuid,
561         OrderByComparator orderByComparator)
562         throws NoSuchFeedException, SystemException {
563         List<JournalFeed> list = findByUuid(uuid, 0, 1, orderByComparator);
564 
565         if (list.isEmpty()) {
566             StringBundler msg = new StringBundler(4);
567 
568             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
569 
570             msg.append("uuid=");
571             msg.append(uuid);
572 
573             msg.append(StringPool.CLOSE_CURLY_BRACE);
574 
575             throw new NoSuchFeedException(msg.toString());
576         }
577         else {
578             return list.get(0);
579         }
580     }
581 
582     public JournalFeed findByUuid_Last(String uuid,
583         OrderByComparator orderByComparator)
584         throws NoSuchFeedException, SystemException {
585         int count = countByUuid(uuid);
586 
587         List<JournalFeed> list = findByUuid(uuid, count - 1, count,
588                 orderByComparator);
589 
590         if (list.isEmpty()) {
591             StringBundler msg = new StringBundler(4);
592 
593             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
594 
595             msg.append("uuid=");
596             msg.append(uuid);
597 
598             msg.append(StringPool.CLOSE_CURLY_BRACE);
599 
600             throw new NoSuchFeedException(msg.toString());
601         }
602         else {
603             return list.get(0);
604         }
605     }
606 
607     public JournalFeed[] findByUuid_PrevAndNext(long id, String uuid,
608         OrderByComparator orderByComparator)
609         throws NoSuchFeedException, SystemException {
610         JournalFeed journalFeed = findByPrimaryKey(id);
611 
612         Session session = null;
613 
614         try {
615             session = openSession();
616 
617             JournalFeed[] array = new JournalFeedImpl[3];
618 
619             array[0] = getByUuid_PrevAndNext(session, journalFeed, uuid,
620                     orderByComparator, true);
621 
622             array[1] = journalFeed;
623 
624             array[2] = getByUuid_PrevAndNext(session, journalFeed, uuid,
625                     orderByComparator, false);
626 
627             return array;
628         }
629         catch (Exception e) {
630             throw processException(e);
631         }
632         finally {
633             closeSession(session);
634         }
635     }
636 
637     protected JournalFeed getByUuid_PrevAndNext(Session session,
638         JournalFeed journalFeed, String uuid,
639         OrderByComparator orderByComparator, boolean previous) {
640         StringBundler query = null;
641 
642         if (orderByComparator != null) {
643             query = new StringBundler(6 +
644                     (orderByComparator.getOrderByFields().length * 6));
645         }
646         else {
647             query = new StringBundler(3);
648         }
649 
650         query.append(_SQL_SELECT_JOURNALFEED_WHERE);
651 
652         if (uuid == null) {
653             query.append(_FINDER_COLUMN_UUID_UUID_1);
654         }
655         else {
656             if (uuid.equals(StringPool.BLANK)) {
657                 query.append(_FINDER_COLUMN_UUID_UUID_3);
658             }
659             else {
660                 query.append(_FINDER_COLUMN_UUID_UUID_2);
661             }
662         }
663 
664         if (orderByComparator != null) {
665             String[] orderByFields = orderByComparator.getOrderByFields();
666 
667             if (orderByFields.length > 0) {
668                 query.append(WHERE_AND);
669             }
670 
671             for (int i = 0; i < orderByFields.length; i++) {
672                 query.append(_ORDER_BY_ENTITY_ALIAS);
673                 query.append(orderByFields[i]);
674 
675                 if ((i + 1) < orderByFields.length) {
676                     if (orderByComparator.isAscending() ^ previous) {
677                         query.append(WHERE_GREATER_THAN_HAS_NEXT);
678                     }
679                     else {
680                         query.append(WHERE_LESSER_THAN_HAS_NEXT);
681                     }
682                 }
683                 else {
684                     if (orderByComparator.isAscending() ^ previous) {
685                         query.append(WHERE_GREATER_THAN);
686                     }
687                     else {
688                         query.append(WHERE_LESSER_THAN);
689                     }
690                 }
691             }
692 
693             query.append(ORDER_BY_CLAUSE);
694 
695             for (int i = 0; i < orderByFields.length; i++) {
696                 query.append(_ORDER_BY_ENTITY_ALIAS);
697                 query.append(orderByFields[i]);
698 
699                 if ((i + 1) < orderByFields.length) {
700                     if (orderByComparator.isAscending() ^ previous) {
701                         query.append(ORDER_BY_ASC_HAS_NEXT);
702                     }
703                     else {
704                         query.append(ORDER_BY_DESC_HAS_NEXT);
705                     }
706                 }
707                 else {
708                     if (orderByComparator.isAscending() ^ previous) {
709                         query.append(ORDER_BY_ASC);
710                     }
711                     else {
712                         query.append(ORDER_BY_DESC);
713                     }
714                 }
715             }
716         }
717 
718         else {
719             query.append(JournalFeedModelImpl.ORDER_BY_JPQL);
720         }
721 
722         String sql = query.toString();
723 
724         Query q = session.createQuery(sql);
725 
726         q.setFirstResult(0);
727         q.setMaxResults(2);
728 
729         QueryPos qPos = QueryPos.getInstance(q);
730 
731         if (uuid != null) {
732             qPos.add(uuid);
733         }
734 
735         if (orderByComparator != null) {
736             Object[] values = orderByComparator.getOrderByValues(journalFeed);
737 
738             for (Object value : values) {
739                 qPos.add(value);
740             }
741         }
742 
743         List<JournalFeed> list = q.list();
744 
745         if (list.size() == 2) {
746             return list.get(1);
747         }
748         else {
749             return null;
750         }
751     }
752 
753     public JournalFeed findByUUID_G(String uuid, long groupId)
754         throws NoSuchFeedException, SystemException {
755         JournalFeed journalFeed = fetchByUUID_G(uuid, groupId);
756 
757         if (journalFeed == null) {
758             StringBundler msg = new StringBundler(6);
759 
760             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
761 
762             msg.append("uuid=");
763             msg.append(uuid);
764 
765             msg.append(", groupId=");
766             msg.append(groupId);
767 
768             msg.append(StringPool.CLOSE_CURLY_BRACE);
769 
770             if (_log.isWarnEnabled()) {
771                 _log.warn(msg.toString());
772             }
773 
774             throw new NoSuchFeedException(msg.toString());
775         }
776 
777         return journalFeed;
778     }
779 
780     public JournalFeed fetchByUUID_G(String uuid, long groupId)
781         throws SystemException {
782         return fetchByUUID_G(uuid, groupId, true);
783     }
784 
785     public JournalFeed fetchByUUID_G(String uuid, long groupId,
786         boolean retrieveFromCache) throws SystemException {
787         Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
788 
789         Object result = null;
790 
791         if (retrieveFromCache) {
792             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
793                     finderArgs, this);
794         }
795 
796         if (result == null) {
797             Session session = null;
798 
799             try {
800                 session = openSession();
801 
802                 StringBundler query = new StringBundler(4);
803 
804                 query.append(_SQL_SELECT_JOURNALFEED_WHERE);
805 
806                 if (uuid == null) {
807                     query.append(_FINDER_COLUMN_UUID_G_UUID_1);
808                 }
809                 else {
810                     if (uuid.equals(StringPool.BLANK)) {
811                         query.append(_FINDER_COLUMN_UUID_G_UUID_3);
812                     }
813                     else {
814                         query.append(_FINDER_COLUMN_UUID_G_UUID_2);
815                     }
816                 }
817 
818                 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
819 
820                 query.append(JournalFeedModelImpl.ORDER_BY_JPQL);
821 
822                 String sql = query.toString();
823 
824                 Query q = session.createQuery(sql);
825 
826                 QueryPos qPos = QueryPos.getInstance(q);
827 
828                 if (uuid != null) {
829                     qPos.add(uuid);
830                 }
831 
832                 qPos.add(groupId);
833 
834                 List<JournalFeed> list = q.list();
835 
836                 result = list;
837 
838                 JournalFeed journalFeed = null;
839 
840                 if (list.isEmpty()) {
841                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
842                         finderArgs, list);
843                 }
844                 else {
845                     journalFeed = list.get(0);
846 
847                     cacheResult(journalFeed);
848 
849                     if ((journalFeed.getUuid() == null) ||
850                             !journalFeed.getUuid().equals(uuid) ||
851                             (journalFeed.getGroupId() != groupId)) {
852                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
853                             finderArgs, journalFeed);
854                     }
855                 }
856 
857                 return journalFeed;
858             }
859             catch (Exception e) {
860                 throw processException(e);
861             }
862             finally {
863                 if (result == null) {
864                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
865                         finderArgs, new ArrayList<JournalFeed>());
866                 }
867 
868                 closeSession(session);
869             }
870         }
871         else {
872             if (result instanceof List<?>) {
873                 return null;
874             }
875             else {
876                 return (JournalFeed)result;
877             }
878         }
879     }
880 
881     public List<JournalFeed> findByGroupId(long groupId)
882         throws SystemException {
883         return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
884     }
885 
886     public List<JournalFeed> findByGroupId(long groupId, int start, int end)
887         throws SystemException {
888         return findByGroupId(groupId, start, end, null);
889     }
890 
891     public List<JournalFeed> findByGroupId(long groupId, int start, int end,
892         OrderByComparator orderByComparator) throws SystemException {
893         Object[] finderArgs = new Object[] {
894                 new Long(groupId),
895                 
896                 String.valueOf(start), String.valueOf(end),
897                 String.valueOf(orderByComparator)
898             };
899 
900         List<JournalFeed> list = (List<JournalFeed>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
901                 finderArgs, this);
902 
903         if (list == null) {
904             Session session = null;
905 
906             try {
907                 session = openSession();
908 
909                 StringBundler query = null;
910 
911                 if (orderByComparator != null) {
912                     query = new StringBundler(3 +
913                             (orderByComparator.getOrderByFields().length * 3));
914                 }
915                 else {
916                     query = new StringBundler(3);
917                 }
918 
919                 query.append(_SQL_SELECT_JOURNALFEED_WHERE);
920 
921                 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
922 
923                 if (orderByComparator != null) {
924                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
925                         orderByComparator);
926                 }
927 
928                 else {
929                     query.append(JournalFeedModelImpl.ORDER_BY_JPQL);
930                 }
931 
932                 String sql = query.toString();
933 
934                 Query q = session.createQuery(sql);
935 
936                 QueryPos qPos = QueryPos.getInstance(q);
937 
938                 qPos.add(groupId);
939 
940                 list = (List<JournalFeed>)QueryUtil.list(q, getDialect(),
941                         start, end);
942             }
943             catch (Exception e) {
944                 throw processException(e);
945             }
946             finally {
947                 if (list == null) {
948                     list = new ArrayList<JournalFeed>();
949                 }
950 
951                 cacheResult(list);
952 
953                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
954                     finderArgs, list);
955 
956                 closeSession(session);
957             }
958         }
959 
960         return list;
961     }
962 
963     public JournalFeed findByGroupId_First(long groupId,
964         OrderByComparator orderByComparator)
965         throws NoSuchFeedException, SystemException {
966         List<JournalFeed> list = findByGroupId(groupId, 0, 1, orderByComparator);
967 
968         if (list.isEmpty()) {
969             StringBundler msg = new StringBundler(4);
970 
971             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
972 
973             msg.append("groupId=");
974             msg.append(groupId);
975 
976             msg.append(StringPool.CLOSE_CURLY_BRACE);
977 
978             throw new NoSuchFeedException(msg.toString());
979         }
980         else {
981             return list.get(0);
982         }
983     }
984 
985     public JournalFeed findByGroupId_Last(long groupId,
986         OrderByComparator orderByComparator)
987         throws NoSuchFeedException, SystemException {
988         int count = countByGroupId(groupId);
989 
990         List<JournalFeed> list = findByGroupId(groupId, count - 1, count,
991                 orderByComparator);
992 
993         if (list.isEmpty()) {
994             StringBundler msg = new StringBundler(4);
995 
996             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
997 
998             msg.append("groupId=");
999             msg.append(groupId);
1000
1001            msg.append(StringPool.CLOSE_CURLY_BRACE);
1002
1003            throw new NoSuchFeedException(msg.toString());
1004        }
1005        else {
1006            return list.get(0);
1007        }
1008    }
1009
1010    public JournalFeed[] findByGroupId_PrevAndNext(long id, long groupId,
1011        OrderByComparator orderByComparator)
1012        throws NoSuchFeedException, SystemException {
1013        JournalFeed journalFeed = findByPrimaryKey(id);
1014
1015        Session session = null;
1016
1017        try {
1018            session = openSession();
1019
1020            JournalFeed[] array = new JournalFeedImpl[3];
1021
1022            array[0] = getByGroupId_PrevAndNext(session, journalFeed, groupId,
1023                    orderByComparator, true);
1024
1025            array[1] = journalFeed;
1026
1027            array[2] = getByGroupId_PrevAndNext(session, journalFeed, groupId,
1028                    orderByComparator, false);
1029
1030            return array;
1031        }
1032        catch (Exception e) {
1033            throw processException(e);
1034        }
1035        finally {
1036            closeSession(session);
1037        }
1038    }
1039
1040    protected JournalFeed getByGroupId_PrevAndNext(Session session,
1041        JournalFeed journalFeed, long groupId,
1042        OrderByComparator orderByComparator, boolean previous) {
1043        StringBundler query = null;
1044
1045        if (orderByComparator != null) {
1046            query = new StringBundler(6 +
1047                    (orderByComparator.getOrderByFields().length * 6));
1048        }
1049        else {
1050            query = new StringBundler(3);
1051        }
1052
1053        query.append(_SQL_SELECT_JOURNALFEED_WHERE);
1054
1055        query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1056
1057        if (orderByComparator != null) {
1058            String[] orderByFields = orderByComparator.getOrderByFields();
1059
1060            if (orderByFields.length > 0) {
1061                query.append(WHERE_AND);
1062            }
1063
1064            for (int i = 0; i < orderByFields.length; i++) {
1065                query.append(_ORDER_BY_ENTITY_ALIAS);
1066                query.append(orderByFields[i]);
1067
1068                if ((i + 1) < orderByFields.length) {
1069                    if (orderByComparator.isAscending() ^ previous) {
1070                        query.append(WHERE_GREATER_THAN_HAS_NEXT);
1071                    }
1072                    else {
1073                        query.append(WHERE_LESSER_THAN_HAS_NEXT);
1074                    }
1075                }
1076                else {
1077                    if (orderByComparator.isAscending() ^ previous) {
1078                        query.append(WHERE_GREATER_THAN);
1079                    }
1080                    else {
1081                        query.append(WHERE_LESSER_THAN);
1082                    }
1083                }
1084            }
1085
1086            query.append(ORDER_BY_CLAUSE);
1087
1088            for (int i = 0; i < orderByFields.length; i++) {
1089                query.append(_ORDER_BY_ENTITY_ALIAS);
1090                query.append(orderByFields[i]);
1091
1092                if ((i + 1) < orderByFields.length) {
1093                    if (orderByComparator.isAscending() ^ previous) {
1094                        query.append(ORDER_BY_ASC_HAS_NEXT);
1095                    }
1096                    else {
1097                        query.append(ORDER_BY_DESC_HAS_NEXT);
1098                    }
1099                }
1100                else {
1101                    if (orderByComparator.isAscending() ^ previous) {
1102                        query.append(ORDER_BY_ASC);
1103                    }
1104                    else {
1105                        query.append(ORDER_BY_DESC);
1106                    }
1107                }
1108            }
1109        }
1110
1111        else {
1112            query.append(JournalFeedModelImpl.ORDER_BY_JPQL);
1113        }
1114
1115        String sql = query.toString();
1116
1117        Query q = session.createQuery(sql);
1118
1119        q.setFirstResult(0);
1120        q.setMaxResults(2);
1121
1122        QueryPos qPos = QueryPos.getInstance(q);
1123
1124        qPos.add(groupId);
1125
1126        if (orderByComparator != null) {
1127            Object[] values = orderByComparator.getOrderByValues(journalFeed);
1128
1129            for (Object value : values) {
1130                qPos.add(value);
1131            }
1132        }
1133
1134        List<JournalFeed> list = q.list();
1135
1136        if (list.size() == 2) {
1137            return list.get(1);
1138        }
1139        else {
1140            return null;
1141        }
1142    }
1143
1144    public List<JournalFeed> filterFindByGroupId(long groupId)
1145        throws SystemException {
1146        return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1147            QueryUtil.ALL_POS, null);
1148    }
1149
1150    public List<JournalFeed> filterFindByGroupId(long groupId, int start,
1151        int end) throws SystemException {
1152        return filterFindByGroupId(groupId, start, end, null);
1153    }
1154
1155    public List<JournalFeed> filterFindByGroupId(long groupId, int start,
1156        int end, OrderByComparator orderByComparator) throws SystemException {
1157        if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1158            return findByGroupId(groupId, start, end, orderByComparator);
1159        }
1160
1161        Session session = null;
1162
1163        try {
1164            session = openSession();
1165
1166            StringBundler query = null;
1167
1168            if (orderByComparator != null) {
1169                query = new StringBundler(3 +
1170                        (orderByComparator.getOrderByFields().length * 3));
1171            }
1172            else {
1173                query = new StringBundler(3);
1174            }
1175
1176            query.append(_FILTER_SQL_SELECT_JOURNALFEED_WHERE);
1177
1178            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1179
1180            if (orderByComparator != null) {
1181                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1182                    orderByComparator);
1183            }
1184
1185            else {
1186                query.append(JournalFeedModelImpl.ORDER_BY_JPQL);
1187            }
1188
1189            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1190                    JournalFeed.class.getName(), _FILTER_COLUMN_ID,
1191                    _FILTER_COLUMN_USERID, groupId);
1192
1193            SQLQuery q = session.createSQLQuery(sql);
1194
1195            q.addEntity(_FILTER_ENTITY_ALIAS, JournalFeedImpl.class);
1196
1197            QueryPos qPos = QueryPos.getInstance(q);
1198
1199            qPos.add(groupId);
1200
1201            return (List<JournalFeed>)QueryUtil.list(q, getDialect(), start, end);
1202        }
1203        catch (Exception e) {
1204            throw processException(e);
1205        }
1206        finally {
1207            closeSession(session);
1208        }
1209    }
1210
1211    public JournalFeed findByG_F(long groupId, String feedId)
1212        throws NoSuchFeedException, SystemException {
1213        JournalFeed journalFeed = fetchByG_F(groupId, feedId);
1214
1215        if (journalFeed == null) {
1216            StringBundler msg = new StringBundler(6);
1217
1218            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1219
1220            msg.append("groupId=");
1221            msg.append(groupId);
1222
1223            msg.append(", feedId=");
1224            msg.append(feedId);
1225
1226            msg.append(StringPool.CLOSE_CURLY_BRACE);
1227
1228            if (_log.isWarnEnabled()) {
1229                _log.warn(msg.toString());
1230            }
1231
1232            throw new NoSuchFeedException(msg.toString());
1233        }
1234
1235        return journalFeed;
1236    }
1237
1238    public JournalFeed fetchByG_F(long groupId, String feedId)
1239        throws SystemException {
1240        return fetchByG_F(groupId, feedId, true);
1241    }
1242
1243    public JournalFeed fetchByG_F(long groupId, String feedId,
1244        boolean retrieveFromCache) throws SystemException {
1245        Object[] finderArgs = new Object[] { new Long(groupId), feedId };
1246
1247        Object result = null;
1248
1249        if (retrieveFromCache) {
1250            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_F,
1251                    finderArgs, this);
1252        }
1253
1254        if (result == null) {
1255            Session session = null;
1256
1257            try {
1258                session = openSession();
1259
1260                StringBundler query = new StringBundler(4);
1261
1262                query.append(_SQL_SELECT_JOURNALFEED_WHERE);
1263
1264                query.append(_FINDER_COLUMN_G_F_GROUPID_2);
1265
1266                if (feedId == null) {
1267                    query.append(_FINDER_COLUMN_G_F_FEEDID_1);
1268                }
1269                else {
1270                    if (feedId.equals(StringPool.BLANK)) {
1271                        query.append(_FINDER_COLUMN_G_F_FEEDID_3);
1272                    }
1273                    else {
1274                        query.append(_FINDER_COLUMN_G_F_FEEDID_2);
1275                    }
1276                }
1277
1278                query.append(JournalFeedModelImpl.ORDER_BY_JPQL);
1279
1280                String sql = query.toString();
1281
1282                Query q = session.createQuery(sql);
1283
1284                QueryPos qPos = QueryPos.getInstance(q);
1285
1286                qPos.add(groupId);
1287
1288                if (feedId != null) {
1289                    qPos.add(feedId);
1290                }
1291
1292                List<JournalFeed> list = q.list();
1293
1294                result = list;
1295
1296                JournalFeed journalFeed = null;
1297
1298                if (list.isEmpty()) {
1299                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_F,
1300                        finderArgs, list);
1301                }
1302                else {
1303                    journalFeed = list.get(0);
1304
1305                    cacheResult(journalFeed);
1306
1307                    if ((journalFeed.getGroupId() != groupId) ||
1308                            (journalFeed.getFeedId() == null) ||
1309                            !journalFeed.getFeedId().equals(feedId)) {
1310                        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_F,
1311                            finderArgs, journalFeed);
1312                    }
1313                }
1314
1315                return journalFeed;
1316            }
1317            catch (Exception e) {
1318                throw processException(e);
1319            }
1320            finally {
1321                if (result == null) {
1322                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_F,
1323                        finderArgs, new ArrayList<JournalFeed>());
1324                }
1325
1326                closeSession(session);
1327            }
1328        }
1329        else {
1330            if (result instanceof List<?>) {
1331                return null;
1332            }
1333            else {
1334                return (JournalFeed)result;
1335            }
1336        }
1337    }
1338
1339    public List<JournalFeed> findAll() throws SystemException {
1340        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1341    }
1342
1343    public List<JournalFeed> findAll(int start, int end)
1344        throws SystemException {
1345        return findAll(start, end, null);
1346    }
1347
1348    public List<JournalFeed> findAll(int start, int end,
1349        OrderByComparator orderByComparator) throws SystemException {
1350        Object[] finderArgs = new Object[] {
1351                String.valueOf(start), String.valueOf(end),
1352                String.valueOf(orderByComparator)
1353            };
1354
1355        List<JournalFeed> list = (List<JournalFeed>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1356                finderArgs, this);
1357
1358        if (list == null) {
1359            Session session = null;
1360
1361            try {
1362                session = openSession();
1363
1364                StringBundler query = null;
1365                String sql = null;
1366
1367                if (orderByComparator != null) {
1368                    query = new StringBundler(2 +
1369                            (orderByComparator.getOrderByFields().length * 3));
1370
1371                    query.append(_SQL_SELECT_JOURNALFEED);
1372
1373                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1374                        orderByComparator);
1375
1376                    sql = query.toString();
1377                }
1378
1379                else {
1380                    sql = _SQL_SELECT_JOURNALFEED.concat(JournalFeedModelImpl.ORDER_BY_JPQL);
1381                }
1382
1383                Query q = session.createQuery(sql);
1384
1385                if (orderByComparator == null) {
1386                    list = (List<JournalFeed>)QueryUtil.list(q, getDialect(),
1387                            start, end, false);
1388
1389                    Collections.sort(list);
1390                }
1391                else {
1392                    list = (List<JournalFeed>)QueryUtil.list(q, getDialect(),
1393                            start, end);
1394                }
1395            }
1396            catch (Exception e) {
1397                throw processException(e);
1398            }
1399            finally {
1400                if (list == null) {
1401                    list = new ArrayList<JournalFeed>();
1402                }
1403
1404                cacheResult(list);
1405
1406                FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1407
1408                closeSession(session);
1409            }
1410        }
1411
1412        return list;
1413    }
1414
1415    public void removeByUuid(String uuid) throws SystemException {
1416        for (JournalFeed journalFeed : findByUuid(uuid)) {
1417            remove(journalFeed);
1418        }
1419    }
1420
1421    public void removeByUUID_G(String uuid, long groupId)
1422        throws NoSuchFeedException, SystemException {
1423        JournalFeed journalFeed = findByUUID_G(uuid, groupId);
1424
1425        remove(journalFeed);
1426    }
1427
1428    public void removeByGroupId(long groupId) throws SystemException {
1429        for (JournalFeed journalFeed : findByGroupId(groupId)) {
1430            remove(journalFeed);
1431        }
1432    }
1433
1434    public void removeByG_F(long groupId, String feedId)
1435        throws NoSuchFeedException, SystemException {
1436        JournalFeed journalFeed = findByG_F(groupId, feedId);
1437
1438        remove(journalFeed);
1439    }
1440
1441    public void removeAll() throws SystemException {
1442        for (JournalFeed journalFeed : findAll()) {
1443            remove(journalFeed);
1444        }
1445    }
1446
1447    public int countByUuid(String uuid) throws SystemException {
1448        Object[] finderArgs = new Object[] { uuid };
1449
1450        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1451                finderArgs, this);
1452
1453        if (count == null) {
1454            Session session = null;
1455
1456            try {
1457                session = openSession();
1458
1459                StringBundler query = new StringBundler(2);
1460
1461                query.append(_SQL_COUNT_JOURNALFEED_WHERE);
1462
1463                if (uuid == null) {
1464                    query.append(_FINDER_COLUMN_UUID_UUID_1);
1465                }
1466                else {
1467                    if (uuid.equals(StringPool.BLANK)) {
1468                        query.append(_FINDER_COLUMN_UUID_UUID_3);
1469                    }
1470                    else {
1471                        query.append(_FINDER_COLUMN_UUID_UUID_2);
1472                    }
1473                }
1474
1475                String sql = query.toString();
1476
1477                Query q = session.createQuery(sql);
1478
1479                QueryPos qPos = QueryPos.getInstance(q);
1480
1481                if (uuid != null) {
1482                    qPos.add(uuid);
1483                }
1484
1485                count = (Long)q.uniqueResult();
1486            }
1487            catch (Exception e) {
1488                throw processException(e);
1489            }
1490            finally {
1491                if (count == null) {
1492                    count = Long.valueOf(0);
1493                }
1494
1495                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
1496                    finderArgs, count);
1497
1498                closeSession(session);
1499            }
1500        }
1501
1502        return count.intValue();
1503    }
1504
1505    public int countByUUID_G(String uuid, long groupId)
1506        throws SystemException {
1507        Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
1508
1509        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
1510                finderArgs, this);
1511
1512        if (count == null) {
1513            Session session = null;
1514
1515            try {
1516                session = openSession();
1517
1518                StringBundler query = new StringBundler(3);
1519
1520                query.append(_SQL_COUNT_JOURNALFEED_WHERE);
1521
1522                if (uuid == null) {
1523                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1524                }
1525                else {
1526                    if (uuid.equals(StringPool.BLANK)) {
1527                        query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1528                    }
1529                    else {
1530                        query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1531                    }
1532                }
1533
1534                query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1535
1536                String sql = query.toString();
1537
1538                Query q = session.createQuery(sql);
1539
1540                QueryPos qPos = QueryPos.getInstance(q);
1541
1542                if (uuid != null) {
1543                    qPos.add(uuid);
1544                }
1545
1546                qPos.add(groupId);
1547
1548                count = (Long)q.uniqueResult();
1549            }
1550            catch (Exception e) {
1551                throw processException(e);
1552            }
1553            finally {
1554                if (count == null) {
1555                    count = Long.valueOf(0);
1556                }
1557
1558                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
1559                    finderArgs, count);
1560
1561                closeSession(session);
1562            }
1563        }
1564
1565        return count.intValue();
1566    }
1567
1568    public int countByGroupId(long groupId) throws SystemException {
1569        Object[] finderArgs = new Object[] { new Long(groupId) };
1570
1571        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1572                finderArgs, this);
1573
1574        if (count == null) {
1575            Session session = null;
1576
1577            try {
1578                session = openSession();
1579
1580                StringBundler query = new StringBundler(2);
1581
1582                query.append(_SQL_COUNT_JOURNALFEED_WHERE);
1583
1584                query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1585
1586                String sql = query.toString();
1587
1588                Query q = session.createQuery(sql);
1589
1590                QueryPos qPos = QueryPos.getInstance(q);
1591
1592                qPos.add(groupId);
1593
1594                count = (Long)q.uniqueResult();
1595            }
1596            catch (Exception e) {
1597                throw processException(e);
1598            }
1599            finally {
1600                if (count == null) {
1601                    count = Long.valueOf(0);
1602                }
1603
1604                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1605                    finderArgs, count);
1606
1607                closeSession(session);
1608            }
1609        }
1610
1611        return count.intValue();
1612    }
1613
1614    public int filterCountByGroupId(long groupId) throws SystemException {
1615        if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1616            return countByGroupId(groupId);
1617        }
1618
1619        Session session = null;
1620
1621        try {
1622            session = openSession();
1623
1624            StringBundler query = new StringBundler(2);
1625
1626            query.append(_FILTER_SQL_COUNT_JOURNALFEED_WHERE);
1627
1628            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1629
1630            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1631                    JournalFeed.class.getName(), _FILTER_COLUMN_ID,
1632                    _FILTER_COLUMN_USERID, groupId);
1633
1634            SQLQuery q = session.createSQLQuery(sql);
1635
1636            q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
1637
1638            QueryPos qPos = QueryPos.getInstance(q);
1639
1640            qPos.add(groupId);
1641
1642            Long count = (Long)q.uniqueResult();
1643
1644            return count.intValue();
1645        }
1646        catch (Exception e) {
1647            throw processException(e);
1648        }
1649        finally {
1650            closeSession(session);
1651        }
1652    }
1653
1654    public int countByG_F(long groupId, String feedId)
1655        throws SystemException {
1656        Object[] finderArgs = new Object[] { new Long(groupId), feedId };
1657
1658        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_F,
1659                finderArgs, this);
1660
1661        if (count == null) {
1662            Session session = null;
1663
1664            try {
1665                session = openSession();
1666
1667                StringBundler query = new StringBundler(3);
1668
1669                query.append(_SQL_COUNT_JOURNALFEED_WHERE);
1670
1671                query.append(_FINDER_COLUMN_G_F_GROUPID_2);
1672
1673                if (feedId == null) {
1674                    query.append(_FINDER_COLUMN_G_F_FEEDID_1);
1675                }
1676                else {
1677                    if (feedId.equals(StringPool.BLANK)) {
1678                        query.append(_FINDER_COLUMN_G_F_FEEDID_3);
1679                    }
1680                    else {
1681                        query.append(_FINDER_COLUMN_G_F_FEEDID_2);
1682                    }
1683                }
1684
1685                String sql = query.toString();
1686
1687                Query q = session.createQuery(sql);
1688
1689                QueryPos qPos = QueryPos.getInstance(q);
1690
1691                qPos.add(groupId);
1692
1693                if (feedId != null) {
1694                    qPos.add(feedId);
1695                }
1696
1697                count = (Long)q.uniqueResult();
1698            }
1699            catch (Exception e) {
1700                throw processException(e);
1701            }
1702            finally {
1703                if (count == null) {
1704                    count = Long.valueOf(0);
1705                }
1706
1707                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_F, finderArgs,
1708                    count);
1709
1710                closeSession(session);
1711            }
1712        }
1713
1714        return count.intValue();
1715    }
1716
1717    public int filterCountByG_F(long groupId, String feedId)
1718        throws SystemException {
1719        if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1720            return countByG_F(groupId, feedId);
1721        }
1722
1723        Session session = null;
1724
1725        try {
1726            session = openSession();
1727
1728            StringBundler query = new StringBundler(3);
1729
1730            query.append(_FILTER_SQL_COUNT_JOURNALFEED_WHERE);
1731
1732            query.append(_FINDER_COLUMN_G_F_GROUPID_2);
1733
1734            if (feedId == null) {
1735                query.append(_FINDER_COLUMN_G_F_FEEDID_1);
1736            }
1737            else {
1738                if (feedId.equals(StringPool.BLANK)) {
1739                    query.append(_FINDER_COLUMN_G_F_FEEDID_3);
1740                }
1741                else {
1742                    query.append(_FINDER_COLUMN_G_F_FEEDID_2);
1743                }
1744            }
1745
1746            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1747                    JournalFeed.class.getName(), _FILTER_COLUMN_ID,
1748                    _FILTER_COLUMN_USERID, groupId);
1749
1750            SQLQuery q = session.createSQLQuery(sql);
1751
1752            q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
1753
1754            QueryPos qPos = QueryPos.getInstance(q);
1755
1756            qPos.add(groupId);
1757
1758            if (feedId != null) {
1759                qPos.add(feedId);
1760            }
1761
1762            Long count = (Long)q.uniqueResult();
1763
1764            return count.intValue();
1765        }
1766        catch (Exception e) {
1767            throw processException(e);
1768        }
1769        finally {
1770            closeSession(session);
1771        }
1772    }
1773
1774    public int countAll() throws SystemException {
1775        Object[] finderArgs = new Object[0];
1776
1777        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1778                finderArgs, this);
1779
1780        if (count == null) {
1781            Session session = null;
1782
1783            try {
1784                session = openSession();
1785
1786                Query q = session.createQuery(_SQL_COUNT_JOURNALFEED);
1787
1788                count = (Long)q.uniqueResult();
1789            }
1790            catch (Exception e) {
1791                throw processException(e);
1792            }
1793            finally {
1794                if (count == null) {
1795                    count = Long.valueOf(0);
1796                }
1797
1798                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1799                    count);
1800
1801                closeSession(session);
1802            }
1803        }
1804
1805        return count.intValue();
1806    }
1807
1808    public void afterPropertiesSet() {
1809        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1810                    com.liferay.portal.util.PropsUtil.get(
1811                        "value.object.listener.com.liferay.portlet.journal.model.JournalFeed")));
1812
1813        if (listenerClassNames.length > 0) {
1814            try {
1815                List<ModelListener<JournalFeed>> listenersList = new ArrayList<ModelListener<JournalFeed>>();
1816
1817                for (String listenerClassName : listenerClassNames) {
1818                    listenersList.add((ModelListener<JournalFeed>)InstanceFactory.newInstance(
1819                            listenerClassName));
1820                }
1821
1822                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1823            }
1824            catch (Exception e) {
1825                _log.error(e);
1826            }
1827        }
1828    }
1829
1830    @BeanReference(type = JournalArticlePersistence.class)
1831    protected JournalArticlePersistence journalArticlePersistence;
1832    @BeanReference(type = JournalArticleImagePersistence.class)
1833    protected JournalArticleImagePersistence journalArticleImagePersistence;
1834    @BeanReference(type = JournalArticleResourcePersistence.class)
1835    protected JournalArticleResourcePersistence journalArticleResourcePersistence;
1836    @BeanReference(type = JournalContentSearchPersistence.class)
1837    protected JournalContentSearchPersistence journalContentSearchPersistence;
1838    @BeanReference(type = JournalFeedPersistence.class)
1839    protected JournalFeedPersistence journalFeedPersistence;
1840    @BeanReference(type = JournalStructurePersistence.class)
1841    protected JournalStructurePersistence journalStructurePersistence;
1842    @BeanReference(type = JournalTemplatePersistence.class)
1843    protected JournalTemplatePersistence journalTemplatePersistence;
1844    @BeanReference(type = ResourcePersistence.class)
1845    protected ResourcePersistence resourcePersistence;
1846    @BeanReference(type = UserPersistence.class)
1847    protected UserPersistence userPersistence;
1848    @BeanReference(type = ExpandoValuePersistence.class)
1849    protected ExpandoValuePersistence expandoValuePersistence;
1850    private static final String _SQL_SELECT_JOURNALFEED = "SELECT journalFeed FROM JournalFeed journalFeed";
1851    private static final String _SQL_SELECT_JOURNALFEED_WHERE = "SELECT journalFeed FROM JournalFeed journalFeed WHERE ";
1852    private static final String _SQL_COUNT_JOURNALFEED = "SELECT COUNT(journalFeed) FROM JournalFeed journalFeed";
1853    private static final String _SQL_COUNT_JOURNALFEED_WHERE = "SELECT COUNT(journalFeed) FROM JournalFeed journalFeed WHERE ";
1854    private static final String _FINDER_COLUMN_UUID_UUID_1 = "journalFeed.uuid IS NULL";
1855    private static final String _FINDER_COLUMN_UUID_UUID_2 = "journalFeed.uuid = ?";
1856    private static final String _FINDER_COLUMN_UUID_UUID_3 = "(journalFeed.uuid IS NULL OR journalFeed.uuid = ?)";
1857    private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "journalFeed.uuid IS NULL AND ";
1858    private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "journalFeed.uuid = ? AND ";
1859    private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(journalFeed.uuid IS NULL OR journalFeed.uuid = ?) AND ";
1860    private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "journalFeed.groupId = ?";
1861    private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "journalFeed.groupId = ?";
1862    private static final String _FINDER_COLUMN_G_F_GROUPID_2 = "journalFeed.groupId = ? AND ";
1863    private static final String _FINDER_COLUMN_G_F_FEEDID_1 = "journalFeed.feedId IS NULL";
1864    private static final String _FINDER_COLUMN_G_F_FEEDID_2 = "journalFeed.feedId = ?";
1865    private static final String _FINDER_COLUMN_G_F_FEEDID_3 = "(journalFeed.feedId IS NULL OR journalFeed.feedId = ?)";
1866    private static final String _FILTER_SQL_SELECT_JOURNALFEED_WHERE = "SELECT DISTINCT {journalFeed.*} FROM JournalFeed journalFeed WHERE ";
1867    private static final String _FILTER_SQL_COUNT_JOURNALFEED_WHERE = "SELECT COUNT(DISTINCT journalFeed.id) AS COUNT_VALUE FROM JournalFeed journalFeed WHERE ";
1868    private static final String _FILTER_COLUMN_ID = "journalFeed.id";
1869    private static final String _FILTER_COLUMN_USERID = "journalFeed.userId";
1870    private static final String _FILTER_ENTITY_ALIAS = "journalFeed";
1871    private static final String _ORDER_BY_ENTITY_ALIAS = "journalFeed.";
1872    private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No JournalFeed exists with the primary key ";
1873    private static final String _NO_SUCH_ENTITY_WITH_KEY = "No JournalFeed exists with the key {";
1874    private static Log _log = LogFactoryUtil.getLog(JournalFeedPersistenceImpl.class);
1875}