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