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
064 public class JournalFeedPersistenceImpl extends BasePersistenceImpl<JournalFeed>
065 implements JournalFeedPersistence {
066 public static final String FINDER_CLASS_NAME_ENTITY = JournalFeedImpl.class.getName();
067 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
068 ".List";
069 public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
070 JournalFeedModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
071 "findByUuid",
072 new String[] {
073 String.class.getName(),
074
075 "java.lang.Integer", "java.lang.Integer",
076 "com.liferay.portal.kernel.util.OrderByComparator"
077 });
078 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
079 JournalFeedModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
080 "countByUuid", new String[] { String.class.getName() });
081 public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
082 JournalFeedModelImpl.FINDER_CACHE_ENABLED,
083 FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
084 new String[] { String.class.getName(), Long.class.getName() });
085 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
086 JournalFeedModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
087 "countByUUID_G",
088 new String[] { String.class.getName(), Long.class.getName() });
089 public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
090 JournalFeedModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
091 "findByGroupId",
092 new String[] {
093 Long.class.getName(),
094
095 "java.lang.Integer", "java.lang.Integer",
096 "com.liferay.portal.kernel.util.OrderByComparator"
097 });
098 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
099 JournalFeedModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
100 "countByGroupId", new String[] { Long.class.getName() });
101 public static final FinderPath FINDER_PATH_FETCH_BY_G_F = new FinderPath(JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
102 JournalFeedModelImpl.FINDER_CACHE_ENABLED,
103 FINDER_CLASS_NAME_ENTITY, "fetchByG_F",
104 new String[] { Long.class.getName(), String.class.getName() });
105 public static final FinderPath FINDER_PATH_COUNT_BY_G_F = new FinderPath(JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
106 JournalFeedModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
107 "countByG_F",
108 new String[] { Long.class.getName(), String.class.getName() });
109 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
110 JournalFeedModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
111 "findAll", new String[0]);
112 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
113 JournalFeedModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
114 "countAll", new String[0]);
115
116 public void cacheResult(JournalFeed journalFeed) {
117 EntityCacheUtil.putResult(JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
118 JournalFeedImpl.class, journalFeed.getPrimaryKey(), journalFeed);
119
120 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
121 new Object[] {
122 journalFeed.getUuid(), new Long(journalFeed.getGroupId())
123 }, journalFeed);
124
125 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_F,
126 new Object[] {
127 new Long(journalFeed.getGroupId()),
128
129 journalFeed.getFeedId()
130 }, journalFeed);
131 }
132
133 public void cacheResult(List<JournalFeed> journalFeeds) {
134 for (JournalFeed journalFeed : journalFeeds) {
135 if (EntityCacheUtil.getResult(
136 JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
137 JournalFeedImpl.class, journalFeed.getPrimaryKey(), this) == null) {
138 cacheResult(journalFeed);
139 }
140 }
141 }
142
143 public void clearCache() {
144 CacheRegistryUtil.clear(JournalFeedImpl.class.getName());
145 EntityCacheUtil.clearCache(JournalFeedImpl.class.getName());
146 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
147 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
148 }
149
150 public void clearCache(JournalFeed journalFeed) {
151 EntityCacheUtil.removeResult(JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
152 JournalFeedImpl.class, journalFeed.getPrimaryKey());
153
154 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
155 new Object[] {
156 journalFeed.getUuid(), new Long(journalFeed.getGroupId())
157 });
158
159 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_F,
160 new Object[] {
161 new Long(journalFeed.getGroupId()),
162
163 journalFeed.getFeedId()
164 });
165 }
166
167 public JournalFeed create(long id) {
168 JournalFeed journalFeed = new JournalFeedImpl();
169
170 journalFeed.setNew(true);
171 journalFeed.setPrimaryKey(id);
172
173 String uuid = PortalUUIDUtil.generate();
174
175 journalFeed.setUuid(uuid);
176
177 return journalFeed;
178 }
179
180 public JournalFeed remove(Serializable primaryKey)
181 throws NoSuchModelException, SystemException {
182 return remove(((Long)primaryKey).longValue());
183 }
184
185 public JournalFeed remove(long id)
186 throws NoSuchFeedException, SystemException {
187 Session session = null;
188
189 try {
190 session = openSession();
191
192 JournalFeed journalFeed = (JournalFeed)session.get(JournalFeedImpl.class,
193 new Long(id));
194
195 if (journalFeed == null) {
196 if (_log.isWarnEnabled()) {
197 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + id);
198 }
199
200 throw new NoSuchFeedException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
201 id);
202 }
203
204 return remove(journalFeed);
205 }
206 catch (NoSuchFeedException nsee) {
207 throw nsee;
208 }
209 catch (Exception e) {
210 throw processException(e);
211 }
212 finally {
213 closeSession(session);
214 }
215 }
216
217 protected JournalFeed removeImpl(JournalFeed journalFeed)
218 throws SystemException {
219 journalFeed = toUnwrappedModel(journalFeed);
220
221 Session session = null;
222
223 try {
224 session = openSession();
225
226 if (journalFeed.isCachedModel() || BatchSessionUtil.isEnabled()) {
227 Object staleObject = session.get(JournalFeedImpl.class,
228 journalFeed.getPrimaryKeyObj());
229
230 if (staleObject != null) {
231 session.evict(staleObject);
232 }
233 }
234
235 session.delete(journalFeed);
236
237 session.flush();
238 }
239 catch (Exception e) {
240 throw processException(e);
241 }
242 finally {
243 closeSession(session);
244 }
245
246 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
247
248 JournalFeedModelImpl journalFeedModelImpl = (JournalFeedModelImpl)journalFeed;
249
250 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
251 new Object[] {
252 journalFeedModelImpl.getOriginalUuid(),
253 new Long(journalFeedModelImpl.getOriginalGroupId())
254 });
255
256 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_F,
257 new Object[] {
258 new Long(journalFeedModelImpl.getOriginalGroupId()),
259
260 journalFeedModelImpl.getOriginalFeedId()
261 });
262
263 EntityCacheUtil.removeResult(JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
264 JournalFeedImpl.class, journalFeed.getPrimaryKey());
265
266 return journalFeed;
267 }
268
269 public JournalFeed updateImpl(
270 com.liferay.portlet.journal.model.JournalFeed journalFeed, boolean merge)
271 throws SystemException {
272 journalFeed = toUnwrappedModel(journalFeed);
273
274 boolean isNew = journalFeed.isNew();
275
276 JournalFeedModelImpl journalFeedModelImpl = (JournalFeedModelImpl)journalFeed;
277
278 if (Validator.isNull(journalFeed.getUuid())) {
279 String uuid = PortalUUIDUtil.generate();
280
281 journalFeed.setUuid(uuid);
282 }
283
284 Session session = null;
285
286 try {
287 session = openSession();
288
289 BatchSessionUtil.update(session, journalFeed, merge);
290
291 journalFeed.setNew(false);
292 }
293 catch (Exception e) {
294 throw processException(e);
295 }
296 finally {
297 closeSession(session);
298 }
299
300 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
301
302 EntityCacheUtil.putResult(JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
303 JournalFeedImpl.class, journalFeed.getPrimaryKey(), journalFeed);
304
305 if (!isNew &&
306 (!Validator.equals(journalFeed.getUuid(),
307 journalFeedModelImpl.getOriginalUuid()) ||
308 (journalFeed.getGroupId() != journalFeedModelImpl.getOriginalGroupId()))) {
309 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
310 new Object[] {
311 journalFeedModelImpl.getOriginalUuid(),
312 new Long(journalFeedModelImpl.getOriginalGroupId())
313 });
314 }
315
316 if (isNew ||
317 (!Validator.equals(journalFeed.getUuid(),
318 journalFeedModelImpl.getOriginalUuid()) ||
319 (journalFeed.getGroupId() != journalFeedModelImpl.getOriginalGroupId()))) {
320 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
321 new Object[] {
322 journalFeed.getUuid(), new Long(journalFeed.getGroupId())
323 }, journalFeed);
324 }
325
326 if (!isNew &&
327 ((journalFeed.getGroupId() != journalFeedModelImpl.getOriginalGroupId()) ||
328 !Validator.equals(journalFeed.getFeedId(),
329 journalFeedModelImpl.getOriginalFeedId()))) {
330 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_F,
331 new Object[] {
332 new Long(journalFeedModelImpl.getOriginalGroupId()),
333
334 journalFeedModelImpl.getOriginalFeedId()
335 });
336 }
337
338 if (isNew ||
339 ((journalFeed.getGroupId() != journalFeedModelImpl.getOriginalGroupId()) ||
340 !Validator.equals(journalFeed.getFeedId(),
341 journalFeedModelImpl.getOriginalFeedId()))) {
342 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_F,
343 new Object[] {
344 new Long(journalFeed.getGroupId()),
345
346 journalFeed.getFeedId()
347 }, journalFeed);
348 }
349
350 return journalFeed;
351 }
352
353 protected JournalFeed toUnwrappedModel(JournalFeed journalFeed) {
354 if (journalFeed instanceof JournalFeedImpl) {
355 return journalFeed;
356 }
357
358 JournalFeedImpl journalFeedImpl = new JournalFeedImpl();
359
360 journalFeedImpl.setNew(journalFeed.isNew());
361 journalFeedImpl.setPrimaryKey(journalFeed.getPrimaryKey());
362
363 journalFeedImpl.setUuid(journalFeed.getUuid());
364 journalFeedImpl.setId(journalFeed.getId());
365 journalFeedImpl.setGroupId(journalFeed.getGroupId());
366 journalFeedImpl.setCompanyId(journalFeed.getCompanyId());
367 journalFeedImpl.setUserId(journalFeed.getUserId());
368 journalFeedImpl.setUserName(journalFeed.getUserName());
369 journalFeedImpl.setCreateDate(journalFeed.getCreateDate());
370 journalFeedImpl.setModifiedDate(journalFeed.getModifiedDate());
371 journalFeedImpl.setFeedId(journalFeed.getFeedId());
372 journalFeedImpl.setName(journalFeed.getName());
373 journalFeedImpl.setDescription(journalFeed.getDescription());
374 journalFeedImpl.setType(journalFeed.getType());
375 journalFeedImpl.setStructureId(journalFeed.getStructureId());
376 journalFeedImpl.setTemplateId(journalFeed.getTemplateId());
377 journalFeedImpl.setRendererTemplateId(journalFeed.getRendererTemplateId());
378 journalFeedImpl.setDelta(journalFeed.getDelta());
379 journalFeedImpl.setOrderByCol(journalFeed.getOrderByCol());
380 journalFeedImpl.setOrderByType(journalFeed.getOrderByType());
381 journalFeedImpl.setTargetLayoutFriendlyUrl(journalFeed.getTargetLayoutFriendlyUrl());
382 journalFeedImpl.setTargetPortletId(journalFeed.getTargetPortletId());
383 journalFeedImpl.setContentField(journalFeed.getContentField());
384 journalFeedImpl.setFeedType(journalFeed.getFeedType());
385 journalFeedImpl.setFeedVersion(journalFeed.getFeedVersion());
386
387 return journalFeedImpl;
388 }
389
390 public JournalFeed findByPrimaryKey(Serializable primaryKey)
391 throws NoSuchModelException, SystemException {
392 return findByPrimaryKey(((Long)primaryKey).longValue());
393 }
394
395 public JournalFeed findByPrimaryKey(long id)
396 throws NoSuchFeedException, SystemException {
397 JournalFeed journalFeed = fetchByPrimaryKey(id);
398
399 if (journalFeed == null) {
400 if (_log.isWarnEnabled()) {
401 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + id);
402 }
403
404 throw new NoSuchFeedException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
405 id);
406 }
407
408 return journalFeed;
409 }
410
411 public JournalFeed fetchByPrimaryKey(Serializable primaryKey)
412 throws SystemException {
413 return fetchByPrimaryKey(((Long)primaryKey).longValue());
414 }
415
416 public JournalFeed fetchByPrimaryKey(long id) throws SystemException {
417 JournalFeed journalFeed = (JournalFeed)EntityCacheUtil.getResult(JournalFeedModelImpl.ENTITY_CACHE_ENABLED,
418 JournalFeedImpl.class, id, this);
419
420 if (journalFeed == null) {
421 Session session = null;
422
423 try {
424 session = openSession();
425
426 journalFeed = (JournalFeed)session.get(JournalFeedImpl.class,
427 new Long(id));
428 }
429 catch (Exception e) {
430 throw processException(e);
431 }
432 finally {
433 if (journalFeed != null) {
434 cacheResult(journalFeed);
435 }
436
437 closeSession(session);
438 }
439 }
440
441 return journalFeed;
442 }
443
444 public List<JournalFeed> findByUuid(String uuid) throws SystemException {
445 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
446 }
447
448 public List<JournalFeed> findByUuid(String uuid, int start, int end)
449 throws SystemException {
450 return findByUuid(uuid, start, end, null);
451 }
452
453 public List<JournalFeed> findByUuid(String uuid, int start, int end,
454 OrderByComparator orderByComparator) throws SystemException {
455 Object[] finderArgs = new Object[] {
456 uuid,
457
458 String.valueOf(start), String.valueOf(end),
459 String.valueOf(orderByComparator)
460 };
461
462 List<JournalFeed> list = (List<JournalFeed>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
463 finderArgs, this);
464
465 if (list == null) {
466 Session session = null;
467
468 try {
469 session = openSession();
470
471 StringBundler query = null;
472
473 if (orderByComparator != null) {
474 query = new StringBundler(3 +
475 (orderByComparator.getOrderByFields().length * 3));
476 }
477 else {
478 query = new StringBundler(3);
479 }
480
481 query.append(_SQL_SELECT_JOURNALFEED_WHERE);
482
483 if (uuid == null) {
484 query.append(_FINDER_COLUMN_UUID_UUID_1);
485 }
486 else {
487 if (uuid.equals(StringPool.BLANK)) {
488 query.append(_FINDER_COLUMN_UUID_UUID_3);
489 }
490 else {
491 query.append(_FINDER_COLUMN_UUID_UUID_2);
492 }
493 }
494
495 if (orderByComparator != null) {
496 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
497 orderByComparator);
498 }
499
500 else {
501 query.append(JournalFeedModelImpl.ORDER_BY_JPQL);
502 }
503
504 String sql = query.toString();
505
506 Query q = session.createQuery(sql);
507
508 QueryPos qPos = QueryPos.getInstance(q);
509
510 if (uuid != null) {
511 qPos.add(uuid);
512 }
513
514 list = (List<JournalFeed>)QueryUtil.list(q, getDialect(),
515 start, end);
516 }
517 catch (Exception e) {
518 throw processException(e);
519 }
520 finally {
521 if (list == null) {
522 list = new ArrayList<JournalFeed>();
523 }
524
525 cacheResult(list);
526
527 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
528 list);
529
530 closeSession(session);
531 }
532 }
533
534 return list;
535 }
536
537 public JournalFeed findByUuid_First(String uuid,
538 OrderByComparator orderByComparator)
539 throws NoSuchFeedException, SystemException {
540 List<JournalFeed> list = findByUuid(uuid, 0, 1, orderByComparator);
541
542 if (list.isEmpty()) {
543 StringBundler msg = new StringBundler(4);
544
545 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
546
547 msg.append("uuid=");
548 msg.append(uuid);
549
550 msg.append(StringPool.CLOSE_CURLY_BRACE);
551
552 throw new NoSuchFeedException(msg.toString());
553 }
554 else {
555 return list.get(0);
556 }
557 }
558
559 public JournalFeed findByUuid_Last(String uuid,
560 OrderByComparator orderByComparator)
561 throws NoSuchFeedException, SystemException {
562 int count = countByUuid(uuid);
563
564 List<JournalFeed> list = findByUuid(uuid, count - 1, count,
565 orderByComparator);
566
567 if (list.isEmpty()) {
568 StringBundler msg = new StringBundler(4);
569
570 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
571
572 msg.append("uuid=");
573 msg.append(uuid);
574
575 msg.append(StringPool.CLOSE_CURLY_BRACE);
576
577 throw new NoSuchFeedException(msg.toString());
578 }
579 else {
580 return list.get(0);
581 }
582 }
583
584 public JournalFeed[] findByUuid_PrevAndNext(long id, String uuid,
585 OrderByComparator orderByComparator)
586 throws NoSuchFeedException, SystemException {
587 JournalFeed journalFeed = findByPrimaryKey(id);
588
589 Session session = null;
590
591 try {
592 session = openSession();
593
594 JournalFeed[] array = new JournalFeedImpl[3];
595
596 array[0] = getByUuid_PrevAndNext(session, journalFeed, uuid,
597 orderByComparator, true);
598
599 array[1] = journalFeed;
600
601 array[2] = getByUuid_PrevAndNext(session, journalFeed, uuid,
602 orderByComparator, false);
603
604 return array;
605 }
606 catch (Exception e) {
607 throw processException(e);
608 }
609 finally {
610 closeSession(session);
611 }
612 }
613
614 protected JournalFeed getByUuid_PrevAndNext(Session session,
615 JournalFeed journalFeed, String uuid,
616 OrderByComparator orderByComparator, boolean previous) {
617 StringBundler query = null;
618
619 if (orderByComparator != null) {
620 query = new StringBundler(6 +
621 (orderByComparator.getOrderByFields().length * 6));
622 }
623 else {
624 query = new StringBundler(3);
625 }
626
627 query.append(_SQL_SELECT_JOURNALFEED_WHERE);
628
629 if (uuid == null) {
630 query.append(_FINDER_COLUMN_UUID_UUID_1);
631 }
632 else {
633 if (uuid.equals(StringPool.BLANK)) {
634 query.append(_FINDER_COLUMN_UUID_UUID_3);
635 }
636 else {
637 query.append(_FINDER_COLUMN_UUID_UUID_2);
638 }
639 }
640
641 if (orderByComparator != null) {
642 String[] orderByFields = orderByComparator.getOrderByFields();
643
644 if (orderByFields.length > 0) {
645 query.append(WHERE_AND);
646 }
647
648 for (int i = 0; i < orderByFields.length; i++) {
649 query.append(_ORDER_BY_ENTITY_ALIAS);
650 query.append(orderByFields[i]);
651
652 if ((i + 1) < orderByFields.length) {
653 if (orderByComparator.isAscending() ^ previous) {
654 query.append(WHERE_GREATER_THAN_HAS_NEXT);
655 }
656 else {
657 query.append(WHERE_LESSER_THAN_HAS_NEXT);
658 }
659 }
660 else {
661 if (orderByComparator.isAscending() ^ previous) {
662 query.append(WHERE_GREATER_THAN);
663 }
664 else {
665 query.append(WHERE_LESSER_THAN);
666 }
667 }
668 }
669
670 query.append(ORDER_BY_CLAUSE);
671
672 for (int i = 0; i < orderByFields.length; i++) {
673 query.append(_ORDER_BY_ENTITY_ALIAS);
674 query.append(orderByFields[i]);
675
676 if ((i + 1) < orderByFields.length) {
677 if (orderByComparator.isAscending() ^ previous) {
678 query.append(ORDER_BY_ASC_HAS_NEXT);
679 }
680 else {
681 query.append(ORDER_BY_DESC_HAS_NEXT);
682 }
683 }
684 else {
685 if (orderByComparator.isAscending() ^ previous) {
686 query.append(ORDER_BY_ASC);
687 }
688 else {
689 query.append(ORDER_BY_DESC);
690 }
691 }
692 }
693 }
694
695 else {
696 query.append(JournalFeedModelImpl.ORDER_BY_JPQL);
697 }
698
699 String sql = query.toString();
700
701 Query q = session.createQuery(sql);
702
703 q.setFirstResult(0);
704 q.setMaxResults(2);
705
706 QueryPos qPos = QueryPos.getInstance(q);
707
708 if (uuid != null) {
709 qPos.add(uuid);
710 }
711
712 if (orderByComparator != null) {
713 Object[] values = orderByComparator.getOrderByValues(journalFeed);
714
715 for (Object value : values) {
716 qPos.add(value);
717 }
718 }
719
720 List<JournalFeed> list = q.list();
721
722 if (list.size() == 2) {
723 return list.get(1);
724 }
725 else {
726 return null;
727 }
728 }
729
730 public JournalFeed findByUUID_G(String uuid, long groupId)
731 throws NoSuchFeedException, SystemException {
732 JournalFeed journalFeed = fetchByUUID_G(uuid, groupId);
733
734 if (journalFeed == null) {
735 StringBundler msg = new StringBundler(6);
736
737 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
738
739 msg.append("uuid=");
740 msg.append(uuid);
741
742 msg.append(", groupId=");
743 msg.append(groupId);
744
745 msg.append(StringPool.CLOSE_CURLY_BRACE);
746
747 if (_log.isWarnEnabled()) {
748 _log.warn(msg.toString());
749 }
750
751 throw new NoSuchFeedException(msg.toString());
752 }
753
754 return journalFeed;
755 }
756
757 public JournalFeed fetchByUUID_G(String uuid, long groupId)
758 throws SystemException {
759 return fetchByUUID_G(uuid, groupId, true);
760 }
761
762 public JournalFeed fetchByUUID_G(String uuid, long groupId,
763 boolean retrieveFromCache) throws SystemException {
764 Object[] finderArgs = new Object[] { uuid, groupId };
765
766 Object result = null;
767
768 if (retrieveFromCache) {
769 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
770 finderArgs, this);
771 }
772
773 if (result == null) {
774 Session session = null;
775
776 try {
777 session = openSession();
778
779 StringBundler query = new StringBundler(4);
780
781 query.append(_SQL_SELECT_JOURNALFEED_WHERE);
782
783 if (uuid == null) {
784 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
785 }
786 else {
787 if (uuid.equals(StringPool.BLANK)) {
788 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
789 }
790 else {
791 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
792 }
793 }
794
795 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
796
797 query.append(JournalFeedModelImpl.ORDER_BY_JPQL);
798
799 String sql = query.toString();
800
801 Query q = session.createQuery(sql);
802
803 QueryPos qPos = QueryPos.getInstance(q);
804
805 if (uuid != null) {
806 qPos.add(uuid);
807 }
808
809 qPos.add(groupId);
810
811 List<JournalFeed> list = q.list();
812
813 result = list;
814
815 JournalFeed journalFeed = null;
816
817 if (list.isEmpty()) {
818 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
819 finderArgs, list);
820 }
821 else {
822 journalFeed = list.get(0);
823
824 cacheResult(journalFeed);
825
826 if ((journalFeed.getUuid() == null) ||
827 !journalFeed.getUuid().equals(uuid) ||
828 (journalFeed.getGroupId() != groupId)) {
829 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
830 finderArgs, journalFeed);
831 }
832 }
833
834 return journalFeed;
835 }
836 catch (Exception e) {
837 throw processException(e);
838 }
839 finally {
840 if (result == null) {
841 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
842 finderArgs, new ArrayList<JournalFeed>());
843 }
844
845 closeSession(session);
846 }
847 }
848 else {
849 if (result instanceof List<?>) {
850 return null;
851 }
852 else {
853 return (JournalFeed)result;
854 }
855 }
856 }
857
858 public List<JournalFeed> findByGroupId(long groupId)
859 throws SystemException {
860 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
861 }
862
863 public List<JournalFeed> findByGroupId(long groupId, int start, int end)
864 throws SystemException {
865 return findByGroupId(groupId, start, end, null);
866 }
867
868 public List<JournalFeed> findByGroupId(long groupId, int start, int end,
869 OrderByComparator orderByComparator) throws SystemException {
870 Object[] finderArgs = new Object[] {
871 groupId,
872
873 String.valueOf(start), String.valueOf(end),
874 String.valueOf(orderByComparator)
875 };
876
877 List<JournalFeed> list = (List<JournalFeed>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
878 finderArgs, this);
879
880 if (list == null) {
881 Session session = null;
882
883 try {
884 session = openSession();
885
886 StringBundler query = null;
887
888 if (orderByComparator != null) {
889 query = new StringBundler(3 +
890 (orderByComparator.getOrderByFields().length * 3));
891 }
892 else {
893 query = new StringBundler(3);
894 }
895
896 query.append(_SQL_SELECT_JOURNALFEED_WHERE);
897
898 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
899
900 if (orderByComparator != null) {
901 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
902 orderByComparator);
903 }
904
905 else {
906 query.append(JournalFeedModelImpl.ORDER_BY_JPQL);
907 }
908
909 String sql = query.toString();
910
911 Query q = session.createQuery(sql);
912
913 QueryPos qPos = QueryPos.getInstance(q);
914
915 qPos.add(groupId);
916
917 list = (List<JournalFeed>)QueryUtil.list(q, getDialect(),
918 start, end);
919 }
920 catch (Exception e) {
921 throw processException(e);
922 }
923 finally {
924 if (list == null) {
925 list = new ArrayList<JournalFeed>();
926 }
927
928 cacheResult(list);
929
930 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
931 finderArgs, list);
932
933 closeSession(session);
934 }
935 }
936
937 return list;
938 }
939
940 public JournalFeed findByGroupId_First(long groupId,
941 OrderByComparator orderByComparator)
942 throws NoSuchFeedException, SystemException {
943 List<JournalFeed> list = findByGroupId(groupId, 0, 1, orderByComparator);
944
945 if (list.isEmpty()) {
946 StringBundler msg = new StringBundler(4);
947
948 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
949
950 msg.append("groupId=");
951 msg.append(groupId);
952
953 msg.append(StringPool.CLOSE_CURLY_BRACE);
954
955 throw new NoSuchFeedException(msg.toString());
956 }
957 else {
958 return list.get(0);
959 }
960 }
961
962 public JournalFeed findByGroupId_Last(long groupId,
963 OrderByComparator orderByComparator)
964 throws NoSuchFeedException, SystemException {
965 int count = countByGroupId(groupId);
966
967 List<JournalFeed> list = findByGroupId(groupId, count - 1, count,
968 orderByComparator);
969
970 if (list.isEmpty()) {
971 StringBundler msg = new StringBundler(4);
972
973 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
974
975 msg.append("groupId=");
976 msg.append(groupId);
977
978 msg.append(StringPool.CLOSE_CURLY_BRACE);
979
980 throw new NoSuchFeedException(msg.toString());
981 }
982 else {
983 return list.get(0);
984 }
985 }
986
987 public JournalFeed[] findByGroupId_PrevAndNext(long id, long groupId,
988 OrderByComparator orderByComparator)
989 throws NoSuchFeedException, SystemException {
990 JournalFeed journalFeed = findByPrimaryKey(id);
991
992 Session session = null;
993
994 try {
995 session = openSession();
996
997 JournalFeed[] array = new JournalFeedImpl[3];
998
999 array[0] = getByGroupId_PrevAndNext(session, journalFeed, groupId,
1000 orderByComparator, true);
1001
1002 array[1] = journalFeed;
1003
1004 array[2] = getByGroupId_PrevAndNext(session, journalFeed, groupId,
1005 orderByComparator, false);
1006
1007 return array;
1008 }
1009 catch (Exception e) {
1010 throw processException(e);
1011 }
1012 finally {
1013 closeSession(session);
1014 }
1015 }
1016
1017 protected JournalFeed getByGroupId_PrevAndNext(Session session,
1018 JournalFeed journalFeed, long groupId,
1019 OrderByComparator orderByComparator, boolean previous) {
1020 StringBundler query = null;
1021
1022 if (orderByComparator != null) {
1023 query = new StringBundler(6 +
1024 (orderByComparator.getOrderByFields().length * 6));
1025 }
1026 else {
1027 query = new StringBundler(3);
1028 }
1029
1030 query.append(_SQL_SELECT_JOURNALFEED_WHERE);
1031
1032 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1033
1034 if (orderByComparator != null) {
1035 String[] orderByFields = orderByComparator.getOrderByFields();
1036
1037 if (orderByFields.length > 0) {
1038 query.append(WHERE_AND);
1039 }
1040
1041 for (int i = 0; i < orderByFields.length; i++) {
1042 query.append(_ORDER_BY_ENTITY_ALIAS);
1043 query.append(orderByFields[i]);
1044
1045 if ((i + 1) < orderByFields.length) {
1046 if (orderByComparator.isAscending() ^ previous) {
1047 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1048 }
1049 else {
1050 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1051 }
1052 }
1053 else {
1054 if (orderByComparator.isAscending() ^ previous) {
1055 query.append(WHERE_GREATER_THAN);
1056 }
1057 else {
1058 query.append(WHERE_LESSER_THAN);
1059 }
1060 }
1061 }
1062
1063 query.append(ORDER_BY_CLAUSE);
1064
1065 for (int i = 0; i < orderByFields.length; i++) {
1066 query.append(_ORDER_BY_ENTITY_ALIAS);
1067 query.append(orderByFields[i]);
1068
1069 if ((i + 1) < orderByFields.length) {
1070 if (orderByComparator.isAscending() ^ previous) {
1071 query.append(ORDER_BY_ASC_HAS_NEXT);
1072 }
1073 else {
1074 query.append(ORDER_BY_DESC_HAS_NEXT);
1075 }
1076 }
1077 else {
1078 if (orderByComparator.isAscending() ^ previous) {
1079 query.append(ORDER_BY_ASC);
1080 }
1081 else {
1082 query.append(ORDER_BY_DESC);
1083 }
1084 }
1085 }
1086 }
1087
1088 else {
1089 query.append(JournalFeedModelImpl.ORDER_BY_JPQL);
1090 }
1091
1092 String sql = query.toString();
1093
1094 Query q = session.createQuery(sql);
1095
1096 q.setFirstResult(0);
1097 q.setMaxResults(2);
1098
1099 QueryPos qPos = QueryPos.getInstance(q);
1100
1101 qPos.add(groupId);
1102
1103 if (orderByComparator != null) {
1104 Object[] values = orderByComparator.getOrderByValues(journalFeed);
1105
1106 for (Object value : values) {
1107 qPos.add(value);
1108 }
1109 }
1110
1111 List<JournalFeed> list = q.list();
1112
1113 if (list.size() == 2) {
1114 return list.get(1);
1115 }
1116 else {
1117 return null;
1118 }
1119 }
1120
1121 public List<JournalFeed> filterFindByGroupId(long groupId)
1122 throws SystemException {
1123 return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1124 QueryUtil.ALL_POS, null);
1125 }
1126
1127 public List<JournalFeed> filterFindByGroupId(long groupId, int start,
1128 int end) throws SystemException {
1129 return filterFindByGroupId(groupId, start, end, null);
1130 }
1131
1132 public List<JournalFeed> filterFindByGroupId(long groupId, int start,
1133 int end, OrderByComparator orderByComparator) throws SystemException {
1134 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1135 return findByGroupId(groupId, start, end, orderByComparator);
1136 }
1137
1138 Session session = null;
1139
1140 try {
1141 session = openSession();
1142
1143 StringBundler query = null;
1144
1145 if (orderByComparator != null) {
1146 query = new StringBundler(3 +
1147 (orderByComparator.getOrderByFields().length * 3));
1148 }
1149 else {
1150 query = new StringBundler(3);
1151 }
1152
1153 query.append(_FILTER_SQL_SELECT_JOURNALFEED_WHERE);
1154
1155 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1156
1157 if (orderByComparator != null) {
1158 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1159 orderByComparator);
1160 }
1161
1162 else {
1163 query.append(JournalFeedModelImpl.ORDER_BY_JPQL);
1164 }
1165
1166 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1167 JournalFeed.class.getName(), _FILTER_COLUMN_PK,
1168 _FILTER_COLUMN_USERID, groupId);
1169
1170 SQLQuery q = session.createSQLQuery(sql);
1171
1172 q.addEntity(_FILTER_ENTITY_ALIAS, JournalFeedImpl.class);
1173
1174 QueryPos qPos = QueryPos.getInstance(q);
1175
1176 qPos.add(groupId);
1177
1178 return (List<JournalFeed>)QueryUtil.list(q, getDialect(), start, end);
1179 }
1180 catch (Exception e) {
1181 throw processException(e);
1182 }
1183 finally {
1184 closeSession(session);
1185 }
1186 }
1187
1188 public JournalFeed findByG_F(long groupId, String feedId)
1189 throws NoSuchFeedException, SystemException {
1190 JournalFeed journalFeed = fetchByG_F(groupId, feedId);
1191
1192 if (journalFeed == null) {
1193 StringBundler msg = new StringBundler(6);
1194
1195 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1196
1197 msg.append("groupId=");
1198 msg.append(groupId);
1199
1200 msg.append(", feedId=");
1201 msg.append(feedId);
1202
1203 msg.append(StringPool.CLOSE_CURLY_BRACE);
1204
1205 if (_log.isWarnEnabled()) {
1206 _log.warn(msg.toString());
1207 }
1208
1209 throw new NoSuchFeedException(msg.toString());
1210 }
1211
1212 return journalFeed;
1213 }
1214
1215 public JournalFeed fetchByG_F(long groupId, String feedId)
1216 throws SystemException {
1217 return fetchByG_F(groupId, feedId, true);
1218 }
1219
1220 public JournalFeed fetchByG_F(long groupId, String feedId,
1221 boolean retrieveFromCache) throws SystemException {
1222 Object[] finderArgs = new Object[] { groupId, feedId };
1223
1224 Object result = null;
1225
1226 if (retrieveFromCache) {
1227 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_F,
1228 finderArgs, this);
1229 }
1230
1231 if (result == null) {
1232 Session session = null;
1233
1234 try {
1235 session = openSession();
1236
1237 StringBundler query = new StringBundler(4);
1238
1239 query.append(_SQL_SELECT_JOURNALFEED_WHERE);
1240
1241 query.append(_FINDER_COLUMN_G_F_GROUPID_2);
1242
1243 if (feedId == null) {
1244 query.append(_FINDER_COLUMN_G_F_FEEDID_1);
1245 }
1246 else {
1247 if (feedId.equals(StringPool.BLANK)) {
1248 query.append(_FINDER_COLUMN_G_F_FEEDID_3);
1249 }
1250 else {
1251 query.append(_FINDER_COLUMN_G_F_FEEDID_2);
1252 }
1253 }
1254
1255 query.append(JournalFeedModelImpl.ORDER_BY_JPQL);
1256
1257 String sql = query.toString();
1258
1259 Query q = session.createQuery(sql);
1260
1261 QueryPos qPos = QueryPos.getInstance(q);
1262
1263 qPos.add(groupId);
1264
1265 if (feedId != null) {
1266 qPos.add(feedId);
1267 }
1268
1269 List<JournalFeed> list = q.list();
1270
1271 result = list;
1272
1273 JournalFeed journalFeed = null;
1274
1275 if (list.isEmpty()) {
1276 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_F,
1277 finderArgs, list);
1278 }
1279 else {
1280 journalFeed = list.get(0);
1281
1282 cacheResult(journalFeed);
1283
1284 if ((journalFeed.getGroupId() != groupId) ||
1285 (journalFeed.getFeedId() == null) ||
1286 !journalFeed.getFeedId().equals(feedId)) {
1287 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_F,
1288 finderArgs, journalFeed);
1289 }
1290 }
1291
1292 return journalFeed;
1293 }
1294 catch (Exception e) {
1295 throw processException(e);
1296 }
1297 finally {
1298 if (result == null) {
1299 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_F,
1300 finderArgs, new ArrayList<JournalFeed>());
1301 }
1302
1303 closeSession(session);
1304 }
1305 }
1306 else {
1307 if (result instanceof List<?>) {
1308 return null;
1309 }
1310 else {
1311 return (JournalFeed)result;
1312 }
1313 }
1314 }
1315
1316 public List<JournalFeed> findAll() throws SystemException {
1317 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1318 }
1319
1320 public List<JournalFeed> findAll(int start, int end)
1321 throws SystemException {
1322 return findAll(start, end, null);
1323 }
1324
1325 public List<JournalFeed> findAll(int start, int end,
1326 OrderByComparator orderByComparator) throws SystemException {
1327 Object[] finderArgs = new Object[] {
1328 String.valueOf(start), String.valueOf(end),
1329 String.valueOf(orderByComparator)
1330 };
1331
1332 List<JournalFeed> list = (List<JournalFeed>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1333 finderArgs, this);
1334
1335 if (list == null) {
1336 Session session = null;
1337
1338 try {
1339 session = openSession();
1340
1341 StringBundler query = null;
1342 String sql = null;
1343
1344 if (orderByComparator != null) {
1345 query = new StringBundler(2 +
1346 (orderByComparator.getOrderByFields().length * 3));
1347
1348 query.append(_SQL_SELECT_JOURNALFEED);
1349
1350 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1351 orderByComparator);
1352
1353 sql = query.toString();
1354 }
1355 else {
1356 sql = _SQL_SELECT_JOURNALFEED.concat(JournalFeedModelImpl.ORDER_BY_JPQL);
1357 }
1358
1359 Query q = session.createQuery(sql);
1360
1361 if (orderByComparator == null) {
1362 list = (List<JournalFeed>)QueryUtil.list(q, getDialect(),
1363 start, end, false);
1364
1365 Collections.sort(list);
1366 }
1367 else {
1368 list = (List<JournalFeed>)QueryUtil.list(q, getDialect(),
1369 start, end);
1370 }
1371 }
1372 catch (Exception e) {
1373 throw processException(e);
1374 }
1375 finally {
1376 if (list == null) {
1377 list = new ArrayList<JournalFeed>();
1378 }
1379
1380 cacheResult(list);
1381
1382 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1383
1384 closeSession(session);
1385 }
1386 }
1387
1388 return list;
1389 }
1390
1391 public void removeByUuid(String uuid) throws SystemException {
1392 for (JournalFeed journalFeed : findByUuid(uuid)) {
1393 remove(journalFeed);
1394 }
1395 }
1396
1397 public void removeByUUID_G(String uuid, long groupId)
1398 throws NoSuchFeedException, SystemException {
1399 JournalFeed journalFeed = findByUUID_G(uuid, groupId);
1400
1401 remove(journalFeed);
1402 }
1403
1404 public void removeByGroupId(long groupId) throws SystemException {
1405 for (JournalFeed journalFeed : findByGroupId(groupId)) {
1406 remove(journalFeed);
1407 }
1408 }
1409
1410 public void removeByG_F(long groupId, String feedId)
1411 throws NoSuchFeedException, SystemException {
1412 JournalFeed journalFeed = findByG_F(groupId, feedId);
1413
1414 remove(journalFeed);
1415 }
1416
1417 public void removeAll() throws SystemException {
1418 for (JournalFeed journalFeed : findAll()) {
1419 remove(journalFeed);
1420 }
1421 }
1422
1423 public int countByUuid(String uuid) throws SystemException {
1424 Object[] finderArgs = new Object[] { uuid };
1425
1426 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1427 finderArgs, this);
1428
1429 if (count == null) {
1430 Session session = null;
1431
1432 try {
1433 session = openSession();
1434
1435 StringBundler query = new StringBundler(2);
1436
1437 query.append(_SQL_COUNT_JOURNALFEED_WHERE);
1438
1439 if (uuid == null) {
1440 query.append(_FINDER_COLUMN_UUID_UUID_1);
1441 }
1442 else {
1443 if (uuid.equals(StringPool.BLANK)) {
1444 query.append(_FINDER_COLUMN_UUID_UUID_3);
1445 }
1446 else {
1447 query.append(_FINDER_COLUMN_UUID_UUID_2);
1448 }
1449 }
1450
1451 String sql = query.toString();
1452
1453 Query q = session.createQuery(sql);
1454
1455 QueryPos qPos = QueryPos.getInstance(q);
1456
1457 if (uuid != null) {
1458 qPos.add(uuid);
1459 }
1460
1461 count = (Long)q.uniqueResult();
1462 }
1463 catch (Exception e) {
1464 throw processException(e);
1465 }
1466 finally {
1467 if (count == null) {
1468 count = Long.valueOf(0);
1469 }
1470
1471 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
1472 finderArgs, count);
1473
1474 closeSession(session);
1475 }
1476 }
1477
1478 return count.intValue();
1479 }
1480
1481 public int countByUUID_G(String uuid, long groupId)
1482 throws SystemException {
1483 Object[] finderArgs = new Object[] { uuid, groupId };
1484
1485 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
1486 finderArgs, this);
1487
1488 if (count == null) {
1489 Session session = null;
1490
1491 try {
1492 session = openSession();
1493
1494 StringBundler query = new StringBundler(3);
1495
1496 query.append(_SQL_COUNT_JOURNALFEED_WHERE);
1497
1498 if (uuid == null) {
1499 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1500 }
1501 else {
1502 if (uuid.equals(StringPool.BLANK)) {
1503 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1504 }
1505 else {
1506 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1507 }
1508 }
1509
1510 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1511
1512 String sql = query.toString();
1513
1514 Query q = session.createQuery(sql);
1515
1516 QueryPos qPos = QueryPos.getInstance(q);
1517
1518 if (uuid != null) {
1519 qPos.add(uuid);
1520 }
1521
1522 qPos.add(groupId);
1523
1524 count = (Long)q.uniqueResult();
1525 }
1526 catch (Exception e) {
1527 throw processException(e);
1528 }
1529 finally {
1530 if (count == null) {
1531 count = Long.valueOf(0);
1532 }
1533
1534 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
1535 finderArgs, count);
1536
1537 closeSession(session);
1538 }
1539 }
1540
1541 return count.intValue();
1542 }
1543
1544 public int countByGroupId(long groupId) throws SystemException {
1545 Object[] finderArgs = new Object[] { groupId };
1546
1547 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1548 finderArgs, this);
1549
1550 if (count == null) {
1551 Session session = null;
1552
1553 try {
1554 session = openSession();
1555
1556 StringBundler query = new StringBundler(2);
1557
1558 query.append(_SQL_COUNT_JOURNALFEED_WHERE);
1559
1560 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1561
1562 String sql = query.toString();
1563
1564 Query q = session.createQuery(sql);
1565
1566 QueryPos qPos = QueryPos.getInstance(q);
1567
1568 qPos.add(groupId);
1569
1570 count = (Long)q.uniqueResult();
1571 }
1572 catch (Exception e) {
1573 throw processException(e);
1574 }
1575 finally {
1576 if (count == null) {
1577 count = Long.valueOf(0);
1578 }
1579
1580 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1581 finderArgs, count);
1582
1583 closeSession(session);
1584 }
1585 }
1586
1587 return count.intValue();
1588 }
1589
1590 public int filterCountByGroupId(long groupId) throws SystemException {
1591 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1592 return countByGroupId(groupId);
1593 }
1594
1595 Session session = null;
1596
1597 try {
1598 session = openSession();
1599
1600 StringBundler query = new StringBundler(2);
1601
1602 query.append(_FILTER_SQL_COUNT_JOURNALFEED_WHERE);
1603
1604 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1605
1606 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1607 JournalFeed.class.getName(), _FILTER_COLUMN_PK,
1608 _FILTER_COLUMN_USERID, groupId);
1609
1610 SQLQuery q = session.createSQLQuery(sql);
1611
1612 q.addScalar(COUNT_COLUMN_NAME,
1613 com.liferay.portal.kernel.dao.orm.Type.LONG);
1614
1615 QueryPos qPos = QueryPos.getInstance(q);
1616
1617 qPos.add(groupId);
1618
1619 Long count = (Long)q.uniqueResult();
1620
1621 return count.intValue();
1622 }
1623 catch (Exception e) {
1624 throw processException(e);
1625 }
1626 finally {
1627 closeSession(session);
1628 }
1629 }
1630
1631 public int countByG_F(long groupId, String feedId)
1632 throws SystemException {
1633 Object[] finderArgs = new Object[] { groupId, feedId };
1634
1635 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_F,
1636 finderArgs, this);
1637
1638 if (count == null) {
1639 Session session = null;
1640
1641 try {
1642 session = openSession();
1643
1644 StringBundler query = new StringBundler(3);
1645
1646 query.append(_SQL_COUNT_JOURNALFEED_WHERE);
1647
1648 query.append(_FINDER_COLUMN_G_F_GROUPID_2);
1649
1650 if (feedId == null) {
1651 query.append(_FINDER_COLUMN_G_F_FEEDID_1);
1652 }
1653 else {
1654 if (feedId.equals(StringPool.BLANK)) {
1655 query.append(_FINDER_COLUMN_G_F_FEEDID_3);
1656 }
1657 else {
1658 query.append(_FINDER_COLUMN_G_F_FEEDID_2);
1659 }
1660 }
1661
1662 String sql = query.toString();
1663
1664 Query q = session.createQuery(sql);
1665
1666 QueryPos qPos = QueryPos.getInstance(q);
1667
1668 qPos.add(groupId);
1669
1670 if (feedId != null) {
1671 qPos.add(feedId);
1672 }
1673
1674 count = (Long)q.uniqueResult();
1675 }
1676 catch (Exception e) {
1677 throw processException(e);
1678 }
1679 finally {
1680 if (count == null) {
1681 count = Long.valueOf(0);
1682 }
1683
1684 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_F, finderArgs,
1685 count);
1686
1687 closeSession(session);
1688 }
1689 }
1690
1691 return count.intValue();
1692 }
1693
1694 public int filterCountByG_F(long groupId, String feedId)
1695 throws SystemException {
1696 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1697 return countByG_F(groupId, feedId);
1698 }
1699
1700 Session session = null;
1701
1702 try {
1703 session = openSession();
1704
1705 StringBundler query = new StringBundler(3);
1706
1707 query.append(_FILTER_SQL_COUNT_JOURNALFEED_WHERE);
1708
1709 query.append(_FINDER_COLUMN_G_F_GROUPID_2);
1710
1711 if (feedId == null) {
1712 query.append(_FINDER_COLUMN_G_F_FEEDID_1);
1713 }
1714 else {
1715 if (feedId.equals(StringPool.BLANK)) {
1716 query.append(_FINDER_COLUMN_G_F_FEEDID_3);
1717 }
1718 else {
1719 query.append(_FINDER_COLUMN_G_F_FEEDID_2);
1720 }
1721 }
1722
1723 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1724 JournalFeed.class.getName(), _FILTER_COLUMN_PK,
1725 _FILTER_COLUMN_USERID, groupId);
1726
1727 SQLQuery q = session.createSQLQuery(sql);
1728
1729 q.addScalar(COUNT_COLUMN_NAME,
1730 com.liferay.portal.kernel.dao.orm.Type.LONG);
1731
1732 QueryPos qPos = QueryPos.getInstance(q);
1733
1734 qPos.add(groupId);
1735
1736 if (feedId != null) {
1737 qPos.add(feedId);
1738 }
1739
1740 Long count = (Long)q.uniqueResult();
1741
1742 return count.intValue();
1743 }
1744 catch (Exception e) {
1745 throw processException(e);
1746 }
1747 finally {
1748 closeSession(session);
1749 }
1750 }
1751
1752 public int countAll() throws SystemException {
1753 Object[] finderArgs = new Object[0];
1754
1755 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1756 finderArgs, this);
1757
1758 if (count == null) {
1759 Session session = null;
1760
1761 try {
1762 session = openSession();
1763
1764 Query q = session.createQuery(_SQL_COUNT_JOURNALFEED);
1765
1766 count = (Long)q.uniqueResult();
1767 }
1768 catch (Exception e) {
1769 throw processException(e);
1770 }
1771 finally {
1772 if (count == null) {
1773 count = Long.valueOf(0);
1774 }
1775
1776 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1777 count);
1778
1779 closeSession(session);
1780 }
1781 }
1782
1783 return count.intValue();
1784 }
1785
1786 public void afterPropertiesSet() {
1787 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1788 com.liferay.portal.util.PropsUtil.get(
1789 "value.object.listener.com.liferay.portlet.journal.model.JournalFeed")));
1790
1791 if (listenerClassNames.length > 0) {
1792 try {
1793 List<ModelListener<JournalFeed>> listenersList = new ArrayList<ModelListener<JournalFeed>>();
1794
1795 for (String listenerClassName : listenerClassNames) {
1796 listenersList.add((ModelListener<JournalFeed>)InstanceFactory.newInstance(
1797 listenerClassName));
1798 }
1799
1800 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1801 }
1802 catch (Exception e) {
1803 _log.error(e);
1804 }
1805 }
1806 }
1807
1808 @BeanReference(type = JournalArticlePersistence.class)
1809 protected JournalArticlePersistence journalArticlePersistence;
1810 @BeanReference(type = JournalArticleImagePersistence.class)
1811 protected JournalArticleImagePersistence journalArticleImagePersistence;
1812 @BeanReference(type = JournalArticleResourcePersistence.class)
1813 protected JournalArticleResourcePersistence journalArticleResourcePersistence;
1814 @BeanReference(type = JournalContentSearchPersistence.class)
1815 protected JournalContentSearchPersistence journalContentSearchPersistence;
1816 @BeanReference(type = JournalFeedPersistence.class)
1817 protected JournalFeedPersistence journalFeedPersistence;
1818 @BeanReference(type = JournalStructurePersistence.class)
1819 protected JournalStructurePersistence journalStructurePersistence;
1820 @BeanReference(type = JournalTemplatePersistence.class)
1821 protected JournalTemplatePersistence journalTemplatePersistence;
1822 @BeanReference(type = ResourcePersistence.class)
1823 protected ResourcePersistence resourcePersistence;
1824 @BeanReference(type = UserPersistence.class)
1825 protected UserPersistence userPersistence;
1826 @BeanReference(type = ExpandoValuePersistence.class)
1827 protected ExpandoValuePersistence expandoValuePersistence;
1828 private static final String _SQL_SELECT_JOURNALFEED = "SELECT journalFeed FROM JournalFeed journalFeed";
1829 private static final String _SQL_SELECT_JOURNALFEED_WHERE = "SELECT journalFeed FROM JournalFeed journalFeed WHERE ";
1830 private static final String _SQL_COUNT_JOURNALFEED = "SELECT COUNT(journalFeed) FROM JournalFeed journalFeed";
1831 private static final String _SQL_COUNT_JOURNALFEED_WHERE = "SELECT COUNT(journalFeed) FROM JournalFeed journalFeed WHERE ";
1832 private static final String _FINDER_COLUMN_UUID_UUID_1 = "journalFeed.uuid IS NULL";
1833 private static final String _FINDER_COLUMN_UUID_UUID_2 = "journalFeed.uuid = ?";
1834 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(journalFeed.uuid IS NULL OR journalFeed.uuid = ?)";
1835 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "journalFeed.uuid IS NULL AND ";
1836 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "journalFeed.uuid = ? AND ";
1837 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(journalFeed.uuid IS NULL OR journalFeed.uuid = ?) AND ";
1838 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "journalFeed.groupId = ?";
1839 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "journalFeed.groupId = ?";
1840 private static final String _FINDER_COLUMN_G_F_GROUPID_2 = "journalFeed.groupId = ? AND ";
1841 private static final String _FINDER_COLUMN_G_F_FEEDID_1 = "journalFeed.feedId IS NULL";
1842 private static final String _FINDER_COLUMN_G_F_FEEDID_2 = "journalFeed.feedId = ?";
1843 private static final String _FINDER_COLUMN_G_F_FEEDID_3 = "(journalFeed.feedId IS NULL OR journalFeed.feedId = ?)";
1844 private static final String _FILTER_SQL_SELECT_JOURNALFEED_WHERE = "SELECT DISTINCT {journalFeed.*} FROM JournalFeed journalFeed WHERE ";
1845 private static final String _FILTER_SQL_COUNT_JOURNALFEED_WHERE = "SELECT COUNT(DISTINCT journalFeed.id) AS COUNT_VALUE FROM JournalFeed journalFeed WHERE ";
1846 private static final String _FILTER_COLUMN_PK = "journalFeed.id";
1847 private static final String _FILTER_COLUMN_USERID = "journalFeed.userId";
1848 private static final String _FILTER_ENTITY_ALIAS = "journalFeed";
1849 private static final String _ORDER_BY_ENTITY_ALIAS = "journalFeed.";
1850 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No JournalFeed exists with the primary key ";
1851 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No JournalFeed exists with the key {";
1852 private static Log _log = LogFactoryUtil.getLog(JournalFeedPersistenceImpl.class);
1853 }