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