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,
113 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "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, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
117 "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 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_T,
197 new Object[] {
198 Long.valueOf(wikiPageResource.getNodeId()),
199
200 wikiPageResource.getTitle()
201 });
202 }
203
204
210 public WikiPageResource create(long resourcePrimKey) {
211 WikiPageResource wikiPageResource = new WikiPageResourceImpl();
212
213 wikiPageResource.setNew(true);
214 wikiPageResource.setPrimaryKey(resourcePrimKey);
215
216 String uuid = PortalUUIDUtil.generate();
217
218 wikiPageResource.setUuid(uuid);
219
220 return wikiPageResource;
221 }
222
223
231 @Override
232 public WikiPageResource remove(Serializable primaryKey)
233 throws NoSuchModelException, SystemException {
234 return remove(((Long)primaryKey).longValue());
235 }
236
237
245 public WikiPageResource remove(long resourcePrimKey)
246 throws NoSuchPageResourceException, SystemException {
247 Session session = null;
248
249 try {
250 session = openSession();
251
252 WikiPageResource wikiPageResource = (WikiPageResource)session.get(WikiPageResourceImpl.class,
253 Long.valueOf(resourcePrimKey));
254
255 if (wikiPageResource == null) {
256 if (_log.isWarnEnabled()) {
257 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
258 resourcePrimKey);
259 }
260
261 throw new NoSuchPageResourceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
262 resourcePrimKey);
263 }
264
265 return wikiPageResourcePersistence.remove(wikiPageResource);
266 }
267 catch (NoSuchPageResourceException nsee) {
268 throw nsee;
269 }
270 catch (Exception e) {
271 throw processException(e);
272 }
273 finally {
274 closeSession(session);
275 }
276 }
277
278
285 @Override
286 public WikiPageResource remove(WikiPageResource wikiPageResource)
287 throws SystemException {
288 return super.remove(wikiPageResource);
289 }
290
291 @Override
292 protected WikiPageResource removeImpl(WikiPageResource wikiPageResource)
293 throws SystemException {
294 wikiPageResource = toUnwrappedModel(wikiPageResource);
295
296 Session session = null;
297
298 try {
299 session = openSession();
300
301 BatchSessionUtil.delete(session, wikiPageResource);
302 }
303 catch (Exception e) {
304 throw processException(e);
305 }
306 finally {
307 closeSession(session);
308 }
309
310 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
311 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
312
313 WikiPageResourceModelImpl wikiPageResourceModelImpl = (WikiPageResourceModelImpl)wikiPageResource;
314
315 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_T,
316 new Object[] {
317 Long.valueOf(wikiPageResourceModelImpl.getNodeId()),
318
319 wikiPageResourceModelImpl.getTitle()
320 });
321
322 EntityCacheUtil.removeResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
323 WikiPageResourceImpl.class, wikiPageResource.getPrimaryKey());
324
325 return wikiPageResource;
326 }
327
328 @Override
329 public WikiPageResource updateImpl(
330 com.liferay.portlet.wiki.model.WikiPageResource wikiPageResource,
331 boolean merge) throws SystemException {
332 wikiPageResource = toUnwrappedModel(wikiPageResource);
333
334 boolean isNew = wikiPageResource.isNew();
335
336 WikiPageResourceModelImpl wikiPageResourceModelImpl = (WikiPageResourceModelImpl)wikiPageResource;
337
338 if (Validator.isNull(wikiPageResource.getUuid())) {
339 String uuid = PortalUUIDUtil.generate();
340
341 wikiPageResource.setUuid(uuid);
342 }
343
344 Session session = null;
345
346 try {
347 session = openSession();
348
349 BatchSessionUtil.update(session, wikiPageResource, merge);
350
351 wikiPageResource.setNew(false);
352 }
353 catch (Exception e) {
354 throw processException(e);
355 }
356 finally {
357 closeSession(session);
358 }
359
360 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
361
362 if (isNew || !WikiPageResourceModelImpl.COLUMN_BITMASK_ENABLED) {
363 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
364 }
365
366 else {
367 if ((wikiPageResourceModelImpl.getColumnBitmask() &
368 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
369 Object[] args = new Object[] {
370 wikiPageResourceModelImpl.getOriginalUuid()
371 };
372
373 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
374 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
375 args);
376
377 args = new Object[] { wikiPageResourceModelImpl.getUuid() };
378
379 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
380 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
381 args);
382 }
383 }
384
385 EntityCacheUtil.putResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
386 WikiPageResourceImpl.class, wikiPageResource.getPrimaryKey(),
387 wikiPageResource);
388
389 if (isNew) {
390 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T,
391 new Object[] {
392 Long.valueOf(wikiPageResource.getNodeId()),
393
394 wikiPageResource.getTitle()
395 }, wikiPageResource);
396 }
397 else {
398 if ((wikiPageResourceModelImpl.getColumnBitmask() &
399 FINDER_PATH_FETCH_BY_N_T.getColumnBitmask()) != 0) {
400 Object[] args = new Object[] {
401 Long.valueOf(wikiPageResourceModelImpl.getOriginalNodeId()),
402
403 wikiPageResourceModelImpl.getOriginalTitle()
404 };
405
406 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T, args);
407 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_T, args);
408
409 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T,
410 new Object[] {
411 Long.valueOf(wikiPageResource.getNodeId()),
412
413 wikiPageResource.getTitle()
414 }, wikiPageResource);
415 }
416 }
417
418 return wikiPageResource;
419 }
420
421 protected WikiPageResource toUnwrappedModel(
422 WikiPageResource wikiPageResource) {
423 if (wikiPageResource instanceof WikiPageResourceImpl) {
424 return wikiPageResource;
425 }
426
427 WikiPageResourceImpl wikiPageResourceImpl = new WikiPageResourceImpl();
428
429 wikiPageResourceImpl.setNew(wikiPageResource.isNew());
430 wikiPageResourceImpl.setPrimaryKey(wikiPageResource.getPrimaryKey());
431
432 wikiPageResourceImpl.setUuid(wikiPageResource.getUuid());
433 wikiPageResourceImpl.setResourcePrimKey(wikiPageResource.getResourcePrimKey());
434 wikiPageResourceImpl.setNodeId(wikiPageResource.getNodeId());
435 wikiPageResourceImpl.setTitle(wikiPageResource.getTitle());
436
437 return wikiPageResourceImpl;
438 }
439
440
448 @Override
449 public WikiPageResource findByPrimaryKey(Serializable primaryKey)
450 throws NoSuchModelException, SystemException {
451 return findByPrimaryKey(((Long)primaryKey).longValue());
452 }
453
454
462 public WikiPageResource findByPrimaryKey(long resourcePrimKey)
463 throws NoSuchPageResourceException, SystemException {
464 WikiPageResource wikiPageResource = fetchByPrimaryKey(resourcePrimKey);
465
466 if (wikiPageResource == null) {
467 if (_log.isWarnEnabled()) {
468 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + resourcePrimKey);
469 }
470
471 throw new NoSuchPageResourceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
472 resourcePrimKey);
473 }
474
475 return wikiPageResource;
476 }
477
478
485 @Override
486 public WikiPageResource fetchByPrimaryKey(Serializable primaryKey)
487 throws SystemException {
488 return fetchByPrimaryKey(((Long)primaryKey).longValue());
489 }
490
491
498 public WikiPageResource fetchByPrimaryKey(long resourcePrimKey)
499 throws SystemException {
500 WikiPageResource wikiPageResource = (WikiPageResource)EntityCacheUtil.getResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
501 WikiPageResourceImpl.class, resourcePrimKey);
502
503 if (wikiPageResource == _nullWikiPageResource) {
504 return null;
505 }
506
507 if (wikiPageResource == null) {
508 Session session = null;
509
510 boolean hasException = false;
511
512 try {
513 session = openSession();
514
515 wikiPageResource = (WikiPageResource)session.get(WikiPageResourceImpl.class,
516 Long.valueOf(resourcePrimKey));
517 }
518 catch (Exception e) {
519 hasException = true;
520
521 throw processException(e);
522 }
523 finally {
524 if (wikiPageResource != null) {
525 cacheResult(wikiPageResource);
526 }
527 else if (!hasException) {
528 EntityCacheUtil.putResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
529 WikiPageResourceImpl.class, resourcePrimKey,
530 _nullWikiPageResource);
531 }
532
533 closeSession(session);
534 }
535 }
536
537 return wikiPageResource;
538 }
539
540
547 public List<WikiPageResource> findByUuid(String uuid)
548 throws SystemException {
549 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
550 }
551
552
565 public List<WikiPageResource> findByUuid(String uuid, int start, int end)
566 throws SystemException {
567 return findByUuid(uuid, start, end, null);
568 }
569
570
584 public List<WikiPageResource> findByUuid(String uuid, int start, int end,
585 OrderByComparator orderByComparator) throws SystemException {
586 FinderPath finderPath = null;
587 Object[] finderArgs = null;
588
589 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
590 (orderByComparator == null)) {
591 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
592 finderArgs = new Object[] { uuid };
593 }
594 else {
595 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
596 finderArgs = new Object[] { uuid, start, end, orderByComparator };
597 }
598
599 List<WikiPageResource> list = (List<WikiPageResource>)FinderCacheUtil.getResult(finderPath,
600 finderArgs, this);
601
602 if (list == null) {
603 StringBundler query = null;
604
605 if (orderByComparator != null) {
606 query = new StringBundler(3 +
607 (orderByComparator.getOrderByFields().length * 3));
608 }
609 else {
610 query = new StringBundler(2);
611 }
612
613 query.append(_SQL_SELECT_WIKIPAGERESOURCE_WHERE);
614
615 if (uuid == null) {
616 query.append(_FINDER_COLUMN_UUID_UUID_1);
617 }
618 else {
619 if (uuid.equals(StringPool.BLANK)) {
620 query.append(_FINDER_COLUMN_UUID_UUID_3);
621 }
622 else {
623 query.append(_FINDER_COLUMN_UUID_UUID_2);
624 }
625 }
626
627 if (orderByComparator != null) {
628 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
629 orderByComparator);
630 }
631
632 String sql = query.toString();
633
634 Session session = null;
635
636 try {
637 session = openSession();
638
639 Query q = session.createQuery(sql);
640
641 QueryPos qPos = QueryPos.getInstance(q);
642
643 if (uuid != null) {
644 qPos.add(uuid);
645 }
646
647 list = (List<WikiPageResource>)QueryUtil.list(q, getDialect(),
648 start, end);
649 }
650 catch (Exception e) {
651 throw processException(e);
652 }
653 finally {
654 if (list == null) {
655 FinderCacheUtil.removeResult(finderPath, finderArgs);
656 }
657 else {
658 cacheResult(list);
659
660 FinderCacheUtil.putResult(finderPath, finderArgs, list);
661 }
662
663 closeSession(session);
664 }
665 }
666
667 return list;
668 }
669
670
683 public WikiPageResource findByUuid_First(String uuid,
684 OrderByComparator orderByComparator)
685 throws NoSuchPageResourceException, SystemException {
686 List<WikiPageResource> list = findByUuid(uuid, 0, 1, orderByComparator);
687
688 if (list.isEmpty()) {
689 StringBundler msg = new StringBundler(4);
690
691 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
692
693 msg.append("uuid=");
694 msg.append(uuid);
695
696 msg.append(StringPool.CLOSE_CURLY_BRACE);
697
698 throw new NoSuchPageResourceException(msg.toString());
699 }
700 else {
701 return list.get(0);
702 }
703 }
704
705
718 public WikiPageResource findByUuid_Last(String uuid,
719 OrderByComparator orderByComparator)
720 throws NoSuchPageResourceException, SystemException {
721 int count = countByUuid(uuid);
722
723 List<WikiPageResource> list = findByUuid(uuid, count - 1, count,
724 orderByComparator);
725
726 if (list.isEmpty()) {
727 StringBundler msg = new StringBundler(4);
728
729 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
730
731 msg.append("uuid=");
732 msg.append(uuid);
733
734 msg.append(StringPool.CLOSE_CURLY_BRACE);
735
736 throw new NoSuchPageResourceException(msg.toString());
737 }
738 else {
739 return list.get(0);
740 }
741 }
742
743
757 public WikiPageResource[] findByUuid_PrevAndNext(long resourcePrimKey,
758 String uuid, OrderByComparator orderByComparator)
759 throws NoSuchPageResourceException, SystemException {
760 WikiPageResource wikiPageResource = findByPrimaryKey(resourcePrimKey);
761
762 Session session = null;
763
764 try {
765 session = openSession();
766
767 WikiPageResource[] array = new WikiPageResourceImpl[3];
768
769 array[0] = getByUuid_PrevAndNext(session, wikiPageResource, uuid,
770 orderByComparator, true);
771
772 array[1] = wikiPageResource;
773
774 array[2] = getByUuid_PrevAndNext(session, wikiPageResource, uuid,
775 orderByComparator, false);
776
777 return array;
778 }
779 catch (Exception e) {
780 throw processException(e);
781 }
782 finally {
783 closeSession(session);
784 }
785 }
786
787 protected WikiPageResource getByUuid_PrevAndNext(Session session,
788 WikiPageResource wikiPageResource, String uuid,
789 OrderByComparator orderByComparator, boolean previous) {
790 StringBundler query = null;
791
792 if (orderByComparator != null) {
793 query = new StringBundler(6 +
794 (orderByComparator.getOrderByFields().length * 6));
795 }
796 else {
797 query = new StringBundler(3);
798 }
799
800 query.append(_SQL_SELECT_WIKIPAGERESOURCE_WHERE);
801
802 if (uuid == null) {
803 query.append(_FINDER_COLUMN_UUID_UUID_1);
804 }
805 else {
806 if (uuid.equals(StringPool.BLANK)) {
807 query.append(_FINDER_COLUMN_UUID_UUID_3);
808 }
809 else {
810 query.append(_FINDER_COLUMN_UUID_UUID_2);
811 }
812 }
813
814 if (orderByComparator != null) {
815 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
816
817 if (orderByConditionFields.length > 0) {
818 query.append(WHERE_AND);
819 }
820
821 for (int i = 0; i < orderByConditionFields.length; i++) {
822 query.append(_ORDER_BY_ENTITY_ALIAS);
823 query.append(orderByConditionFields[i]);
824
825 if ((i + 1) < orderByConditionFields.length) {
826 if (orderByComparator.isAscending() ^ previous) {
827 query.append(WHERE_GREATER_THAN_HAS_NEXT);
828 }
829 else {
830 query.append(WHERE_LESSER_THAN_HAS_NEXT);
831 }
832 }
833 else {
834 if (orderByComparator.isAscending() ^ previous) {
835 query.append(WHERE_GREATER_THAN);
836 }
837 else {
838 query.append(WHERE_LESSER_THAN);
839 }
840 }
841 }
842
843 query.append(ORDER_BY_CLAUSE);
844
845 String[] orderByFields = orderByComparator.getOrderByFields();
846
847 for (int i = 0; i < orderByFields.length; i++) {
848 query.append(_ORDER_BY_ENTITY_ALIAS);
849 query.append(orderByFields[i]);
850
851 if ((i + 1) < orderByFields.length) {
852 if (orderByComparator.isAscending() ^ previous) {
853 query.append(ORDER_BY_ASC_HAS_NEXT);
854 }
855 else {
856 query.append(ORDER_BY_DESC_HAS_NEXT);
857 }
858 }
859 else {
860 if (orderByComparator.isAscending() ^ previous) {
861 query.append(ORDER_BY_ASC);
862 }
863 else {
864 query.append(ORDER_BY_DESC);
865 }
866 }
867 }
868 }
869
870 String sql = query.toString();
871
872 Query q = session.createQuery(sql);
873
874 q.setFirstResult(0);
875 q.setMaxResults(2);
876
877 QueryPos qPos = QueryPos.getInstance(q);
878
879 if (uuid != null) {
880 qPos.add(uuid);
881 }
882
883 if (orderByComparator != null) {
884 Object[] values = orderByComparator.getOrderByConditionValues(wikiPageResource);
885
886 for (Object value : values) {
887 qPos.add(value);
888 }
889 }
890
891 List<WikiPageResource> list = q.list();
892
893 if (list.size() == 2) {
894 return list.get(1);
895 }
896 else {
897 return null;
898 }
899 }
900
901
910 public WikiPageResource findByN_T(long nodeId, String title)
911 throws NoSuchPageResourceException, SystemException {
912 WikiPageResource wikiPageResource = fetchByN_T(nodeId, title);
913
914 if (wikiPageResource == null) {
915 StringBundler msg = new StringBundler(6);
916
917 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
918
919 msg.append("nodeId=");
920 msg.append(nodeId);
921
922 msg.append(", title=");
923 msg.append(title);
924
925 msg.append(StringPool.CLOSE_CURLY_BRACE);
926
927 if (_log.isWarnEnabled()) {
928 _log.warn(msg.toString());
929 }
930
931 throw new NoSuchPageResourceException(msg.toString());
932 }
933
934 return wikiPageResource;
935 }
936
937
945 public WikiPageResource fetchByN_T(long nodeId, String title)
946 throws SystemException {
947 return fetchByN_T(nodeId, title, true);
948 }
949
950
959 public WikiPageResource fetchByN_T(long nodeId, String title,
960 boolean retrieveFromCache) throws SystemException {
961 Object[] finderArgs = new Object[] { nodeId, title };
962
963 Object result = null;
964
965 if (retrieveFromCache) {
966 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_N_T,
967 finderArgs, this);
968 }
969
970 if (result == null) {
971 StringBundler query = new StringBundler(3);
972
973 query.append(_SQL_SELECT_WIKIPAGERESOURCE_WHERE);
974
975 query.append(_FINDER_COLUMN_N_T_NODEID_2);
976
977 if (title == null) {
978 query.append(_FINDER_COLUMN_N_T_TITLE_1);
979 }
980 else {
981 if (title.equals(StringPool.BLANK)) {
982 query.append(_FINDER_COLUMN_N_T_TITLE_3);
983 }
984 else {
985 query.append(_FINDER_COLUMN_N_T_TITLE_2);
986 }
987 }
988
989 String sql = query.toString();
990
991 Session session = null;
992
993 try {
994 session = openSession();
995
996 Query q = session.createQuery(sql);
997
998 QueryPos qPos = QueryPos.getInstance(q);
999
1000 qPos.add(nodeId);
1001
1002 if (title != null) {
1003 qPos.add(title);
1004 }
1005
1006 List<WikiPageResource> list = q.list();
1007
1008 result = list;
1009
1010 WikiPageResource wikiPageResource = null;
1011
1012 if (list.isEmpty()) {
1013 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T,
1014 finderArgs, list);
1015 }
1016 else {
1017 wikiPageResource = list.get(0);
1018
1019 cacheResult(wikiPageResource);
1020
1021 if ((wikiPageResource.getNodeId() != nodeId) ||
1022 (wikiPageResource.getTitle() == null) ||
1023 !wikiPageResource.getTitle().equals(title)) {
1024 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T,
1025 finderArgs, wikiPageResource);
1026 }
1027 }
1028
1029 return wikiPageResource;
1030 }
1031 catch (Exception e) {
1032 throw processException(e);
1033 }
1034 finally {
1035 if (result == null) {
1036 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_T,
1037 finderArgs);
1038 }
1039
1040 closeSession(session);
1041 }
1042 }
1043 else {
1044 if (result instanceof List<?>) {
1045 return null;
1046 }
1047 else {
1048 return (WikiPageResource)result;
1049 }
1050 }
1051 }
1052
1053
1059 public List<WikiPageResource> findAll() throws SystemException {
1060 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1061 }
1062
1063
1075 public List<WikiPageResource> findAll(int start, int end)
1076 throws SystemException {
1077 return findAll(start, end, null);
1078 }
1079
1080
1093 public List<WikiPageResource> findAll(int start, int end,
1094 OrderByComparator orderByComparator) throws SystemException {
1095 FinderPath finderPath = null;
1096 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1097
1098 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1099 (orderByComparator == null)) {
1100 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1101 finderArgs = FINDER_ARGS_EMPTY;
1102 }
1103 else {
1104 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1105 finderArgs = new Object[] { start, end, orderByComparator };
1106 }
1107
1108 List<WikiPageResource> list = (List<WikiPageResource>)FinderCacheUtil.getResult(finderPath,
1109 finderArgs, this);
1110
1111 if (list == null) {
1112 StringBundler query = null;
1113 String sql = null;
1114
1115 if (orderByComparator != null) {
1116 query = new StringBundler(2 +
1117 (orderByComparator.getOrderByFields().length * 3));
1118
1119 query.append(_SQL_SELECT_WIKIPAGERESOURCE);
1120
1121 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1122 orderByComparator);
1123
1124 sql = query.toString();
1125 }
1126 else {
1127 sql = _SQL_SELECT_WIKIPAGERESOURCE;
1128 }
1129
1130 Session session = null;
1131
1132 try {
1133 session = openSession();
1134
1135 Query q = session.createQuery(sql);
1136
1137 if (orderByComparator == null) {
1138 list = (List<WikiPageResource>)QueryUtil.list(q,
1139 getDialect(), start, end, false);
1140
1141 Collections.sort(list);
1142 }
1143 else {
1144 list = (List<WikiPageResource>)QueryUtil.list(q,
1145 getDialect(), start, end);
1146 }
1147 }
1148 catch (Exception e) {
1149 throw processException(e);
1150 }
1151 finally {
1152 if (list == null) {
1153 FinderCacheUtil.removeResult(finderPath, finderArgs);
1154 }
1155 else {
1156 cacheResult(list);
1157
1158 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1159 }
1160
1161 closeSession(session);
1162 }
1163 }
1164
1165 return list;
1166 }
1167
1168
1174 public void removeByUuid(String uuid) throws SystemException {
1175 for (WikiPageResource wikiPageResource : findByUuid(uuid)) {
1176 wikiPageResourcePersistence.remove(wikiPageResource);
1177 }
1178 }
1179
1180
1187 public void removeByN_T(long nodeId, String title)
1188 throws NoSuchPageResourceException, SystemException {
1189 WikiPageResource wikiPageResource = findByN_T(nodeId, title);
1190
1191 wikiPageResourcePersistence.remove(wikiPageResource);
1192 }
1193
1194
1199 public void removeAll() throws SystemException {
1200 for (WikiPageResource wikiPageResource : findAll()) {
1201 wikiPageResourcePersistence.remove(wikiPageResource);
1202 }
1203 }
1204
1205
1212 public int countByUuid(String uuid) throws SystemException {
1213 Object[] finderArgs = new Object[] { uuid };
1214
1215 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1216 finderArgs, this);
1217
1218 if (count == null) {
1219 StringBundler query = new StringBundler(2);
1220
1221 query.append(_SQL_COUNT_WIKIPAGERESOURCE_WHERE);
1222
1223 if (uuid == null) {
1224 query.append(_FINDER_COLUMN_UUID_UUID_1);
1225 }
1226 else {
1227 if (uuid.equals(StringPool.BLANK)) {
1228 query.append(_FINDER_COLUMN_UUID_UUID_3);
1229 }
1230 else {
1231 query.append(_FINDER_COLUMN_UUID_UUID_2);
1232 }
1233 }
1234
1235 String sql = query.toString();
1236
1237 Session session = null;
1238
1239 try {
1240 session = openSession();
1241
1242 Query q = session.createQuery(sql);
1243
1244 QueryPos qPos = QueryPos.getInstance(q);
1245
1246 if (uuid != null) {
1247 qPos.add(uuid);
1248 }
1249
1250 count = (Long)q.uniqueResult();
1251 }
1252 catch (Exception e) {
1253 throw processException(e);
1254 }
1255 finally {
1256 if (count == null) {
1257 count = Long.valueOf(0);
1258 }
1259
1260 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
1261 finderArgs, count);
1262
1263 closeSession(session);
1264 }
1265 }
1266
1267 return count.intValue();
1268 }
1269
1270
1278 public int countByN_T(long nodeId, String title) throws SystemException {
1279 Object[] finderArgs = new Object[] { nodeId, title };
1280
1281 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_N_T,
1282 finderArgs, this);
1283
1284 if (count == null) {
1285 StringBundler query = new StringBundler(3);
1286
1287 query.append(_SQL_COUNT_WIKIPAGERESOURCE_WHERE);
1288
1289 query.append(_FINDER_COLUMN_N_T_NODEID_2);
1290
1291 if (title == null) {
1292 query.append(_FINDER_COLUMN_N_T_TITLE_1);
1293 }
1294 else {
1295 if (title.equals(StringPool.BLANK)) {
1296 query.append(_FINDER_COLUMN_N_T_TITLE_3);
1297 }
1298 else {
1299 query.append(_FINDER_COLUMN_N_T_TITLE_2);
1300 }
1301 }
1302
1303 String sql = query.toString();
1304
1305 Session session = null;
1306
1307 try {
1308 session = openSession();
1309
1310 Query q = session.createQuery(sql);
1311
1312 QueryPos qPos = QueryPos.getInstance(q);
1313
1314 qPos.add(nodeId);
1315
1316 if (title != null) {
1317 qPos.add(title);
1318 }
1319
1320 count = (Long)q.uniqueResult();
1321 }
1322 catch (Exception e) {
1323 throw processException(e);
1324 }
1325 finally {
1326 if (count == null) {
1327 count = Long.valueOf(0);
1328 }
1329
1330 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_T, finderArgs,
1331 count);
1332
1333 closeSession(session);
1334 }
1335 }
1336
1337 return count.intValue();
1338 }
1339
1340
1346 public int countAll() throws SystemException {
1347 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1348 FINDER_ARGS_EMPTY, this);
1349
1350 if (count == null) {
1351 Session session = null;
1352
1353 try {
1354 session = openSession();
1355
1356 Query q = session.createQuery(_SQL_COUNT_WIKIPAGERESOURCE);
1357
1358 count = (Long)q.uniqueResult();
1359 }
1360 catch (Exception e) {
1361 throw processException(e);
1362 }
1363 finally {
1364 if (count == null) {
1365 count = Long.valueOf(0);
1366 }
1367
1368 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1369 FINDER_ARGS_EMPTY, count);
1370
1371 closeSession(session);
1372 }
1373 }
1374
1375 return count.intValue();
1376 }
1377
1378
1381 public void afterPropertiesSet() {
1382 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1383 com.liferay.portal.util.PropsUtil.get(
1384 "value.object.listener.com.liferay.portlet.wiki.model.WikiPageResource")));
1385
1386 if (listenerClassNames.length > 0) {
1387 try {
1388 List<ModelListener<WikiPageResource>> listenersList = new ArrayList<ModelListener<WikiPageResource>>();
1389
1390 for (String listenerClassName : listenerClassNames) {
1391 listenersList.add((ModelListener<WikiPageResource>)InstanceFactory.newInstance(
1392 listenerClassName));
1393 }
1394
1395 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1396 }
1397 catch (Exception e) {
1398 _log.error(e);
1399 }
1400 }
1401 }
1402
1403 public void destroy() {
1404 EntityCacheUtil.removeCache(WikiPageResourceImpl.class.getName());
1405 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1406 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1407 }
1408
1409 @BeanReference(type = WikiNodePersistence.class)
1410 protected WikiNodePersistence wikiNodePersistence;
1411 @BeanReference(type = WikiPagePersistence.class)
1412 protected WikiPagePersistence wikiPagePersistence;
1413 @BeanReference(type = WikiPageResourcePersistence.class)
1414 protected WikiPageResourcePersistence wikiPageResourcePersistence;
1415 @BeanReference(type = ResourcePersistence.class)
1416 protected ResourcePersistence resourcePersistence;
1417 @BeanReference(type = UserPersistence.class)
1418 protected UserPersistence userPersistence;
1419 private static final String _SQL_SELECT_WIKIPAGERESOURCE = "SELECT wikiPageResource FROM WikiPageResource wikiPageResource";
1420 private static final String _SQL_SELECT_WIKIPAGERESOURCE_WHERE = "SELECT wikiPageResource FROM WikiPageResource wikiPageResource WHERE ";
1421 private static final String _SQL_COUNT_WIKIPAGERESOURCE = "SELECT COUNT(wikiPageResource) FROM WikiPageResource wikiPageResource";
1422 private static final String _SQL_COUNT_WIKIPAGERESOURCE_WHERE = "SELECT COUNT(wikiPageResource) FROM WikiPageResource wikiPageResource WHERE ";
1423 private static final String _FINDER_COLUMN_UUID_UUID_1 = "wikiPageResource.uuid IS NULL";
1424 private static final String _FINDER_COLUMN_UUID_UUID_2 = "wikiPageResource.uuid = ?";
1425 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(wikiPageResource.uuid IS NULL OR wikiPageResource.uuid = ?)";
1426 private static final String _FINDER_COLUMN_N_T_NODEID_2 = "wikiPageResource.nodeId = ? AND ";
1427 private static final String _FINDER_COLUMN_N_T_TITLE_1 = "wikiPageResource.title IS NULL";
1428 private static final String _FINDER_COLUMN_N_T_TITLE_2 = "wikiPageResource.title = ?";
1429 private static final String _FINDER_COLUMN_N_T_TITLE_3 = "(wikiPageResource.title IS NULL OR wikiPageResource.title = ?)";
1430 private static final String _ORDER_BY_ENTITY_ALIAS = "wikiPageResource.";
1431 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No WikiPageResource exists with the primary key ";
1432 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No WikiPageResource exists with the key {";
1433 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1434 private static Log _log = LogFactoryUtil.getLog(WikiPageResourcePersistenceImpl.class);
1435 private static WikiPageResource _nullWikiPageResource = new WikiPageResourceImpl() {
1436 @Override
1437 public Object clone() {
1438 return this;
1439 }
1440
1441 @Override
1442 public CacheModel<WikiPageResource> toCacheModel() {
1443 return _nullWikiPageResourceCacheModel;
1444 }
1445 };
1446
1447 private static CacheModel<WikiPageResource> _nullWikiPageResourceCacheModel = new CacheModel<WikiPageResource>() {
1448 public WikiPageResource toEntityModel() {
1449 return _nullWikiPageResource;
1450 }
1451 };
1452 }