001
014
015 package com.liferay.portlet.journal.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.annotation.BeanReference;
019 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.SQLQuery;
027 import com.liferay.portal.kernel.dao.orm.Session;
028 import com.liferay.portal.kernel.exception.SystemException;
029 import com.liferay.portal.kernel.log.Log;
030 import com.liferay.portal.kernel.log.LogFactoryUtil;
031 import com.liferay.portal.kernel.util.GetterUtil;
032 import com.liferay.portal.kernel.util.InstanceFactory;
033 import com.liferay.portal.kernel.util.OrderByComparator;
034 import com.liferay.portal.kernel.util.StringBundler;
035 import com.liferay.portal.kernel.util.StringPool;
036 import com.liferay.portal.kernel.util.StringUtil;
037 import com.liferay.portal.kernel.util.Validator;
038 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
039 import com.liferay.portal.model.ModelListener;
040 import com.liferay.portal.security.permission.InlineSQLHelperUtil;
041 import com.liferay.portal.service.persistence.BatchSessionUtil;
042 import com.liferay.portal.service.persistence.ResourcePersistence;
043 import com.liferay.portal.service.persistence.UserPersistence;
044 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
045
046 import com.liferay.portlet.expando.service.persistence.ExpandoValuePersistence;
047 import com.liferay.portlet.journal.NoSuchFeedException;
048 import com.liferay.portlet.journal.model.JournalFeed;
049 import com.liferay.portlet.journal.model.impl.JournalFeedImpl;
050 import com.liferay.portlet.journal.model.impl.JournalFeedModelImpl;
051
052 import java.io.Serializable;
053
054 import java.util.ArrayList;
055 import java.util.Collections;
056 import java.util.List;
057
058
074 public class JournalFeedPersistenceImpl extends BasePersistenceImpl<JournalFeed>
075 implements JournalFeedPersistence {
076 public static final String FINDER_CLASS_NAME_ENTITY = JournalFeedImpl.class.getName();
077 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
078 ".List";
079 public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
080 JournalFeedModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
081 "findByUuid",
082 new String[] {
083 String.class.getName(),
084
085 "java.lang.Integer", "java.lang.Integer",
086 "com.liferay.portal.kernel.util.OrderByComparator"
087 });
088 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
089 JournalFeedModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
090 "countByUuid", new String[] { String.class.getName() });
091 public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
092 JournalFeedModelImpl.FINDER_CACHE_ENABLED,
093 FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
094 new String[] { String.class.getName(), Long.class.getName() });
095 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
096 JournalFeedModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
097 "countByUUID_G",
098 new String[] { String.class.getName(), Long.class.getName() });
099 public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
100 JournalFeedModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
101 "findByGroupId",
102 new String[] {
103 Long.class.getName(),
104
105 "java.lang.Integer", "java.lang.Integer",
106 "com.liferay.portal.kernel.util.OrderByComparator"
107 });
108 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
109 JournalFeedModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
110 "countByGroupId", new String[] { Long.class.getName() });
111 public static final FinderPath FINDER_PATH_FETCH_BY_G_F = new FinderPath(JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
112 JournalFeedModelImpl.FINDER_CACHE_ENABLED,
113 FINDER_CLASS_NAME_ENTITY, "fetchByG_F",
114 new String[] { Long.class.getName(), String.class.getName() });
115 public static final FinderPath FINDER_PATH_COUNT_BY_G_F = new FinderPath(JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
116 JournalFeedModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
117 "countByG_F",
118 new String[] { Long.class.getName(), String.class.getName() });
119 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
120 JournalFeedModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
121 "findAll", new String[0]);
122 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
123 JournalFeedModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
124 "countAll", new String[0]);
125
126
131 public void cacheResult(JournalFeed journalFeed) {
132 EntityCacheUtil.putResult(JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
133 JournalFeedImpl.class, journalFeed.getPrimaryKey(), journalFeed);
134
135 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
136 new Object[] {
137 journalFeed.getUuid(), new Long(journalFeed.getGroupId())
138 }, journalFeed);
139
140 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_F,
141 new Object[] {
142 new Long(journalFeed.getGroupId()),
143
144 journalFeed.getFeedId()
145 }, journalFeed);
146 }
147
148
153 public void cacheResult(List<JournalFeed> journalFeeds) {
154 for (JournalFeed journalFeed : journalFeeds) {
155 if (EntityCacheUtil.getResult(
156 JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
157 JournalFeedImpl.class, journalFeed.getPrimaryKey(), this) == null) {
158 cacheResult(journalFeed);
159 }
160 }
161 }
162
163
170 public void clearCache() {
171 CacheRegistryUtil.clear(JournalFeedImpl.class.getName());
172 EntityCacheUtil.clearCache(JournalFeedImpl.class.getName());
173 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
174 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
175 }
176
177
184 public void clearCache(JournalFeed journalFeed) {
185 EntityCacheUtil.removeResult(JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
186 JournalFeedImpl.class, journalFeed.getPrimaryKey());
187
188 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
189 new Object[] {
190 journalFeed.getUuid(), new Long(journalFeed.getGroupId())
191 });
192
193 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_F,
194 new Object[] {
195 new Long(journalFeed.getGroupId()),
196
197 journalFeed.getFeedId()
198 });
199 }
200
201
207 public JournalFeed create(long id) {
208 JournalFeed journalFeed = new JournalFeedImpl();
209
210 journalFeed.setNew(true);
211 journalFeed.setPrimaryKey(id);
212
213 String uuid = PortalUUIDUtil.generate();
214
215 journalFeed.setUuid(uuid);
216
217 return journalFeed;
218 }
219
220
228 public JournalFeed remove(Serializable primaryKey)
229 throws NoSuchModelException, SystemException {
230 return remove(((Long)primaryKey).longValue());
231 }
232
233
241 public JournalFeed remove(long id)
242 throws NoSuchFeedException, SystemException {
243 Session session = null;
244
245 try {
246 session = openSession();
247
248 JournalFeed journalFeed = (JournalFeed)session.get(JournalFeedImpl.class,
249 new Long(id));
250
251 if (journalFeed == null) {
252 if (_log.isWarnEnabled()) {
253 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + id);
254 }
255
256 throw new NoSuchFeedException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
257 id);
258 }
259
260 return remove(journalFeed);
261 }
262 catch (NoSuchFeedException nsee) {
263 throw nsee;
264 }
265 catch (Exception e) {
266 throw processException(e);
267 }
268 finally {
269 closeSession(session);
270 }
271 }
272
273 protected JournalFeed removeImpl(JournalFeed journalFeed)
274 throws SystemException {
275 journalFeed = toUnwrappedModel(journalFeed);
276
277 Session session = null;
278
279 try {
280 session = openSession();
281
282 BatchSessionUtil.delete(session, journalFeed);
283 }
284 catch (Exception e) {
285 throw processException(e);
286 }
287 finally {
288 closeSession(session);
289 }
290
291 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
292
293 JournalFeedModelImpl journalFeedModelImpl = (JournalFeedModelImpl)journalFeed;
294
295 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
296 new Object[] {
297 journalFeedModelImpl.getOriginalUuid(),
298 new Long(journalFeedModelImpl.getOriginalGroupId())
299 });
300
301 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_F,
302 new Object[] {
303 new Long(journalFeedModelImpl.getOriginalGroupId()),
304
305 journalFeedModelImpl.getOriginalFeedId()
306 });
307
308 EntityCacheUtil.removeResult(JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
309 JournalFeedImpl.class, journalFeed.getPrimaryKey());
310
311 return journalFeed;
312 }
313
314 public JournalFeed updateImpl(
315 com.liferay.portlet.journal.model.JournalFeed journalFeed, boolean merge)
316 throws SystemException {
317 journalFeed = toUnwrappedModel(journalFeed);
318
319 boolean isNew = journalFeed.isNew();
320
321 JournalFeedModelImpl journalFeedModelImpl = (JournalFeedModelImpl)journalFeed;
322
323 if (Validator.isNull(journalFeed.getUuid())) {
324 String uuid = PortalUUIDUtil.generate();
325
326 journalFeed.setUuid(uuid);
327 }
328
329 Session session = null;
330
331 try {
332 session = openSession();
333
334 BatchSessionUtil.update(session, journalFeed, merge);
335
336 journalFeed.setNew(false);
337 }
338 catch (Exception e) {
339 throw processException(e);
340 }
341 finally {
342 closeSession(session);
343 }
344
345 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
346
347 EntityCacheUtil.putResult(JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
348 JournalFeedImpl.class, journalFeed.getPrimaryKey(), journalFeed);
349
350 if (!isNew &&
351 (!Validator.equals(journalFeed.getUuid(),
352 journalFeedModelImpl.getOriginalUuid()) ||
353 (journalFeed.getGroupId() != journalFeedModelImpl.getOriginalGroupId()))) {
354 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
355 new Object[] {
356 journalFeedModelImpl.getOriginalUuid(),
357 new Long(journalFeedModelImpl.getOriginalGroupId())
358 });
359 }
360
361 if (isNew ||
362 (!Validator.equals(journalFeed.getUuid(),
363 journalFeedModelImpl.getOriginalUuid()) ||
364 (journalFeed.getGroupId() != journalFeedModelImpl.getOriginalGroupId()))) {
365 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
366 new Object[] {
367 journalFeed.getUuid(), new Long(journalFeed.getGroupId())
368 }, journalFeed);
369 }
370
371 if (!isNew &&
372 ((journalFeed.getGroupId() != journalFeedModelImpl.getOriginalGroupId()) ||
373 !Validator.equals(journalFeed.getFeedId(),
374 journalFeedModelImpl.getOriginalFeedId()))) {
375 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_F,
376 new Object[] {
377 new Long(journalFeedModelImpl.getOriginalGroupId()),
378
379 journalFeedModelImpl.getOriginalFeedId()
380 });
381 }
382
383 if (isNew ||
384 ((journalFeed.getGroupId() != journalFeedModelImpl.getOriginalGroupId()) ||
385 !Validator.equals(journalFeed.getFeedId(),
386 journalFeedModelImpl.getOriginalFeedId()))) {
387 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_F,
388 new Object[] {
389 new Long(journalFeed.getGroupId()),
390
391 journalFeed.getFeedId()
392 }, journalFeed);
393 }
394
395 return journalFeed;
396 }
397
398 protected JournalFeed toUnwrappedModel(JournalFeed journalFeed) {
399 if (journalFeed instanceof JournalFeedImpl) {
400 return journalFeed;
401 }
402
403 JournalFeedImpl journalFeedImpl = new JournalFeedImpl();
404
405 journalFeedImpl.setNew(journalFeed.isNew());
406 journalFeedImpl.setPrimaryKey(journalFeed.getPrimaryKey());
407
408 journalFeedImpl.setUuid(journalFeed.getUuid());
409 journalFeedImpl.setId(journalFeed.getId());
410 journalFeedImpl.setGroupId(journalFeed.getGroupId());
411 journalFeedImpl.setCompanyId(journalFeed.getCompanyId());
412 journalFeedImpl.setUserId(journalFeed.getUserId());
413 journalFeedImpl.setUserName(journalFeed.getUserName());
414 journalFeedImpl.setCreateDate(journalFeed.getCreateDate());
415 journalFeedImpl.setModifiedDate(journalFeed.getModifiedDate());
416 journalFeedImpl.setFeedId(journalFeed.getFeedId());
417 journalFeedImpl.setName(journalFeed.getName());
418 journalFeedImpl.setDescription(journalFeed.getDescription());
419 journalFeedImpl.setType(journalFeed.getType());
420 journalFeedImpl.setStructureId(journalFeed.getStructureId());
421 journalFeedImpl.setTemplateId(journalFeed.getTemplateId());
422 journalFeedImpl.setRendererTemplateId(journalFeed.getRendererTemplateId());
423 journalFeedImpl.setDelta(journalFeed.getDelta());
424 journalFeedImpl.setOrderByCol(journalFeed.getOrderByCol());
425 journalFeedImpl.setOrderByType(journalFeed.getOrderByType());
426 journalFeedImpl.setTargetLayoutFriendlyUrl(journalFeed.getTargetLayoutFriendlyUrl());
427 journalFeedImpl.setTargetPortletId(journalFeed.getTargetPortletId());
428 journalFeedImpl.setContentField(journalFeed.getContentField());
429 journalFeedImpl.setFeedType(journalFeed.getFeedType());
430 journalFeedImpl.setFeedVersion(journalFeed.getFeedVersion());
431
432 return journalFeedImpl;
433 }
434
435
443 public JournalFeed findByPrimaryKey(Serializable primaryKey)
444 throws NoSuchModelException, SystemException {
445 return findByPrimaryKey(((Long)primaryKey).longValue());
446 }
447
448
456 public JournalFeed findByPrimaryKey(long id)
457 throws NoSuchFeedException, SystemException {
458 JournalFeed journalFeed = fetchByPrimaryKey(id);
459
460 if (journalFeed == null) {
461 if (_log.isWarnEnabled()) {
462 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + id);
463 }
464
465 throw new NoSuchFeedException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
466 id);
467 }
468
469 return journalFeed;
470 }
471
472
479 public JournalFeed fetchByPrimaryKey(Serializable primaryKey)
480 throws SystemException {
481 return fetchByPrimaryKey(((Long)primaryKey).longValue());
482 }
483
484
491 public JournalFeed fetchByPrimaryKey(long id) throws SystemException {
492 JournalFeed journalFeed = (JournalFeed)EntityCacheUtil.getResult(JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
493 JournalFeedImpl.class, id, this);
494
495 if (journalFeed == null) {
496 Session session = null;
497
498 try {
499 session = openSession();
500
501 journalFeed = (JournalFeed)session.get(JournalFeedImpl.class,
502 new Long(id));
503 }
504 catch (Exception e) {
505 throw processException(e);
506 }
507 finally {
508 if (journalFeed != null) {
509 cacheResult(journalFeed);
510 }
511
512 closeSession(session);
513 }
514 }
515
516 return journalFeed;
517 }
518
519
526 public List<JournalFeed> findByUuid(String uuid) throws SystemException {
527 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
528 }
529
530
543 public List<JournalFeed> findByUuid(String uuid, int start, int end)
544 throws SystemException {
545 return findByUuid(uuid, start, end, null);
546 }
547
548
562 public List<JournalFeed> findByUuid(String uuid, int start, int end,
563 OrderByComparator orderByComparator) throws SystemException {
564 Object[] finderArgs = new Object[] {
565 uuid,
566
567 String.valueOf(start), String.valueOf(end),
568 String.valueOf(orderByComparator)
569 };
570
571 List<JournalFeed> list = (List<JournalFeed>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
572 finderArgs, this);
573
574 if (list == null) {
575 Session session = null;
576
577 try {
578 session = openSession();
579
580 StringBundler query = null;
581
582 if (orderByComparator != null) {
583 query = new StringBundler(3 +
584 (orderByComparator.getOrderByFields().length * 3));
585 }
586 else {
587 query = new StringBundler(3);
588 }
589
590 query.append(_SQL_SELECT_JOURNALFEED_WHERE);
591
592 if (uuid == null) {
593 query.append(_FINDER_COLUMN_UUID_UUID_1);
594 }
595 else {
596 if (uuid.equals(StringPool.BLANK)) {
597 query.append(_FINDER_COLUMN_UUID_UUID_3);
598 }
599 else {
600 query.append(_FINDER_COLUMN_UUID_UUID_2);
601 }
602 }
603
604 if (orderByComparator != null) {
605 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
606 orderByComparator);
607 }
608
609 else {
610 query.append(JournalFeedModelImpl.ORDER_BY_JPQL);
611 }
612
613 String sql = query.toString();
614
615 Query q = session.createQuery(sql);
616
617 QueryPos qPos = QueryPos.getInstance(q);
618
619 if (uuid != null) {
620 qPos.add(uuid);
621 }
622
623 list = (List<JournalFeed>)QueryUtil.list(q, getDialect(),
624 start, end);
625 }
626 catch (Exception e) {
627 throw processException(e);
628 }
629 finally {
630 if (list == null) {
631 list = new ArrayList<JournalFeed>();
632 }
633
634 cacheResult(list);
635
636 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
637 list);
638
639 closeSession(session);
640 }
641 }
642
643 return list;
644 }
645
646
659 public JournalFeed findByUuid_First(String uuid,
660 OrderByComparator orderByComparator)
661 throws NoSuchFeedException, SystemException {
662 List<JournalFeed> list = findByUuid(uuid, 0, 1, orderByComparator);
663
664 if (list.isEmpty()) {
665 StringBundler msg = new StringBundler(4);
666
667 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
668
669 msg.append("uuid=");
670 msg.append(uuid);
671
672 msg.append(StringPool.CLOSE_CURLY_BRACE);
673
674 throw new NoSuchFeedException(msg.toString());
675 }
676 else {
677 return list.get(0);
678 }
679 }
680
681
694 public JournalFeed findByUuid_Last(String uuid,
695 OrderByComparator orderByComparator)
696 throws NoSuchFeedException, SystemException {
697 int count = countByUuid(uuid);
698
699 List<JournalFeed> list = findByUuid(uuid, count - 1, count,
700 orderByComparator);
701
702 if (list.isEmpty()) {
703 StringBundler msg = new StringBundler(4);
704
705 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
706
707 msg.append("uuid=");
708 msg.append(uuid);
709
710 msg.append(StringPool.CLOSE_CURLY_BRACE);
711
712 throw new NoSuchFeedException(msg.toString());
713 }
714 else {
715 return list.get(0);
716 }
717 }
718
719
733 public JournalFeed[] findByUuid_PrevAndNext(long id, String uuid,
734 OrderByComparator orderByComparator)
735 throws NoSuchFeedException, SystemException {
736 JournalFeed journalFeed = findByPrimaryKey(id);
737
738 Session session = null;
739
740 try {
741 session = openSession();
742
743 JournalFeed[] array = new JournalFeedImpl[3];
744
745 array[0] = getByUuid_PrevAndNext(session, journalFeed, uuid,
746 orderByComparator, true);
747
748 array[1] = journalFeed;
749
750 array[2] = getByUuid_PrevAndNext(session, journalFeed, uuid,
751 orderByComparator, false);
752
753 return array;
754 }
755 catch (Exception e) {
756 throw processException(e);
757 }
758 finally {
759 closeSession(session);
760 }
761 }
762
763 protected JournalFeed getByUuid_PrevAndNext(Session session,
764 JournalFeed journalFeed, String uuid,
765 OrderByComparator orderByComparator, boolean previous) {
766 StringBundler query = null;
767
768 if (orderByComparator != null) {
769 query = new StringBundler(6 +
770 (orderByComparator.getOrderByFields().length * 6));
771 }
772 else {
773 query = new StringBundler(3);
774 }
775
776 query.append(_SQL_SELECT_JOURNALFEED_WHERE);
777
778 if (uuid == null) {
779 query.append(_FINDER_COLUMN_UUID_UUID_1);
780 }
781 else {
782 if (uuid.equals(StringPool.BLANK)) {
783 query.append(_FINDER_COLUMN_UUID_UUID_3);
784 }
785 else {
786 query.append(_FINDER_COLUMN_UUID_UUID_2);
787 }
788 }
789
790 if (orderByComparator != null) {
791 String[] orderByFields = orderByComparator.getOrderByFields();
792
793 if (orderByFields.length > 0) {
794 query.append(WHERE_AND);
795 }
796
797 for (int i = 0; i < orderByFields.length; i++) {
798 query.append(_ORDER_BY_ENTITY_ALIAS);
799 query.append(orderByFields[i]);
800
801 if ((i + 1) < orderByFields.length) {
802 if (orderByComparator.isAscending() ^ previous) {
803 query.append(WHERE_GREATER_THAN_HAS_NEXT);
804 }
805 else {
806 query.append(WHERE_LESSER_THAN_HAS_NEXT);
807 }
808 }
809 else {
810 if (orderByComparator.isAscending() ^ previous) {
811 query.append(WHERE_GREATER_THAN);
812 }
813 else {
814 query.append(WHERE_LESSER_THAN);
815 }
816 }
817 }
818
819 query.append(ORDER_BY_CLAUSE);
820
821 for (int i = 0; i < orderByFields.length; i++) {
822 query.append(_ORDER_BY_ENTITY_ALIAS);
823 query.append(orderByFields[i]);
824
825 if ((i + 1) < orderByFields.length) {
826 if (orderByComparator.isAscending() ^ previous) {
827 query.append(ORDER_BY_ASC_HAS_NEXT);
828 }
829 else {
830 query.append(ORDER_BY_DESC_HAS_NEXT);
831 }
832 }
833 else {
834 if (orderByComparator.isAscending() ^ previous) {
835 query.append(ORDER_BY_ASC);
836 }
837 else {
838 query.append(ORDER_BY_DESC);
839 }
840 }
841 }
842 }
843
844 else {
845 query.append(JournalFeedModelImpl.ORDER_BY_JPQL);
846 }
847
848 String sql = query.toString();
849
850 Query q = session.createQuery(sql);
851
852 q.setFirstResult(0);
853 q.setMaxResults(2);
854
855 QueryPos qPos = QueryPos.getInstance(q);
856
857 if (uuid != null) {
858 qPos.add(uuid);
859 }
860
861 if (orderByComparator != null) {
862 Object[] values = orderByComparator.getOrderByValues(journalFeed);
863
864 for (Object value : values) {
865 qPos.add(value);
866 }
867 }
868
869 List<JournalFeed> list = q.list();
870
871 if (list.size() == 2) {
872 return list.get(1);
873 }
874 else {
875 return null;
876 }
877 }
878
879
888 public JournalFeed findByUUID_G(String uuid, long groupId)
889 throws NoSuchFeedException, SystemException {
890 JournalFeed journalFeed = fetchByUUID_G(uuid, groupId);
891
892 if (journalFeed == null) {
893 StringBundler msg = new StringBundler(6);
894
895 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
896
897 msg.append("uuid=");
898 msg.append(uuid);
899
900 msg.append(", groupId=");
901 msg.append(groupId);
902
903 msg.append(StringPool.CLOSE_CURLY_BRACE);
904
905 if (_log.isWarnEnabled()) {
906 _log.warn(msg.toString());
907 }
908
909 throw new NoSuchFeedException(msg.toString());
910 }
911
912 return journalFeed;
913 }
914
915
923 public JournalFeed fetchByUUID_G(String uuid, long groupId)
924 throws SystemException {
925 return fetchByUUID_G(uuid, groupId, true);
926 }
927
928
936 public JournalFeed fetchByUUID_G(String uuid, long groupId,
937 boolean retrieveFromCache) throws SystemException {
938 Object[] finderArgs = new Object[] { uuid, groupId };
939
940 Object result = null;
941
942 if (retrieveFromCache) {
943 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
944 finderArgs, this);
945 }
946
947 if (result == null) {
948 Session session = null;
949
950 try {
951 session = openSession();
952
953 StringBundler query = new StringBundler(4);
954
955 query.append(_SQL_SELECT_JOURNALFEED_WHERE);
956
957 if (uuid == null) {
958 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
959 }
960 else {
961 if (uuid.equals(StringPool.BLANK)) {
962 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
963 }
964 else {
965 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
966 }
967 }
968
969 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
970
971 query.append(JournalFeedModelImpl.ORDER_BY_JPQL);
972
973 String sql = query.toString();
974
975 Query q = session.createQuery(sql);
976
977 QueryPos qPos = QueryPos.getInstance(q);
978
979 if (uuid != null) {
980 qPos.add(uuid);
981 }
982
983 qPos.add(groupId);
984
985 List<JournalFeed> list = q.list();
986
987 result = list;
988
989 JournalFeed journalFeed = null;
990
991 if (list.isEmpty()) {
992 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
993 finderArgs, list);
994 }
995 else {
996 journalFeed = list.get(0);
997
998 cacheResult(journalFeed);
999
1000 if ((journalFeed.getUuid() == null) ||
1001 !journalFeed.getUuid().equals(uuid) ||
1002 (journalFeed.getGroupId() != groupId)) {
1003 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1004 finderArgs, journalFeed);
1005 }
1006 }
1007
1008 return journalFeed;
1009 }
1010 catch (Exception e) {
1011 throw processException(e);
1012 }
1013 finally {
1014 if (result == null) {
1015 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1016 finderArgs, new ArrayList<JournalFeed>());
1017 }
1018
1019 closeSession(session);
1020 }
1021 }
1022 else {
1023 if (result instanceof List<?>) {
1024 return null;
1025 }
1026 else {
1027 return (JournalFeed)result;
1028 }
1029 }
1030 }
1031
1032
1039 public List<JournalFeed> findByGroupId(long groupId)
1040 throws SystemException {
1041 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1042 }
1043
1044
1057 public List<JournalFeed> findByGroupId(long groupId, int start, int end)
1058 throws SystemException {
1059 return findByGroupId(groupId, start, end, null);
1060 }
1061
1062
1076 public List<JournalFeed> findByGroupId(long groupId, int start, int end,
1077 OrderByComparator orderByComparator) throws SystemException {
1078 Object[] finderArgs = new Object[] {
1079 groupId,
1080
1081 String.valueOf(start), String.valueOf(end),
1082 String.valueOf(orderByComparator)
1083 };
1084
1085 List<JournalFeed> list = (List<JournalFeed>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
1086 finderArgs, this);
1087
1088 if (list == null) {
1089 Session session = null;
1090
1091 try {
1092 session = openSession();
1093
1094 StringBundler query = null;
1095
1096 if (orderByComparator != null) {
1097 query = new StringBundler(3 +
1098 (orderByComparator.getOrderByFields().length * 3));
1099 }
1100 else {
1101 query = new StringBundler(3);
1102 }
1103
1104 query.append(_SQL_SELECT_JOURNALFEED_WHERE);
1105
1106 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1107
1108 if (orderByComparator != null) {
1109 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1110 orderByComparator);
1111 }
1112
1113 else {
1114 query.append(JournalFeedModelImpl.ORDER_BY_JPQL);
1115 }
1116
1117 String sql = query.toString();
1118
1119 Query q = session.createQuery(sql);
1120
1121 QueryPos qPos = QueryPos.getInstance(q);
1122
1123 qPos.add(groupId);
1124
1125 list = (List<JournalFeed>)QueryUtil.list(q, getDialect(),
1126 start, end);
1127 }
1128 catch (Exception e) {
1129 throw processException(e);
1130 }
1131 finally {
1132 if (list == null) {
1133 list = new ArrayList<JournalFeed>();
1134 }
1135
1136 cacheResult(list);
1137
1138 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
1139 finderArgs, list);
1140
1141 closeSession(session);
1142 }
1143 }
1144
1145 return list;
1146 }
1147
1148
1161 public JournalFeed findByGroupId_First(long groupId,
1162 OrderByComparator orderByComparator)
1163 throws NoSuchFeedException, SystemException {
1164 List<JournalFeed> list = findByGroupId(groupId, 0, 1, orderByComparator);
1165
1166 if (list.isEmpty()) {
1167 StringBundler msg = new StringBundler(4);
1168
1169 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1170
1171 msg.append("groupId=");
1172 msg.append(groupId);
1173
1174 msg.append(StringPool.CLOSE_CURLY_BRACE);
1175
1176 throw new NoSuchFeedException(msg.toString());
1177 }
1178 else {
1179 return list.get(0);
1180 }
1181 }
1182
1183
1196 public JournalFeed findByGroupId_Last(long groupId,
1197 OrderByComparator orderByComparator)
1198 throws NoSuchFeedException, SystemException {
1199 int count = countByGroupId(groupId);
1200
1201 List<JournalFeed> list = findByGroupId(groupId, count - 1, count,
1202 orderByComparator);
1203
1204 if (list.isEmpty()) {
1205 StringBundler msg = new StringBundler(4);
1206
1207 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1208
1209 msg.append("groupId=");
1210 msg.append(groupId);
1211
1212 msg.append(StringPool.CLOSE_CURLY_BRACE);
1213
1214 throw new NoSuchFeedException(msg.toString());
1215 }
1216 else {
1217 return list.get(0);
1218 }
1219 }
1220
1221
1235 public JournalFeed[] findByGroupId_PrevAndNext(long id, long groupId,
1236 OrderByComparator orderByComparator)
1237 throws NoSuchFeedException, SystemException {
1238 JournalFeed journalFeed = findByPrimaryKey(id);
1239
1240 Session session = null;
1241
1242 try {
1243 session = openSession();
1244
1245 JournalFeed[] array = new JournalFeedImpl[3];
1246
1247 array[0] = getByGroupId_PrevAndNext(session, journalFeed, groupId,
1248 orderByComparator, true);
1249
1250 array[1] = journalFeed;
1251
1252 array[2] = getByGroupId_PrevAndNext(session, journalFeed, groupId,
1253 orderByComparator, false);
1254
1255 return array;
1256 }
1257 catch (Exception e) {
1258 throw processException(e);
1259 }
1260 finally {
1261 closeSession(session);
1262 }
1263 }
1264
1265 protected JournalFeed getByGroupId_PrevAndNext(Session session,
1266 JournalFeed journalFeed, long groupId,
1267 OrderByComparator orderByComparator, boolean previous) {
1268 StringBundler query = null;
1269
1270 if (orderByComparator != null) {
1271 query = new StringBundler(6 +
1272 (orderByComparator.getOrderByFields().length * 6));
1273 }
1274 else {
1275 query = new StringBundler(3);
1276 }
1277
1278 query.append(_SQL_SELECT_JOURNALFEED_WHERE);
1279
1280 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1281
1282 if (orderByComparator != null) {
1283 String[] orderByFields = orderByComparator.getOrderByFields();
1284
1285 if (orderByFields.length > 0) {
1286 query.append(WHERE_AND);
1287 }
1288
1289 for (int i = 0; i < orderByFields.length; i++) {
1290 query.append(_ORDER_BY_ENTITY_ALIAS);
1291 query.append(orderByFields[i]);
1292
1293 if ((i + 1) < orderByFields.length) {
1294 if (orderByComparator.isAscending() ^ previous) {
1295 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1296 }
1297 else {
1298 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1299 }
1300 }
1301 else {
1302 if (orderByComparator.isAscending() ^ previous) {
1303 query.append(WHERE_GREATER_THAN);
1304 }
1305 else {
1306 query.append(WHERE_LESSER_THAN);
1307 }
1308 }
1309 }
1310
1311 query.append(ORDER_BY_CLAUSE);
1312
1313 for (int i = 0; i < orderByFields.length; i++) {
1314 query.append(_ORDER_BY_ENTITY_ALIAS);
1315 query.append(orderByFields[i]);
1316
1317 if ((i + 1) < orderByFields.length) {
1318 if (orderByComparator.isAscending() ^ previous) {
1319 query.append(ORDER_BY_ASC_HAS_NEXT);
1320 }
1321 else {
1322 query.append(ORDER_BY_DESC_HAS_NEXT);
1323 }
1324 }
1325 else {
1326 if (orderByComparator.isAscending() ^ previous) {
1327 query.append(ORDER_BY_ASC);
1328 }
1329 else {
1330 query.append(ORDER_BY_DESC);
1331 }
1332 }
1333 }
1334 }
1335
1336 else {
1337 query.append(JournalFeedModelImpl.ORDER_BY_JPQL);
1338 }
1339
1340 String sql = query.toString();
1341
1342 Query q = session.createQuery(sql);
1343
1344 q.setFirstResult(0);
1345 q.setMaxResults(2);
1346
1347 QueryPos qPos = QueryPos.getInstance(q);
1348
1349 qPos.add(groupId);
1350
1351 if (orderByComparator != null) {
1352 Object[] values = orderByComparator.getOrderByValues(journalFeed);
1353
1354 for (Object value : values) {
1355 qPos.add(value);
1356 }
1357 }
1358
1359 List<JournalFeed> list = q.list();
1360
1361 if (list.size() == 2) {
1362 return list.get(1);
1363 }
1364 else {
1365 return null;
1366 }
1367 }
1368
1369
1376 public List<JournalFeed> filterFindByGroupId(long groupId)
1377 throws SystemException {
1378 return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1379 QueryUtil.ALL_POS, null);
1380 }
1381
1382
1395 public List<JournalFeed> filterFindByGroupId(long groupId, int start,
1396 int end) throws SystemException {
1397 return filterFindByGroupId(groupId, start, end, null);
1398 }
1399
1400
1414 public List<JournalFeed> filterFindByGroupId(long groupId, int start,
1415 int end, OrderByComparator orderByComparator) throws SystemException {
1416 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1417 return findByGroupId(groupId, start, end, orderByComparator);
1418 }
1419
1420 Session session = null;
1421
1422 try {
1423 session = openSession();
1424
1425 StringBundler query = null;
1426
1427 if (orderByComparator != null) {
1428 query = new StringBundler(3 +
1429 (orderByComparator.getOrderByFields().length * 3));
1430 }
1431 else {
1432 query = new StringBundler(3);
1433 }
1434
1435 if (getDB().isSupportsInlineDistinct()) {
1436 query.append(_FILTER_SQL_SELECT_JOURNALFEED_WHERE);
1437 }
1438 else {
1439 query.append(_FILTER_SQL_SELECT_JOURNALFEED_NO_INLINE_DISTINCT_WHERE);
1440 }
1441
1442 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1443
1444 if (orderByComparator != null) {
1445 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1446 orderByComparator);
1447 }
1448
1449 else {
1450 query.append(JournalFeedModelImpl.ORDER_BY_JPQL);
1451 }
1452
1453 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1454 JournalFeed.class.getName(), _FILTER_COLUMN_PK,
1455 _FILTER_COLUMN_USERID, groupId);
1456
1457 SQLQuery q = session.createSQLQuery(sql);
1458
1459 q.addEntity(_FILTER_ENTITY_ALIAS, JournalFeedImpl.class);
1460
1461 QueryPos qPos = QueryPos.getInstance(q);
1462
1463 qPos.add(groupId);
1464
1465 return (List<JournalFeed>)QueryUtil.list(q, getDialect(), start, end);
1466 }
1467 catch (Exception e) {
1468 throw processException(e);
1469 }
1470 finally {
1471 closeSession(session);
1472 }
1473 }
1474
1475
1484 public JournalFeed findByG_F(long groupId, String feedId)
1485 throws NoSuchFeedException, SystemException {
1486 JournalFeed journalFeed = fetchByG_F(groupId, feedId);
1487
1488 if (journalFeed == null) {
1489 StringBundler msg = new StringBundler(6);
1490
1491 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1492
1493 msg.append("groupId=");
1494 msg.append(groupId);
1495
1496 msg.append(", feedId=");
1497 msg.append(feedId);
1498
1499 msg.append(StringPool.CLOSE_CURLY_BRACE);
1500
1501 if (_log.isWarnEnabled()) {
1502 _log.warn(msg.toString());
1503 }
1504
1505 throw new NoSuchFeedException(msg.toString());
1506 }
1507
1508 return journalFeed;
1509 }
1510
1511
1519 public JournalFeed fetchByG_F(long groupId, String feedId)
1520 throws SystemException {
1521 return fetchByG_F(groupId, feedId, true);
1522 }
1523
1524
1532 public JournalFeed fetchByG_F(long groupId, String feedId,
1533 boolean retrieveFromCache) throws SystemException {
1534 Object[] finderArgs = new Object[] { groupId, feedId };
1535
1536 Object result = null;
1537
1538 if (retrieveFromCache) {
1539 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_F,
1540 finderArgs, this);
1541 }
1542
1543 if (result == null) {
1544 Session session = null;
1545
1546 try {
1547 session = openSession();
1548
1549 StringBundler query = new StringBundler(4);
1550
1551 query.append(_SQL_SELECT_JOURNALFEED_WHERE);
1552
1553 query.append(_FINDER_COLUMN_G_F_GROUPID_2);
1554
1555 if (feedId == null) {
1556 query.append(_FINDER_COLUMN_G_F_FEEDID_1);
1557 }
1558 else {
1559 if (feedId.equals(StringPool.BLANK)) {
1560 query.append(_FINDER_COLUMN_G_F_FEEDID_3);
1561 }
1562 else {
1563 query.append(_FINDER_COLUMN_G_F_FEEDID_2);
1564 }
1565 }
1566
1567 query.append(JournalFeedModelImpl.ORDER_BY_JPQL);
1568
1569 String sql = query.toString();
1570
1571 Query q = session.createQuery(sql);
1572
1573 QueryPos qPos = QueryPos.getInstance(q);
1574
1575 qPos.add(groupId);
1576
1577 if (feedId != null) {
1578 qPos.add(feedId);
1579 }
1580
1581 List<JournalFeed> list = q.list();
1582
1583 result = list;
1584
1585 JournalFeed journalFeed = null;
1586
1587 if (list.isEmpty()) {
1588 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_F,
1589 finderArgs, list);
1590 }
1591 else {
1592 journalFeed = list.get(0);
1593
1594 cacheResult(journalFeed);
1595
1596 if ((journalFeed.getGroupId() != groupId) ||
1597 (journalFeed.getFeedId() == null) ||
1598 !journalFeed.getFeedId().equals(feedId)) {
1599 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_F,
1600 finderArgs, journalFeed);
1601 }
1602 }
1603
1604 return journalFeed;
1605 }
1606 catch (Exception e) {
1607 throw processException(e);
1608 }
1609 finally {
1610 if (result == null) {
1611 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_F,
1612 finderArgs, new ArrayList<JournalFeed>());
1613 }
1614
1615 closeSession(session);
1616 }
1617 }
1618 else {
1619 if (result instanceof List<?>) {
1620 return null;
1621 }
1622 else {
1623 return (JournalFeed)result;
1624 }
1625 }
1626 }
1627
1628
1634 public List<JournalFeed> findAll() throws SystemException {
1635 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1636 }
1637
1638
1650 public List<JournalFeed> findAll(int start, int end)
1651 throws SystemException {
1652 return findAll(start, end, null);
1653 }
1654
1655
1668 public List<JournalFeed> findAll(int start, int end,
1669 OrderByComparator orderByComparator) throws SystemException {
1670 Object[] finderArgs = new Object[] {
1671 String.valueOf(start), String.valueOf(end),
1672 String.valueOf(orderByComparator)
1673 };
1674
1675 List<JournalFeed> list = (List<JournalFeed>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1676 finderArgs, this);
1677
1678 if (list == null) {
1679 Session session = null;
1680
1681 try {
1682 session = openSession();
1683
1684 StringBundler query = null;
1685 String sql = null;
1686
1687 if (orderByComparator != null) {
1688 query = new StringBundler(2 +
1689 (orderByComparator.getOrderByFields().length * 3));
1690
1691 query.append(_SQL_SELECT_JOURNALFEED);
1692
1693 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1694 orderByComparator);
1695
1696 sql = query.toString();
1697 }
1698 else {
1699 sql = _SQL_SELECT_JOURNALFEED.concat(JournalFeedModelImpl.ORDER_BY_JPQL);
1700 }
1701
1702 Query q = session.createQuery(sql);
1703
1704 if (orderByComparator == null) {
1705 list = (List<JournalFeed>)QueryUtil.list(q, getDialect(),
1706 start, end, false);
1707
1708 Collections.sort(list);
1709 }
1710 else {
1711 list = (List<JournalFeed>)QueryUtil.list(q, getDialect(),
1712 start, end);
1713 }
1714 }
1715 catch (Exception e) {
1716 throw processException(e);
1717 }
1718 finally {
1719 if (list == null) {
1720 list = new ArrayList<JournalFeed>();
1721 }
1722
1723 cacheResult(list);
1724
1725 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1726
1727 closeSession(session);
1728 }
1729 }
1730
1731 return list;
1732 }
1733
1734
1740 public void removeByUuid(String uuid) throws SystemException {
1741 for (JournalFeed journalFeed : findByUuid(uuid)) {
1742 remove(journalFeed);
1743 }
1744 }
1745
1746
1753 public void removeByUUID_G(String uuid, long groupId)
1754 throws NoSuchFeedException, SystemException {
1755 JournalFeed journalFeed = findByUUID_G(uuid, groupId);
1756
1757 remove(journalFeed);
1758 }
1759
1760
1766 public void removeByGroupId(long groupId) throws SystemException {
1767 for (JournalFeed journalFeed : findByGroupId(groupId)) {
1768 remove(journalFeed);
1769 }
1770 }
1771
1772
1779 public void removeByG_F(long groupId, String feedId)
1780 throws NoSuchFeedException, SystemException {
1781 JournalFeed journalFeed = findByG_F(groupId, feedId);
1782
1783 remove(journalFeed);
1784 }
1785
1786
1791 public void removeAll() throws SystemException {
1792 for (JournalFeed journalFeed : findAll()) {
1793 remove(journalFeed);
1794 }
1795 }
1796
1797
1804 public int countByUuid(String uuid) throws SystemException {
1805 Object[] finderArgs = new Object[] { uuid };
1806
1807 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1808 finderArgs, this);
1809
1810 if (count == null) {
1811 Session session = null;
1812
1813 try {
1814 session = openSession();
1815
1816 StringBundler query = new StringBundler(2);
1817
1818 query.append(_SQL_COUNT_JOURNALFEED_WHERE);
1819
1820 if (uuid == null) {
1821 query.append(_FINDER_COLUMN_UUID_UUID_1);
1822 }
1823 else {
1824 if (uuid.equals(StringPool.BLANK)) {
1825 query.append(_FINDER_COLUMN_UUID_UUID_3);
1826 }
1827 else {
1828 query.append(_FINDER_COLUMN_UUID_UUID_2);
1829 }
1830 }
1831
1832 String sql = query.toString();
1833
1834 Query q = session.createQuery(sql);
1835
1836 QueryPos qPos = QueryPos.getInstance(q);
1837
1838 if (uuid != null) {
1839 qPos.add(uuid);
1840 }
1841
1842 count = (Long)q.uniqueResult();
1843 }
1844 catch (Exception e) {
1845 throw processException(e);
1846 }
1847 finally {
1848 if (count == null) {
1849 count = Long.valueOf(0);
1850 }
1851
1852 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
1853 finderArgs, count);
1854
1855 closeSession(session);
1856 }
1857 }
1858
1859 return count.intValue();
1860 }
1861
1862
1870 public int countByUUID_G(String uuid, long groupId)
1871 throws SystemException {
1872 Object[] finderArgs = new Object[] { uuid, groupId };
1873
1874 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
1875 finderArgs, this);
1876
1877 if (count == null) {
1878 Session session = null;
1879
1880 try {
1881 session = openSession();
1882
1883 StringBundler query = new StringBundler(3);
1884
1885 query.append(_SQL_COUNT_JOURNALFEED_WHERE);
1886
1887 if (uuid == null) {
1888 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1889 }
1890 else {
1891 if (uuid.equals(StringPool.BLANK)) {
1892 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1893 }
1894 else {
1895 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1896 }
1897 }
1898
1899 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1900
1901 String sql = query.toString();
1902
1903 Query q = session.createQuery(sql);
1904
1905 QueryPos qPos = QueryPos.getInstance(q);
1906
1907 if (uuid != null) {
1908 qPos.add(uuid);
1909 }
1910
1911 qPos.add(groupId);
1912
1913 count = (Long)q.uniqueResult();
1914 }
1915 catch (Exception e) {
1916 throw processException(e);
1917 }
1918 finally {
1919 if (count == null) {
1920 count = Long.valueOf(0);
1921 }
1922
1923 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
1924 finderArgs, count);
1925
1926 closeSession(session);
1927 }
1928 }
1929
1930 return count.intValue();
1931 }
1932
1933
1940 public int countByGroupId(long groupId) throws SystemException {
1941 Object[] finderArgs = new Object[] { groupId };
1942
1943 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1944 finderArgs, this);
1945
1946 if (count == null) {
1947 Session session = null;
1948
1949 try {
1950 session = openSession();
1951
1952 StringBundler query = new StringBundler(2);
1953
1954 query.append(_SQL_COUNT_JOURNALFEED_WHERE);
1955
1956 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1957
1958 String sql = query.toString();
1959
1960 Query q = session.createQuery(sql);
1961
1962 QueryPos qPos = QueryPos.getInstance(q);
1963
1964 qPos.add(groupId);
1965
1966 count = (Long)q.uniqueResult();
1967 }
1968 catch (Exception e) {
1969 throw processException(e);
1970 }
1971 finally {
1972 if (count == null) {
1973 count = Long.valueOf(0);
1974 }
1975
1976 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1977 finderArgs, count);
1978
1979 closeSession(session);
1980 }
1981 }
1982
1983 return count.intValue();
1984 }
1985
1986
1993 public int filterCountByGroupId(long groupId) throws SystemException {
1994 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1995 return countByGroupId(groupId);
1996 }
1997
1998 Session session = null;
1999
2000 try {
2001 session = openSession();
2002
2003 StringBundler query = new StringBundler(2);
2004
2005 query.append(_FILTER_SQL_COUNT_JOURNALFEED_WHERE);
2006
2007 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2008
2009 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2010 JournalFeed.class.getName(), _FILTER_COLUMN_PK,
2011 _FILTER_COLUMN_USERID, groupId);
2012
2013 SQLQuery q = session.createSQLQuery(sql);
2014
2015 q.addScalar(COUNT_COLUMN_NAME,
2016 com.liferay.portal.kernel.dao.orm.Type.LONG);
2017
2018 QueryPos qPos = QueryPos.getInstance(q);
2019
2020 qPos.add(groupId);
2021
2022 Long count = (Long)q.uniqueResult();
2023
2024 return count.intValue();
2025 }
2026 catch (Exception e) {
2027 throw processException(e);
2028 }
2029 finally {
2030 closeSession(session);
2031 }
2032 }
2033
2034
2042 public int countByG_F(long groupId, String feedId)
2043 throws SystemException {
2044 Object[] finderArgs = new Object[] { groupId, feedId };
2045
2046 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_F,
2047 finderArgs, this);
2048
2049 if (count == null) {
2050 Session session = null;
2051
2052 try {
2053 session = openSession();
2054
2055 StringBundler query = new StringBundler(3);
2056
2057 query.append(_SQL_COUNT_JOURNALFEED_WHERE);
2058
2059 query.append(_FINDER_COLUMN_G_F_GROUPID_2);
2060
2061 if (feedId == null) {
2062 query.append(_FINDER_COLUMN_G_F_FEEDID_1);
2063 }
2064 else {
2065 if (feedId.equals(StringPool.BLANK)) {
2066 query.append(_FINDER_COLUMN_G_F_FEEDID_3);
2067 }
2068 else {
2069 query.append(_FINDER_COLUMN_G_F_FEEDID_2);
2070 }
2071 }
2072
2073 String sql = query.toString();
2074
2075 Query q = session.createQuery(sql);
2076
2077 QueryPos qPos = QueryPos.getInstance(q);
2078
2079 qPos.add(groupId);
2080
2081 if (feedId != null) {
2082 qPos.add(feedId);
2083 }
2084
2085 count = (Long)q.uniqueResult();
2086 }
2087 catch (Exception e) {
2088 throw processException(e);
2089 }
2090 finally {
2091 if (count == null) {
2092 count = Long.valueOf(0);
2093 }
2094
2095 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_F, finderArgs,
2096 count);
2097
2098 closeSession(session);
2099 }
2100 }
2101
2102 return count.intValue();
2103 }
2104
2105
2113 public int filterCountByG_F(long groupId, String feedId)
2114 throws SystemException {
2115 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2116 return countByG_F(groupId, feedId);
2117 }
2118
2119 Session session = null;
2120
2121 try {
2122 session = openSession();
2123
2124 StringBundler query = new StringBundler(3);
2125
2126 query.append(_FILTER_SQL_COUNT_JOURNALFEED_WHERE);
2127
2128 query.append(_FINDER_COLUMN_G_F_GROUPID_2);
2129
2130 if (feedId == null) {
2131 query.append(_FINDER_COLUMN_G_F_FEEDID_1);
2132 }
2133 else {
2134 if (feedId.equals(StringPool.BLANK)) {
2135 query.append(_FINDER_COLUMN_G_F_FEEDID_3);
2136 }
2137 else {
2138 query.append(_FINDER_COLUMN_G_F_FEEDID_2);
2139 }
2140 }
2141
2142 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2143 JournalFeed.class.getName(), _FILTER_COLUMN_PK,
2144 _FILTER_COLUMN_USERID, groupId);
2145
2146 SQLQuery q = session.createSQLQuery(sql);
2147
2148 q.addScalar(COUNT_COLUMN_NAME,
2149 com.liferay.portal.kernel.dao.orm.Type.LONG);
2150
2151 QueryPos qPos = QueryPos.getInstance(q);
2152
2153 qPos.add(groupId);
2154
2155 if (feedId != null) {
2156 qPos.add(feedId);
2157 }
2158
2159 Long count = (Long)q.uniqueResult();
2160
2161 return count.intValue();
2162 }
2163 catch (Exception e) {
2164 throw processException(e);
2165 }
2166 finally {
2167 closeSession(session);
2168 }
2169 }
2170
2171
2177 public int countAll() throws SystemException {
2178 Object[] finderArgs = new Object[0];
2179
2180 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2181 finderArgs, this);
2182
2183 if (count == null) {
2184 Session session = null;
2185
2186 try {
2187 session = openSession();
2188
2189 Query q = session.createQuery(_SQL_COUNT_JOURNALFEED);
2190
2191 count = (Long)q.uniqueResult();
2192 }
2193 catch (Exception e) {
2194 throw processException(e);
2195 }
2196 finally {
2197 if (count == null) {
2198 count = Long.valueOf(0);
2199 }
2200
2201 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
2202 count);
2203
2204 closeSession(session);
2205 }
2206 }
2207
2208 return count.intValue();
2209 }
2210
2211
2214 public void afterPropertiesSet() {
2215 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2216 com.liferay.portal.util.PropsUtil.get(
2217 "value.object.listener.com.liferay.portlet.journal.model.JournalFeed")));
2218
2219 if (listenerClassNames.length > 0) {
2220 try {
2221 List<ModelListener<JournalFeed>> listenersList = new ArrayList<ModelListener<JournalFeed>>();
2222
2223 for (String listenerClassName : listenerClassNames) {
2224 listenersList.add((ModelListener<JournalFeed>)InstanceFactory.newInstance(
2225 listenerClassName));
2226 }
2227
2228 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2229 }
2230 catch (Exception e) {
2231 _log.error(e);
2232 }
2233 }
2234 }
2235
2236 public void destroy() {
2237 EntityCacheUtil.removeCache(JournalFeedImpl.class.getName());
2238 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2239 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
2240 }
2241
2242 @BeanReference(type = JournalArticlePersistence.class)
2243 protected JournalArticlePersistence journalArticlePersistence;
2244 @BeanReference(type = JournalArticleImagePersistence.class)
2245 protected JournalArticleImagePersistence journalArticleImagePersistence;
2246 @BeanReference(type = JournalArticleResourcePersistence.class)
2247 protected JournalArticleResourcePersistence journalArticleResourcePersistence;
2248 @BeanReference(type = JournalContentSearchPersistence.class)
2249 protected JournalContentSearchPersistence journalContentSearchPersistence;
2250 @BeanReference(type = JournalFeedPersistence.class)
2251 protected JournalFeedPersistence journalFeedPersistence;
2252 @BeanReference(type = JournalStructurePersistence.class)
2253 protected JournalStructurePersistence journalStructurePersistence;
2254 @BeanReference(type = JournalTemplatePersistence.class)
2255 protected JournalTemplatePersistence journalTemplatePersistence;
2256 @BeanReference(type = ResourcePersistence.class)
2257 protected ResourcePersistence resourcePersistence;
2258 @BeanReference(type = UserPersistence.class)
2259 protected UserPersistence userPersistence;
2260 @BeanReference(type = ExpandoValuePersistence.class)
2261 protected ExpandoValuePersistence expandoValuePersistence;
2262 private static final String _SQL_SELECT_JOURNALFEED = "SELECT journalFeed FROM JournalFeed journalFeed";
2263 private static final String _SQL_SELECT_JOURNALFEED_WHERE = "SELECT journalFeed FROM JournalFeed journalFeed WHERE ";
2264 private static final String _SQL_COUNT_JOURNALFEED = "SELECT COUNT(journalFeed) FROM JournalFeed journalFeed";
2265 private static final String _SQL_COUNT_JOURNALFEED_WHERE = "SELECT COUNT(journalFeed) FROM JournalFeed journalFeed WHERE ";
2266 private static final String _FINDER_COLUMN_UUID_UUID_1 = "journalFeed.uuid IS NULL";
2267 private static final String _FINDER_COLUMN_UUID_UUID_2 = "journalFeed.uuid = ?";
2268 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(journalFeed.uuid IS NULL OR journalFeed.uuid = ?)";
2269 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "journalFeed.uuid IS NULL AND ";
2270 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "journalFeed.uuid = ? AND ";
2271 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(journalFeed.uuid IS NULL OR journalFeed.uuid = ?) AND ";
2272 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "journalFeed.groupId = ?";
2273 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "journalFeed.groupId = ?";
2274 private static final String _FINDER_COLUMN_G_F_GROUPID_2 = "journalFeed.groupId = ? AND ";
2275 private static final String _FINDER_COLUMN_G_F_FEEDID_1 = "journalFeed.feedId IS NULL";
2276 private static final String _FINDER_COLUMN_G_F_FEEDID_2 = "journalFeed.feedId = ?";
2277 private static final String _FINDER_COLUMN_G_F_FEEDID_3 = "(journalFeed.feedId IS NULL OR journalFeed.feedId = ?)";
2278 private static final String _FILTER_SQL_SELECT_JOURNALFEED_WHERE = "SELECT DISTINCT {journalFeed.*} FROM JournalFeed journalFeed WHERE ";
2279 private static final String _FILTER_SQL_SELECT_JOURNALFEED_NO_INLINE_DISTINCT_WHERE =
2280 "SELECT {journalFeed.*} FROM (SELECT DISTINCT id FROM JournalFeed) journalFeed2 INNER JOIN JournalFeed journalFeed ON (journalFeed2.id = journalFeed.id) WHERE ";
2281 private static final String _FILTER_SQL_COUNT_JOURNALFEED_WHERE = "SELECT COUNT(DISTINCT journalFeed.id) AS COUNT_VALUE FROM JournalFeed journalFeed WHERE ";
2282 private static final String _FILTER_COLUMN_PK = "journalFeed.id";
2283 private static final String _FILTER_COLUMN_USERID = "journalFeed.userId";
2284 private static final String _FILTER_ENTITY_ALIAS = "journalFeed";
2285 private static final String _ORDER_BY_ENTITY_ALIAS = "journalFeed.";
2286 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No JournalFeed exists with the primary key ";
2287 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No JournalFeed exists with the key {";
2288 private static Log _log = LogFactoryUtil.getLog(JournalFeedPersistenceImpl.class);
2289 }