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