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