001
014
015 package com.liferay.portlet.wiki.service.persistence;
016
017 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
018 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
019 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderPath;
021 import com.liferay.portal.kernel.dao.orm.Query;
022 import com.liferay.portal.kernel.dao.orm.QueryPos;
023 import com.liferay.portal.kernel.dao.orm.QueryUtil;
024 import com.liferay.portal.kernel.dao.orm.Session;
025 import com.liferay.portal.kernel.exception.SystemException;
026 import com.liferay.portal.kernel.log.Log;
027 import com.liferay.portal.kernel.log.LogFactoryUtil;
028 import com.liferay.portal.kernel.util.GetterUtil;
029 import com.liferay.portal.kernel.util.InstanceFactory;
030 import com.liferay.portal.kernel.util.OrderByComparator;
031 import com.liferay.portal.kernel.util.SetUtil;
032 import com.liferay.portal.kernel.util.StringBundler;
033 import com.liferay.portal.kernel.util.StringPool;
034 import com.liferay.portal.kernel.util.StringUtil;
035 import com.liferay.portal.kernel.util.UnmodifiableList;
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.impl.BasePersistenceImpl;
041
042 import com.liferay.portlet.wiki.NoSuchPageResourceException;
043 import com.liferay.portlet.wiki.model.WikiPageResource;
044 import com.liferay.portlet.wiki.model.impl.WikiPageResourceImpl;
045 import com.liferay.portlet.wiki.model.impl.WikiPageResourceModelImpl;
046
047 import java.io.Serializable;
048
049 import java.util.ArrayList;
050 import java.util.Collections;
051 import java.util.List;
052 import java.util.Set;
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_ALL = new FinderPath(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
079 WikiPageResourceModelImpl.FINDER_CACHE_ENABLED,
080 WikiPageResourceImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
081 "findAll", new String[0]);
082 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
083 WikiPageResourceModelImpl.FINDER_CACHE_ENABLED,
084 WikiPageResourceImpl.class,
085 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
086 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
087 WikiPageResourceModelImpl.FINDER_CACHE_ENABLED, Long.class,
088 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
089 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
090 WikiPageResourceModelImpl.FINDER_CACHE_ENABLED,
091 WikiPageResourceImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
092 "findByUuid",
093 new String[] {
094 String.class.getName(),
095
096 Integer.class.getName(), Integer.class.getName(),
097 OrderByComparator.class.getName()
098 });
099 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
100 WikiPageResourceModelImpl.FINDER_CACHE_ENABLED,
101 WikiPageResourceImpl.class,
102 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
103 new String[] { String.class.getName() },
104 WikiPageResourceModelImpl.UUID_COLUMN_BITMASK);
105 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
106 WikiPageResourceModelImpl.FINDER_CACHE_ENABLED, Long.class,
107 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
108 new String[] { String.class.getName() });
109
110
117 public List<WikiPageResource> findByUuid(String uuid)
118 throws SystemException {
119 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
120 }
121
122
135 public List<WikiPageResource> findByUuid(String uuid, int start, int end)
136 throws SystemException {
137 return findByUuid(uuid, start, end, null);
138 }
139
140
154 public List<WikiPageResource> findByUuid(String uuid, int start, int end,
155 OrderByComparator orderByComparator) throws SystemException {
156 boolean pagination = true;
157 FinderPath finderPath = null;
158 Object[] finderArgs = null;
159
160 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
161 (orderByComparator == null)) {
162 pagination = false;
163 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
164 finderArgs = new Object[] { uuid };
165 }
166 else {
167 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
168 finderArgs = new Object[] { uuid, start, end, orderByComparator };
169 }
170
171 List<WikiPageResource> list = (List<WikiPageResource>)FinderCacheUtil.getResult(finderPath,
172 finderArgs, this);
173
174 if ((list != null) && !list.isEmpty()) {
175 for (WikiPageResource wikiPageResource : list) {
176 if (!Validator.equals(uuid, wikiPageResource.getUuid())) {
177 list = null;
178
179 break;
180 }
181 }
182 }
183
184 if (list == null) {
185 StringBundler query = null;
186
187 if (orderByComparator != null) {
188 query = new StringBundler(3 +
189 (orderByComparator.getOrderByFields().length * 3));
190 }
191 else {
192 query = new StringBundler(3);
193 }
194
195 query.append(_SQL_SELECT_WIKIPAGERESOURCE_WHERE);
196
197 boolean bindUuid = false;
198
199 if (uuid == null) {
200 query.append(_FINDER_COLUMN_UUID_UUID_1);
201 }
202 else if (uuid.equals(StringPool.BLANK)) {
203 query.append(_FINDER_COLUMN_UUID_UUID_3);
204 }
205 else {
206 bindUuid = true;
207
208 query.append(_FINDER_COLUMN_UUID_UUID_2);
209 }
210
211 if (orderByComparator != null) {
212 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
213 orderByComparator);
214 }
215 else
216 if (pagination) {
217 query.append(WikiPageResourceModelImpl.ORDER_BY_JPQL);
218 }
219
220 String sql = query.toString();
221
222 Session session = null;
223
224 try {
225 session = openSession();
226
227 Query q = session.createQuery(sql);
228
229 QueryPos qPos = QueryPos.getInstance(q);
230
231 if (bindUuid) {
232 qPos.add(uuid);
233 }
234
235 if (!pagination) {
236 list = (List<WikiPageResource>)QueryUtil.list(q,
237 getDialect(), start, end, false);
238
239 Collections.sort(list);
240
241 list = new UnmodifiableList<WikiPageResource>(list);
242 }
243 else {
244 list = (List<WikiPageResource>)QueryUtil.list(q,
245 getDialect(), start, end);
246 }
247
248 cacheResult(list);
249
250 FinderCacheUtil.putResult(finderPath, finderArgs, list);
251 }
252 catch (Exception e) {
253 FinderCacheUtil.removeResult(finderPath, finderArgs);
254
255 throw processException(e);
256 }
257 finally {
258 closeSession(session);
259 }
260 }
261
262 return list;
263 }
264
265
274 public WikiPageResource findByUuid_First(String uuid,
275 OrderByComparator orderByComparator)
276 throws NoSuchPageResourceException, SystemException {
277 WikiPageResource wikiPageResource = fetchByUuid_First(uuid,
278 orderByComparator);
279
280 if (wikiPageResource != null) {
281 return wikiPageResource;
282 }
283
284 StringBundler msg = new StringBundler(4);
285
286 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
287
288 msg.append("uuid=");
289 msg.append(uuid);
290
291 msg.append(StringPool.CLOSE_CURLY_BRACE);
292
293 throw new NoSuchPageResourceException(msg.toString());
294 }
295
296
304 public WikiPageResource fetchByUuid_First(String uuid,
305 OrderByComparator orderByComparator) throws SystemException {
306 List<WikiPageResource> list = findByUuid(uuid, 0, 1, orderByComparator);
307
308 if (!list.isEmpty()) {
309 return list.get(0);
310 }
311
312 return null;
313 }
314
315
324 public WikiPageResource findByUuid_Last(String uuid,
325 OrderByComparator orderByComparator)
326 throws NoSuchPageResourceException, SystemException {
327 WikiPageResource wikiPageResource = fetchByUuid_Last(uuid,
328 orderByComparator);
329
330 if (wikiPageResource != null) {
331 return wikiPageResource;
332 }
333
334 StringBundler msg = new StringBundler(4);
335
336 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
337
338 msg.append("uuid=");
339 msg.append(uuid);
340
341 msg.append(StringPool.CLOSE_CURLY_BRACE);
342
343 throw new NoSuchPageResourceException(msg.toString());
344 }
345
346
354 public WikiPageResource fetchByUuid_Last(String uuid,
355 OrderByComparator orderByComparator) throws SystemException {
356 int count = countByUuid(uuid);
357
358 List<WikiPageResource> list = findByUuid(uuid, count - 1, count,
359 orderByComparator);
360
361 if (!list.isEmpty()) {
362 return list.get(0);
363 }
364
365 return null;
366 }
367
368
378 public WikiPageResource[] findByUuid_PrevAndNext(long resourcePrimKey,
379 String uuid, OrderByComparator orderByComparator)
380 throws NoSuchPageResourceException, SystemException {
381 WikiPageResource wikiPageResource = findByPrimaryKey(resourcePrimKey);
382
383 Session session = null;
384
385 try {
386 session = openSession();
387
388 WikiPageResource[] array = new WikiPageResourceImpl[3];
389
390 array[0] = getByUuid_PrevAndNext(session, wikiPageResource, uuid,
391 orderByComparator, true);
392
393 array[1] = wikiPageResource;
394
395 array[2] = getByUuid_PrevAndNext(session, wikiPageResource, uuid,
396 orderByComparator, false);
397
398 return array;
399 }
400 catch (Exception e) {
401 throw processException(e);
402 }
403 finally {
404 closeSession(session);
405 }
406 }
407
408 protected WikiPageResource getByUuid_PrevAndNext(Session session,
409 WikiPageResource wikiPageResource, String uuid,
410 OrderByComparator orderByComparator, boolean previous) {
411 StringBundler query = null;
412
413 if (orderByComparator != null) {
414 query = new StringBundler(6 +
415 (orderByComparator.getOrderByFields().length * 6));
416 }
417 else {
418 query = new StringBundler(3);
419 }
420
421 query.append(_SQL_SELECT_WIKIPAGERESOURCE_WHERE);
422
423 boolean bindUuid = false;
424
425 if (uuid == null) {
426 query.append(_FINDER_COLUMN_UUID_UUID_1);
427 }
428 else if (uuid.equals(StringPool.BLANK)) {
429 query.append(_FINDER_COLUMN_UUID_UUID_3);
430 }
431 else {
432 bindUuid = true;
433
434 query.append(_FINDER_COLUMN_UUID_UUID_2);
435 }
436
437 if (orderByComparator != null) {
438 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
439
440 if (orderByConditionFields.length > 0) {
441 query.append(WHERE_AND);
442 }
443
444 for (int i = 0; i < orderByConditionFields.length; i++) {
445 query.append(_ORDER_BY_ENTITY_ALIAS);
446 query.append(orderByConditionFields[i]);
447
448 if ((i + 1) < orderByConditionFields.length) {
449 if (orderByComparator.isAscending() ^ previous) {
450 query.append(WHERE_GREATER_THAN_HAS_NEXT);
451 }
452 else {
453 query.append(WHERE_LESSER_THAN_HAS_NEXT);
454 }
455 }
456 else {
457 if (orderByComparator.isAscending() ^ previous) {
458 query.append(WHERE_GREATER_THAN);
459 }
460 else {
461 query.append(WHERE_LESSER_THAN);
462 }
463 }
464 }
465
466 query.append(ORDER_BY_CLAUSE);
467
468 String[] orderByFields = orderByComparator.getOrderByFields();
469
470 for (int i = 0; i < orderByFields.length; i++) {
471 query.append(_ORDER_BY_ENTITY_ALIAS);
472 query.append(orderByFields[i]);
473
474 if ((i + 1) < orderByFields.length) {
475 if (orderByComparator.isAscending() ^ previous) {
476 query.append(ORDER_BY_ASC_HAS_NEXT);
477 }
478 else {
479 query.append(ORDER_BY_DESC_HAS_NEXT);
480 }
481 }
482 else {
483 if (orderByComparator.isAscending() ^ previous) {
484 query.append(ORDER_BY_ASC);
485 }
486 else {
487 query.append(ORDER_BY_DESC);
488 }
489 }
490 }
491 }
492 else {
493 query.append(WikiPageResourceModelImpl.ORDER_BY_JPQL);
494 }
495
496 String sql = query.toString();
497
498 Query q = session.createQuery(sql);
499
500 q.setFirstResult(0);
501 q.setMaxResults(2);
502
503 QueryPos qPos = QueryPos.getInstance(q);
504
505 if (bindUuid) {
506 qPos.add(uuid);
507 }
508
509 if (orderByComparator != null) {
510 Object[] values = orderByComparator.getOrderByConditionValues(wikiPageResource);
511
512 for (Object value : values) {
513 qPos.add(value);
514 }
515 }
516
517 List<WikiPageResource> list = q.list();
518
519 if (list.size() == 2) {
520 return list.get(1);
521 }
522 else {
523 return null;
524 }
525 }
526
527
533 public void removeByUuid(String uuid) throws SystemException {
534 for (WikiPageResource wikiPageResource : findByUuid(uuid,
535 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
536 remove(wikiPageResource);
537 }
538 }
539
540
547 public int countByUuid(String uuid) throws SystemException {
548 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
549
550 Object[] finderArgs = new Object[] { uuid };
551
552 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
553 this);
554
555 if (count == null) {
556 StringBundler query = new StringBundler(2);
557
558 query.append(_SQL_COUNT_WIKIPAGERESOURCE_WHERE);
559
560 boolean bindUuid = false;
561
562 if (uuid == null) {
563 query.append(_FINDER_COLUMN_UUID_UUID_1);
564 }
565 else if (uuid.equals(StringPool.BLANK)) {
566 query.append(_FINDER_COLUMN_UUID_UUID_3);
567 }
568 else {
569 bindUuid = true;
570
571 query.append(_FINDER_COLUMN_UUID_UUID_2);
572 }
573
574 String sql = query.toString();
575
576 Session session = null;
577
578 try {
579 session = openSession();
580
581 Query q = session.createQuery(sql);
582
583 QueryPos qPos = QueryPos.getInstance(q);
584
585 if (bindUuid) {
586 qPos.add(uuid);
587 }
588
589 count = (Long)q.uniqueResult();
590
591 FinderCacheUtil.putResult(finderPath, finderArgs, count);
592 }
593 catch (Exception e) {
594 FinderCacheUtil.removeResult(finderPath, finderArgs);
595
596 throw processException(e);
597 }
598 finally {
599 closeSession(session);
600 }
601 }
602
603 return count.intValue();
604 }
605
606 private static final String _FINDER_COLUMN_UUID_UUID_1 = "wikiPageResource.uuid IS NULL";
607 private static final String _FINDER_COLUMN_UUID_UUID_2 = "wikiPageResource.uuid = ?";
608 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(wikiPageResource.uuid IS NULL OR wikiPageResource.uuid = '')";
609 public static final FinderPath FINDER_PATH_FETCH_BY_N_T = new FinderPath(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
610 WikiPageResourceModelImpl.FINDER_CACHE_ENABLED,
611 WikiPageResourceImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByN_T",
612 new String[] { Long.class.getName(), String.class.getName() },
613 WikiPageResourceModelImpl.NODEID_COLUMN_BITMASK |
614 WikiPageResourceModelImpl.TITLE_COLUMN_BITMASK);
615 public static final FinderPath FINDER_PATH_COUNT_BY_N_T = new FinderPath(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
616 WikiPageResourceModelImpl.FINDER_CACHE_ENABLED, Long.class,
617 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_T",
618 new String[] { Long.class.getName(), String.class.getName() });
619
620
629 public WikiPageResource findByN_T(long nodeId, String title)
630 throws NoSuchPageResourceException, SystemException {
631 WikiPageResource wikiPageResource = fetchByN_T(nodeId, title);
632
633 if (wikiPageResource == null) {
634 StringBundler msg = new StringBundler(6);
635
636 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
637
638 msg.append("nodeId=");
639 msg.append(nodeId);
640
641 msg.append(", title=");
642 msg.append(title);
643
644 msg.append(StringPool.CLOSE_CURLY_BRACE);
645
646 if (_log.isWarnEnabled()) {
647 _log.warn(msg.toString());
648 }
649
650 throw new NoSuchPageResourceException(msg.toString());
651 }
652
653 return wikiPageResource;
654 }
655
656
664 public WikiPageResource fetchByN_T(long nodeId, String title)
665 throws SystemException {
666 return fetchByN_T(nodeId, title, true);
667 }
668
669
678 public WikiPageResource fetchByN_T(long nodeId, String title,
679 boolean retrieveFromCache) throws SystemException {
680 Object[] finderArgs = new Object[] { nodeId, title };
681
682 Object result = null;
683
684 if (retrieveFromCache) {
685 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_N_T,
686 finderArgs, this);
687 }
688
689 if (result instanceof WikiPageResource) {
690 WikiPageResource wikiPageResource = (WikiPageResource)result;
691
692 if ((nodeId != wikiPageResource.getNodeId()) ||
693 !Validator.equals(title, wikiPageResource.getTitle())) {
694 result = null;
695 }
696 }
697
698 if (result == null) {
699 StringBundler query = new StringBundler(4);
700
701 query.append(_SQL_SELECT_WIKIPAGERESOURCE_WHERE);
702
703 query.append(_FINDER_COLUMN_N_T_NODEID_2);
704
705 boolean bindTitle = false;
706
707 if (title == null) {
708 query.append(_FINDER_COLUMN_N_T_TITLE_1);
709 }
710 else if (title.equals(StringPool.BLANK)) {
711 query.append(_FINDER_COLUMN_N_T_TITLE_3);
712 }
713 else {
714 bindTitle = true;
715
716 query.append(_FINDER_COLUMN_N_T_TITLE_2);
717 }
718
719 String sql = query.toString();
720
721 Session session = null;
722
723 try {
724 session = openSession();
725
726 Query q = session.createQuery(sql);
727
728 QueryPos qPos = QueryPos.getInstance(q);
729
730 qPos.add(nodeId);
731
732 if (bindTitle) {
733 qPos.add(title);
734 }
735
736 List<WikiPageResource> list = q.list();
737
738 if (list.isEmpty()) {
739 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T,
740 finderArgs, list);
741 }
742 else {
743 WikiPageResource wikiPageResource = list.get(0);
744
745 result = wikiPageResource;
746
747 cacheResult(wikiPageResource);
748
749 if ((wikiPageResource.getNodeId() != nodeId) ||
750 (wikiPageResource.getTitle() == null) ||
751 !wikiPageResource.getTitle().equals(title)) {
752 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T,
753 finderArgs, wikiPageResource);
754 }
755 }
756 }
757 catch (Exception e) {
758 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_T,
759 finderArgs);
760
761 throw processException(e);
762 }
763 finally {
764 closeSession(session);
765 }
766 }
767
768 if (result instanceof List<?>) {
769 return null;
770 }
771 else {
772 return (WikiPageResource)result;
773 }
774 }
775
776
784 public WikiPageResource removeByN_T(long nodeId, String title)
785 throws NoSuchPageResourceException, SystemException {
786 WikiPageResource wikiPageResource = findByN_T(nodeId, title);
787
788 return remove(wikiPageResource);
789 }
790
791
799 public int countByN_T(long nodeId, String title) throws SystemException {
800 FinderPath finderPath = FINDER_PATH_COUNT_BY_N_T;
801
802 Object[] finderArgs = new Object[] { nodeId, title };
803
804 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
805 this);
806
807 if (count == null) {
808 StringBundler query = new StringBundler(3);
809
810 query.append(_SQL_COUNT_WIKIPAGERESOURCE_WHERE);
811
812 query.append(_FINDER_COLUMN_N_T_NODEID_2);
813
814 boolean bindTitle = false;
815
816 if (title == null) {
817 query.append(_FINDER_COLUMN_N_T_TITLE_1);
818 }
819 else if (title.equals(StringPool.BLANK)) {
820 query.append(_FINDER_COLUMN_N_T_TITLE_3);
821 }
822 else {
823 bindTitle = true;
824
825 query.append(_FINDER_COLUMN_N_T_TITLE_2);
826 }
827
828 String sql = query.toString();
829
830 Session session = null;
831
832 try {
833 session = openSession();
834
835 Query q = session.createQuery(sql);
836
837 QueryPos qPos = QueryPos.getInstance(q);
838
839 qPos.add(nodeId);
840
841 if (bindTitle) {
842 qPos.add(title);
843 }
844
845 count = (Long)q.uniqueResult();
846
847 FinderCacheUtil.putResult(finderPath, finderArgs, count);
848 }
849 catch (Exception e) {
850 FinderCacheUtil.removeResult(finderPath, finderArgs);
851
852 throw processException(e);
853 }
854 finally {
855 closeSession(session);
856 }
857 }
858
859 return count.intValue();
860 }
861
862 private static final String _FINDER_COLUMN_N_T_NODEID_2 = "wikiPageResource.nodeId = ? AND ";
863 private static final String _FINDER_COLUMN_N_T_TITLE_1 = "wikiPageResource.title IS NULL";
864 private static final String _FINDER_COLUMN_N_T_TITLE_2 = "wikiPageResource.title = ?";
865 private static final String _FINDER_COLUMN_N_T_TITLE_3 = "(wikiPageResource.title IS NULL OR wikiPageResource.title = '')";
866
867
872 public void cacheResult(WikiPageResource wikiPageResource) {
873 EntityCacheUtil.putResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
874 WikiPageResourceImpl.class, wikiPageResource.getPrimaryKey(),
875 wikiPageResource);
876
877 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T,
878 new Object[] {
879 wikiPageResource.getNodeId(), wikiPageResource.getTitle()
880 }, wikiPageResource);
881
882 wikiPageResource.resetOriginalValues();
883 }
884
885
890 public void cacheResult(List<WikiPageResource> wikiPageResources) {
891 for (WikiPageResource wikiPageResource : wikiPageResources) {
892 if (EntityCacheUtil.getResult(
893 WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
894 WikiPageResourceImpl.class,
895 wikiPageResource.getPrimaryKey()) == null) {
896 cacheResult(wikiPageResource);
897 }
898 else {
899 wikiPageResource.resetOriginalValues();
900 }
901 }
902 }
903
904
911 @Override
912 public void clearCache() {
913 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
914 CacheRegistryUtil.clear(WikiPageResourceImpl.class.getName());
915 }
916
917 EntityCacheUtil.clearCache(WikiPageResourceImpl.class.getName());
918
919 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
920 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
921 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
922 }
923
924
931 @Override
932 public void clearCache(WikiPageResource wikiPageResource) {
933 EntityCacheUtil.removeResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
934 WikiPageResourceImpl.class, wikiPageResource.getPrimaryKey());
935
936 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
937 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
938
939 clearUniqueFindersCache(wikiPageResource);
940 }
941
942 @Override
943 public void clearCache(List<WikiPageResource> wikiPageResources) {
944 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
945 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
946
947 for (WikiPageResource wikiPageResource : wikiPageResources) {
948 EntityCacheUtil.removeResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
949 WikiPageResourceImpl.class, wikiPageResource.getPrimaryKey());
950
951 clearUniqueFindersCache(wikiPageResource);
952 }
953 }
954
955 protected void cacheUniqueFindersCache(WikiPageResource wikiPageResource) {
956 if (wikiPageResource.isNew()) {
957 Object[] args = new Object[] {
958 wikiPageResource.getNodeId(), wikiPageResource.getTitle()
959 };
960
961 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_T, args,
962 Long.valueOf(1));
963 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T, args,
964 wikiPageResource);
965 }
966 else {
967 WikiPageResourceModelImpl wikiPageResourceModelImpl = (WikiPageResourceModelImpl)wikiPageResource;
968
969 if ((wikiPageResourceModelImpl.getColumnBitmask() &
970 FINDER_PATH_FETCH_BY_N_T.getColumnBitmask()) != 0) {
971 Object[] args = new Object[] {
972 wikiPageResource.getNodeId(),
973 wikiPageResource.getTitle()
974 };
975
976 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_T, args,
977 Long.valueOf(1));
978 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T, args,
979 wikiPageResource);
980 }
981 }
982 }
983
984 protected void clearUniqueFindersCache(WikiPageResource wikiPageResource) {
985 WikiPageResourceModelImpl wikiPageResourceModelImpl = (WikiPageResourceModelImpl)wikiPageResource;
986
987 Object[] args = new Object[] {
988 wikiPageResource.getNodeId(), wikiPageResource.getTitle()
989 };
990
991 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T, args);
992 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_T, args);
993
994 if ((wikiPageResourceModelImpl.getColumnBitmask() &
995 FINDER_PATH_FETCH_BY_N_T.getColumnBitmask()) != 0) {
996 args = new Object[] {
997 wikiPageResourceModelImpl.getOriginalNodeId(),
998 wikiPageResourceModelImpl.getOriginalTitle()
999 };
1000
1001 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T, args);
1002 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_T, args);
1003 }
1004 }
1005
1006
1012 public WikiPageResource create(long resourcePrimKey) {
1013 WikiPageResource wikiPageResource = new WikiPageResourceImpl();
1014
1015 wikiPageResource.setNew(true);
1016 wikiPageResource.setPrimaryKey(resourcePrimKey);
1017
1018 String uuid = PortalUUIDUtil.generate();
1019
1020 wikiPageResource.setUuid(uuid);
1021
1022 return wikiPageResource;
1023 }
1024
1025
1033 public WikiPageResource remove(long resourcePrimKey)
1034 throws NoSuchPageResourceException, SystemException {
1035 return remove((Serializable)resourcePrimKey);
1036 }
1037
1038
1046 @Override
1047 public WikiPageResource remove(Serializable primaryKey)
1048 throws NoSuchPageResourceException, SystemException {
1049 Session session = null;
1050
1051 try {
1052 session = openSession();
1053
1054 WikiPageResource wikiPageResource = (WikiPageResource)session.get(WikiPageResourceImpl.class,
1055 primaryKey);
1056
1057 if (wikiPageResource == null) {
1058 if (_log.isWarnEnabled()) {
1059 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1060 }
1061
1062 throw new NoSuchPageResourceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1063 primaryKey);
1064 }
1065
1066 return remove(wikiPageResource);
1067 }
1068 catch (NoSuchPageResourceException nsee) {
1069 throw nsee;
1070 }
1071 catch (Exception e) {
1072 throw processException(e);
1073 }
1074 finally {
1075 closeSession(session);
1076 }
1077 }
1078
1079 @Override
1080 protected WikiPageResource removeImpl(WikiPageResource wikiPageResource)
1081 throws SystemException {
1082 wikiPageResource = toUnwrappedModel(wikiPageResource);
1083
1084 Session session = null;
1085
1086 try {
1087 session = openSession();
1088
1089 if (!session.contains(wikiPageResource)) {
1090 wikiPageResource = (WikiPageResource)session.get(WikiPageResourceImpl.class,
1091 wikiPageResource.getPrimaryKeyObj());
1092 }
1093
1094 if (wikiPageResource != null) {
1095 session.delete(wikiPageResource);
1096 }
1097 }
1098 catch (Exception e) {
1099 throw processException(e);
1100 }
1101 finally {
1102 closeSession(session);
1103 }
1104
1105 if (wikiPageResource != null) {
1106 clearCache(wikiPageResource);
1107 }
1108
1109 return wikiPageResource;
1110 }
1111
1112 @Override
1113 public WikiPageResource updateImpl(
1114 com.liferay.portlet.wiki.model.WikiPageResource wikiPageResource)
1115 throws SystemException {
1116 wikiPageResource = toUnwrappedModel(wikiPageResource);
1117
1118 boolean isNew = wikiPageResource.isNew();
1119
1120 WikiPageResourceModelImpl wikiPageResourceModelImpl = (WikiPageResourceModelImpl)wikiPageResource;
1121
1122 if (Validator.isNull(wikiPageResource.getUuid())) {
1123 String uuid = PortalUUIDUtil.generate();
1124
1125 wikiPageResource.setUuid(uuid);
1126 }
1127
1128 Session session = null;
1129
1130 try {
1131 session = openSession();
1132
1133 if (wikiPageResource.isNew()) {
1134 session.save(wikiPageResource);
1135
1136 wikiPageResource.setNew(false);
1137 }
1138 else {
1139 session.merge(wikiPageResource);
1140 }
1141 }
1142 catch (Exception e) {
1143 throw processException(e);
1144 }
1145 finally {
1146 closeSession(session);
1147 }
1148
1149 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1150
1151 if (isNew || !WikiPageResourceModelImpl.COLUMN_BITMASK_ENABLED) {
1152 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1153 }
1154
1155 else {
1156 if ((wikiPageResourceModelImpl.getColumnBitmask() &
1157 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
1158 Object[] args = new Object[] {
1159 wikiPageResourceModelImpl.getOriginalUuid()
1160 };
1161
1162 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
1163 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
1164 args);
1165
1166 args = new Object[] { wikiPageResourceModelImpl.getUuid() };
1167
1168 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
1169 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
1170 args);
1171 }
1172 }
1173
1174 EntityCacheUtil.putResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
1175 WikiPageResourceImpl.class, wikiPageResource.getPrimaryKey(),
1176 wikiPageResource);
1177
1178 clearUniqueFindersCache(wikiPageResource);
1179 cacheUniqueFindersCache(wikiPageResource);
1180
1181 return wikiPageResource;
1182 }
1183
1184 protected WikiPageResource toUnwrappedModel(
1185 WikiPageResource wikiPageResource) {
1186 if (wikiPageResource instanceof WikiPageResourceImpl) {
1187 return wikiPageResource;
1188 }
1189
1190 WikiPageResourceImpl wikiPageResourceImpl = new WikiPageResourceImpl();
1191
1192 wikiPageResourceImpl.setNew(wikiPageResource.isNew());
1193 wikiPageResourceImpl.setPrimaryKey(wikiPageResource.getPrimaryKey());
1194
1195 wikiPageResourceImpl.setUuid(wikiPageResource.getUuid());
1196 wikiPageResourceImpl.setResourcePrimKey(wikiPageResource.getResourcePrimKey());
1197 wikiPageResourceImpl.setNodeId(wikiPageResource.getNodeId());
1198 wikiPageResourceImpl.setTitle(wikiPageResource.getTitle());
1199
1200 return wikiPageResourceImpl;
1201 }
1202
1203
1211 @Override
1212 public WikiPageResource findByPrimaryKey(Serializable primaryKey)
1213 throws NoSuchPageResourceException, SystemException {
1214 WikiPageResource wikiPageResource = fetchByPrimaryKey(primaryKey);
1215
1216 if (wikiPageResource == null) {
1217 if (_log.isWarnEnabled()) {
1218 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1219 }
1220
1221 throw new NoSuchPageResourceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1222 primaryKey);
1223 }
1224
1225 return wikiPageResource;
1226 }
1227
1228
1236 public WikiPageResource findByPrimaryKey(long resourcePrimKey)
1237 throws NoSuchPageResourceException, SystemException {
1238 return findByPrimaryKey((Serializable)resourcePrimKey);
1239 }
1240
1241
1248 @Override
1249 public WikiPageResource fetchByPrimaryKey(Serializable primaryKey)
1250 throws SystemException {
1251 WikiPageResource wikiPageResource = (WikiPageResource)EntityCacheUtil.getResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
1252 WikiPageResourceImpl.class, primaryKey);
1253
1254 if (wikiPageResource == _nullWikiPageResource) {
1255 return null;
1256 }
1257
1258 if (wikiPageResource == null) {
1259 Session session = null;
1260
1261 try {
1262 session = openSession();
1263
1264 wikiPageResource = (WikiPageResource)session.get(WikiPageResourceImpl.class,
1265 primaryKey);
1266
1267 if (wikiPageResource != null) {
1268 cacheResult(wikiPageResource);
1269 }
1270 else {
1271 EntityCacheUtil.putResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
1272 WikiPageResourceImpl.class, primaryKey,
1273 _nullWikiPageResource);
1274 }
1275 }
1276 catch (Exception e) {
1277 EntityCacheUtil.removeResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
1278 WikiPageResourceImpl.class, primaryKey);
1279
1280 throw processException(e);
1281 }
1282 finally {
1283 closeSession(session);
1284 }
1285 }
1286
1287 return wikiPageResource;
1288 }
1289
1290
1297 public WikiPageResource fetchByPrimaryKey(long resourcePrimKey)
1298 throws SystemException {
1299 return fetchByPrimaryKey((Serializable)resourcePrimKey);
1300 }
1301
1302
1308 public List<WikiPageResource> findAll() throws SystemException {
1309 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1310 }
1311
1312
1324 public List<WikiPageResource> findAll(int start, int end)
1325 throws SystemException {
1326 return findAll(start, end, null);
1327 }
1328
1329
1342 public List<WikiPageResource> findAll(int start, int end,
1343 OrderByComparator orderByComparator) throws SystemException {
1344 boolean pagination = true;
1345 FinderPath finderPath = null;
1346 Object[] finderArgs = null;
1347
1348 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1349 (orderByComparator == null)) {
1350 pagination = false;
1351 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1352 finderArgs = FINDER_ARGS_EMPTY;
1353 }
1354 else {
1355 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1356 finderArgs = new Object[] { start, end, orderByComparator };
1357 }
1358
1359 List<WikiPageResource> list = (List<WikiPageResource>)FinderCacheUtil.getResult(finderPath,
1360 finderArgs, this);
1361
1362 if (list == null) {
1363 StringBundler query = null;
1364 String sql = null;
1365
1366 if (orderByComparator != null) {
1367 query = new StringBundler(2 +
1368 (orderByComparator.getOrderByFields().length * 3));
1369
1370 query.append(_SQL_SELECT_WIKIPAGERESOURCE);
1371
1372 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1373 orderByComparator);
1374
1375 sql = query.toString();
1376 }
1377 else {
1378 sql = _SQL_SELECT_WIKIPAGERESOURCE;
1379
1380 if (pagination) {
1381 sql = sql.concat(WikiPageResourceModelImpl.ORDER_BY_JPQL);
1382 }
1383 }
1384
1385 Session session = null;
1386
1387 try {
1388 session = openSession();
1389
1390 Query q = session.createQuery(sql);
1391
1392 if (!pagination) {
1393 list = (List<WikiPageResource>)QueryUtil.list(q,
1394 getDialect(), start, end, false);
1395
1396 Collections.sort(list);
1397
1398 list = new UnmodifiableList<WikiPageResource>(list);
1399 }
1400 else {
1401 list = (List<WikiPageResource>)QueryUtil.list(q,
1402 getDialect(), start, end);
1403 }
1404
1405 cacheResult(list);
1406
1407 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1408 }
1409 catch (Exception e) {
1410 FinderCacheUtil.removeResult(finderPath, finderArgs);
1411
1412 throw processException(e);
1413 }
1414 finally {
1415 closeSession(session);
1416 }
1417 }
1418
1419 return list;
1420 }
1421
1422
1427 public void removeAll() throws SystemException {
1428 for (WikiPageResource wikiPageResource : findAll()) {
1429 remove(wikiPageResource);
1430 }
1431 }
1432
1433
1439 public int countAll() throws SystemException {
1440 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1441 FINDER_ARGS_EMPTY, this);
1442
1443 if (count == null) {
1444 Session session = null;
1445
1446 try {
1447 session = openSession();
1448
1449 Query q = session.createQuery(_SQL_COUNT_WIKIPAGERESOURCE);
1450
1451 count = (Long)q.uniqueResult();
1452
1453 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1454 FINDER_ARGS_EMPTY, count);
1455 }
1456 catch (Exception e) {
1457 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1458 FINDER_ARGS_EMPTY);
1459
1460 throw processException(e);
1461 }
1462 finally {
1463 closeSession(session);
1464 }
1465 }
1466
1467 return count.intValue();
1468 }
1469
1470 @Override
1471 protected Set<String> getBadColumnNames() {
1472 return _badColumnNames;
1473 }
1474
1475
1478 public void afterPropertiesSet() {
1479 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1480 com.liferay.portal.util.PropsUtil.get(
1481 "value.object.listener.com.liferay.portlet.wiki.model.WikiPageResource")));
1482
1483 if (listenerClassNames.length > 0) {
1484 try {
1485 List<ModelListener<WikiPageResource>> listenersList = new ArrayList<ModelListener<WikiPageResource>>();
1486
1487 for (String listenerClassName : listenerClassNames) {
1488 listenersList.add((ModelListener<WikiPageResource>)InstanceFactory.newInstance(
1489 getClassLoader(), listenerClassName));
1490 }
1491
1492 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1493 }
1494 catch (Exception e) {
1495 _log.error(e);
1496 }
1497 }
1498 }
1499
1500 public void destroy() {
1501 EntityCacheUtil.removeCache(WikiPageResourceImpl.class.getName());
1502 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1503 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1504 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1505 }
1506
1507 private static final String _SQL_SELECT_WIKIPAGERESOURCE = "SELECT wikiPageResource FROM WikiPageResource wikiPageResource";
1508 private static final String _SQL_SELECT_WIKIPAGERESOURCE_WHERE = "SELECT wikiPageResource FROM WikiPageResource wikiPageResource WHERE ";
1509 private static final String _SQL_COUNT_WIKIPAGERESOURCE = "SELECT COUNT(wikiPageResource) FROM WikiPageResource wikiPageResource";
1510 private static final String _SQL_COUNT_WIKIPAGERESOURCE_WHERE = "SELECT COUNT(wikiPageResource) FROM WikiPageResource wikiPageResource WHERE ";
1511 private static final String _ORDER_BY_ENTITY_ALIAS = "wikiPageResource.";
1512 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No WikiPageResource exists with the primary key ";
1513 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No WikiPageResource exists with the key {";
1514 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1515 private static Log _log = LogFactoryUtil.getLog(WikiPageResourcePersistenceImpl.class);
1516 private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
1517 "uuid"
1518 });
1519 private static WikiPageResource _nullWikiPageResource = new WikiPageResourceImpl() {
1520 @Override
1521 public Object clone() {
1522 return this;
1523 }
1524
1525 @Override
1526 public CacheModel<WikiPageResource> toCacheModel() {
1527 return _nullWikiPageResourceCacheModel;
1528 }
1529 };
1530
1531 private static CacheModel<WikiPageResource> _nullWikiPageResourceCacheModel = new CacheModel<WikiPageResource>() {
1532 public WikiPageResource toEntityModel() {
1533 return _nullWikiPageResource;
1534 }
1535 };
1536 }