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