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.BatchSessionUtil;
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 {
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 if (BatchSessionUtil.isEnabled()) {
137 Object staleObject = session.get(JournalFeedImpl.class,
138 journalFeed.getPrimaryKeyObj());
139
140 if (staleObject != null) {
141 session.evict(staleObject);
142 }
143 }
144
145 session.delete(journalFeed);
146
147 session.flush();
148
149 return journalFeed;
150 }
151 catch (Exception e) {
152 throw processException(e);
153 }
154 finally {
155 closeSession(session);
156
157 FinderCacheUtil.clearCache(JournalFeed.class.getName());
158 }
159 }
160
161
164 public JournalFeed update(JournalFeed journalFeed)
165 throws SystemException {
166 if (_log.isWarnEnabled()) {
167 _log.warn(
168 "Using the deprecated update(JournalFeed journalFeed) method. Use update(JournalFeed journalFeed, boolean merge) instead.");
169 }
170
171 return update(journalFeed, false);
172 }
173
174
187 public JournalFeed update(JournalFeed journalFeed, boolean merge)
188 throws SystemException {
189 boolean isNew = journalFeed.isNew();
190
191 if (_listeners.length > 0) {
192 for (ModelListener listener : _listeners) {
193 if (isNew) {
194 listener.onBeforeCreate(journalFeed);
195 }
196 else {
197 listener.onBeforeUpdate(journalFeed);
198 }
199 }
200 }
201
202 journalFeed = updateImpl(journalFeed, merge);
203
204 if (_listeners.length > 0) {
205 for (ModelListener listener : _listeners) {
206 if (isNew) {
207 listener.onAfterCreate(journalFeed);
208 }
209 else {
210 listener.onAfterUpdate(journalFeed);
211 }
212 }
213 }
214
215 return journalFeed;
216 }
217
218 public JournalFeed updateImpl(
219 com.liferay.portlet.journal.model.JournalFeed journalFeed, boolean merge)
220 throws SystemException {
221 if (Validator.isNull(journalFeed.getUuid())) {
222 String uuid = PortalUUIDUtil.generate();
223
224 journalFeed.setUuid(uuid);
225 }
226
227 Session session = null;
228
229 try {
230 session = openSession();
231
232 BatchSessionUtil.update(session, journalFeed, merge);
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 = null;
1100
1101 if (obc == null) {
1102 list = (List<JournalFeed>)QueryUtil.list(q, getDialect(),
1103 start, end, false);
1104
1105 Collections.sort(list);
1106 }
1107 else {
1108 list = (List<JournalFeed>)QueryUtil.list(q, getDialect(),
1109 start, end);
1110 }
1111
1112 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1113 finderClassName, finderMethodName, finderParams,
1114 finderArgs, list);
1115
1116 return list;
1117 }
1118 catch (Exception e) {
1119 throw processException(e);
1120 }
1121 finally {
1122 closeSession(session);
1123 }
1124 }
1125 else {
1126 return (List<JournalFeed>)result;
1127 }
1128 }
1129
1130 public void removeByUuid(String uuid) throws SystemException {
1131 for (JournalFeed journalFeed : findByUuid(uuid)) {
1132 remove(journalFeed);
1133 }
1134 }
1135
1136 public void removeByUUID_G(String uuid, long groupId)
1137 throws NoSuchFeedException, SystemException {
1138 JournalFeed journalFeed = findByUUID_G(uuid, groupId);
1139
1140 remove(journalFeed);
1141 }
1142
1143 public void removeByGroupId(long groupId) throws SystemException {
1144 for (JournalFeed journalFeed : findByGroupId(groupId)) {
1145 remove(journalFeed);
1146 }
1147 }
1148
1149 public void removeByG_F(long groupId, String feedId)
1150 throws NoSuchFeedException, SystemException {
1151 JournalFeed journalFeed = findByG_F(groupId, feedId);
1152
1153 remove(journalFeed);
1154 }
1155
1156 public void removeAll() throws SystemException {
1157 for (JournalFeed journalFeed : findAll()) {
1158 remove(journalFeed);
1159 }
1160 }
1161
1162 public int countByUuid(String uuid) throws SystemException {
1163 boolean finderClassNameCacheEnabled = JournalFeedModelImpl.CACHE_ENABLED;
1164 String finderClassName = JournalFeed.class.getName();
1165 String finderMethodName = "countByUuid";
1166 String[] finderParams = new String[] { String.class.getName() };
1167 Object[] finderArgs = new Object[] { uuid };
1168
1169 Object result = null;
1170
1171 if (finderClassNameCacheEnabled) {
1172 result = FinderCacheUtil.getResult(finderClassName,
1173 finderMethodName, finderParams, finderArgs, this);
1174 }
1175
1176 if (result == null) {
1177 Session session = null;
1178
1179 try {
1180 session = openSession();
1181
1182 StringBuilder query = new StringBuilder();
1183
1184 query.append("SELECT COUNT(*) ");
1185 query.append(
1186 "FROM com.liferay.portlet.journal.model.JournalFeed WHERE ");
1187
1188 if (uuid == null) {
1189 query.append("uuid_ IS NULL");
1190 }
1191 else {
1192 query.append("uuid_ = ?");
1193 }
1194
1195 query.append(" ");
1196
1197 Query q = session.createQuery(query.toString());
1198
1199 QueryPos qPos = QueryPos.getInstance(q);
1200
1201 if (uuid != null) {
1202 qPos.add(uuid);
1203 }
1204
1205 Long count = null;
1206
1207 Iterator<Long> itr = q.list().iterator();
1208
1209 if (itr.hasNext()) {
1210 count = itr.next();
1211 }
1212
1213 if (count == null) {
1214 count = new Long(0);
1215 }
1216
1217 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1218 finderClassName, finderMethodName, finderParams,
1219 finderArgs, count);
1220
1221 return count.intValue();
1222 }
1223 catch (Exception e) {
1224 throw processException(e);
1225 }
1226 finally {
1227 closeSession(session);
1228 }
1229 }
1230 else {
1231 return ((Long)result).intValue();
1232 }
1233 }
1234
1235 public int countByUUID_G(String uuid, long groupId)
1236 throws SystemException {
1237 boolean finderClassNameCacheEnabled = JournalFeedModelImpl.CACHE_ENABLED;
1238 String finderClassName = JournalFeed.class.getName();
1239 String finderMethodName = "countByUUID_G";
1240 String[] finderParams = new String[] {
1241 String.class.getName(), Long.class.getName()
1242 };
1243 Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
1244
1245 Object result = null;
1246
1247 if (finderClassNameCacheEnabled) {
1248 result = FinderCacheUtil.getResult(finderClassName,
1249 finderMethodName, finderParams, finderArgs, this);
1250 }
1251
1252 if (result == null) {
1253 Session session = null;
1254
1255 try {
1256 session = openSession();
1257
1258 StringBuilder query = new StringBuilder();
1259
1260 query.append("SELECT COUNT(*) ");
1261 query.append(
1262 "FROM com.liferay.portlet.journal.model.JournalFeed WHERE ");
1263
1264 if (uuid == null) {
1265 query.append("uuid_ IS NULL");
1266 }
1267 else {
1268 query.append("uuid_ = ?");
1269 }
1270
1271 query.append(" AND ");
1272
1273 query.append("groupId = ?");
1274
1275 query.append(" ");
1276
1277 Query q = session.createQuery(query.toString());
1278
1279 QueryPos qPos = QueryPos.getInstance(q);
1280
1281 if (uuid != null) {
1282 qPos.add(uuid);
1283 }
1284
1285 qPos.add(groupId);
1286
1287 Long count = null;
1288
1289 Iterator<Long> itr = q.list().iterator();
1290
1291 if (itr.hasNext()) {
1292 count = itr.next();
1293 }
1294
1295 if (count == null) {
1296 count = new Long(0);
1297 }
1298
1299 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1300 finderClassName, finderMethodName, finderParams,
1301 finderArgs, count);
1302
1303 return count.intValue();
1304 }
1305 catch (Exception e) {
1306 throw processException(e);
1307 }
1308 finally {
1309 closeSession(session);
1310 }
1311 }
1312 else {
1313 return ((Long)result).intValue();
1314 }
1315 }
1316
1317 public int countByGroupId(long groupId) throws SystemException {
1318 boolean finderClassNameCacheEnabled = JournalFeedModelImpl.CACHE_ENABLED;
1319 String finderClassName = JournalFeed.class.getName();
1320 String finderMethodName = "countByGroupId";
1321 String[] finderParams = new String[] { Long.class.getName() };
1322 Object[] finderArgs = new Object[] { new Long(groupId) };
1323
1324 Object result = null;
1325
1326 if (finderClassNameCacheEnabled) {
1327 result = FinderCacheUtil.getResult(finderClassName,
1328 finderMethodName, finderParams, finderArgs, this);
1329 }
1330
1331 if (result == null) {
1332 Session session = null;
1333
1334 try {
1335 session = openSession();
1336
1337 StringBuilder query = new StringBuilder();
1338
1339 query.append("SELECT COUNT(*) ");
1340 query.append(
1341 "FROM com.liferay.portlet.journal.model.JournalFeed WHERE ");
1342
1343 query.append("groupId = ?");
1344
1345 query.append(" ");
1346
1347 Query q = session.createQuery(query.toString());
1348
1349 QueryPos qPos = QueryPos.getInstance(q);
1350
1351 qPos.add(groupId);
1352
1353 Long count = null;
1354
1355 Iterator<Long> itr = q.list().iterator();
1356
1357 if (itr.hasNext()) {
1358 count = itr.next();
1359 }
1360
1361 if (count == null) {
1362 count = new Long(0);
1363 }
1364
1365 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1366 finderClassName, finderMethodName, finderParams,
1367 finderArgs, count);
1368
1369 return count.intValue();
1370 }
1371 catch (Exception e) {
1372 throw processException(e);
1373 }
1374 finally {
1375 closeSession(session);
1376 }
1377 }
1378 else {
1379 return ((Long)result).intValue();
1380 }
1381 }
1382
1383 public int countByG_F(long groupId, String feedId)
1384 throws SystemException {
1385 boolean finderClassNameCacheEnabled = JournalFeedModelImpl.CACHE_ENABLED;
1386 String finderClassName = JournalFeed.class.getName();
1387 String finderMethodName = "countByG_F";
1388 String[] finderParams = new String[] {
1389 Long.class.getName(), String.class.getName()
1390 };
1391 Object[] finderArgs = new Object[] { new Long(groupId), feedId };
1392
1393 Object result = null;
1394
1395 if (finderClassNameCacheEnabled) {
1396 result = FinderCacheUtil.getResult(finderClassName,
1397 finderMethodName, finderParams, finderArgs, this);
1398 }
1399
1400 if (result == null) {
1401 Session session = null;
1402
1403 try {
1404 session = openSession();
1405
1406 StringBuilder query = new StringBuilder();
1407
1408 query.append("SELECT COUNT(*) ");
1409 query.append(
1410 "FROM com.liferay.portlet.journal.model.JournalFeed WHERE ");
1411
1412 query.append("groupId = ?");
1413
1414 query.append(" AND ");
1415
1416 if (feedId == null) {
1417 query.append("feedId IS NULL");
1418 }
1419 else {
1420 query.append("feedId = ?");
1421 }
1422
1423 query.append(" ");
1424
1425 Query q = session.createQuery(query.toString());
1426
1427 QueryPos qPos = QueryPos.getInstance(q);
1428
1429 qPos.add(groupId);
1430
1431 if (feedId != null) {
1432 qPos.add(feedId);
1433 }
1434
1435 Long count = null;
1436
1437 Iterator<Long> itr = q.list().iterator();
1438
1439 if (itr.hasNext()) {
1440 count = itr.next();
1441 }
1442
1443 if (count == null) {
1444 count = new Long(0);
1445 }
1446
1447 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1448 finderClassName, finderMethodName, finderParams,
1449 finderArgs, count);
1450
1451 return count.intValue();
1452 }
1453 catch (Exception e) {
1454 throw processException(e);
1455 }
1456 finally {
1457 closeSession(session);
1458 }
1459 }
1460 else {
1461 return ((Long)result).intValue();
1462 }
1463 }
1464
1465 public int countAll() throws SystemException {
1466 boolean finderClassNameCacheEnabled = JournalFeedModelImpl.CACHE_ENABLED;
1467 String finderClassName = JournalFeed.class.getName();
1468 String finderMethodName = "countAll";
1469 String[] finderParams = new String[] { };
1470 Object[] finderArgs = new Object[] { };
1471
1472 Object result = null;
1473
1474 if (finderClassNameCacheEnabled) {
1475 result = FinderCacheUtil.getResult(finderClassName,
1476 finderMethodName, finderParams, finderArgs, this);
1477 }
1478
1479 if (result == null) {
1480 Session session = null;
1481
1482 try {
1483 session = openSession();
1484
1485 Query q = session.createQuery(
1486 "SELECT COUNT(*) FROM com.liferay.portlet.journal.model.JournalFeed");
1487
1488 Long count = null;
1489
1490 Iterator<Long> itr = q.list().iterator();
1491
1492 if (itr.hasNext()) {
1493 count = itr.next();
1494 }
1495
1496 if (count == null) {
1497 count = new Long(0);
1498 }
1499
1500 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1501 finderClassName, finderMethodName, finderParams,
1502 finderArgs, count);
1503
1504 return count.intValue();
1505 }
1506 catch (Exception e) {
1507 throw processException(e);
1508 }
1509 finally {
1510 closeSession(session);
1511 }
1512 }
1513 else {
1514 return ((Long)result).intValue();
1515 }
1516 }
1517
1518 public void registerListener(ModelListener listener) {
1519 List<ModelListener> listeners = ListUtil.fromArray(_listeners);
1520
1521 listeners.add(listener);
1522
1523 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1524 }
1525
1526 public void unregisterListener(ModelListener listener) {
1527 List<ModelListener> listeners = ListUtil.fromArray(_listeners);
1528
1529 listeners.remove(listener);
1530
1531 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1532 }
1533
1534 public void afterPropertiesSet() {
1535 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1536 com.liferay.portal.util.PropsUtil.get(
1537 "value.object.listener.com.liferay.portlet.journal.model.JournalFeed")));
1538
1539 if (listenerClassNames.length > 0) {
1540 try {
1541 List<ModelListener> listeners = new ArrayList<ModelListener>();
1542
1543 for (String listenerClassName : listenerClassNames) {
1544 listeners.add((ModelListener)Class.forName(
1545 listenerClassName).newInstance());
1546 }
1547
1548 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1549 }
1550 catch (Exception e) {
1551 _log.error(e);
1552 }
1553 }
1554 }
1555
1556 private static Log _log = LogFactory.getLog(JournalFeedPersistenceImpl.class);
1557 private ModelListener[] _listeners = new ModelListener[0];
1558}