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