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