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