001
014
015 package com.liferay.portlet.wiki.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.bean.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.kernel.uuid.PortalUUIDUtil;
038 import com.liferay.portal.model.CacheModel;
039 import com.liferay.portal.model.ModelListener;
040 import com.liferay.portal.service.persistence.BatchSessionUtil;
041 import com.liferay.portal.service.persistence.ResourcePersistence;
042 import com.liferay.portal.service.persistence.UserPersistence;
043 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044
045 import com.liferay.portlet.wiki.NoSuchPageResourceException;
046 import com.liferay.portlet.wiki.model.WikiPageResource;
047 import com.liferay.portlet.wiki.model.impl.WikiPageResourceImpl;
048 import com.liferay.portlet.wiki.model.impl.WikiPageResourceModelImpl;
049
050 import java.io.Serializable;
051
052 import java.util.ArrayList;
053 import java.util.Collections;
054 import java.util.List;
055
056
068 public class WikiPageResourcePersistenceImpl extends BasePersistenceImpl<WikiPageResource>
069 implements WikiPageResourcePersistence {
070
075 public static final String FINDER_CLASS_NAME_ENTITY = WikiPageResourceImpl.class.getName();
076 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077 ".List1";
078 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079 ".List2";
080 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
081 WikiPageResourceModelImpl.FINDER_CACHE_ENABLED,
082 WikiPageResourceImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
083 "findByUuid",
084 new String[] {
085 String.class.getName(),
086
087 "java.lang.Integer", "java.lang.Integer",
088 "com.liferay.portal.kernel.util.OrderByComparator"
089 });
090 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
091 WikiPageResourceModelImpl.FINDER_CACHE_ENABLED,
092 WikiPageResourceImpl.class,
093 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
094 new String[] { String.class.getName() },
095 WikiPageResourceModelImpl.UUID_COLUMN_BITMASK);
096 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
097 WikiPageResourceModelImpl.FINDER_CACHE_ENABLED, Long.class,
098 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
099 new String[] { String.class.getName() });
100 public static final FinderPath FINDER_PATH_FETCH_BY_N_T = new FinderPath(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
101 WikiPageResourceModelImpl.FINDER_CACHE_ENABLED,
102 WikiPageResourceImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByN_T",
103 new String[] { Long.class.getName(), String.class.getName() },
104 WikiPageResourceModelImpl.NODEID_COLUMN_BITMASK |
105 WikiPageResourceModelImpl.TITLE_COLUMN_BITMASK);
106 public static final FinderPath FINDER_PATH_COUNT_BY_N_T = new FinderPath(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
107 WikiPageResourceModelImpl.FINDER_CACHE_ENABLED, Long.class,
108 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_T",
109 new String[] { Long.class.getName(), String.class.getName() });
110 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
111 WikiPageResourceModelImpl.FINDER_CACHE_ENABLED,
112 WikiPageResourceImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
113 "findAll", new String[0]);
114 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
115 WikiPageResourceModelImpl.FINDER_CACHE_ENABLED,
116 WikiPageResourceImpl.class,
117 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
118 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
119 WikiPageResourceModelImpl.FINDER_CACHE_ENABLED, Long.class,
120 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
121
122
127 public void cacheResult(WikiPageResource wikiPageResource) {
128 EntityCacheUtil.putResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
129 WikiPageResourceImpl.class, wikiPageResource.getPrimaryKey(),
130 wikiPageResource);
131
132 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T,
133 new Object[] {
134 Long.valueOf(wikiPageResource.getNodeId()),
135
136 wikiPageResource.getTitle()
137 }, wikiPageResource);
138
139 wikiPageResource.resetOriginalValues();
140 }
141
142
147 public void cacheResult(List<WikiPageResource> wikiPageResources) {
148 for (WikiPageResource wikiPageResource : wikiPageResources) {
149 if (EntityCacheUtil.getResult(
150 WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
151 WikiPageResourceImpl.class,
152 wikiPageResource.getPrimaryKey()) == null) {
153 cacheResult(wikiPageResource);
154 }
155 else {
156 wikiPageResource.resetOriginalValues();
157 }
158 }
159 }
160
161
168 @Override
169 public void clearCache() {
170 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
171 CacheRegistryUtil.clear(WikiPageResourceImpl.class.getName());
172 }
173
174 EntityCacheUtil.clearCache(WikiPageResourceImpl.class.getName());
175
176 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
177 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
178 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
179 }
180
181
188 @Override
189 public void clearCache(WikiPageResource wikiPageResource) {
190 EntityCacheUtil.removeResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
191 WikiPageResourceImpl.class, wikiPageResource.getPrimaryKey());
192
193 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
194 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
195
196 clearUniqueFindersCache(wikiPageResource);
197 }
198
199 @Override
200 public void clearCache(List<WikiPageResource> wikiPageResources) {
201 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
202 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
203
204 for (WikiPageResource wikiPageResource : wikiPageResources) {
205 EntityCacheUtil.removeResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
206 WikiPageResourceImpl.class, wikiPageResource.getPrimaryKey());
207
208 clearUniqueFindersCache(wikiPageResource);
209 }
210 }
211
212 protected void clearUniqueFindersCache(WikiPageResource wikiPageResource) {
213 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_T,
214 new Object[] {
215 Long.valueOf(wikiPageResource.getNodeId()),
216
217 wikiPageResource.getTitle()
218 });
219 }
220
221
227 public WikiPageResource create(long resourcePrimKey) {
228 WikiPageResource wikiPageResource = new WikiPageResourceImpl();
229
230 wikiPageResource.setNew(true);
231 wikiPageResource.setPrimaryKey(resourcePrimKey);
232
233 String uuid = PortalUUIDUtil.generate();
234
235 wikiPageResource.setUuid(uuid);
236
237 return wikiPageResource;
238 }
239
240
248 public WikiPageResource remove(long resourcePrimKey)
249 throws NoSuchPageResourceException, SystemException {
250 return remove(Long.valueOf(resourcePrimKey));
251 }
252
253
261 @Override
262 public WikiPageResource remove(Serializable primaryKey)
263 throws NoSuchPageResourceException, SystemException {
264 Session session = null;
265
266 try {
267 session = openSession();
268
269 WikiPageResource wikiPageResource = (WikiPageResource)session.get(WikiPageResourceImpl.class,
270 primaryKey);
271
272 if (wikiPageResource == null) {
273 if (_log.isWarnEnabled()) {
274 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
275 }
276
277 throw new NoSuchPageResourceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
278 primaryKey);
279 }
280
281 return remove(wikiPageResource);
282 }
283 catch (NoSuchPageResourceException nsee) {
284 throw nsee;
285 }
286 catch (Exception e) {
287 throw processException(e);
288 }
289 finally {
290 closeSession(session);
291 }
292 }
293
294 @Override
295 protected WikiPageResource removeImpl(WikiPageResource wikiPageResource)
296 throws SystemException {
297 wikiPageResource = toUnwrappedModel(wikiPageResource);
298
299 Session session = null;
300
301 try {
302 session = openSession();
303
304 BatchSessionUtil.delete(session, wikiPageResource);
305 }
306 catch (Exception e) {
307 throw processException(e);
308 }
309 finally {
310 closeSession(session);
311 }
312
313 clearCache(wikiPageResource);
314
315 return wikiPageResource;
316 }
317
318 @Override
319 public WikiPageResource updateImpl(
320 com.liferay.portlet.wiki.model.WikiPageResource wikiPageResource,
321 boolean merge) throws SystemException {
322 wikiPageResource = toUnwrappedModel(wikiPageResource);
323
324 boolean isNew = wikiPageResource.isNew();
325
326 WikiPageResourceModelImpl wikiPageResourceModelImpl = (WikiPageResourceModelImpl)wikiPageResource;
327
328 if (Validator.isNull(wikiPageResource.getUuid())) {
329 String uuid = PortalUUIDUtil.generate();
330
331 wikiPageResource.setUuid(uuid);
332 }
333
334 Session session = null;
335
336 try {
337 session = openSession();
338
339 BatchSessionUtil.update(session, wikiPageResource, merge);
340
341 wikiPageResource.setNew(false);
342 }
343 catch (Exception e) {
344 throw processException(e);
345 }
346 finally {
347 closeSession(session);
348 }
349
350 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
351
352 if (isNew || !WikiPageResourceModelImpl.COLUMN_BITMASK_ENABLED) {
353 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
354 }
355
356 else {
357 if ((wikiPageResourceModelImpl.getColumnBitmask() &
358 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
359 Object[] args = new Object[] {
360 wikiPageResourceModelImpl.getOriginalUuid()
361 };
362
363 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
364 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
365 args);
366
367 args = new Object[] { wikiPageResourceModelImpl.getUuid() };
368
369 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
370 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
371 args);
372 }
373 }
374
375 EntityCacheUtil.putResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
376 WikiPageResourceImpl.class, wikiPageResource.getPrimaryKey(),
377 wikiPageResource);
378
379 if (isNew) {
380 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T,
381 new Object[] {
382 Long.valueOf(wikiPageResource.getNodeId()),
383
384 wikiPageResource.getTitle()
385 }, wikiPageResource);
386 }
387 else {
388 if ((wikiPageResourceModelImpl.getColumnBitmask() &
389 FINDER_PATH_FETCH_BY_N_T.getColumnBitmask()) != 0) {
390 Object[] args = new Object[] {
391 Long.valueOf(wikiPageResourceModelImpl.getOriginalNodeId()),
392
393 wikiPageResourceModelImpl.getOriginalTitle()
394 };
395
396 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T, args);
397
398 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_T, args);
399
400 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T,
401 new Object[] {
402 Long.valueOf(wikiPageResource.getNodeId()),
403
404 wikiPageResource.getTitle()
405 }, wikiPageResource);
406 }
407 }
408
409 return wikiPageResource;
410 }
411
412 protected WikiPageResource toUnwrappedModel(
413 WikiPageResource wikiPageResource) {
414 if (wikiPageResource instanceof WikiPageResourceImpl) {
415 return wikiPageResource;
416 }
417
418 WikiPageResourceImpl wikiPageResourceImpl = new WikiPageResourceImpl();
419
420 wikiPageResourceImpl.setNew(wikiPageResource.isNew());
421 wikiPageResourceImpl.setPrimaryKey(wikiPageResource.getPrimaryKey());
422
423 wikiPageResourceImpl.setUuid(wikiPageResource.getUuid());
424 wikiPageResourceImpl.setResourcePrimKey(wikiPageResource.getResourcePrimKey());
425 wikiPageResourceImpl.setNodeId(wikiPageResource.getNodeId());
426 wikiPageResourceImpl.setTitle(wikiPageResource.getTitle());
427
428 return wikiPageResourceImpl;
429 }
430
431
439 @Override
440 public WikiPageResource findByPrimaryKey(Serializable primaryKey)
441 throws NoSuchModelException, SystemException {
442 return findByPrimaryKey(((Long)primaryKey).longValue());
443 }
444
445
453 public WikiPageResource findByPrimaryKey(long resourcePrimKey)
454 throws NoSuchPageResourceException, SystemException {
455 WikiPageResource wikiPageResource = fetchByPrimaryKey(resourcePrimKey);
456
457 if (wikiPageResource == null) {
458 if (_log.isWarnEnabled()) {
459 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + resourcePrimKey);
460 }
461
462 throw new NoSuchPageResourceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
463 resourcePrimKey);
464 }
465
466 return wikiPageResource;
467 }
468
469
476 @Override
477 public WikiPageResource fetchByPrimaryKey(Serializable primaryKey)
478 throws SystemException {
479 return fetchByPrimaryKey(((Long)primaryKey).longValue());
480 }
481
482
489 public WikiPageResource fetchByPrimaryKey(long resourcePrimKey)
490 throws SystemException {
491 WikiPageResource wikiPageResource = (WikiPageResource)EntityCacheUtil.getResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
492 WikiPageResourceImpl.class, resourcePrimKey);
493
494 if (wikiPageResource == _nullWikiPageResource) {
495 return null;
496 }
497
498 if (wikiPageResource == null) {
499 Session session = null;
500
501 boolean hasException = false;
502
503 try {
504 session = openSession();
505
506 wikiPageResource = (WikiPageResource)session.get(WikiPageResourceImpl.class,
507 Long.valueOf(resourcePrimKey));
508 }
509 catch (Exception e) {
510 hasException = true;
511
512 throw processException(e);
513 }
514 finally {
515 if (wikiPageResource != null) {
516 cacheResult(wikiPageResource);
517 }
518 else if (!hasException) {
519 EntityCacheUtil.putResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
520 WikiPageResourceImpl.class, resourcePrimKey,
521 _nullWikiPageResource);
522 }
523
524 closeSession(session);
525 }
526 }
527
528 return wikiPageResource;
529 }
530
531
538 public List<WikiPageResource> findByUuid(String uuid)
539 throws SystemException {
540 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
541 }
542
543
556 public List<WikiPageResource> findByUuid(String uuid, int start, int end)
557 throws SystemException {
558 return findByUuid(uuid, start, end, null);
559 }
560
561
575 public List<WikiPageResource> findByUuid(String uuid, int start, int end,
576 OrderByComparator orderByComparator) throws SystemException {
577 FinderPath finderPath = null;
578 Object[] finderArgs = null;
579
580 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
581 (orderByComparator == null)) {
582 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
583 finderArgs = new Object[] { uuid };
584 }
585 else {
586 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
587 finderArgs = new Object[] { uuid, start, end, orderByComparator };
588 }
589
590 List<WikiPageResource> list = (List<WikiPageResource>)FinderCacheUtil.getResult(finderPath,
591 finderArgs, this);
592
593 if ((list != null) && !list.isEmpty()) {
594 for (WikiPageResource wikiPageResource : list) {
595 if (!Validator.equals(uuid, wikiPageResource.getUuid())) {
596 list = null;
597
598 break;
599 }
600 }
601 }
602
603 if (list == null) {
604 StringBundler query = null;
605
606 if (orderByComparator != null) {
607 query = new StringBundler(3 +
608 (orderByComparator.getOrderByFields().length * 3));
609 }
610 else {
611 query = new StringBundler(2);
612 }
613
614 query.append(_SQL_SELECT_WIKIPAGERESOURCE_WHERE);
615
616 if (uuid == null) {
617 query.append(_FINDER_COLUMN_UUID_UUID_1);
618 }
619 else {
620 if (uuid.equals(StringPool.BLANK)) {
621 query.append(_FINDER_COLUMN_UUID_UUID_3);
622 }
623 else {
624 query.append(_FINDER_COLUMN_UUID_UUID_2);
625 }
626 }
627
628 if (orderByComparator != null) {
629 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
630 orderByComparator);
631 }
632
633 String sql = query.toString();
634
635 Session session = null;
636
637 try {
638 session = openSession();
639
640 Query q = session.createQuery(sql);
641
642 QueryPos qPos = QueryPos.getInstance(q);
643
644 if (uuid != null) {
645 qPos.add(uuid);
646 }
647
648 list = (List<WikiPageResource>)QueryUtil.list(q, getDialect(),
649 start, end);
650 }
651 catch (Exception e) {
652 throw processException(e);
653 }
654 finally {
655 if (list == null) {
656 FinderCacheUtil.removeResult(finderPath, finderArgs);
657 }
658 else {
659 cacheResult(list);
660
661 FinderCacheUtil.putResult(finderPath, finderArgs, list);
662 }
663
664 closeSession(session);
665 }
666 }
667
668 return list;
669 }
670
671
680 public WikiPageResource findByUuid_First(String uuid,
681 OrderByComparator orderByComparator)
682 throws NoSuchPageResourceException, SystemException {
683 WikiPageResource wikiPageResource = fetchByUuid_First(uuid,
684 orderByComparator);
685
686 if (wikiPageResource != null) {
687 return wikiPageResource;
688 }
689
690 StringBundler msg = new StringBundler(4);
691
692 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
693
694 msg.append("uuid=");
695 msg.append(uuid);
696
697 msg.append(StringPool.CLOSE_CURLY_BRACE);
698
699 throw new NoSuchPageResourceException(msg.toString());
700 }
701
702
710 public WikiPageResource fetchByUuid_First(String uuid,
711 OrderByComparator orderByComparator) throws SystemException {
712 List<WikiPageResource> list = findByUuid(uuid, 0, 1, orderByComparator);
713
714 if (!list.isEmpty()) {
715 return list.get(0);
716 }
717
718 return null;
719 }
720
721
730 public WikiPageResource findByUuid_Last(String uuid,
731 OrderByComparator orderByComparator)
732 throws NoSuchPageResourceException, SystemException {
733 WikiPageResource wikiPageResource = fetchByUuid_Last(uuid,
734 orderByComparator);
735
736 if (wikiPageResource != null) {
737 return wikiPageResource;
738 }
739
740 StringBundler msg = new StringBundler(4);
741
742 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
743
744 msg.append("uuid=");
745 msg.append(uuid);
746
747 msg.append(StringPool.CLOSE_CURLY_BRACE);
748
749 throw new NoSuchPageResourceException(msg.toString());
750 }
751
752
760 public WikiPageResource fetchByUuid_Last(String uuid,
761 OrderByComparator orderByComparator) throws SystemException {
762 int count = countByUuid(uuid);
763
764 List<WikiPageResource> list = findByUuid(uuid, count - 1, count,
765 orderByComparator);
766
767 if (!list.isEmpty()) {
768 return list.get(0);
769 }
770
771 return null;
772 }
773
774
784 public WikiPageResource[] findByUuid_PrevAndNext(long resourcePrimKey,
785 String uuid, OrderByComparator orderByComparator)
786 throws NoSuchPageResourceException, SystemException {
787 WikiPageResource wikiPageResource = findByPrimaryKey(resourcePrimKey);
788
789 Session session = null;
790
791 try {
792 session = openSession();
793
794 WikiPageResource[] array = new WikiPageResourceImpl[3];
795
796 array[0] = getByUuid_PrevAndNext(session, wikiPageResource, uuid,
797 orderByComparator, true);
798
799 array[1] = wikiPageResource;
800
801 array[2] = getByUuid_PrevAndNext(session, wikiPageResource, uuid,
802 orderByComparator, false);
803
804 return array;
805 }
806 catch (Exception e) {
807 throw processException(e);
808 }
809 finally {
810 closeSession(session);
811 }
812 }
813
814 protected WikiPageResource getByUuid_PrevAndNext(Session session,
815 WikiPageResource wikiPageResource, String uuid,
816 OrderByComparator orderByComparator, boolean previous) {
817 StringBundler query = null;
818
819 if (orderByComparator != null) {
820 query = new StringBundler(6 +
821 (orderByComparator.getOrderByFields().length * 6));
822 }
823 else {
824 query = new StringBundler(3);
825 }
826
827 query.append(_SQL_SELECT_WIKIPAGERESOURCE_WHERE);
828
829 if (uuid == null) {
830 query.append(_FINDER_COLUMN_UUID_UUID_1);
831 }
832 else {
833 if (uuid.equals(StringPool.BLANK)) {
834 query.append(_FINDER_COLUMN_UUID_UUID_3);
835 }
836 else {
837 query.append(_FINDER_COLUMN_UUID_UUID_2);
838 }
839 }
840
841 if (orderByComparator != null) {
842 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
843
844 if (orderByConditionFields.length > 0) {
845 query.append(WHERE_AND);
846 }
847
848 for (int i = 0; i < orderByConditionFields.length; i++) {
849 query.append(_ORDER_BY_ENTITY_ALIAS);
850 query.append(orderByConditionFields[i]);
851
852 if ((i + 1) < orderByConditionFields.length) {
853 if (orderByComparator.isAscending() ^ previous) {
854 query.append(WHERE_GREATER_THAN_HAS_NEXT);
855 }
856 else {
857 query.append(WHERE_LESSER_THAN_HAS_NEXT);
858 }
859 }
860 else {
861 if (orderByComparator.isAscending() ^ previous) {
862 query.append(WHERE_GREATER_THAN);
863 }
864 else {
865 query.append(WHERE_LESSER_THAN);
866 }
867 }
868 }
869
870 query.append(ORDER_BY_CLAUSE);
871
872 String[] orderByFields = orderByComparator.getOrderByFields();
873
874 for (int i = 0; i < orderByFields.length; i++) {
875 query.append(_ORDER_BY_ENTITY_ALIAS);
876 query.append(orderByFields[i]);
877
878 if ((i + 1) < orderByFields.length) {
879 if (orderByComparator.isAscending() ^ previous) {
880 query.append(ORDER_BY_ASC_HAS_NEXT);
881 }
882 else {
883 query.append(ORDER_BY_DESC_HAS_NEXT);
884 }
885 }
886 else {
887 if (orderByComparator.isAscending() ^ previous) {
888 query.append(ORDER_BY_ASC);
889 }
890 else {
891 query.append(ORDER_BY_DESC);
892 }
893 }
894 }
895 }
896
897 String sql = query.toString();
898
899 Query q = session.createQuery(sql);
900
901 q.setFirstResult(0);
902 q.setMaxResults(2);
903
904 QueryPos qPos = QueryPos.getInstance(q);
905
906 if (uuid != null) {
907 qPos.add(uuid);
908 }
909
910 if (orderByComparator != null) {
911 Object[] values = orderByComparator.getOrderByConditionValues(wikiPageResource);
912
913 for (Object value : values) {
914 qPos.add(value);
915 }
916 }
917
918 List<WikiPageResource> list = q.list();
919
920 if (list.size() == 2) {
921 return list.get(1);
922 }
923 else {
924 return null;
925 }
926 }
927
928
937 public WikiPageResource findByN_T(long nodeId, String title)
938 throws NoSuchPageResourceException, SystemException {
939 WikiPageResource wikiPageResource = fetchByN_T(nodeId, title);
940
941 if (wikiPageResource == null) {
942 StringBundler msg = new StringBundler(6);
943
944 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
945
946 msg.append("nodeId=");
947 msg.append(nodeId);
948
949 msg.append(", title=");
950 msg.append(title);
951
952 msg.append(StringPool.CLOSE_CURLY_BRACE);
953
954 if (_log.isWarnEnabled()) {
955 _log.warn(msg.toString());
956 }
957
958 throw new NoSuchPageResourceException(msg.toString());
959 }
960
961 return wikiPageResource;
962 }
963
964
972 public WikiPageResource fetchByN_T(long nodeId, String title)
973 throws SystemException {
974 return fetchByN_T(nodeId, title, true);
975 }
976
977
986 public WikiPageResource fetchByN_T(long nodeId, String title,
987 boolean retrieveFromCache) throws SystemException {
988 Object[] finderArgs = new Object[] { nodeId, title };
989
990 Object result = null;
991
992 if (retrieveFromCache) {
993 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_N_T,
994 finderArgs, this);
995 }
996
997 if (result instanceof WikiPageResource) {
998 WikiPageResource wikiPageResource = (WikiPageResource)result;
999
1000 if ((nodeId != wikiPageResource.getNodeId()) ||
1001 !Validator.equals(title, wikiPageResource.getTitle())) {
1002 result = null;
1003 }
1004 }
1005
1006 if (result == null) {
1007 StringBundler query = new StringBundler(3);
1008
1009 query.append(_SQL_SELECT_WIKIPAGERESOURCE_WHERE);
1010
1011 query.append(_FINDER_COLUMN_N_T_NODEID_2);
1012
1013 if (title == null) {
1014 query.append(_FINDER_COLUMN_N_T_TITLE_1);
1015 }
1016 else {
1017 if (title.equals(StringPool.BLANK)) {
1018 query.append(_FINDER_COLUMN_N_T_TITLE_3);
1019 }
1020 else {
1021 query.append(_FINDER_COLUMN_N_T_TITLE_2);
1022 }
1023 }
1024
1025 String sql = query.toString();
1026
1027 Session session = null;
1028
1029 try {
1030 session = openSession();
1031
1032 Query q = session.createQuery(sql);
1033
1034 QueryPos qPos = QueryPos.getInstance(q);
1035
1036 qPos.add(nodeId);
1037
1038 if (title != null) {
1039 qPos.add(title);
1040 }
1041
1042 List<WikiPageResource> list = q.list();
1043
1044 result = list;
1045
1046 WikiPageResource wikiPageResource = null;
1047
1048 if (list.isEmpty()) {
1049 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T,
1050 finderArgs, list);
1051 }
1052 else {
1053 wikiPageResource = list.get(0);
1054
1055 cacheResult(wikiPageResource);
1056
1057 if ((wikiPageResource.getNodeId() != nodeId) ||
1058 (wikiPageResource.getTitle() == null) ||
1059 !wikiPageResource.getTitle().equals(title)) {
1060 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T,
1061 finderArgs, wikiPageResource);
1062 }
1063 }
1064
1065 return wikiPageResource;
1066 }
1067 catch (Exception e) {
1068 throw processException(e);
1069 }
1070 finally {
1071 if (result == null) {
1072 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_T,
1073 finderArgs);
1074 }
1075
1076 closeSession(session);
1077 }
1078 }
1079 else {
1080 if (result instanceof List<?>) {
1081 return null;
1082 }
1083 else {
1084 return (WikiPageResource)result;
1085 }
1086 }
1087 }
1088
1089
1095 public List<WikiPageResource> findAll() throws SystemException {
1096 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1097 }
1098
1099
1111 public List<WikiPageResource> findAll(int start, int end)
1112 throws SystemException {
1113 return findAll(start, end, null);
1114 }
1115
1116
1129 public List<WikiPageResource> findAll(int start, int end,
1130 OrderByComparator orderByComparator) throws SystemException {
1131 FinderPath finderPath = null;
1132 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1133
1134 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1135 (orderByComparator == null)) {
1136 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1137 finderArgs = FINDER_ARGS_EMPTY;
1138 }
1139 else {
1140 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1141 finderArgs = new Object[] { start, end, orderByComparator };
1142 }
1143
1144 List<WikiPageResource> list = (List<WikiPageResource>)FinderCacheUtil.getResult(finderPath,
1145 finderArgs, this);
1146
1147 if (list == null) {
1148 StringBundler query = null;
1149 String sql = null;
1150
1151 if (orderByComparator != null) {
1152 query = new StringBundler(2 +
1153 (orderByComparator.getOrderByFields().length * 3));
1154
1155 query.append(_SQL_SELECT_WIKIPAGERESOURCE);
1156
1157 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1158 orderByComparator);
1159
1160 sql = query.toString();
1161 }
1162 else {
1163 sql = _SQL_SELECT_WIKIPAGERESOURCE;
1164 }
1165
1166 Session session = null;
1167
1168 try {
1169 session = openSession();
1170
1171 Query q = session.createQuery(sql);
1172
1173 if (orderByComparator == null) {
1174 list = (List<WikiPageResource>)QueryUtil.list(q,
1175 getDialect(), start, end, false);
1176
1177 Collections.sort(list);
1178 }
1179 else {
1180 list = (List<WikiPageResource>)QueryUtil.list(q,
1181 getDialect(), start, end);
1182 }
1183 }
1184 catch (Exception e) {
1185 throw processException(e);
1186 }
1187 finally {
1188 if (list == null) {
1189 FinderCacheUtil.removeResult(finderPath, finderArgs);
1190 }
1191 else {
1192 cacheResult(list);
1193
1194 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1195 }
1196
1197 closeSession(session);
1198 }
1199 }
1200
1201 return list;
1202 }
1203
1204
1210 public void removeByUuid(String uuid) throws SystemException {
1211 for (WikiPageResource wikiPageResource : findByUuid(uuid)) {
1212 remove(wikiPageResource);
1213 }
1214 }
1215
1216
1224 public WikiPageResource removeByN_T(long nodeId, String title)
1225 throws NoSuchPageResourceException, SystemException {
1226 WikiPageResource wikiPageResource = findByN_T(nodeId, title);
1227
1228 return remove(wikiPageResource);
1229 }
1230
1231
1236 public void removeAll() throws SystemException {
1237 for (WikiPageResource wikiPageResource : findAll()) {
1238 remove(wikiPageResource);
1239 }
1240 }
1241
1242
1249 public int countByUuid(String uuid) throws SystemException {
1250 Object[] finderArgs = new Object[] { uuid };
1251
1252 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1253 finderArgs, this);
1254
1255 if (count == null) {
1256 StringBundler query = new StringBundler(2);
1257
1258 query.append(_SQL_COUNT_WIKIPAGERESOURCE_WHERE);
1259
1260 if (uuid == null) {
1261 query.append(_FINDER_COLUMN_UUID_UUID_1);
1262 }
1263 else {
1264 if (uuid.equals(StringPool.BLANK)) {
1265 query.append(_FINDER_COLUMN_UUID_UUID_3);
1266 }
1267 else {
1268 query.append(_FINDER_COLUMN_UUID_UUID_2);
1269 }
1270 }
1271
1272 String sql = query.toString();
1273
1274 Session session = null;
1275
1276 try {
1277 session = openSession();
1278
1279 Query q = session.createQuery(sql);
1280
1281 QueryPos qPos = QueryPos.getInstance(q);
1282
1283 if (uuid != null) {
1284 qPos.add(uuid);
1285 }
1286
1287 count = (Long)q.uniqueResult();
1288 }
1289 catch (Exception e) {
1290 throw processException(e);
1291 }
1292 finally {
1293 if (count == null) {
1294 count = Long.valueOf(0);
1295 }
1296
1297 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
1298 finderArgs, count);
1299
1300 closeSession(session);
1301 }
1302 }
1303
1304 return count.intValue();
1305 }
1306
1307
1315 public int countByN_T(long nodeId, String title) throws SystemException {
1316 Object[] finderArgs = new Object[] { nodeId, title };
1317
1318 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_N_T,
1319 finderArgs, this);
1320
1321 if (count == null) {
1322 StringBundler query = new StringBundler(3);
1323
1324 query.append(_SQL_COUNT_WIKIPAGERESOURCE_WHERE);
1325
1326 query.append(_FINDER_COLUMN_N_T_NODEID_2);
1327
1328 if (title == null) {
1329 query.append(_FINDER_COLUMN_N_T_TITLE_1);
1330 }
1331 else {
1332 if (title.equals(StringPool.BLANK)) {
1333 query.append(_FINDER_COLUMN_N_T_TITLE_3);
1334 }
1335 else {
1336 query.append(_FINDER_COLUMN_N_T_TITLE_2);
1337 }
1338 }
1339
1340 String sql = query.toString();
1341
1342 Session session = null;
1343
1344 try {
1345 session = openSession();
1346
1347 Query q = session.createQuery(sql);
1348
1349 QueryPos qPos = QueryPos.getInstance(q);
1350
1351 qPos.add(nodeId);
1352
1353 if (title != null) {
1354 qPos.add(title);
1355 }
1356
1357 count = (Long)q.uniqueResult();
1358 }
1359 catch (Exception e) {
1360 throw processException(e);
1361 }
1362 finally {
1363 if (count == null) {
1364 count = Long.valueOf(0);
1365 }
1366
1367 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_T, finderArgs,
1368 count);
1369
1370 closeSession(session);
1371 }
1372 }
1373
1374 return count.intValue();
1375 }
1376
1377
1383 public int countAll() throws SystemException {
1384 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1385 FINDER_ARGS_EMPTY, this);
1386
1387 if (count == null) {
1388 Session session = null;
1389
1390 try {
1391 session = openSession();
1392
1393 Query q = session.createQuery(_SQL_COUNT_WIKIPAGERESOURCE);
1394
1395 count = (Long)q.uniqueResult();
1396 }
1397 catch (Exception e) {
1398 throw processException(e);
1399 }
1400 finally {
1401 if (count == null) {
1402 count = Long.valueOf(0);
1403 }
1404
1405 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1406 FINDER_ARGS_EMPTY, count);
1407
1408 closeSession(session);
1409 }
1410 }
1411
1412 return count.intValue();
1413 }
1414
1415
1418 public void afterPropertiesSet() {
1419 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1420 com.liferay.portal.util.PropsUtil.get(
1421 "value.object.listener.com.liferay.portlet.wiki.model.WikiPageResource")));
1422
1423 if (listenerClassNames.length > 0) {
1424 try {
1425 List<ModelListener<WikiPageResource>> listenersList = new ArrayList<ModelListener<WikiPageResource>>();
1426
1427 for (String listenerClassName : listenerClassNames) {
1428 listenersList.add((ModelListener<WikiPageResource>)InstanceFactory.newInstance(
1429 listenerClassName));
1430 }
1431
1432 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1433 }
1434 catch (Exception e) {
1435 _log.error(e);
1436 }
1437 }
1438 }
1439
1440 public void destroy() {
1441 EntityCacheUtil.removeCache(WikiPageResourceImpl.class.getName());
1442 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1443 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1444 }
1445
1446 @BeanReference(type = WikiNodePersistence.class)
1447 protected WikiNodePersistence wikiNodePersistence;
1448 @BeanReference(type = WikiPagePersistence.class)
1449 protected WikiPagePersistence wikiPagePersistence;
1450 @BeanReference(type = WikiPageResourcePersistence.class)
1451 protected WikiPageResourcePersistence wikiPageResourcePersistence;
1452 @BeanReference(type = ResourcePersistence.class)
1453 protected ResourcePersistence resourcePersistence;
1454 @BeanReference(type = UserPersistence.class)
1455 protected UserPersistence userPersistence;
1456 private static final String _SQL_SELECT_WIKIPAGERESOURCE = "SELECT wikiPageResource FROM WikiPageResource wikiPageResource";
1457 private static final String _SQL_SELECT_WIKIPAGERESOURCE_WHERE = "SELECT wikiPageResource FROM WikiPageResource wikiPageResource WHERE ";
1458 private static final String _SQL_COUNT_WIKIPAGERESOURCE = "SELECT COUNT(wikiPageResource) FROM WikiPageResource wikiPageResource";
1459 private static final String _SQL_COUNT_WIKIPAGERESOURCE_WHERE = "SELECT COUNT(wikiPageResource) FROM WikiPageResource wikiPageResource WHERE ";
1460 private static final String _FINDER_COLUMN_UUID_UUID_1 = "wikiPageResource.uuid IS NULL";
1461 private static final String _FINDER_COLUMN_UUID_UUID_2 = "wikiPageResource.uuid = ?";
1462 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(wikiPageResource.uuid IS NULL OR wikiPageResource.uuid = ?)";
1463 private static final String _FINDER_COLUMN_N_T_NODEID_2 = "wikiPageResource.nodeId = ? AND ";
1464 private static final String _FINDER_COLUMN_N_T_TITLE_1 = "wikiPageResource.title IS NULL";
1465 private static final String _FINDER_COLUMN_N_T_TITLE_2 = "wikiPageResource.title = ?";
1466 private static final String _FINDER_COLUMN_N_T_TITLE_3 = "(wikiPageResource.title IS NULL OR wikiPageResource.title = ?)";
1467 private static final String _ORDER_BY_ENTITY_ALIAS = "wikiPageResource.";
1468 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No WikiPageResource exists with the primary key ";
1469 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No WikiPageResource exists with the key {";
1470 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1471 private static Log _log = LogFactoryUtil.getLog(WikiPageResourcePersistenceImpl.class);
1472 private static WikiPageResource _nullWikiPageResource = new WikiPageResourceImpl() {
1473 @Override
1474 public Object clone() {
1475 return this;
1476 }
1477
1478 @Override
1479 public CacheModel<WikiPageResource> toCacheModel() {
1480 return _nullWikiPageResourceCacheModel;
1481 }
1482 };
1483
1484 private static CacheModel<WikiPageResource> _nullWikiPageResourceCacheModel = new CacheModel<WikiPageResource>() {
1485 public WikiPageResource toEntityModel() {
1486 return _nullWikiPageResource;
1487 }
1488 };
1489 }