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.UserPersistence;
041 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042
043 import com.liferay.portlet.wiki.NoSuchPageResourceException;
044 import com.liferay.portlet.wiki.model.WikiPageResource;
045 import com.liferay.portlet.wiki.model.impl.WikiPageResourceImpl;
046 import com.liferay.portlet.wiki.model.impl.WikiPageResourceModelImpl;
047
048 import java.io.Serializable;
049
050 import java.util.ArrayList;
051 import java.util.Collections;
052 import java.util.List;
053
054
066 public class WikiPageResourcePersistenceImpl extends BasePersistenceImpl<WikiPageResource>
067 implements WikiPageResourcePersistence {
068
073 public static final String FINDER_CLASS_NAME_ENTITY = WikiPageResourceImpl.class.getName();
074 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075 ".List1";
076 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077 ".List2";
078 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
079 WikiPageResourceModelImpl.FINDER_CACHE_ENABLED,
080 WikiPageResourceImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
081 "findByUuid",
082 new String[] {
083 String.class.getName(),
084
085 "java.lang.Integer", "java.lang.Integer",
086 "com.liferay.portal.kernel.util.OrderByComparator"
087 });
088 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
089 WikiPageResourceModelImpl.FINDER_CACHE_ENABLED,
090 WikiPageResourceImpl.class,
091 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
092 new String[] { String.class.getName() },
093 WikiPageResourceModelImpl.UUID_COLUMN_BITMASK);
094 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
095 WikiPageResourceModelImpl.FINDER_CACHE_ENABLED, Long.class,
096 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
097 new String[] { String.class.getName() });
098 public static final FinderPath FINDER_PATH_FETCH_BY_N_T = new FinderPath(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
099 WikiPageResourceModelImpl.FINDER_CACHE_ENABLED,
100 WikiPageResourceImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByN_T",
101 new String[] { Long.class.getName(), String.class.getName() },
102 WikiPageResourceModelImpl.NODEID_COLUMN_BITMASK |
103 WikiPageResourceModelImpl.TITLE_COLUMN_BITMASK);
104 public static final FinderPath FINDER_PATH_COUNT_BY_N_T = new FinderPath(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
105 WikiPageResourceModelImpl.FINDER_CACHE_ENABLED, Long.class,
106 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_T",
107 new String[] { Long.class.getName(), String.class.getName() });
108 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
109 WikiPageResourceModelImpl.FINDER_CACHE_ENABLED,
110 WikiPageResourceImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
111 "findAll", new String[0]);
112 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
113 WikiPageResourceModelImpl.FINDER_CACHE_ENABLED,
114 WikiPageResourceImpl.class,
115 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
116 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
117 WikiPageResourceModelImpl.FINDER_CACHE_ENABLED, Long.class,
118 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
119
120
125 public void cacheResult(WikiPageResource wikiPageResource) {
126 EntityCacheUtil.putResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
127 WikiPageResourceImpl.class, wikiPageResource.getPrimaryKey(),
128 wikiPageResource);
129
130 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T,
131 new Object[] {
132 Long.valueOf(wikiPageResource.getNodeId()),
133
134 wikiPageResource.getTitle()
135 }, wikiPageResource);
136
137 wikiPageResource.resetOriginalValues();
138 }
139
140
145 public void cacheResult(List<WikiPageResource> wikiPageResources) {
146 for (WikiPageResource wikiPageResource : wikiPageResources) {
147 if (EntityCacheUtil.getResult(
148 WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
149 WikiPageResourceImpl.class,
150 wikiPageResource.getPrimaryKey()) == null) {
151 cacheResult(wikiPageResource);
152 }
153 else {
154 wikiPageResource.resetOriginalValues();
155 }
156 }
157 }
158
159
166 @Override
167 public void clearCache() {
168 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
169 CacheRegistryUtil.clear(WikiPageResourceImpl.class.getName());
170 }
171
172 EntityCacheUtil.clearCache(WikiPageResourceImpl.class.getName());
173
174 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
175 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
176 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
177 }
178
179
186 @Override
187 public void clearCache(WikiPageResource wikiPageResource) {
188 EntityCacheUtil.removeResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
189 WikiPageResourceImpl.class, wikiPageResource.getPrimaryKey());
190
191 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
192 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
193
194 clearUniqueFindersCache(wikiPageResource);
195 }
196
197 @Override
198 public void clearCache(List<WikiPageResource> wikiPageResources) {
199 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
200 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
201
202 for (WikiPageResource wikiPageResource : wikiPageResources) {
203 EntityCacheUtil.removeResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
204 WikiPageResourceImpl.class, wikiPageResource.getPrimaryKey());
205
206 clearUniqueFindersCache(wikiPageResource);
207 }
208 }
209
210 protected void clearUniqueFindersCache(WikiPageResource wikiPageResource) {
211 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_T,
212 new Object[] {
213 Long.valueOf(wikiPageResource.getNodeId()),
214
215 wikiPageResource.getTitle()
216 });
217 }
218
219
225 public WikiPageResource create(long resourcePrimKey) {
226 WikiPageResource wikiPageResource = new WikiPageResourceImpl();
227
228 wikiPageResource.setNew(true);
229 wikiPageResource.setPrimaryKey(resourcePrimKey);
230
231 String uuid = PortalUUIDUtil.generate();
232
233 wikiPageResource.setUuid(uuid);
234
235 return wikiPageResource;
236 }
237
238
246 public WikiPageResource remove(long resourcePrimKey)
247 throws NoSuchPageResourceException, SystemException {
248 return remove(Long.valueOf(resourcePrimKey));
249 }
250
251
259 @Override
260 public WikiPageResource remove(Serializable primaryKey)
261 throws NoSuchPageResourceException, SystemException {
262 Session session = null;
263
264 try {
265 session = openSession();
266
267 WikiPageResource wikiPageResource = (WikiPageResource)session.get(WikiPageResourceImpl.class,
268 primaryKey);
269
270 if (wikiPageResource == null) {
271 if (_log.isWarnEnabled()) {
272 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
273 }
274
275 throw new NoSuchPageResourceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
276 primaryKey);
277 }
278
279 return remove(wikiPageResource);
280 }
281 catch (NoSuchPageResourceException nsee) {
282 throw nsee;
283 }
284 catch (Exception e) {
285 throw processException(e);
286 }
287 finally {
288 closeSession(session);
289 }
290 }
291
292 @Override
293 protected WikiPageResource removeImpl(WikiPageResource wikiPageResource)
294 throws SystemException {
295 wikiPageResource = toUnwrappedModel(wikiPageResource);
296
297 Session session = null;
298
299 try {
300 session = openSession();
301
302 if (wikiPageResource.isCachedModel()) {
303 wikiPageResource = (WikiPageResource)session.get(WikiPageResourceImpl.class,
304 wikiPageResource.getPrimaryKeyObj());
305 }
306
307 session.delete(wikiPageResource);
308 }
309 catch (Exception e) {
310 throw processException(e);
311 }
312 finally {
313 closeSession(session);
314 }
315
316 clearCache(wikiPageResource);
317
318 return wikiPageResource;
319 }
320
321 @Override
322 public WikiPageResource updateImpl(
323 com.liferay.portlet.wiki.model.WikiPageResource wikiPageResource)
324 throws SystemException {
325 wikiPageResource = toUnwrappedModel(wikiPageResource);
326
327 boolean isNew = wikiPageResource.isNew();
328
329 WikiPageResourceModelImpl wikiPageResourceModelImpl = (WikiPageResourceModelImpl)wikiPageResource;
330
331 if (Validator.isNull(wikiPageResource.getUuid())) {
332 String uuid = PortalUUIDUtil.generate();
333
334 wikiPageResource.setUuid(uuid);
335 }
336
337 Session session = null;
338
339 try {
340 session = openSession();
341
342 if (wikiPageResource.isNew()) {
343 session.save(wikiPageResource);
344
345 wikiPageResource.setNew(false);
346 }
347 else {
348 session.merge(wikiPageResource);
349 }
350 }
351 catch (Exception e) {
352 throw processException(e);
353 }
354 finally {
355 closeSession(session);
356 }
357
358 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
359
360 if (isNew || !WikiPageResourceModelImpl.COLUMN_BITMASK_ENABLED) {
361 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
362 }
363
364 else {
365 if ((wikiPageResourceModelImpl.getColumnBitmask() &
366 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
367 Object[] args = new Object[] {
368 wikiPageResourceModelImpl.getOriginalUuid()
369 };
370
371 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
372 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
373 args);
374
375 args = new Object[] { wikiPageResourceModelImpl.getUuid() };
376
377 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
378 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
379 args);
380 }
381 }
382
383 EntityCacheUtil.putResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
384 WikiPageResourceImpl.class, wikiPageResource.getPrimaryKey(),
385 wikiPageResource);
386
387 if (isNew) {
388 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T,
389 new Object[] {
390 Long.valueOf(wikiPageResource.getNodeId()),
391
392 wikiPageResource.getTitle()
393 }, wikiPageResource);
394 }
395 else {
396 if ((wikiPageResourceModelImpl.getColumnBitmask() &
397 FINDER_PATH_FETCH_BY_N_T.getColumnBitmask()) != 0) {
398 Object[] args = new Object[] {
399 Long.valueOf(wikiPageResourceModelImpl.getOriginalNodeId()),
400
401 wikiPageResourceModelImpl.getOriginalTitle()
402 };
403
404 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T, args);
405
406 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_T, args);
407
408 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T,
409 new Object[] {
410 Long.valueOf(wikiPageResource.getNodeId()),
411
412 wikiPageResource.getTitle()
413 }, wikiPageResource);
414 }
415 }
416
417 return wikiPageResource;
418 }
419
420 protected WikiPageResource toUnwrappedModel(
421 WikiPageResource wikiPageResource) {
422 if (wikiPageResource instanceof WikiPageResourceImpl) {
423 return wikiPageResource;
424 }
425
426 WikiPageResourceImpl wikiPageResourceImpl = new WikiPageResourceImpl();
427
428 wikiPageResourceImpl.setNew(wikiPageResource.isNew());
429 wikiPageResourceImpl.setPrimaryKey(wikiPageResource.getPrimaryKey());
430
431 wikiPageResourceImpl.setUuid(wikiPageResource.getUuid());
432 wikiPageResourceImpl.setResourcePrimKey(wikiPageResource.getResourcePrimKey());
433 wikiPageResourceImpl.setNodeId(wikiPageResource.getNodeId());
434 wikiPageResourceImpl.setTitle(wikiPageResource.getTitle());
435
436 return wikiPageResourceImpl;
437 }
438
439
447 @Override
448 public WikiPageResource findByPrimaryKey(Serializable primaryKey)
449 throws NoSuchModelException, SystemException {
450 return findByPrimaryKey(((Long)primaryKey).longValue());
451 }
452
453
461 public WikiPageResource findByPrimaryKey(long resourcePrimKey)
462 throws NoSuchPageResourceException, SystemException {
463 WikiPageResource wikiPageResource = fetchByPrimaryKey(resourcePrimKey);
464
465 if (wikiPageResource == null) {
466 if (_log.isWarnEnabled()) {
467 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + resourcePrimKey);
468 }
469
470 throw new NoSuchPageResourceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
471 resourcePrimKey);
472 }
473
474 return wikiPageResource;
475 }
476
477
484 @Override
485 public WikiPageResource fetchByPrimaryKey(Serializable primaryKey)
486 throws SystemException {
487 return fetchByPrimaryKey(((Long)primaryKey).longValue());
488 }
489
490
497 public WikiPageResource fetchByPrimaryKey(long resourcePrimKey)
498 throws SystemException {
499 WikiPageResource wikiPageResource = (WikiPageResource)EntityCacheUtil.getResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
500 WikiPageResourceImpl.class, resourcePrimKey);
501
502 if (wikiPageResource == _nullWikiPageResource) {
503 return null;
504 }
505
506 if (wikiPageResource == null) {
507 Session session = null;
508
509 boolean hasException = false;
510
511 try {
512 session = openSession();
513
514 wikiPageResource = (WikiPageResource)session.get(WikiPageResourceImpl.class,
515 Long.valueOf(resourcePrimKey));
516 }
517 catch (Exception e) {
518 hasException = true;
519
520 throw processException(e);
521 }
522 finally {
523 if (wikiPageResource != null) {
524 cacheResult(wikiPageResource);
525 }
526 else if (!hasException) {
527 EntityCacheUtil.putResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
528 WikiPageResourceImpl.class, resourcePrimKey,
529 _nullWikiPageResource);
530 }
531
532 closeSession(session);
533 }
534 }
535
536 return wikiPageResource;
537 }
538
539
546 public List<WikiPageResource> findByUuid(String uuid)
547 throws SystemException {
548 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
549 }
550
551
564 public List<WikiPageResource> findByUuid(String uuid, int start, int end)
565 throws SystemException {
566 return findByUuid(uuid, start, end, null);
567 }
568
569
583 public List<WikiPageResource> findByUuid(String uuid, int start, int end,
584 OrderByComparator orderByComparator) throws SystemException {
585 FinderPath finderPath = null;
586 Object[] finderArgs = null;
587
588 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
589 (orderByComparator == null)) {
590 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
591 finderArgs = new Object[] { uuid };
592 }
593 else {
594 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
595 finderArgs = new Object[] { uuid, start, end, orderByComparator };
596 }
597
598 List<WikiPageResource> list = (List<WikiPageResource>)FinderCacheUtil.getResult(finderPath,
599 finderArgs, this);
600
601 if ((list != null) && !list.isEmpty()) {
602 for (WikiPageResource wikiPageResource : list) {
603 if (!Validator.equals(uuid, wikiPageResource.getUuid())) {
604 list = null;
605
606 break;
607 }
608 }
609 }
610
611 if (list == null) {
612 StringBundler query = null;
613
614 if (orderByComparator != null) {
615 query = new StringBundler(3 +
616 (orderByComparator.getOrderByFields().length * 3));
617 }
618 else {
619 query = new StringBundler(2);
620 }
621
622 query.append(_SQL_SELECT_WIKIPAGERESOURCE_WHERE);
623
624 if (uuid == null) {
625 query.append(_FINDER_COLUMN_UUID_UUID_1);
626 }
627 else {
628 if (uuid.equals(StringPool.BLANK)) {
629 query.append(_FINDER_COLUMN_UUID_UUID_3);
630 }
631 else {
632 query.append(_FINDER_COLUMN_UUID_UUID_2);
633 }
634 }
635
636 if (orderByComparator != null) {
637 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
638 orderByComparator);
639 }
640
641 String sql = query.toString();
642
643 Session session = null;
644
645 try {
646 session = openSession();
647
648 Query q = session.createQuery(sql);
649
650 QueryPos qPos = QueryPos.getInstance(q);
651
652 if (uuid != null) {
653 qPos.add(uuid);
654 }
655
656 list = (List<WikiPageResource>)QueryUtil.list(q, getDialect(),
657 start, end);
658 }
659 catch (Exception e) {
660 throw processException(e);
661 }
662 finally {
663 if (list == null) {
664 FinderCacheUtil.removeResult(finderPath, finderArgs);
665 }
666 else {
667 cacheResult(list);
668
669 FinderCacheUtil.putResult(finderPath, finderArgs, list);
670 }
671
672 closeSession(session);
673 }
674 }
675
676 return list;
677 }
678
679
688 public WikiPageResource findByUuid_First(String uuid,
689 OrderByComparator orderByComparator)
690 throws NoSuchPageResourceException, SystemException {
691 WikiPageResource wikiPageResource = fetchByUuid_First(uuid,
692 orderByComparator);
693
694 if (wikiPageResource != null) {
695 return wikiPageResource;
696 }
697
698 StringBundler msg = new StringBundler(4);
699
700 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
701
702 msg.append("uuid=");
703 msg.append(uuid);
704
705 msg.append(StringPool.CLOSE_CURLY_BRACE);
706
707 throw new NoSuchPageResourceException(msg.toString());
708 }
709
710
718 public WikiPageResource fetchByUuid_First(String uuid,
719 OrderByComparator orderByComparator) throws SystemException {
720 List<WikiPageResource> list = findByUuid(uuid, 0, 1, orderByComparator);
721
722 if (!list.isEmpty()) {
723 return list.get(0);
724 }
725
726 return null;
727 }
728
729
738 public WikiPageResource findByUuid_Last(String uuid,
739 OrderByComparator orderByComparator)
740 throws NoSuchPageResourceException, SystemException {
741 WikiPageResource wikiPageResource = fetchByUuid_Last(uuid,
742 orderByComparator);
743
744 if (wikiPageResource != null) {
745 return wikiPageResource;
746 }
747
748 StringBundler msg = new StringBundler(4);
749
750 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
751
752 msg.append("uuid=");
753 msg.append(uuid);
754
755 msg.append(StringPool.CLOSE_CURLY_BRACE);
756
757 throw new NoSuchPageResourceException(msg.toString());
758 }
759
760
768 public WikiPageResource fetchByUuid_Last(String uuid,
769 OrderByComparator orderByComparator) throws SystemException {
770 int count = countByUuid(uuid);
771
772 List<WikiPageResource> list = findByUuid(uuid, count - 1, count,
773 orderByComparator);
774
775 if (!list.isEmpty()) {
776 return list.get(0);
777 }
778
779 return null;
780 }
781
782
792 public WikiPageResource[] findByUuid_PrevAndNext(long resourcePrimKey,
793 String uuid, OrderByComparator orderByComparator)
794 throws NoSuchPageResourceException, SystemException {
795 WikiPageResource wikiPageResource = findByPrimaryKey(resourcePrimKey);
796
797 Session session = null;
798
799 try {
800 session = openSession();
801
802 WikiPageResource[] array = new WikiPageResourceImpl[3];
803
804 array[0] = getByUuid_PrevAndNext(session, wikiPageResource, uuid,
805 orderByComparator, true);
806
807 array[1] = wikiPageResource;
808
809 array[2] = getByUuid_PrevAndNext(session, wikiPageResource, uuid,
810 orderByComparator, false);
811
812 return array;
813 }
814 catch (Exception e) {
815 throw processException(e);
816 }
817 finally {
818 closeSession(session);
819 }
820 }
821
822 protected WikiPageResource getByUuid_PrevAndNext(Session session,
823 WikiPageResource wikiPageResource, String uuid,
824 OrderByComparator orderByComparator, boolean previous) {
825 StringBundler query = null;
826
827 if (orderByComparator != null) {
828 query = new StringBundler(6 +
829 (orderByComparator.getOrderByFields().length * 6));
830 }
831 else {
832 query = new StringBundler(3);
833 }
834
835 query.append(_SQL_SELECT_WIKIPAGERESOURCE_WHERE);
836
837 if (uuid == null) {
838 query.append(_FINDER_COLUMN_UUID_UUID_1);
839 }
840 else {
841 if (uuid.equals(StringPool.BLANK)) {
842 query.append(_FINDER_COLUMN_UUID_UUID_3);
843 }
844 else {
845 query.append(_FINDER_COLUMN_UUID_UUID_2);
846 }
847 }
848
849 if (orderByComparator != null) {
850 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
851
852 if (orderByConditionFields.length > 0) {
853 query.append(WHERE_AND);
854 }
855
856 for (int i = 0; i < orderByConditionFields.length; i++) {
857 query.append(_ORDER_BY_ENTITY_ALIAS);
858 query.append(orderByConditionFields[i]);
859
860 if ((i + 1) < orderByConditionFields.length) {
861 if (orderByComparator.isAscending() ^ previous) {
862 query.append(WHERE_GREATER_THAN_HAS_NEXT);
863 }
864 else {
865 query.append(WHERE_LESSER_THAN_HAS_NEXT);
866 }
867 }
868 else {
869 if (orderByComparator.isAscending() ^ previous) {
870 query.append(WHERE_GREATER_THAN);
871 }
872 else {
873 query.append(WHERE_LESSER_THAN);
874 }
875 }
876 }
877
878 query.append(ORDER_BY_CLAUSE);
879
880 String[] orderByFields = orderByComparator.getOrderByFields();
881
882 for (int i = 0; i < orderByFields.length; i++) {
883 query.append(_ORDER_BY_ENTITY_ALIAS);
884 query.append(orderByFields[i]);
885
886 if ((i + 1) < orderByFields.length) {
887 if (orderByComparator.isAscending() ^ previous) {
888 query.append(ORDER_BY_ASC_HAS_NEXT);
889 }
890 else {
891 query.append(ORDER_BY_DESC_HAS_NEXT);
892 }
893 }
894 else {
895 if (orderByComparator.isAscending() ^ previous) {
896 query.append(ORDER_BY_ASC);
897 }
898 else {
899 query.append(ORDER_BY_DESC);
900 }
901 }
902 }
903 }
904
905 String sql = query.toString();
906
907 Query q = session.createQuery(sql);
908
909 q.setFirstResult(0);
910 q.setMaxResults(2);
911
912 QueryPos qPos = QueryPos.getInstance(q);
913
914 if (uuid != null) {
915 qPos.add(uuid);
916 }
917
918 if (orderByComparator != null) {
919 Object[] values = orderByComparator.getOrderByConditionValues(wikiPageResource);
920
921 for (Object value : values) {
922 qPos.add(value);
923 }
924 }
925
926 List<WikiPageResource> list = q.list();
927
928 if (list.size() == 2) {
929 return list.get(1);
930 }
931 else {
932 return null;
933 }
934 }
935
936
945 public WikiPageResource findByN_T(long nodeId, String title)
946 throws NoSuchPageResourceException, SystemException {
947 WikiPageResource wikiPageResource = fetchByN_T(nodeId, title);
948
949 if (wikiPageResource == null) {
950 StringBundler msg = new StringBundler(6);
951
952 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
953
954 msg.append("nodeId=");
955 msg.append(nodeId);
956
957 msg.append(", title=");
958 msg.append(title);
959
960 msg.append(StringPool.CLOSE_CURLY_BRACE);
961
962 if (_log.isWarnEnabled()) {
963 _log.warn(msg.toString());
964 }
965
966 throw new NoSuchPageResourceException(msg.toString());
967 }
968
969 return wikiPageResource;
970 }
971
972
980 public WikiPageResource fetchByN_T(long nodeId, String title)
981 throws SystemException {
982 return fetchByN_T(nodeId, title, true);
983 }
984
985
994 public WikiPageResource fetchByN_T(long nodeId, String title,
995 boolean retrieveFromCache) throws SystemException {
996 Object[] finderArgs = new Object[] { nodeId, title };
997
998 Object result = null;
999
1000 if (retrieveFromCache) {
1001 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_N_T,
1002 finderArgs, this);
1003 }
1004
1005 if (result instanceof WikiPageResource) {
1006 WikiPageResource wikiPageResource = (WikiPageResource)result;
1007
1008 if ((nodeId != wikiPageResource.getNodeId()) ||
1009 !Validator.equals(title, wikiPageResource.getTitle())) {
1010 result = null;
1011 }
1012 }
1013
1014 if (result == null) {
1015 StringBundler query = new StringBundler(3);
1016
1017 query.append(_SQL_SELECT_WIKIPAGERESOURCE_WHERE);
1018
1019 query.append(_FINDER_COLUMN_N_T_NODEID_2);
1020
1021 if (title == null) {
1022 query.append(_FINDER_COLUMN_N_T_TITLE_1);
1023 }
1024 else {
1025 if (title.equals(StringPool.BLANK)) {
1026 query.append(_FINDER_COLUMN_N_T_TITLE_3);
1027 }
1028 else {
1029 query.append(_FINDER_COLUMN_N_T_TITLE_2);
1030 }
1031 }
1032
1033 String sql = query.toString();
1034
1035 Session session = null;
1036
1037 try {
1038 session = openSession();
1039
1040 Query q = session.createQuery(sql);
1041
1042 QueryPos qPos = QueryPos.getInstance(q);
1043
1044 qPos.add(nodeId);
1045
1046 if (title != null) {
1047 qPos.add(title);
1048 }
1049
1050 List<WikiPageResource> list = q.list();
1051
1052 result = list;
1053
1054 WikiPageResource wikiPageResource = null;
1055
1056 if (list.isEmpty()) {
1057 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T,
1058 finderArgs, list);
1059 }
1060 else {
1061 wikiPageResource = list.get(0);
1062
1063 cacheResult(wikiPageResource);
1064
1065 if ((wikiPageResource.getNodeId() != nodeId) ||
1066 (wikiPageResource.getTitle() == null) ||
1067 !wikiPageResource.getTitle().equals(title)) {
1068 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T,
1069 finderArgs, wikiPageResource);
1070 }
1071 }
1072
1073 return wikiPageResource;
1074 }
1075 catch (Exception e) {
1076 throw processException(e);
1077 }
1078 finally {
1079 if (result == null) {
1080 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_T,
1081 finderArgs);
1082 }
1083
1084 closeSession(session);
1085 }
1086 }
1087 else {
1088 if (result instanceof List<?>) {
1089 return null;
1090 }
1091 else {
1092 return (WikiPageResource)result;
1093 }
1094 }
1095 }
1096
1097
1103 public List<WikiPageResource> findAll() throws SystemException {
1104 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1105 }
1106
1107
1119 public List<WikiPageResource> findAll(int start, int end)
1120 throws SystemException {
1121 return findAll(start, end, null);
1122 }
1123
1124
1137 public List<WikiPageResource> findAll(int start, int end,
1138 OrderByComparator orderByComparator) throws SystemException {
1139 FinderPath finderPath = null;
1140 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1141
1142 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1143 (orderByComparator == null)) {
1144 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1145 finderArgs = FINDER_ARGS_EMPTY;
1146 }
1147 else {
1148 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1149 finderArgs = new Object[] { start, end, orderByComparator };
1150 }
1151
1152 List<WikiPageResource> list = (List<WikiPageResource>)FinderCacheUtil.getResult(finderPath,
1153 finderArgs, this);
1154
1155 if (list == null) {
1156 StringBundler query = null;
1157 String sql = null;
1158
1159 if (orderByComparator != null) {
1160 query = new StringBundler(2 +
1161 (orderByComparator.getOrderByFields().length * 3));
1162
1163 query.append(_SQL_SELECT_WIKIPAGERESOURCE);
1164
1165 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1166 orderByComparator);
1167
1168 sql = query.toString();
1169 }
1170 else {
1171 sql = _SQL_SELECT_WIKIPAGERESOURCE;
1172 }
1173
1174 Session session = null;
1175
1176 try {
1177 session = openSession();
1178
1179 Query q = session.createQuery(sql);
1180
1181 if (orderByComparator == null) {
1182 list = (List<WikiPageResource>)QueryUtil.list(q,
1183 getDialect(), start, end, false);
1184
1185 Collections.sort(list);
1186 }
1187 else {
1188 list = (List<WikiPageResource>)QueryUtil.list(q,
1189 getDialect(), start, end);
1190 }
1191 }
1192 catch (Exception e) {
1193 throw processException(e);
1194 }
1195 finally {
1196 if (list == null) {
1197 FinderCacheUtil.removeResult(finderPath, finderArgs);
1198 }
1199 else {
1200 cacheResult(list);
1201
1202 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1203 }
1204
1205 closeSession(session);
1206 }
1207 }
1208
1209 return list;
1210 }
1211
1212
1218 public void removeByUuid(String uuid) throws SystemException {
1219 for (WikiPageResource wikiPageResource : findByUuid(uuid)) {
1220 remove(wikiPageResource);
1221 }
1222 }
1223
1224
1232 public WikiPageResource removeByN_T(long nodeId, String title)
1233 throws NoSuchPageResourceException, SystemException {
1234 WikiPageResource wikiPageResource = findByN_T(nodeId, title);
1235
1236 return remove(wikiPageResource);
1237 }
1238
1239
1244 public void removeAll() throws SystemException {
1245 for (WikiPageResource wikiPageResource : findAll()) {
1246 remove(wikiPageResource);
1247 }
1248 }
1249
1250
1257 public int countByUuid(String uuid) throws SystemException {
1258 Object[] finderArgs = new Object[] { uuid };
1259
1260 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1261 finderArgs, this);
1262
1263 if (count == null) {
1264 StringBundler query = new StringBundler(2);
1265
1266 query.append(_SQL_COUNT_WIKIPAGERESOURCE_WHERE);
1267
1268 if (uuid == null) {
1269 query.append(_FINDER_COLUMN_UUID_UUID_1);
1270 }
1271 else {
1272 if (uuid.equals(StringPool.BLANK)) {
1273 query.append(_FINDER_COLUMN_UUID_UUID_3);
1274 }
1275 else {
1276 query.append(_FINDER_COLUMN_UUID_UUID_2);
1277 }
1278 }
1279
1280 String sql = query.toString();
1281
1282 Session session = null;
1283
1284 try {
1285 session = openSession();
1286
1287 Query q = session.createQuery(sql);
1288
1289 QueryPos qPos = QueryPos.getInstance(q);
1290
1291 if (uuid != null) {
1292 qPos.add(uuid);
1293 }
1294
1295 count = (Long)q.uniqueResult();
1296 }
1297 catch (Exception e) {
1298 throw processException(e);
1299 }
1300 finally {
1301 if (count == null) {
1302 count = Long.valueOf(0);
1303 }
1304
1305 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
1306 finderArgs, count);
1307
1308 closeSession(session);
1309 }
1310 }
1311
1312 return count.intValue();
1313 }
1314
1315
1323 public int countByN_T(long nodeId, String title) throws SystemException {
1324 Object[] finderArgs = new Object[] { nodeId, title };
1325
1326 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_N_T,
1327 finderArgs, this);
1328
1329 if (count == null) {
1330 StringBundler query = new StringBundler(3);
1331
1332 query.append(_SQL_COUNT_WIKIPAGERESOURCE_WHERE);
1333
1334 query.append(_FINDER_COLUMN_N_T_NODEID_2);
1335
1336 if (title == null) {
1337 query.append(_FINDER_COLUMN_N_T_TITLE_1);
1338 }
1339 else {
1340 if (title.equals(StringPool.BLANK)) {
1341 query.append(_FINDER_COLUMN_N_T_TITLE_3);
1342 }
1343 else {
1344 query.append(_FINDER_COLUMN_N_T_TITLE_2);
1345 }
1346 }
1347
1348 String sql = query.toString();
1349
1350 Session session = null;
1351
1352 try {
1353 session = openSession();
1354
1355 Query q = session.createQuery(sql);
1356
1357 QueryPos qPos = QueryPos.getInstance(q);
1358
1359 qPos.add(nodeId);
1360
1361 if (title != null) {
1362 qPos.add(title);
1363 }
1364
1365 count = (Long)q.uniqueResult();
1366 }
1367 catch (Exception e) {
1368 throw processException(e);
1369 }
1370 finally {
1371 if (count == null) {
1372 count = Long.valueOf(0);
1373 }
1374
1375 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_T, finderArgs,
1376 count);
1377
1378 closeSession(session);
1379 }
1380 }
1381
1382 return count.intValue();
1383 }
1384
1385
1391 public int countAll() throws SystemException {
1392 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1393 FINDER_ARGS_EMPTY, this);
1394
1395 if (count == null) {
1396 Session session = null;
1397
1398 try {
1399 session = openSession();
1400
1401 Query q = session.createQuery(_SQL_COUNT_WIKIPAGERESOURCE);
1402
1403 count = (Long)q.uniqueResult();
1404 }
1405 catch (Exception e) {
1406 throw processException(e);
1407 }
1408 finally {
1409 if (count == null) {
1410 count = Long.valueOf(0);
1411 }
1412
1413 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1414 FINDER_ARGS_EMPTY, count);
1415
1416 closeSession(session);
1417 }
1418 }
1419
1420 return count.intValue();
1421 }
1422
1423
1426 public void afterPropertiesSet() {
1427 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1428 com.liferay.portal.util.PropsUtil.get(
1429 "value.object.listener.com.liferay.portlet.wiki.model.WikiPageResource")));
1430
1431 if (listenerClassNames.length > 0) {
1432 try {
1433 List<ModelListener<WikiPageResource>> listenersList = new ArrayList<ModelListener<WikiPageResource>>();
1434
1435 for (String listenerClassName : listenerClassNames) {
1436 listenersList.add((ModelListener<WikiPageResource>)InstanceFactory.newInstance(
1437 listenerClassName));
1438 }
1439
1440 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1441 }
1442 catch (Exception e) {
1443 _log.error(e);
1444 }
1445 }
1446 }
1447
1448 public void destroy() {
1449 EntityCacheUtil.removeCache(WikiPageResourceImpl.class.getName());
1450 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1451 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1452 }
1453
1454 @BeanReference(type = WikiNodePersistence.class)
1455 protected WikiNodePersistence wikiNodePersistence;
1456 @BeanReference(type = WikiPagePersistence.class)
1457 protected WikiPagePersistence wikiPagePersistence;
1458 @BeanReference(type = WikiPageResourcePersistence.class)
1459 protected WikiPageResourcePersistence wikiPageResourcePersistence;
1460 @BeanReference(type = UserPersistence.class)
1461 protected UserPersistence userPersistence;
1462 private static final String _SQL_SELECT_WIKIPAGERESOURCE = "SELECT wikiPageResource FROM WikiPageResource wikiPageResource";
1463 private static final String _SQL_SELECT_WIKIPAGERESOURCE_WHERE = "SELECT wikiPageResource FROM WikiPageResource wikiPageResource WHERE ";
1464 private static final String _SQL_COUNT_WIKIPAGERESOURCE = "SELECT COUNT(wikiPageResource) FROM WikiPageResource wikiPageResource";
1465 private static final String _SQL_COUNT_WIKIPAGERESOURCE_WHERE = "SELECT COUNT(wikiPageResource) FROM WikiPageResource wikiPageResource WHERE ";
1466 private static final String _FINDER_COLUMN_UUID_UUID_1 = "wikiPageResource.uuid IS NULL";
1467 private static final String _FINDER_COLUMN_UUID_UUID_2 = "wikiPageResource.uuid = ?";
1468 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(wikiPageResource.uuid IS NULL OR wikiPageResource.uuid = ?)";
1469 private static final String _FINDER_COLUMN_N_T_NODEID_2 = "wikiPageResource.nodeId = ? AND ";
1470 private static final String _FINDER_COLUMN_N_T_TITLE_1 = "wikiPageResource.title IS NULL";
1471 private static final String _FINDER_COLUMN_N_T_TITLE_2 = "wikiPageResource.title = ?";
1472 private static final String _FINDER_COLUMN_N_T_TITLE_3 = "(wikiPageResource.title IS NULL OR wikiPageResource.title = ?)";
1473 private static final String _ORDER_BY_ENTITY_ALIAS = "wikiPageResource.";
1474 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No WikiPageResource exists with the primary key ";
1475 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No WikiPageResource exists with the key {";
1476 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1477 private static Log _log = LogFactoryUtil.getLog(WikiPageResourcePersistenceImpl.class);
1478 private static WikiPageResource _nullWikiPageResource = new WikiPageResourceImpl() {
1479 @Override
1480 public Object clone() {
1481 return this;
1482 }
1483
1484 @Override
1485 public CacheModel<WikiPageResource> toCacheModel() {
1486 return _nullWikiPageResourceCacheModel;
1487 }
1488 };
1489
1490 private static CacheModel<WikiPageResource> _nullWikiPageResourceCacheModel = new CacheModel<WikiPageResource>() {
1491 public WikiPageResource toEntityModel() {
1492 return _nullWikiPageResource;
1493 }
1494 };
1495 }