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.Session;
027 import com.liferay.portal.kernel.exception.SystemException;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.GetterUtil;
031 import com.liferay.portal.kernel.util.InstanceFactory;
032 import com.liferay.portal.kernel.util.OrderByComparator;
033 import com.liferay.portal.kernel.util.StringBundler;
034 import com.liferay.portal.kernel.util.StringPool;
035 import com.liferay.portal.kernel.util.StringUtil;
036 import com.liferay.portal.kernel.util.Validator;
037 import com.liferay.portal.model.ModelListener;
038 import com.liferay.portal.service.persistence.BatchSessionUtil;
039 import com.liferay.portal.service.persistence.ResourcePersistence;
040 import com.liferay.portal.service.persistence.UserPersistence;
041 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042
043 import com.liferay.portlet.journal.NoSuchArticleResourceException;
044 import com.liferay.portlet.journal.model.JournalArticleResource;
045 import com.liferay.portlet.journal.model.impl.JournalArticleResourceImpl;
046 import com.liferay.portlet.journal.model.impl.JournalArticleResourceModelImpl;
047
048 import java.io.Serializable;
049
050 import java.util.ArrayList;
051 import java.util.Collections;
052 import java.util.List;
053
054
070 public class JournalArticleResourcePersistenceImpl extends BasePersistenceImpl<JournalArticleResource>
071 implements JournalArticleResourcePersistence {
072 public static final String FINDER_CLASS_NAME_ENTITY = JournalArticleResourceImpl.class.getName();
073 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
074 ".List";
075 public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(JournalArticleResourceModelImpl.ENTITY_CACHE_ENABLED,
076 JournalArticleResourceModelImpl.FINDER_CACHE_ENABLED,
077 FINDER_CLASS_NAME_LIST, "findByGroupId",
078 new String[] {
079 Long.class.getName(),
080
081 "java.lang.Integer", "java.lang.Integer",
082 "com.liferay.portal.kernel.util.OrderByComparator"
083 });
084 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(JournalArticleResourceModelImpl.ENTITY_CACHE_ENABLED,
085 JournalArticleResourceModelImpl.FINDER_CACHE_ENABLED,
086 FINDER_CLASS_NAME_LIST, "countByGroupId",
087 new String[] { Long.class.getName() });
088 public static final FinderPath FINDER_PATH_FETCH_BY_G_A = new FinderPath(JournalArticleResourceModelImpl.ENTITY_CACHE_ENABLED,
089 JournalArticleResourceModelImpl.FINDER_CACHE_ENABLED,
090 FINDER_CLASS_NAME_ENTITY, "fetchByG_A",
091 new String[] { Long.class.getName(), String.class.getName() });
092 public static final FinderPath FINDER_PATH_COUNT_BY_G_A = new FinderPath(JournalArticleResourceModelImpl.ENTITY_CACHE_ENABLED,
093 JournalArticleResourceModelImpl.FINDER_CACHE_ENABLED,
094 FINDER_CLASS_NAME_LIST, "countByG_A",
095 new String[] { Long.class.getName(), String.class.getName() });
096 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(JournalArticleResourceModelImpl.ENTITY_CACHE_ENABLED,
097 JournalArticleResourceModelImpl.FINDER_CACHE_ENABLED,
098 FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
099 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(JournalArticleResourceModelImpl.ENTITY_CACHE_ENABLED,
100 JournalArticleResourceModelImpl.FINDER_CACHE_ENABLED,
101 FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
102
103
108 public void cacheResult(JournalArticleResource journalArticleResource) {
109 EntityCacheUtil.putResult(JournalArticleResourceModelImpl.ENTITY_CACHE_ENABLED,
110 JournalArticleResourceImpl.class,
111 journalArticleResource.getPrimaryKey(), journalArticleResource);
112
113 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_A,
114 new Object[] {
115 new Long(journalArticleResource.getGroupId()),
116
117 journalArticleResource.getArticleId()
118 }, journalArticleResource);
119 }
120
121
126 public void cacheResult(
127 List<JournalArticleResource> journalArticleResources) {
128 for (JournalArticleResource journalArticleResource : journalArticleResources) {
129 if (EntityCacheUtil.getResult(
130 JournalArticleResourceModelImpl.ENTITY_CACHE_ENABLED,
131 JournalArticleResourceImpl.class,
132 journalArticleResource.getPrimaryKey(), this) == null) {
133 cacheResult(journalArticleResource);
134 }
135 }
136 }
137
138
145 public void clearCache() {
146 CacheRegistryUtil.clear(JournalArticleResourceImpl.class.getName());
147 EntityCacheUtil.clearCache(JournalArticleResourceImpl.class.getName());
148 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
149 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
150 }
151
152
159 public void clearCache(JournalArticleResource journalArticleResource) {
160 EntityCacheUtil.removeResult(JournalArticleResourceModelImpl.ENTITY_CACHE_ENABLED,
161 JournalArticleResourceImpl.class,
162 journalArticleResource.getPrimaryKey());
163
164 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_A,
165 new Object[] {
166 new Long(journalArticleResource.getGroupId()),
167
168 journalArticleResource.getArticleId()
169 });
170 }
171
172
178 public JournalArticleResource create(long resourcePrimKey) {
179 JournalArticleResource journalArticleResource = new JournalArticleResourceImpl();
180
181 journalArticleResource.setNew(true);
182 journalArticleResource.setPrimaryKey(resourcePrimKey);
183
184 return journalArticleResource;
185 }
186
187
195 public JournalArticleResource remove(Serializable primaryKey)
196 throws NoSuchModelException, SystemException {
197 return remove(((Long)primaryKey).longValue());
198 }
199
200
208 public JournalArticleResource remove(long resourcePrimKey)
209 throws NoSuchArticleResourceException, SystemException {
210 Session session = null;
211
212 try {
213 session = openSession();
214
215 JournalArticleResource journalArticleResource = (JournalArticleResource)session.get(JournalArticleResourceImpl.class,
216 new Long(resourcePrimKey));
217
218 if (journalArticleResource == null) {
219 if (_log.isWarnEnabled()) {
220 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
221 resourcePrimKey);
222 }
223
224 throw new NoSuchArticleResourceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
225 resourcePrimKey);
226 }
227
228 return remove(journalArticleResource);
229 }
230 catch (NoSuchArticleResourceException nsee) {
231 throw nsee;
232 }
233 catch (Exception e) {
234 throw processException(e);
235 }
236 finally {
237 closeSession(session);
238 }
239 }
240
241 protected JournalArticleResource removeImpl(
242 JournalArticleResource journalArticleResource)
243 throws SystemException {
244 journalArticleResource = toUnwrappedModel(journalArticleResource);
245
246 Session session = null;
247
248 try {
249 session = openSession();
250
251 if (journalArticleResource.isCachedModel() ||
252 BatchSessionUtil.isEnabled()) {
253 Object staleObject = session.get(JournalArticleResourceImpl.class,
254 journalArticleResource.getPrimaryKeyObj());
255
256 if (staleObject != null) {
257 session.evict(staleObject);
258 }
259 }
260
261 session.delete(journalArticleResource);
262
263 session.flush();
264 }
265 catch (Exception e) {
266 throw processException(e);
267 }
268 finally {
269 closeSession(session);
270 }
271
272 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
273
274 JournalArticleResourceModelImpl journalArticleResourceModelImpl = (JournalArticleResourceModelImpl)journalArticleResource;
275
276 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_A,
277 new Object[] {
278 new Long(journalArticleResourceModelImpl.getOriginalGroupId()),
279
280 journalArticleResourceModelImpl.getOriginalArticleId()
281 });
282
283 EntityCacheUtil.removeResult(JournalArticleResourceModelImpl.ENTITY_CACHE_ENABLED,
284 JournalArticleResourceImpl.class,
285 journalArticleResource.getPrimaryKey());
286
287 return journalArticleResource;
288 }
289
290 public JournalArticleResource updateImpl(
291 com.liferay.portlet.journal.model.JournalArticleResource journalArticleResource,
292 boolean merge) throws SystemException {
293 journalArticleResource = toUnwrappedModel(journalArticleResource);
294
295 boolean isNew = journalArticleResource.isNew();
296
297 JournalArticleResourceModelImpl journalArticleResourceModelImpl = (JournalArticleResourceModelImpl)journalArticleResource;
298
299 Session session = null;
300
301 try {
302 session = openSession();
303
304 BatchSessionUtil.update(session, journalArticleResource, merge);
305
306 journalArticleResource.setNew(false);
307 }
308 catch (Exception e) {
309 throw processException(e);
310 }
311 finally {
312 closeSession(session);
313 }
314
315 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
316
317 EntityCacheUtil.putResult(JournalArticleResourceModelImpl.ENTITY_CACHE_ENABLED,
318 JournalArticleResourceImpl.class,
319 journalArticleResource.getPrimaryKey(), journalArticleResource);
320
321 if (!isNew &&
322 ((journalArticleResource.getGroupId() != journalArticleResourceModelImpl.getOriginalGroupId()) ||
323 !Validator.equals(journalArticleResource.getArticleId(),
324 journalArticleResourceModelImpl.getOriginalArticleId()))) {
325 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_A,
326 new Object[] {
327 new Long(journalArticleResourceModelImpl.getOriginalGroupId()),
328
329 journalArticleResourceModelImpl.getOriginalArticleId()
330 });
331 }
332
333 if (isNew ||
334 ((journalArticleResource.getGroupId() != journalArticleResourceModelImpl.getOriginalGroupId()) ||
335 !Validator.equals(journalArticleResource.getArticleId(),
336 journalArticleResourceModelImpl.getOriginalArticleId()))) {
337 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_A,
338 new Object[] {
339 new Long(journalArticleResource.getGroupId()),
340
341 journalArticleResource.getArticleId()
342 }, journalArticleResource);
343 }
344
345 return journalArticleResource;
346 }
347
348 protected JournalArticleResource toUnwrappedModel(
349 JournalArticleResource journalArticleResource) {
350 if (journalArticleResource instanceof JournalArticleResourceImpl) {
351 return journalArticleResource;
352 }
353
354 JournalArticleResourceImpl journalArticleResourceImpl = new JournalArticleResourceImpl();
355
356 journalArticleResourceImpl.setNew(journalArticleResource.isNew());
357 journalArticleResourceImpl.setPrimaryKey(journalArticleResource.getPrimaryKey());
358
359 journalArticleResourceImpl.setResourcePrimKey(journalArticleResource.getResourcePrimKey());
360 journalArticleResourceImpl.setGroupId(journalArticleResource.getGroupId());
361 journalArticleResourceImpl.setArticleId(journalArticleResource.getArticleId());
362
363 return journalArticleResourceImpl;
364 }
365
366
374 public JournalArticleResource findByPrimaryKey(Serializable primaryKey)
375 throws NoSuchModelException, SystemException {
376 return findByPrimaryKey(((Long)primaryKey).longValue());
377 }
378
379
387 public JournalArticleResource findByPrimaryKey(long resourcePrimKey)
388 throws NoSuchArticleResourceException, SystemException {
389 JournalArticleResource journalArticleResource = fetchByPrimaryKey(resourcePrimKey);
390
391 if (journalArticleResource == null) {
392 if (_log.isWarnEnabled()) {
393 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + resourcePrimKey);
394 }
395
396 throw new NoSuchArticleResourceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
397 resourcePrimKey);
398 }
399
400 return journalArticleResource;
401 }
402
403
410 public JournalArticleResource fetchByPrimaryKey(Serializable primaryKey)
411 throws SystemException {
412 return fetchByPrimaryKey(((Long)primaryKey).longValue());
413 }
414
415
422 public JournalArticleResource fetchByPrimaryKey(long resourcePrimKey)
423 throws SystemException {
424 JournalArticleResource journalArticleResource = (JournalArticleResource)EntityCacheUtil.getResult(JournalArticleResourceModelImpl.ENTITY_CACHE_ENABLED,
425 JournalArticleResourceImpl.class, resourcePrimKey, this);
426
427 if (journalArticleResource == null) {
428 Session session = null;
429
430 try {
431 session = openSession();
432
433 journalArticleResource = (JournalArticleResource)session.get(JournalArticleResourceImpl.class,
434 new Long(resourcePrimKey));
435 }
436 catch (Exception e) {
437 throw processException(e);
438 }
439 finally {
440 if (journalArticleResource != null) {
441 cacheResult(journalArticleResource);
442 }
443
444 closeSession(session);
445 }
446 }
447
448 return journalArticleResource;
449 }
450
451
458 public List<JournalArticleResource> findByGroupId(long groupId)
459 throws SystemException {
460 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
461 }
462
463
476 public List<JournalArticleResource> findByGroupId(long groupId, int start,
477 int end) throws SystemException {
478 return findByGroupId(groupId, start, end, null);
479 }
480
481
495 public List<JournalArticleResource> findByGroupId(long groupId, int start,
496 int end, OrderByComparator orderByComparator) throws SystemException {
497 Object[] finderArgs = new Object[] {
498 groupId,
499
500 String.valueOf(start), String.valueOf(end),
501 String.valueOf(orderByComparator)
502 };
503
504 List<JournalArticleResource> list = (List<JournalArticleResource>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
505 finderArgs, this);
506
507 if (list == null) {
508 Session session = null;
509
510 try {
511 session = openSession();
512
513 StringBundler query = null;
514
515 if (orderByComparator != null) {
516 query = new StringBundler(3 +
517 (orderByComparator.getOrderByFields().length * 3));
518 }
519 else {
520 query = new StringBundler(2);
521 }
522
523 query.append(_SQL_SELECT_JOURNALARTICLERESOURCE_WHERE);
524
525 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
526
527 if (orderByComparator != null) {
528 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
529 orderByComparator);
530 }
531
532 String sql = query.toString();
533
534 Query q = session.createQuery(sql);
535
536 QueryPos qPos = QueryPos.getInstance(q);
537
538 qPos.add(groupId);
539
540 list = (List<JournalArticleResource>)QueryUtil.list(q,
541 getDialect(), start, end);
542 }
543 catch (Exception e) {
544 throw processException(e);
545 }
546 finally {
547 if (list == null) {
548 list = new ArrayList<JournalArticleResource>();
549 }
550
551 cacheResult(list);
552
553 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
554 finderArgs, list);
555
556 closeSession(session);
557 }
558 }
559
560 return list;
561 }
562
563
576 public JournalArticleResource findByGroupId_First(long groupId,
577 OrderByComparator orderByComparator)
578 throws NoSuchArticleResourceException, SystemException {
579 List<JournalArticleResource> list = findByGroupId(groupId, 0, 1,
580 orderByComparator);
581
582 if (list.isEmpty()) {
583 StringBundler msg = new StringBundler(4);
584
585 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
586
587 msg.append("groupId=");
588 msg.append(groupId);
589
590 msg.append(StringPool.CLOSE_CURLY_BRACE);
591
592 throw new NoSuchArticleResourceException(msg.toString());
593 }
594 else {
595 return list.get(0);
596 }
597 }
598
599
612 public JournalArticleResource findByGroupId_Last(long groupId,
613 OrderByComparator orderByComparator)
614 throws NoSuchArticleResourceException, SystemException {
615 int count = countByGroupId(groupId);
616
617 List<JournalArticleResource> list = findByGroupId(groupId, count - 1,
618 count, orderByComparator);
619
620 if (list.isEmpty()) {
621 StringBundler msg = new StringBundler(4);
622
623 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
624
625 msg.append("groupId=");
626 msg.append(groupId);
627
628 msg.append(StringPool.CLOSE_CURLY_BRACE);
629
630 throw new NoSuchArticleResourceException(msg.toString());
631 }
632 else {
633 return list.get(0);
634 }
635 }
636
637
651 public JournalArticleResource[] findByGroupId_PrevAndNext(
652 long resourcePrimKey, long groupId, OrderByComparator orderByComparator)
653 throws NoSuchArticleResourceException, SystemException {
654 JournalArticleResource journalArticleResource = findByPrimaryKey(resourcePrimKey);
655
656 Session session = null;
657
658 try {
659 session = openSession();
660
661 JournalArticleResource[] array = new JournalArticleResourceImpl[3];
662
663 array[0] = getByGroupId_PrevAndNext(session,
664 journalArticleResource, groupId, orderByComparator, true);
665
666 array[1] = journalArticleResource;
667
668 array[2] = getByGroupId_PrevAndNext(session,
669 journalArticleResource, groupId, orderByComparator, false);
670
671 return array;
672 }
673 catch (Exception e) {
674 throw processException(e);
675 }
676 finally {
677 closeSession(session);
678 }
679 }
680
681 protected JournalArticleResource getByGroupId_PrevAndNext(Session session,
682 JournalArticleResource journalArticleResource, long groupId,
683 OrderByComparator orderByComparator, boolean previous) {
684 StringBundler query = null;
685
686 if (orderByComparator != null) {
687 query = new StringBundler(6 +
688 (orderByComparator.getOrderByFields().length * 6));
689 }
690 else {
691 query = new StringBundler(3);
692 }
693
694 query.append(_SQL_SELECT_JOURNALARTICLERESOURCE_WHERE);
695
696 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
697
698 if (orderByComparator != null) {
699 String[] orderByFields = orderByComparator.getOrderByFields();
700
701 if (orderByFields.length > 0) {
702 query.append(WHERE_AND);
703 }
704
705 for (int i = 0; i < orderByFields.length; i++) {
706 query.append(_ORDER_BY_ENTITY_ALIAS);
707 query.append(orderByFields[i]);
708
709 if ((i + 1) < orderByFields.length) {
710 if (orderByComparator.isAscending() ^ previous) {
711 query.append(WHERE_GREATER_THAN_HAS_NEXT);
712 }
713 else {
714 query.append(WHERE_LESSER_THAN_HAS_NEXT);
715 }
716 }
717 else {
718 if (orderByComparator.isAscending() ^ previous) {
719 query.append(WHERE_GREATER_THAN);
720 }
721 else {
722 query.append(WHERE_LESSER_THAN);
723 }
724 }
725 }
726
727 query.append(ORDER_BY_CLAUSE);
728
729 for (int i = 0; i < orderByFields.length; i++) {
730 query.append(_ORDER_BY_ENTITY_ALIAS);
731 query.append(orderByFields[i]);
732
733 if ((i + 1) < orderByFields.length) {
734 if (orderByComparator.isAscending() ^ previous) {
735 query.append(ORDER_BY_ASC_HAS_NEXT);
736 }
737 else {
738 query.append(ORDER_BY_DESC_HAS_NEXT);
739 }
740 }
741 else {
742 if (orderByComparator.isAscending() ^ previous) {
743 query.append(ORDER_BY_ASC);
744 }
745 else {
746 query.append(ORDER_BY_DESC);
747 }
748 }
749 }
750 }
751
752 String sql = query.toString();
753
754 Query q = session.createQuery(sql);
755
756 q.setFirstResult(0);
757 q.setMaxResults(2);
758
759 QueryPos qPos = QueryPos.getInstance(q);
760
761 qPos.add(groupId);
762
763 if (orderByComparator != null) {
764 Object[] values = orderByComparator.getOrderByValues(journalArticleResource);
765
766 for (Object value : values) {
767 qPos.add(value);
768 }
769 }
770
771 List<JournalArticleResource> list = q.list();
772
773 if (list.size() == 2) {
774 return list.get(1);
775 }
776 else {
777 return null;
778 }
779 }
780
781
790 public JournalArticleResource findByG_A(long groupId, String articleId)
791 throws NoSuchArticleResourceException, SystemException {
792 JournalArticleResource journalArticleResource = fetchByG_A(groupId,
793 articleId);
794
795 if (journalArticleResource == null) {
796 StringBundler msg = new StringBundler(6);
797
798 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
799
800 msg.append("groupId=");
801 msg.append(groupId);
802
803 msg.append(", articleId=");
804 msg.append(articleId);
805
806 msg.append(StringPool.CLOSE_CURLY_BRACE);
807
808 if (_log.isWarnEnabled()) {
809 _log.warn(msg.toString());
810 }
811
812 throw new NoSuchArticleResourceException(msg.toString());
813 }
814
815 return journalArticleResource;
816 }
817
818
826 public JournalArticleResource fetchByG_A(long groupId, String articleId)
827 throws SystemException {
828 return fetchByG_A(groupId, articleId, true);
829 }
830
831
839 public JournalArticleResource fetchByG_A(long groupId, String articleId,
840 boolean retrieveFromCache) throws SystemException {
841 Object[] finderArgs = new Object[] { groupId, articleId };
842
843 Object result = null;
844
845 if (retrieveFromCache) {
846 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_A,
847 finderArgs, this);
848 }
849
850 if (result == null) {
851 Session session = null;
852
853 try {
854 session = openSession();
855
856 StringBundler query = new StringBundler(3);
857
858 query.append(_SQL_SELECT_JOURNALARTICLERESOURCE_WHERE);
859
860 query.append(_FINDER_COLUMN_G_A_GROUPID_2);
861
862 if (articleId == null) {
863 query.append(_FINDER_COLUMN_G_A_ARTICLEID_1);
864 }
865 else {
866 if (articleId.equals(StringPool.BLANK)) {
867 query.append(_FINDER_COLUMN_G_A_ARTICLEID_3);
868 }
869 else {
870 query.append(_FINDER_COLUMN_G_A_ARTICLEID_2);
871 }
872 }
873
874 String sql = query.toString();
875
876 Query q = session.createQuery(sql);
877
878 QueryPos qPos = QueryPos.getInstance(q);
879
880 qPos.add(groupId);
881
882 if (articleId != null) {
883 qPos.add(articleId);
884 }
885
886 List<JournalArticleResource> list = q.list();
887
888 result = list;
889
890 JournalArticleResource journalArticleResource = null;
891
892 if (list.isEmpty()) {
893 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_A,
894 finderArgs, list);
895 }
896 else {
897 journalArticleResource = list.get(0);
898
899 cacheResult(journalArticleResource);
900
901 if ((journalArticleResource.getGroupId() != groupId) ||
902 (journalArticleResource.getArticleId() == null) ||
903 !journalArticleResource.getArticleId()
904 .equals(articleId)) {
905 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_A,
906 finderArgs, journalArticleResource);
907 }
908 }
909
910 return journalArticleResource;
911 }
912 catch (Exception e) {
913 throw processException(e);
914 }
915 finally {
916 if (result == null) {
917 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_A,
918 finderArgs, new ArrayList<JournalArticleResource>());
919 }
920
921 closeSession(session);
922 }
923 }
924 else {
925 if (result instanceof List<?>) {
926 return null;
927 }
928 else {
929 return (JournalArticleResource)result;
930 }
931 }
932 }
933
934
940 public List<JournalArticleResource> findAll() throws SystemException {
941 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
942 }
943
944
956 public List<JournalArticleResource> findAll(int start, int end)
957 throws SystemException {
958 return findAll(start, end, null);
959 }
960
961
974 public List<JournalArticleResource> findAll(int start, int end,
975 OrderByComparator orderByComparator) throws SystemException {
976 Object[] finderArgs = new Object[] {
977 String.valueOf(start), String.valueOf(end),
978 String.valueOf(orderByComparator)
979 };
980
981 List<JournalArticleResource> list = (List<JournalArticleResource>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
982 finderArgs, this);
983
984 if (list == null) {
985 Session session = null;
986
987 try {
988 session = openSession();
989
990 StringBundler query = null;
991 String sql = null;
992
993 if (orderByComparator != null) {
994 query = new StringBundler(2 +
995 (orderByComparator.getOrderByFields().length * 3));
996
997 query.append(_SQL_SELECT_JOURNALARTICLERESOURCE);
998
999 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1000 orderByComparator);
1001
1002 sql = query.toString();
1003 }
1004 else {
1005 sql = _SQL_SELECT_JOURNALARTICLERESOURCE;
1006 }
1007
1008 Query q = session.createQuery(sql);
1009
1010 if (orderByComparator == null) {
1011 list = (List<JournalArticleResource>)QueryUtil.list(q,
1012 getDialect(), start, end, false);
1013
1014 Collections.sort(list);
1015 }
1016 else {
1017 list = (List<JournalArticleResource>)QueryUtil.list(q,
1018 getDialect(), start, end);
1019 }
1020 }
1021 catch (Exception e) {
1022 throw processException(e);
1023 }
1024 finally {
1025 if (list == null) {
1026 list = new ArrayList<JournalArticleResource>();
1027 }
1028
1029 cacheResult(list);
1030
1031 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1032
1033 closeSession(session);
1034 }
1035 }
1036
1037 return list;
1038 }
1039
1040
1046 public void removeByGroupId(long groupId) throws SystemException {
1047 for (JournalArticleResource journalArticleResource : findByGroupId(
1048 groupId)) {
1049 remove(journalArticleResource);
1050 }
1051 }
1052
1053
1060 public void removeByG_A(long groupId, String articleId)
1061 throws NoSuchArticleResourceException, SystemException {
1062 JournalArticleResource journalArticleResource = findByG_A(groupId,
1063 articleId);
1064
1065 remove(journalArticleResource);
1066 }
1067
1068
1073 public void removeAll() throws SystemException {
1074 for (JournalArticleResource journalArticleResource : findAll()) {
1075 remove(journalArticleResource);
1076 }
1077 }
1078
1079
1086 public int countByGroupId(long groupId) throws SystemException {
1087 Object[] finderArgs = new Object[] { groupId };
1088
1089 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1090 finderArgs, this);
1091
1092 if (count == null) {
1093 Session session = null;
1094
1095 try {
1096 session = openSession();
1097
1098 StringBundler query = new StringBundler(2);
1099
1100 query.append(_SQL_COUNT_JOURNALARTICLERESOURCE_WHERE);
1101
1102 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1103
1104 String sql = query.toString();
1105
1106 Query q = session.createQuery(sql);
1107
1108 QueryPos qPos = QueryPos.getInstance(q);
1109
1110 qPos.add(groupId);
1111
1112 count = (Long)q.uniqueResult();
1113 }
1114 catch (Exception e) {
1115 throw processException(e);
1116 }
1117 finally {
1118 if (count == null) {
1119 count = Long.valueOf(0);
1120 }
1121
1122 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1123 finderArgs, count);
1124
1125 closeSession(session);
1126 }
1127 }
1128
1129 return count.intValue();
1130 }
1131
1132
1140 public int countByG_A(long groupId, String articleId)
1141 throws SystemException {
1142 Object[] finderArgs = new Object[] { groupId, articleId };
1143
1144 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_A,
1145 finderArgs, this);
1146
1147 if (count == null) {
1148 Session session = null;
1149
1150 try {
1151 session = openSession();
1152
1153 StringBundler query = new StringBundler(3);
1154
1155 query.append(_SQL_COUNT_JOURNALARTICLERESOURCE_WHERE);
1156
1157 query.append(_FINDER_COLUMN_G_A_GROUPID_2);
1158
1159 if (articleId == null) {
1160 query.append(_FINDER_COLUMN_G_A_ARTICLEID_1);
1161 }
1162 else {
1163 if (articleId.equals(StringPool.BLANK)) {
1164 query.append(_FINDER_COLUMN_G_A_ARTICLEID_3);
1165 }
1166 else {
1167 query.append(_FINDER_COLUMN_G_A_ARTICLEID_2);
1168 }
1169 }
1170
1171 String sql = query.toString();
1172
1173 Query q = session.createQuery(sql);
1174
1175 QueryPos qPos = QueryPos.getInstance(q);
1176
1177 qPos.add(groupId);
1178
1179 if (articleId != null) {
1180 qPos.add(articleId);
1181 }
1182
1183 count = (Long)q.uniqueResult();
1184 }
1185 catch (Exception e) {
1186 throw processException(e);
1187 }
1188 finally {
1189 if (count == null) {
1190 count = Long.valueOf(0);
1191 }
1192
1193 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_A, finderArgs,
1194 count);
1195
1196 closeSession(session);
1197 }
1198 }
1199
1200 return count.intValue();
1201 }
1202
1203
1209 public int countAll() throws SystemException {
1210 Object[] finderArgs = new Object[0];
1211
1212 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1213 finderArgs, this);
1214
1215 if (count == null) {
1216 Session session = null;
1217
1218 try {
1219 session = openSession();
1220
1221 Query q = session.createQuery(_SQL_COUNT_JOURNALARTICLERESOURCE);
1222
1223 count = (Long)q.uniqueResult();
1224 }
1225 catch (Exception e) {
1226 throw processException(e);
1227 }
1228 finally {
1229 if (count == null) {
1230 count = Long.valueOf(0);
1231 }
1232
1233 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1234 count);
1235
1236 closeSession(session);
1237 }
1238 }
1239
1240 return count.intValue();
1241 }
1242
1243
1246 public void afterPropertiesSet() {
1247 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1248 com.liferay.portal.util.PropsUtil.get(
1249 "value.object.listener.com.liferay.portlet.journal.model.JournalArticleResource")));
1250
1251 if (listenerClassNames.length > 0) {
1252 try {
1253 List<ModelListener<JournalArticleResource>> listenersList = new ArrayList<ModelListener<JournalArticleResource>>();
1254
1255 for (String listenerClassName : listenerClassNames) {
1256 listenersList.add((ModelListener<JournalArticleResource>)InstanceFactory.newInstance(
1257 listenerClassName));
1258 }
1259
1260 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1261 }
1262 catch (Exception e) {
1263 _log.error(e);
1264 }
1265 }
1266 }
1267
1268 @BeanReference(type = JournalArticlePersistence.class)
1269 protected JournalArticlePersistence journalArticlePersistence;
1270 @BeanReference(type = JournalArticleImagePersistence.class)
1271 protected JournalArticleImagePersistence journalArticleImagePersistence;
1272 @BeanReference(type = JournalArticleResourcePersistence.class)
1273 protected JournalArticleResourcePersistence journalArticleResourcePersistence;
1274 @BeanReference(type = JournalContentSearchPersistence.class)
1275 protected JournalContentSearchPersistence journalContentSearchPersistence;
1276 @BeanReference(type = JournalFeedPersistence.class)
1277 protected JournalFeedPersistence journalFeedPersistence;
1278 @BeanReference(type = JournalStructurePersistence.class)
1279 protected JournalStructurePersistence journalStructurePersistence;
1280 @BeanReference(type = JournalTemplatePersistence.class)
1281 protected JournalTemplatePersistence journalTemplatePersistence;
1282 @BeanReference(type = ResourcePersistence.class)
1283 protected ResourcePersistence resourcePersistence;
1284 @BeanReference(type = UserPersistence.class)
1285 protected UserPersistence userPersistence;
1286 private static final String _SQL_SELECT_JOURNALARTICLERESOURCE = "SELECT journalArticleResource FROM JournalArticleResource journalArticleResource";
1287 private static final String _SQL_SELECT_JOURNALARTICLERESOURCE_WHERE = "SELECT journalArticleResource FROM JournalArticleResource journalArticleResource WHERE ";
1288 private static final String _SQL_COUNT_JOURNALARTICLERESOURCE = "SELECT COUNT(journalArticleResource) FROM JournalArticleResource journalArticleResource";
1289 private static final String _SQL_COUNT_JOURNALARTICLERESOURCE_WHERE = "SELECT COUNT(journalArticleResource) FROM JournalArticleResource journalArticleResource WHERE ";
1290 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "journalArticleResource.groupId = ?";
1291 private static final String _FINDER_COLUMN_G_A_GROUPID_2 = "journalArticleResource.groupId = ? AND ";
1292 private static final String _FINDER_COLUMN_G_A_ARTICLEID_1 = "journalArticleResource.articleId IS NULL";
1293 private static final String _FINDER_COLUMN_G_A_ARTICLEID_2 = "journalArticleResource.articleId = ?";
1294 private static final String _FINDER_COLUMN_G_A_ARTICLEID_3 = "(journalArticleResource.articleId IS NULL OR journalArticleResource.articleId = ?)";
1295 private static final String _ORDER_BY_ENTITY_ALIAS = "journalArticleResource.";
1296 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No JournalArticleResource exists with the primary key ";
1297 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No JournalArticleResource exists with the key {";
1298 private static Log _log = LogFactoryUtil.getLog(JournalArticleResourcePersistenceImpl.class);
1299 }