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