1
22
23 package com.liferay.portlet.journal.service.persistence;
24
25 import com.liferay.portal.SystemException;
26 import com.liferay.portal.kernel.dao.DynamicQuery;
27 import com.liferay.portal.kernel.dao.DynamicQueryInitializer;
28 import com.liferay.portal.kernel.util.GetterUtil;
29 import com.liferay.portal.kernel.util.OrderByComparator;
30 import com.liferay.portal.kernel.util.StringMaker;
31 import com.liferay.portal.kernel.util.StringPool;
32 import com.liferay.portal.kernel.util.StringUtil;
33 import com.liferay.portal.kernel.util.Validator;
34 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
35 import com.liferay.portal.model.ModelListener;
36 import com.liferay.portal.service.persistence.BasePersistence;
37 import com.liferay.portal.spring.hibernate.FinderCache;
38 import com.liferay.portal.spring.hibernate.HibernateUtil;
39 import com.liferay.portal.util.PropsUtil;
40
41 import com.liferay.portlet.journal.NoSuchFeedException;
42 import com.liferay.portlet.journal.model.JournalFeed;
43 import com.liferay.portlet.journal.model.impl.JournalFeedImpl;
44 import com.liferay.portlet.journal.model.impl.JournalFeedModelImpl;
45
46 import com.liferay.util.dao.hibernate.QueryUtil;
47
48 import org.apache.commons.logging.Log;
49 import org.apache.commons.logging.LogFactory;
50
51 import org.hibernate.Query;
52 import org.hibernate.Session;
53
54 import java.util.ArrayList;
55 import java.util.Collections;
56 import java.util.Iterator;
57 import java.util.List;
58
59
65 public class JournalFeedPersistenceImpl extends BasePersistence
66 implements JournalFeedPersistence {
67 public JournalFeed create(long id) {
68 JournalFeed journalFeed = new JournalFeedImpl();
69
70 journalFeed.setNew(true);
71 journalFeed.setPrimaryKey(id);
72
73 String uuid = PortalUUIDUtil.generate();
74
75 journalFeed.setUuid(uuid);
76
77 return journalFeed;
78 }
79
80 public JournalFeed remove(long id)
81 throws NoSuchFeedException, SystemException {
82 Session session = null;
83
84 try {
85 session = openSession();
86
87 JournalFeed journalFeed = (JournalFeed)session.get(JournalFeedImpl.class,
88 new Long(id));
89
90 if (journalFeed == null) {
91 if (_log.isWarnEnabled()) {
92 _log.warn("No JournalFeed exists with the primary key " +
93 id);
94 }
95
96 throw new NoSuchFeedException(
97 "No JournalFeed exists with the primary key " + id);
98 }
99
100 return remove(journalFeed);
101 }
102 catch (NoSuchFeedException nsee) {
103 throw nsee;
104 }
105 catch (Exception e) {
106 throw HibernateUtil.processException(e);
107 }
108 finally {
109 closeSession(session);
110 }
111 }
112
113 public JournalFeed remove(JournalFeed journalFeed)
114 throws SystemException {
115 if (_listeners != null) {
116 for (ModelListener listener : _listeners) {
117 listener.onBeforeRemove(journalFeed);
118 }
119 }
120
121 journalFeed = removeImpl(journalFeed);
122
123 if (_listeners != null) {
124 for (ModelListener listener : _listeners) {
125 listener.onAfterRemove(journalFeed);
126 }
127 }
128
129 return journalFeed;
130 }
131
132 protected JournalFeed removeImpl(JournalFeed journalFeed)
133 throws SystemException {
134 Session session = null;
135
136 try {
137 session = openSession();
138
139 session.delete(journalFeed);
140
141 session.flush();
142
143 return journalFeed;
144 }
145 catch (Exception e) {
146 throw HibernateUtil.processException(e);
147 }
148 finally {
149 closeSession(session);
150
151 FinderCache.clearCache(JournalFeed.class.getName());
152 }
153 }
154
155
158 public JournalFeed update(JournalFeed journalFeed)
159 throws SystemException {
160 if (_log.isWarnEnabled()) {
161 _log.warn(
162 "Using the deprecated update(JournalFeed journalFeed) method. Use update(JournalFeed journalFeed, boolean merge) instead.");
163 }
164
165 return update(journalFeed, false);
166 }
167
168
181 public JournalFeed update(JournalFeed journalFeed, boolean merge)
182 throws SystemException {
183 boolean isNew = journalFeed.isNew();
184
185 if (_listeners != null) {
186 for (ModelListener listener : _listeners) {
187 if (isNew) {
188 listener.onBeforeCreate(journalFeed);
189 }
190 else {
191 listener.onBeforeUpdate(journalFeed);
192 }
193 }
194 }
195
196 journalFeed = updateImpl(journalFeed, merge);
197
198 if (_listeners != null) {
199 for (ModelListener listener : _listeners) {
200 if (isNew) {
201 listener.onAfterCreate(journalFeed);
202 }
203 else {
204 listener.onAfterUpdate(journalFeed);
205 }
206 }
207 }
208
209 return journalFeed;
210 }
211
212 public JournalFeed updateImpl(
213 com.liferay.portlet.journal.model.JournalFeed journalFeed, boolean merge)
214 throws SystemException {
215 if (Validator.isNull(journalFeed.getUuid())) {
216 String uuid = PortalUUIDUtil.generate();
217
218 journalFeed.setUuid(uuid);
219 }
220
221 Session session = null;
222
223 try {
224 session = openSession();
225
226 if (merge) {
227 session.merge(journalFeed);
228 }
229 else {
230 if (journalFeed.isNew()) {
231 session.save(journalFeed);
232 }
233 }
234
235 session.flush();
236
237 journalFeed.setNew(false);
238
239 return journalFeed;
240 }
241 catch (Exception e) {
242 throw HibernateUtil.processException(e);
243 }
244 finally {
245 closeSession(session);
246
247 FinderCache.clearCache(JournalFeed.class.getName());
248 }
249 }
250
251 public JournalFeed findByPrimaryKey(long id)
252 throws NoSuchFeedException, SystemException {
253 JournalFeed journalFeed = fetchByPrimaryKey(id);
254
255 if (journalFeed == null) {
256 if (_log.isWarnEnabled()) {
257 _log.warn("No JournalFeed exists with the primary key " + id);
258 }
259
260 throw new NoSuchFeedException(
261 "No JournalFeed exists with the primary key " + id);
262 }
263
264 return journalFeed;
265 }
266
267 public JournalFeed fetchByPrimaryKey(long id) throws SystemException {
268 Session session = null;
269
270 try {
271 session = openSession();
272
273 return (JournalFeed)session.get(JournalFeedImpl.class, new Long(id));
274 }
275 catch (Exception e) {
276 throw HibernateUtil.processException(e);
277 }
278 finally {
279 closeSession(session);
280 }
281 }
282
283 public List<JournalFeed> findByUuid(String uuid) throws SystemException {
284 boolean finderClassNameCacheEnabled = JournalFeedModelImpl.CACHE_ENABLED;
285 String finderClassName = JournalFeed.class.getName();
286 String finderMethodName = "findByUuid";
287 String[] finderParams = new String[] { String.class.getName() };
288 Object[] finderArgs = new Object[] { uuid };
289
290 Object result = null;
291
292 if (finderClassNameCacheEnabled) {
293 result = FinderCache.getResult(finderClassName, finderMethodName,
294 finderParams, finderArgs, getSessionFactory());
295 }
296
297 if (result == null) {
298 Session session = null;
299
300 try {
301 session = openSession();
302
303 StringMaker query = new StringMaker();
304
305 query.append(
306 "FROM com.liferay.portlet.journal.model.JournalFeed WHERE ");
307
308 if (uuid == null) {
309 query.append("uuid_ IS NULL");
310 }
311 else {
312 query.append("uuid_ = ?");
313 }
314
315 query.append(" ");
316
317 query.append("ORDER BY ");
318
319 query.append("feedId ASC");
320
321 Query q = session.createQuery(query.toString());
322
323 int queryPos = 0;
324
325 if (uuid != null) {
326 q.setString(queryPos++, uuid);
327 }
328
329 List<JournalFeed> list = q.list();
330
331 FinderCache.putResult(finderClassNameCacheEnabled,
332 finderClassName, finderMethodName, finderParams,
333 finderArgs, list);
334
335 return list;
336 }
337 catch (Exception e) {
338 throw HibernateUtil.processException(e);
339 }
340 finally {
341 closeSession(session);
342 }
343 }
344 else {
345 return (List<JournalFeed>)result;
346 }
347 }
348
349 public List<JournalFeed> findByUuid(String uuid, int begin, int end)
350 throws SystemException {
351 return findByUuid(uuid, begin, end, null);
352 }
353
354 public List<JournalFeed> findByUuid(String uuid, int begin, int end,
355 OrderByComparator obc) throws SystemException {
356 boolean finderClassNameCacheEnabled = JournalFeedModelImpl.CACHE_ENABLED;
357 String finderClassName = JournalFeed.class.getName();
358 String finderMethodName = "findByUuid";
359 String[] finderParams = new String[] {
360 String.class.getName(),
361
362 "java.lang.Integer", "java.lang.Integer",
363 "com.liferay.portal.kernel.util.OrderByComparator"
364 };
365 Object[] finderArgs = new Object[] {
366 uuid,
367
368 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
369 };
370
371 Object result = null;
372
373 if (finderClassNameCacheEnabled) {
374 result = FinderCache.getResult(finderClassName, finderMethodName,
375 finderParams, finderArgs, getSessionFactory());
376 }
377
378 if (result == null) {
379 Session session = null;
380
381 try {
382 session = openSession();
383
384 StringMaker query = new StringMaker();
385
386 query.append(
387 "FROM com.liferay.portlet.journal.model.JournalFeed WHERE ");
388
389 if (uuid == null) {
390 query.append("uuid_ IS NULL");
391 }
392 else {
393 query.append("uuid_ = ?");
394 }
395
396 query.append(" ");
397
398 if (obc != null) {
399 query.append("ORDER BY ");
400 query.append(obc.getOrderBy());
401 }
402
403 else {
404 query.append("ORDER BY ");
405
406 query.append("feedId ASC");
407 }
408
409 Query q = session.createQuery(query.toString());
410
411 int queryPos = 0;
412
413 if (uuid != null) {
414 q.setString(queryPos++, uuid);
415 }
416
417 List<JournalFeed> list = (List<JournalFeed>)QueryUtil.list(q,
418 getDialect(), begin, end);
419
420 FinderCache.putResult(finderClassNameCacheEnabled,
421 finderClassName, finderMethodName, finderParams,
422 finderArgs, list);
423
424 return list;
425 }
426 catch (Exception e) {
427 throw HibernateUtil.processException(e);
428 }
429 finally {
430 closeSession(session);
431 }
432 }
433 else {
434 return (List<JournalFeed>)result;
435 }
436 }
437
438 public JournalFeed findByUuid_First(String uuid, OrderByComparator obc)
439 throws NoSuchFeedException, SystemException {
440 List<JournalFeed> list = findByUuid(uuid, 0, 1, obc);
441
442 if (list.size() == 0) {
443 StringMaker msg = new StringMaker();
444
445 msg.append("No JournalFeed exists with the key {");
446
447 msg.append("uuid=" + uuid);
448
449 msg.append(StringPool.CLOSE_CURLY_BRACE);
450
451 throw new NoSuchFeedException(msg.toString());
452 }
453 else {
454 return list.get(0);
455 }
456 }
457
458 public JournalFeed findByUuid_Last(String uuid, OrderByComparator obc)
459 throws NoSuchFeedException, SystemException {
460 int count = countByUuid(uuid);
461
462 List<JournalFeed> list = findByUuid(uuid, count - 1, count, obc);
463
464 if (list.size() == 0) {
465 StringMaker msg = new StringMaker();
466
467 msg.append("No JournalFeed exists with the key {");
468
469 msg.append("uuid=" + uuid);
470
471 msg.append(StringPool.CLOSE_CURLY_BRACE);
472
473 throw new NoSuchFeedException(msg.toString());
474 }
475 else {
476 return list.get(0);
477 }
478 }
479
480 public JournalFeed[] findByUuid_PrevAndNext(long id, String uuid,
481 OrderByComparator obc) throws NoSuchFeedException, SystemException {
482 JournalFeed journalFeed = findByPrimaryKey(id);
483
484 int count = countByUuid(uuid);
485
486 Session session = null;
487
488 try {
489 session = openSession();
490
491 StringMaker query = new StringMaker();
492
493 query.append(
494 "FROM com.liferay.portlet.journal.model.JournalFeed WHERE ");
495
496 if (uuid == null) {
497 query.append("uuid_ IS NULL");
498 }
499 else {
500 query.append("uuid_ = ?");
501 }
502
503 query.append(" ");
504
505 if (obc != null) {
506 query.append("ORDER BY ");
507 query.append(obc.getOrderBy());
508 }
509
510 else {
511 query.append("ORDER BY ");
512
513 query.append("feedId ASC");
514 }
515
516 Query q = session.createQuery(query.toString());
517
518 int queryPos = 0;
519
520 if (uuid != null) {
521 q.setString(queryPos++, uuid);
522 }
523
524 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
525 journalFeed);
526
527 JournalFeed[] array = new JournalFeedImpl[3];
528
529 array[0] = (JournalFeed)objArray[0];
530 array[1] = (JournalFeed)objArray[1];
531 array[2] = (JournalFeed)objArray[2];
532
533 return array;
534 }
535 catch (Exception e) {
536 throw HibernateUtil.processException(e);
537 }
538 finally {
539 closeSession(session);
540 }
541 }
542
543 public JournalFeed findByUUID_G(String uuid, long groupId)
544 throws NoSuchFeedException, SystemException {
545 JournalFeed journalFeed = fetchByUUID_G(uuid, groupId);
546
547 if (journalFeed == null) {
548 StringMaker msg = new StringMaker();
549
550 msg.append("No JournalFeed exists with the key {");
551
552 msg.append("uuid=" + uuid);
553
554 msg.append(", ");
555 msg.append("groupId=" + groupId);
556
557 msg.append(StringPool.CLOSE_CURLY_BRACE);
558
559 if (_log.isWarnEnabled()) {
560 _log.warn(msg.toString());
561 }
562
563 throw new NoSuchFeedException(msg.toString());
564 }
565
566 return journalFeed;
567 }
568
569 public JournalFeed fetchByUUID_G(String uuid, long groupId)
570 throws SystemException {
571 boolean finderClassNameCacheEnabled = JournalFeedModelImpl.CACHE_ENABLED;
572 String finderClassName = JournalFeed.class.getName();
573 String finderMethodName = "fetchByUUID_G";
574 String[] finderParams = new String[] {
575 String.class.getName(), Long.class.getName()
576 };
577 Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
578
579 Object result = null;
580
581 if (finderClassNameCacheEnabled) {
582 result = FinderCache.getResult(finderClassName, finderMethodName,
583 finderParams, finderArgs, getSessionFactory());
584 }
585
586 if (result == null) {
587 Session session = null;
588
589 try {
590 session = openSession();
591
592 StringMaker query = new StringMaker();
593
594 query.append(
595 "FROM com.liferay.portlet.journal.model.JournalFeed WHERE ");
596
597 if (uuid == null) {
598 query.append("uuid_ IS NULL");
599 }
600 else {
601 query.append("uuid_ = ?");
602 }
603
604 query.append(" AND ");
605
606 query.append("groupId = ?");
607
608 query.append(" ");
609
610 query.append("ORDER BY ");
611
612 query.append("feedId ASC");
613
614 Query q = session.createQuery(query.toString());
615
616 int queryPos = 0;
617
618 if (uuid != null) {
619 q.setString(queryPos++, uuid);
620 }
621
622 q.setLong(queryPos++, groupId);
623
624 List<JournalFeed> list = q.list();
625
626 FinderCache.putResult(finderClassNameCacheEnabled,
627 finderClassName, finderMethodName, finderParams,
628 finderArgs, list);
629
630 if (list.size() == 0) {
631 return null;
632 }
633 else {
634 return list.get(0);
635 }
636 }
637 catch (Exception e) {
638 throw HibernateUtil.processException(e);
639 }
640 finally {
641 closeSession(session);
642 }
643 }
644 else {
645 List<JournalFeed> list = (List<JournalFeed>)result;
646
647 if (list.size() == 0) {
648 return null;
649 }
650 else {
651 return list.get(0);
652 }
653 }
654 }
655
656 public List<JournalFeed> findByGroupId(long groupId)
657 throws SystemException {
658 boolean finderClassNameCacheEnabled = JournalFeedModelImpl.CACHE_ENABLED;
659 String finderClassName = JournalFeed.class.getName();
660 String finderMethodName = "findByGroupId";
661 String[] finderParams = new String[] { Long.class.getName() };
662 Object[] finderArgs = new Object[] { new Long(groupId) };
663
664 Object result = null;
665
666 if (finderClassNameCacheEnabled) {
667 result = FinderCache.getResult(finderClassName, finderMethodName,
668 finderParams, finderArgs, getSessionFactory());
669 }
670
671 if (result == null) {
672 Session session = null;
673
674 try {
675 session = openSession();
676
677 StringMaker query = new StringMaker();
678
679 query.append(
680 "FROM com.liferay.portlet.journal.model.JournalFeed WHERE ");
681
682 query.append("groupId = ?");
683
684 query.append(" ");
685
686 query.append("ORDER BY ");
687
688 query.append("feedId ASC");
689
690 Query q = session.createQuery(query.toString());
691
692 int queryPos = 0;
693
694 q.setLong(queryPos++, groupId);
695
696 List<JournalFeed> list = q.list();
697
698 FinderCache.putResult(finderClassNameCacheEnabled,
699 finderClassName, finderMethodName, finderParams,
700 finderArgs, list);
701
702 return list;
703 }
704 catch (Exception e) {
705 throw HibernateUtil.processException(e);
706 }
707 finally {
708 closeSession(session);
709 }
710 }
711 else {
712 return (List<JournalFeed>)result;
713 }
714 }
715
716 public List<JournalFeed> findByGroupId(long groupId, int begin, int end)
717 throws SystemException {
718 return findByGroupId(groupId, begin, end, null);
719 }
720
721 public List<JournalFeed> findByGroupId(long groupId, int begin, int end,
722 OrderByComparator obc) throws SystemException {
723 boolean finderClassNameCacheEnabled = JournalFeedModelImpl.CACHE_ENABLED;
724 String finderClassName = JournalFeed.class.getName();
725 String finderMethodName = "findByGroupId";
726 String[] finderParams = new String[] {
727 Long.class.getName(),
728
729 "java.lang.Integer", "java.lang.Integer",
730 "com.liferay.portal.kernel.util.OrderByComparator"
731 };
732 Object[] finderArgs = new Object[] {
733 new Long(groupId),
734
735 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
736 };
737
738 Object result = null;
739
740 if (finderClassNameCacheEnabled) {
741 result = FinderCache.getResult(finderClassName, finderMethodName,
742 finderParams, finderArgs, getSessionFactory());
743 }
744
745 if (result == null) {
746 Session session = null;
747
748 try {
749 session = openSession();
750
751 StringMaker query = new StringMaker();
752
753 query.append(
754 "FROM com.liferay.portlet.journal.model.JournalFeed WHERE ");
755
756 query.append("groupId = ?");
757
758 query.append(" ");
759
760 if (obc != null) {
761 query.append("ORDER BY ");
762 query.append(obc.getOrderBy());
763 }
764
765 else {
766 query.append("ORDER BY ");
767
768 query.append("feedId ASC");
769 }
770
771 Query q = session.createQuery(query.toString());
772
773 int queryPos = 0;
774
775 q.setLong(queryPos++, groupId);
776
777 List<JournalFeed> list = (List<JournalFeed>)QueryUtil.list(q,
778 getDialect(), begin, end);
779
780 FinderCache.putResult(finderClassNameCacheEnabled,
781 finderClassName, finderMethodName, finderParams,
782 finderArgs, list);
783
784 return list;
785 }
786 catch (Exception e) {
787 throw HibernateUtil.processException(e);
788 }
789 finally {
790 closeSession(session);
791 }
792 }
793 else {
794 return (List<JournalFeed>)result;
795 }
796 }
797
798 public JournalFeed findByGroupId_First(long groupId, OrderByComparator obc)
799 throws NoSuchFeedException, SystemException {
800 List<JournalFeed> list = findByGroupId(groupId, 0, 1, obc);
801
802 if (list.size() == 0) {
803 StringMaker msg = new StringMaker();
804
805 msg.append("No JournalFeed exists with the key {");
806
807 msg.append("groupId=" + groupId);
808
809 msg.append(StringPool.CLOSE_CURLY_BRACE);
810
811 throw new NoSuchFeedException(msg.toString());
812 }
813 else {
814 return list.get(0);
815 }
816 }
817
818 public JournalFeed findByGroupId_Last(long groupId, OrderByComparator obc)
819 throws NoSuchFeedException, SystemException {
820 int count = countByGroupId(groupId);
821
822 List<JournalFeed> list = findByGroupId(groupId, count - 1, count, obc);
823
824 if (list.size() == 0) {
825 StringMaker msg = new StringMaker();
826
827 msg.append("No JournalFeed exists with the key {");
828
829 msg.append("groupId=" + groupId);
830
831 msg.append(StringPool.CLOSE_CURLY_BRACE);
832
833 throw new NoSuchFeedException(msg.toString());
834 }
835 else {
836 return list.get(0);
837 }
838 }
839
840 public JournalFeed[] findByGroupId_PrevAndNext(long id, long groupId,
841 OrderByComparator obc) throws NoSuchFeedException, SystemException {
842 JournalFeed journalFeed = findByPrimaryKey(id);
843
844 int count = countByGroupId(groupId);
845
846 Session session = null;
847
848 try {
849 session = openSession();
850
851 StringMaker query = new StringMaker();
852
853 query.append(
854 "FROM com.liferay.portlet.journal.model.JournalFeed WHERE ");
855
856 query.append("groupId = ?");
857
858 query.append(" ");
859
860 if (obc != null) {
861 query.append("ORDER BY ");
862 query.append(obc.getOrderBy());
863 }
864
865 else {
866 query.append("ORDER BY ");
867
868 query.append("feedId ASC");
869 }
870
871 Query q = session.createQuery(query.toString());
872
873 int queryPos = 0;
874
875 q.setLong(queryPos++, groupId);
876
877 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
878 journalFeed);
879
880 JournalFeed[] array = new JournalFeedImpl[3];
881
882 array[0] = (JournalFeed)objArray[0];
883 array[1] = (JournalFeed)objArray[1];
884 array[2] = (JournalFeed)objArray[2];
885
886 return array;
887 }
888 catch (Exception e) {
889 throw HibernateUtil.processException(e);
890 }
891 finally {
892 closeSession(session);
893 }
894 }
895
896 public JournalFeed findByG_F(long groupId, String feedId)
897 throws NoSuchFeedException, SystemException {
898 JournalFeed journalFeed = fetchByG_F(groupId, feedId);
899
900 if (journalFeed == null) {
901 StringMaker msg = new StringMaker();
902
903 msg.append("No JournalFeed exists with the key {");
904
905 msg.append("groupId=" + groupId);
906
907 msg.append(", ");
908 msg.append("feedId=" + feedId);
909
910 msg.append(StringPool.CLOSE_CURLY_BRACE);
911
912 if (_log.isWarnEnabled()) {
913 _log.warn(msg.toString());
914 }
915
916 throw new NoSuchFeedException(msg.toString());
917 }
918
919 return journalFeed;
920 }
921
922 public JournalFeed fetchByG_F(long groupId, String feedId)
923 throws SystemException {
924 boolean finderClassNameCacheEnabled = JournalFeedModelImpl.CACHE_ENABLED;
925 String finderClassName = JournalFeed.class.getName();
926 String finderMethodName = "fetchByG_F";
927 String[] finderParams = new String[] {
928 Long.class.getName(), String.class.getName()
929 };
930 Object[] finderArgs = new Object[] { new Long(groupId), feedId };
931
932 Object result = null;
933
934 if (finderClassNameCacheEnabled) {
935 result = FinderCache.getResult(finderClassName, finderMethodName,
936 finderParams, finderArgs, getSessionFactory());
937 }
938
939 if (result == null) {
940 Session session = null;
941
942 try {
943 session = openSession();
944
945 StringMaker query = new StringMaker();
946
947 query.append(
948 "FROM com.liferay.portlet.journal.model.JournalFeed WHERE ");
949
950 query.append("groupId = ?");
951
952 query.append(" AND ");
953
954 if (feedId == null) {
955 query.append("feedId IS NULL");
956 }
957 else {
958 query.append("feedId = ?");
959 }
960
961 query.append(" ");
962
963 query.append("ORDER BY ");
964
965 query.append("feedId ASC");
966
967 Query q = session.createQuery(query.toString());
968
969 int queryPos = 0;
970
971 q.setLong(queryPos++, groupId);
972
973 if (feedId != null) {
974 q.setString(queryPos++, feedId);
975 }
976
977 List<JournalFeed> list = q.list();
978
979 FinderCache.putResult(finderClassNameCacheEnabled,
980 finderClassName, finderMethodName, finderParams,
981 finderArgs, list);
982
983 if (list.size() == 0) {
984 return null;
985 }
986 else {
987 return list.get(0);
988 }
989 }
990 catch (Exception e) {
991 throw HibernateUtil.processException(e);
992 }
993 finally {
994 closeSession(session);
995 }
996 }
997 else {
998 List<JournalFeed> list = (List<JournalFeed>)result;
999
1000 if (list.size() == 0) {
1001 return null;
1002 }
1003 else {
1004 return list.get(0);
1005 }
1006 }
1007 }
1008
1009 public List<JournalFeed> findWithDynamicQuery(
1010 DynamicQueryInitializer queryInitializer) throws SystemException {
1011 Session session = null;
1012
1013 try {
1014 session = openSession();
1015
1016 DynamicQuery query = queryInitializer.initialize(session);
1017
1018 return query.list();
1019 }
1020 catch (Exception e) {
1021 throw HibernateUtil.processException(e);
1022 }
1023 finally {
1024 closeSession(session);
1025 }
1026 }
1027
1028 public List<JournalFeed> findWithDynamicQuery(
1029 DynamicQueryInitializer queryInitializer, int begin, int end)
1030 throws SystemException {
1031 Session session = null;
1032
1033 try {
1034 session = openSession();
1035
1036 DynamicQuery query = queryInitializer.initialize(session);
1037
1038 query.setLimit(begin, end);
1039
1040 return query.list();
1041 }
1042 catch (Exception e) {
1043 throw HibernateUtil.processException(e);
1044 }
1045 finally {
1046 closeSession(session);
1047 }
1048 }
1049
1050 public List<JournalFeed> findAll() throws SystemException {
1051 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1052 }
1053
1054 public List<JournalFeed> findAll(int begin, int end)
1055 throws SystemException {
1056 return findAll(begin, end, null);
1057 }
1058
1059 public List<JournalFeed> findAll(int begin, int end, OrderByComparator obc)
1060 throws SystemException {
1061 boolean finderClassNameCacheEnabled = JournalFeedModelImpl.CACHE_ENABLED;
1062 String finderClassName = JournalFeed.class.getName();
1063 String finderMethodName = "findAll";
1064 String[] finderParams = new String[] {
1065 "java.lang.Integer", "java.lang.Integer",
1066 "com.liferay.portal.kernel.util.OrderByComparator"
1067 };
1068 Object[] finderArgs = new Object[] {
1069 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
1070 };
1071
1072 Object result = null;
1073
1074 if (finderClassNameCacheEnabled) {
1075 result = FinderCache.getResult(finderClassName, finderMethodName,
1076 finderParams, finderArgs, getSessionFactory());
1077 }
1078
1079 if (result == null) {
1080 Session session = null;
1081
1082 try {
1083 session = openSession();
1084
1085 StringMaker query = new StringMaker();
1086
1087 query.append(
1088 "FROM com.liferay.portlet.journal.model.JournalFeed ");
1089
1090 if (obc != null) {
1091 query.append("ORDER BY ");
1092 query.append(obc.getOrderBy());
1093 }
1094
1095 else {
1096 query.append("ORDER BY ");
1097
1098 query.append("feedId ASC");
1099 }
1100
1101 Query q = session.createQuery(query.toString());
1102
1103 List<JournalFeed> list = (List<JournalFeed>)QueryUtil.list(q,
1104 getDialect(), begin, end);
1105
1106 if (obc == null) {
1107 Collections.sort(list);
1108 }
1109
1110 FinderCache.putResult(finderClassNameCacheEnabled,
1111 finderClassName, finderMethodName, finderParams,
1112 finderArgs, list);
1113
1114 return list;
1115 }
1116 catch (Exception e) {
1117 throw HibernateUtil.processException(e);
1118 }
1119 finally {
1120 closeSession(session);
1121 }
1122 }
1123 else {
1124 return (List<JournalFeed>)result;
1125 }
1126 }
1127
1128 public void removeByUuid(String uuid) throws SystemException {
1129 for (JournalFeed journalFeed : findByUuid(uuid)) {
1130 remove(journalFeed);
1131 }
1132 }
1133
1134 public void removeByUUID_G(String uuid, long groupId)
1135 throws NoSuchFeedException, SystemException {
1136 JournalFeed journalFeed = findByUUID_G(uuid, groupId);
1137
1138 remove(journalFeed);
1139 }
1140
1141 public void removeByGroupId(long groupId) throws SystemException {
1142 for (JournalFeed journalFeed : findByGroupId(groupId)) {
1143 remove(journalFeed);
1144 }
1145 }
1146
1147 public void removeByG_F(long groupId, String feedId)
1148 throws NoSuchFeedException, SystemException {
1149 JournalFeed journalFeed = findByG_F(groupId, feedId);
1150
1151 remove(journalFeed);
1152 }
1153
1154 public void removeAll() throws SystemException {
1155 for (JournalFeed journalFeed : findAll()) {
1156 remove(journalFeed);
1157 }
1158 }
1159
1160 public int countByUuid(String uuid) throws SystemException {
1161 boolean finderClassNameCacheEnabled = JournalFeedModelImpl.CACHE_ENABLED;
1162 String finderClassName = JournalFeed.class.getName();
1163 String finderMethodName = "countByUuid";
1164 String[] finderParams = new String[] { String.class.getName() };
1165 Object[] finderArgs = new Object[] { uuid };
1166
1167 Object result = null;
1168
1169 if (finderClassNameCacheEnabled) {
1170 result = FinderCache.getResult(finderClassName, finderMethodName,
1171 finderParams, finderArgs, getSessionFactory());
1172 }
1173
1174 if (result == null) {
1175 Session session = null;
1176
1177 try {
1178 session = openSession();
1179
1180 StringMaker query = new StringMaker();
1181
1182 query.append("SELECT COUNT(*) ");
1183 query.append(
1184 "FROM com.liferay.portlet.journal.model.JournalFeed WHERE ");
1185
1186 if (uuid == null) {
1187 query.append("uuid_ IS NULL");
1188 }
1189 else {
1190 query.append("uuid_ = ?");
1191 }
1192
1193 query.append(" ");
1194
1195 Query q = session.createQuery(query.toString());
1196
1197 int queryPos = 0;
1198
1199 if (uuid != null) {
1200 q.setString(queryPos++, uuid);
1201 }
1202
1203 Long count = null;
1204
1205 Iterator<Long> itr = q.list().iterator();
1206
1207 if (itr.hasNext()) {
1208 count = itr.next();
1209 }
1210
1211 if (count == null) {
1212 count = new Long(0);
1213 }
1214
1215 FinderCache.putResult(finderClassNameCacheEnabled,
1216 finderClassName, finderMethodName, finderParams,
1217 finderArgs, count);
1218
1219 return count.intValue();
1220 }
1221 catch (Exception e) {
1222 throw HibernateUtil.processException(e);
1223 }
1224 finally {
1225 closeSession(session);
1226 }
1227 }
1228 else {
1229 return ((Long)result).intValue();
1230 }
1231 }
1232
1233 public int countByUUID_G(String uuid, long groupId)
1234 throws SystemException {
1235 boolean finderClassNameCacheEnabled = JournalFeedModelImpl.CACHE_ENABLED;
1236 String finderClassName = JournalFeed.class.getName();
1237 String finderMethodName = "countByUUID_G";
1238 String[] finderParams = new String[] {
1239 String.class.getName(), Long.class.getName()
1240 };
1241 Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
1242
1243 Object result = null;
1244
1245 if (finderClassNameCacheEnabled) {
1246 result = FinderCache.getResult(finderClassName, finderMethodName,
1247 finderParams, finderArgs, getSessionFactory());
1248 }
1249
1250 if (result == null) {
1251 Session session = null;
1252
1253 try {
1254 session = openSession();
1255
1256 StringMaker query = new StringMaker();
1257
1258 query.append("SELECT COUNT(*) ");
1259 query.append(
1260 "FROM com.liferay.portlet.journal.model.JournalFeed WHERE ");
1261
1262 if (uuid == null) {
1263 query.append("uuid_ IS NULL");
1264 }
1265 else {
1266 query.append("uuid_ = ?");
1267 }
1268
1269 query.append(" AND ");
1270
1271 query.append("groupId = ?");
1272
1273 query.append(" ");
1274
1275 Query q = session.createQuery(query.toString());
1276
1277 int queryPos = 0;
1278
1279 if (uuid != null) {
1280 q.setString(queryPos++, uuid);
1281 }
1282
1283 q.setLong(queryPos++, groupId);
1284
1285 Long count = null;
1286
1287 Iterator<Long> itr = q.list().iterator();
1288
1289 if (itr.hasNext()) {
1290 count = itr.next();
1291 }
1292
1293 if (count == null) {
1294 count = new Long(0);
1295 }
1296
1297 FinderCache.putResult(finderClassNameCacheEnabled,
1298 finderClassName, finderMethodName, finderParams,
1299 finderArgs, count);
1300
1301 return count.intValue();
1302 }
1303 catch (Exception e) {
1304 throw HibernateUtil.processException(e);
1305 }
1306 finally {
1307 closeSession(session);
1308 }
1309 }
1310 else {
1311 return ((Long)result).intValue();
1312 }
1313 }
1314
1315 public int countByGroupId(long groupId) throws SystemException {
1316 boolean finderClassNameCacheEnabled = JournalFeedModelImpl.CACHE_ENABLED;
1317 String finderClassName = JournalFeed.class.getName();
1318 String finderMethodName = "countByGroupId";
1319 String[] finderParams = new String[] { Long.class.getName() };
1320 Object[] finderArgs = new Object[] { new Long(groupId) };
1321
1322 Object result = null;
1323
1324 if (finderClassNameCacheEnabled) {
1325 result = FinderCache.getResult(finderClassName, finderMethodName,
1326 finderParams, finderArgs, getSessionFactory());
1327 }
1328
1329 if (result == null) {
1330 Session session = null;
1331
1332 try {
1333 session = openSession();
1334
1335 StringMaker query = new StringMaker();
1336
1337 query.append("SELECT COUNT(*) ");
1338 query.append(
1339 "FROM com.liferay.portlet.journal.model.JournalFeed WHERE ");
1340
1341 query.append("groupId = ?");
1342
1343 query.append(" ");
1344
1345 Query q = session.createQuery(query.toString());
1346
1347 int queryPos = 0;
1348
1349 q.setLong(queryPos++, groupId);
1350
1351 Long count = null;
1352
1353 Iterator<Long> itr = q.list().iterator();
1354
1355 if (itr.hasNext()) {
1356 count = itr.next();
1357 }
1358
1359 if (count == null) {
1360 count = new Long(0);
1361 }
1362
1363 FinderCache.putResult(finderClassNameCacheEnabled,
1364 finderClassName, finderMethodName, finderParams,
1365 finderArgs, count);
1366
1367 return count.intValue();
1368 }
1369 catch (Exception e) {
1370 throw HibernateUtil.processException(e);
1371 }
1372 finally {
1373 closeSession(session);
1374 }
1375 }
1376 else {
1377 return ((Long)result).intValue();
1378 }
1379 }
1380
1381 public int countByG_F(long groupId, String feedId)
1382 throws SystemException {
1383 boolean finderClassNameCacheEnabled = JournalFeedModelImpl.CACHE_ENABLED;
1384 String finderClassName = JournalFeed.class.getName();
1385 String finderMethodName = "countByG_F";
1386 String[] finderParams = new String[] {
1387 Long.class.getName(), String.class.getName()
1388 };
1389 Object[] finderArgs = new Object[] { new Long(groupId), feedId };
1390
1391 Object result = null;
1392
1393 if (finderClassNameCacheEnabled) {
1394 result = FinderCache.getResult(finderClassName, finderMethodName,
1395 finderParams, finderArgs, getSessionFactory());
1396 }
1397
1398 if (result == null) {
1399 Session session = null;
1400
1401 try {
1402 session = openSession();
1403
1404 StringMaker query = new StringMaker();
1405
1406 query.append("SELECT COUNT(*) ");
1407 query.append(
1408 "FROM com.liferay.portlet.journal.model.JournalFeed WHERE ");
1409
1410 query.append("groupId = ?");
1411
1412 query.append(" AND ");
1413
1414 if (feedId == null) {
1415 query.append("feedId IS NULL");
1416 }
1417 else {
1418 query.append("feedId = ?");
1419 }
1420
1421 query.append(" ");
1422
1423 Query q = session.createQuery(query.toString());
1424
1425 int queryPos = 0;
1426
1427 q.setLong(queryPos++, groupId);
1428
1429 if (feedId != null) {
1430 q.setString(queryPos++, feedId);
1431 }
1432
1433 Long count = null;
1434
1435 Iterator<Long> itr = q.list().iterator();
1436
1437 if (itr.hasNext()) {
1438 count = itr.next();
1439 }
1440
1441 if (count == null) {
1442 count = new Long(0);
1443 }
1444
1445 FinderCache.putResult(finderClassNameCacheEnabled,
1446 finderClassName, finderMethodName, finderParams,
1447 finderArgs, count);
1448
1449 return count.intValue();
1450 }
1451 catch (Exception e) {
1452 throw HibernateUtil.processException(e);
1453 }
1454 finally {
1455 closeSession(session);
1456 }
1457 }
1458 else {
1459 return ((Long)result).intValue();
1460 }
1461 }
1462
1463 public int countAll() throws SystemException {
1464 boolean finderClassNameCacheEnabled = JournalFeedModelImpl.CACHE_ENABLED;
1465 String finderClassName = JournalFeed.class.getName();
1466 String finderMethodName = "countAll";
1467 String[] finderParams = new String[] { };
1468 Object[] finderArgs = new Object[] { };
1469
1470 Object result = null;
1471
1472 if (finderClassNameCacheEnabled) {
1473 result = FinderCache.getResult(finderClassName, finderMethodName,
1474 finderParams, finderArgs, getSessionFactory());
1475 }
1476
1477 if (result == null) {
1478 Session session = null;
1479
1480 try {
1481 session = openSession();
1482
1483 Query q = session.createQuery(
1484 "SELECT COUNT(*) FROM com.liferay.portlet.journal.model.JournalFeed");
1485
1486 Long count = null;
1487
1488 Iterator<Long> itr = q.list().iterator();
1489
1490 if (itr.hasNext()) {
1491 count = itr.next();
1492 }
1493
1494 if (count == null) {
1495 count = new Long(0);
1496 }
1497
1498 FinderCache.putResult(finderClassNameCacheEnabled,
1499 finderClassName, finderMethodName, finderParams,
1500 finderArgs, count);
1501
1502 return count.intValue();
1503 }
1504 catch (Exception e) {
1505 throw HibernateUtil.processException(e);
1506 }
1507 finally {
1508 closeSession(session);
1509 }
1510 }
1511 else {
1512 return ((Long)result).intValue();
1513 }
1514 }
1515
1516 protected void initDao() {
1517 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1518 PropsUtil.get(
1519 "value.object.listener.com.liferay.portlet.journal.model.JournalFeed")));
1520
1521 if (listenerClassNames.length > 0) {
1522 try {
1523 List<ModelListener> listeners = new ArrayList<ModelListener>();
1524
1525 for (String listenerClassName : listenerClassNames) {
1526 listeners.add((ModelListener)Class.forName(
1527 listenerClassName).newInstance());
1528 }
1529
1530 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1531 }
1532 catch (Exception e) {
1533 _log.error(e);
1534 }
1535 }
1536 }
1537
1538 private static Log _log = LogFactory.getLog(JournalFeedPersistenceImpl.class);
1539 private ModelListener[] _listeners;
1540}