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