001
014
015 package com.liferay.portlet.wiki.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.annotation.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.ModelListener;
039 import com.liferay.portal.service.persistence.BatchSessionUtil;
040 import com.liferay.portal.service.persistence.ResourcePersistence;
041 import com.liferay.portal.service.persistence.UserPersistence;
042 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043
044 import com.liferay.portlet.wiki.NoSuchPageResourceException;
045 import com.liferay.portlet.wiki.model.WikiPageResource;
046 import com.liferay.portlet.wiki.model.impl.WikiPageResourceImpl;
047 import com.liferay.portlet.wiki.model.impl.WikiPageResourceModelImpl;
048
049 import java.io.Serializable;
050
051 import java.util.ArrayList;
052 import java.util.Collections;
053 import java.util.List;
054
055
071 public class WikiPageResourcePersistenceImpl extends BasePersistenceImpl<WikiPageResource>
072 implements WikiPageResourcePersistence {
073 public static final String FINDER_CLASS_NAME_ENTITY = WikiPageResourceImpl.class.getName();
074 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
075 ".List";
076 public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
077 WikiPageResourceModelImpl.FINDER_CACHE_ENABLED,
078 FINDER_CLASS_NAME_LIST, "findByUuid",
079 new String[] {
080 String.class.getName(),
081
082 "java.lang.Integer", "java.lang.Integer",
083 "com.liferay.portal.kernel.util.OrderByComparator"
084 });
085 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
086 WikiPageResourceModelImpl.FINDER_CACHE_ENABLED,
087 FINDER_CLASS_NAME_LIST, "countByUuid",
088 new String[] { String.class.getName() });
089 public static final FinderPath FINDER_PATH_FETCH_BY_N_T = new FinderPath(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
090 WikiPageResourceModelImpl.FINDER_CACHE_ENABLED,
091 FINDER_CLASS_NAME_ENTITY, "fetchByN_T",
092 new String[] { Long.class.getName(), String.class.getName() });
093 public static final FinderPath FINDER_PATH_COUNT_BY_N_T = new FinderPath(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
094 WikiPageResourceModelImpl.FINDER_CACHE_ENABLED,
095 FINDER_CLASS_NAME_LIST, "countByN_T",
096 new String[] { Long.class.getName(), String.class.getName() });
097 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
098 WikiPageResourceModelImpl.FINDER_CACHE_ENABLED,
099 FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
100 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
101 WikiPageResourceModelImpl.FINDER_CACHE_ENABLED,
102 FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
103
104
109 public void cacheResult(WikiPageResource wikiPageResource) {
110 EntityCacheUtil.putResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
111 WikiPageResourceImpl.class, wikiPageResource.getPrimaryKey(),
112 wikiPageResource);
113
114 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T,
115 new Object[] {
116 new Long(wikiPageResource.getNodeId()),
117
118 wikiPageResource.getTitle()
119 }, wikiPageResource);
120 }
121
122
127 public void cacheResult(List<WikiPageResource> wikiPageResources) {
128 for (WikiPageResource wikiPageResource : wikiPageResources) {
129 if (EntityCacheUtil.getResult(
130 WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
131 WikiPageResourceImpl.class,
132 wikiPageResource.getPrimaryKey(), this) == null) {
133 cacheResult(wikiPageResource);
134 }
135 }
136 }
137
138
145 public void clearCache() {
146 CacheRegistryUtil.clear(WikiPageResourceImpl.class.getName());
147 EntityCacheUtil.clearCache(WikiPageResourceImpl.class.getName());
148 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
149 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
150 }
151
152
159 public void clearCache(WikiPageResource wikiPageResource) {
160 EntityCacheUtil.removeResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
161 WikiPageResourceImpl.class, wikiPageResource.getPrimaryKey());
162
163 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_T,
164 new Object[] {
165 new Long(wikiPageResource.getNodeId()),
166
167 wikiPageResource.getTitle()
168 });
169 }
170
171
177 public WikiPageResource create(long resourcePrimKey) {
178 WikiPageResource wikiPageResource = new WikiPageResourceImpl();
179
180 wikiPageResource.setNew(true);
181 wikiPageResource.setPrimaryKey(resourcePrimKey);
182
183 String uuid = PortalUUIDUtil.generate();
184
185 wikiPageResource.setUuid(uuid);
186
187 return wikiPageResource;
188 }
189
190
198 public WikiPageResource remove(Serializable primaryKey)
199 throws NoSuchModelException, SystemException {
200 return remove(((Long)primaryKey).longValue());
201 }
202
203
211 public WikiPageResource remove(long resourcePrimKey)
212 throws NoSuchPageResourceException, SystemException {
213 Session session = null;
214
215 try {
216 session = openSession();
217
218 WikiPageResource wikiPageResource = (WikiPageResource)session.get(WikiPageResourceImpl.class,
219 new Long(resourcePrimKey));
220
221 if (wikiPageResource == null) {
222 if (_log.isWarnEnabled()) {
223 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
224 resourcePrimKey);
225 }
226
227 throw new NoSuchPageResourceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
228 resourcePrimKey);
229 }
230
231 return remove(wikiPageResource);
232 }
233 catch (NoSuchPageResourceException nsee) {
234 throw nsee;
235 }
236 catch (Exception e) {
237 throw processException(e);
238 }
239 finally {
240 closeSession(session);
241 }
242 }
243
244 protected WikiPageResource removeImpl(WikiPageResource wikiPageResource)
245 throws SystemException {
246 wikiPageResource = toUnwrappedModel(wikiPageResource);
247
248 Session session = null;
249
250 try {
251 session = openSession();
252
253 BatchSessionUtil.delete(session, wikiPageResource);
254 }
255 catch (Exception e) {
256 throw processException(e);
257 }
258 finally {
259 closeSession(session);
260 }
261
262 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
263
264 WikiPageResourceModelImpl wikiPageResourceModelImpl = (WikiPageResourceModelImpl)wikiPageResource;
265
266 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_T,
267 new Object[] {
268 new Long(wikiPageResourceModelImpl.getNodeId()),
269
270 wikiPageResourceModelImpl.getTitle()
271 });
272
273 EntityCacheUtil.removeResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
274 WikiPageResourceImpl.class, wikiPageResource.getPrimaryKey());
275
276 return wikiPageResource;
277 }
278
279 public WikiPageResource updateImpl(
280 com.liferay.portlet.wiki.model.WikiPageResource wikiPageResource,
281 boolean merge) throws SystemException {
282 wikiPageResource = toUnwrappedModel(wikiPageResource);
283
284 boolean isNew = wikiPageResource.isNew();
285
286 WikiPageResourceModelImpl wikiPageResourceModelImpl = (WikiPageResourceModelImpl)wikiPageResource;
287
288 if (Validator.isNull(wikiPageResource.getUuid())) {
289 String uuid = PortalUUIDUtil.generate();
290
291 wikiPageResource.setUuid(uuid);
292 }
293
294 Session session = null;
295
296 try {
297 session = openSession();
298
299 BatchSessionUtil.update(session, wikiPageResource, merge);
300
301 wikiPageResource.setNew(false);
302 }
303 catch (Exception e) {
304 throw processException(e);
305 }
306 finally {
307 closeSession(session);
308 }
309
310 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
311
312 EntityCacheUtil.putResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
313 WikiPageResourceImpl.class, wikiPageResource.getPrimaryKey(),
314 wikiPageResource);
315
316 if (!isNew &&
317 ((wikiPageResource.getNodeId() != wikiPageResourceModelImpl.getOriginalNodeId()) ||
318 !Validator.equals(wikiPageResource.getTitle(),
319 wikiPageResourceModelImpl.getOriginalTitle()))) {
320 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_T,
321 new Object[] {
322 new Long(wikiPageResourceModelImpl.getOriginalNodeId()),
323
324 wikiPageResourceModelImpl.getOriginalTitle()
325 });
326 }
327
328 if (isNew ||
329 ((wikiPageResource.getNodeId() != wikiPageResourceModelImpl.getOriginalNodeId()) ||
330 !Validator.equals(wikiPageResource.getTitle(),
331 wikiPageResourceModelImpl.getOriginalTitle()))) {
332 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T,
333 new Object[] {
334 new Long(wikiPageResource.getNodeId()),
335
336 wikiPageResource.getTitle()
337 }, wikiPageResource);
338 }
339
340 return wikiPageResource;
341 }
342
343 protected WikiPageResource toUnwrappedModel(
344 WikiPageResource wikiPageResource) {
345 if (wikiPageResource instanceof WikiPageResourceImpl) {
346 return wikiPageResource;
347 }
348
349 WikiPageResourceImpl wikiPageResourceImpl = new WikiPageResourceImpl();
350
351 wikiPageResourceImpl.setNew(wikiPageResource.isNew());
352 wikiPageResourceImpl.setPrimaryKey(wikiPageResource.getPrimaryKey());
353
354 wikiPageResourceImpl.setUuid(wikiPageResource.getUuid());
355 wikiPageResourceImpl.setResourcePrimKey(wikiPageResource.getResourcePrimKey());
356 wikiPageResourceImpl.setNodeId(wikiPageResource.getNodeId());
357 wikiPageResourceImpl.setTitle(wikiPageResource.getTitle());
358
359 return wikiPageResourceImpl;
360 }
361
362
370 public WikiPageResource findByPrimaryKey(Serializable primaryKey)
371 throws NoSuchModelException, SystemException {
372 return findByPrimaryKey(((Long)primaryKey).longValue());
373 }
374
375
383 public WikiPageResource findByPrimaryKey(long resourcePrimKey)
384 throws NoSuchPageResourceException, SystemException {
385 WikiPageResource wikiPageResource = fetchByPrimaryKey(resourcePrimKey);
386
387 if (wikiPageResource == null) {
388 if (_log.isWarnEnabled()) {
389 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + resourcePrimKey);
390 }
391
392 throw new NoSuchPageResourceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
393 resourcePrimKey);
394 }
395
396 return wikiPageResource;
397 }
398
399
406 public WikiPageResource fetchByPrimaryKey(Serializable primaryKey)
407 throws SystemException {
408 return fetchByPrimaryKey(((Long)primaryKey).longValue());
409 }
410
411
418 public WikiPageResource fetchByPrimaryKey(long resourcePrimKey)
419 throws SystemException {
420 WikiPageResource wikiPageResource = (WikiPageResource)EntityCacheUtil.getResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
421 WikiPageResourceImpl.class, resourcePrimKey, this);
422
423 if (wikiPageResource == null) {
424 Session session = null;
425
426 try {
427 session = openSession();
428
429 wikiPageResource = (WikiPageResource)session.get(WikiPageResourceImpl.class,
430 new Long(resourcePrimKey));
431 }
432 catch (Exception e) {
433 throw processException(e);
434 }
435 finally {
436 if (wikiPageResource != null) {
437 cacheResult(wikiPageResource);
438 }
439
440 closeSession(session);
441 }
442 }
443
444 return wikiPageResource;
445 }
446
447
454 public List<WikiPageResource> findByUuid(String uuid)
455 throws SystemException {
456 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
457 }
458
459
472 public List<WikiPageResource> findByUuid(String uuid, int start, int end)
473 throws SystemException {
474 return findByUuid(uuid, start, end, null);
475 }
476
477
491 public List<WikiPageResource> findByUuid(String uuid, int start, int end,
492 OrderByComparator orderByComparator) throws SystemException {
493 Object[] finderArgs = new Object[] {
494 uuid,
495
496 String.valueOf(start), String.valueOf(end),
497 String.valueOf(orderByComparator)
498 };
499
500 List<WikiPageResource> list = (List<WikiPageResource>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
501 finderArgs, this);
502
503 if (list == null) {
504 StringBundler query = null;
505
506 if (orderByComparator != null) {
507 query = new StringBundler(3 +
508 (orderByComparator.getOrderByFields().length * 3));
509 }
510 else {
511 query = new StringBundler(2);
512 }
513
514 query.append(_SQL_SELECT_WIKIPAGERESOURCE_WHERE);
515
516 if (uuid == null) {
517 query.append(_FINDER_COLUMN_UUID_UUID_1);
518 }
519 else {
520 if (uuid.equals(StringPool.BLANK)) {
521 query.append(_FINDER_COLUMN_UUID_UUID_3);
522 }
523 else {
524 query.append(_FINDER_COLUMN_UUID_UUID_2);
525 }
526 }
527
528 if (orderByComparator != null) {
529 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
530 orderByComparator);
531 }
532
533 String sql = query.toString();
534
535 Session session = null;
536
537 try {
538 session = openSession();
539
540 Query q = session.createQuery(sql);
541
542 QueryPos qPos = QueryPos.getInstance(q);
543
544 if (uuid != null) {
545 qPos.add(uuid);
546 }
547
548 list = (List<WikiPageResource>)QueryUtil.list(q, getDialect(),
549 start, end);
550 }
551 catch (Exception e) {
552 throw processException(e);
553 }
554 finally {
555 if (list == null) {
556 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_UUID,
557 finderArgs);
558 }
559 else {
560 cacheResult(list);
561
562 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID,
563 finderArgs, list);
564 }
565
566 closeSession(session);
567 }
568 }
569
570 return list;
571 }
572
573
586 public WikiPageResource findByUuid_First(String uuid,
587 OrderByComparator orderByComparator)
588 throws NoSuchPageResourceException, SystemException {
589 List<WikiPageResource> list = findByUuid(uuid, 0, 1, orderByComparator);
590
591 if (list.isEmpty()) {
592 StringBundler msg = new StringBundler(4);
593
594 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
595
596 msg.append("uuid=");
597 msg.append(uuid);
598
599 msg.append(StringPool.CLOSE_CURLY_BRACE);
600
601 throw new NoSuchPageResourceException(msg.toString());
602 }
603 else {
604 return list.get(0);
605 }
606 }
607
608
621 public WikiPageResource findByUuid_Last(String uuid,
622 OrderByComparator orderByComparator)
623 throws NoSuchPageResourceException, SystemException {
624 int count = countByUuid(uuid);
625
626 List<WikiPageResource> list = findByUuid(uuid, count - 1, count,
627 orderByComparator);
628
629 if (list.isEmpty()) {
630 StringBundler msg = new StringBundler(4);
631
632 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
633
634 msg.append("uuid=");
635 msg.append(uuid);
636
637 msg.append(StringPool.CLOSE_CURLY_BRACE);
638
639 throw new NoSuchPageResourceException(msg.toString());
640 }
641 else {
642 return list.get(0);
643 }
644 }
645
646
660 public WikiPageResource[] findByUuid_PrevAndNext(long resourcePrimKey,
661 String uuid, OrderByComparator orderByComparator)
662 throws NoSuchPageResourceException, SystemException {
663 WikiPageResource wikiPageResource = findByPrimaryKey(resourcePrimKey);
664
665 Session session = null;
666
667 try {
668 session = openSession();
669
670 WikiPageResource[] array = new WikiPageResourceImpl[3];
671
672 array[0] = getByUuid_PrevAndNext(session, wikiPageResource, uuid,
673 orderByComparator, true);
674
675 array[1] = wikiPageResource;
676
677 array[2] = getByUuid_PrevAndNext(session, wikiPageResource, uuid,
678 orderByComparator, false);
679
680 return array;
681 }
682 catch (Exception e) {
683 throw processException(e);
684 }
685 finally {
686 closeSession(session);
687 }
688 }
689
690 protected WikiPageResource getByUuid_PrevAndNext(Session session,
691 WikiPageResource wikiPageResource, String uuid,
692 OrderByComparator orderByComparator, boolean previous) {
693 StringBundler query = null;
694
695 if (orderByComparator != null) {
696 query = new StringBundler(6 +
697 (orderByComparator.getOrderByFields().length * 6));
698 }
699 else {
700 query = new StringBundler(3);
701 }
702
703 query.append(_SQL_SELECT_WIKIPAGERESOURCE_WHERE);
704
705 if (uuid == null) {
706 query.append(_FINDER_COLUMN_UUID_UUID_1);
707 }
708 else {
709 if (uuid.equals(StringPool.BLANK)) {
710 query.append(_FINDER_COLUMN_UUID_UUID_3);
711 }
712 else {
713 query.append(_FINDER_COLUMN_UUID_UUID_2);
714 }
715 }
716
717 if (orderByComparator != null) {
718 String[] orderByFields = orderByComparator.getOrderByFields();
719
720 if (orderByFields.length > 0) {
721 query.append(WHERE_AND);
722 }
723
724 for (int i = 0; i < orderByFields.length; i++) {
725 query.append(_ORDER_BY_ENTITY_ALIAS);
726 query.append(orderByFields[i]);
727
728 if ((i + 1) < orderByFields.length) {
729 if (orderByComparator.isAscending() ^ previous) {
730 query.append(WHERE_GREATER_THAN_HAS_NEXT);
731 }
732 else {
733 query.append(WHERE_LESSER_THAN_HAS_NEXT);
734 }
735 }
736 else {
737 if (orderByComparator.isAscending() ^ previous) {
738 query.append(WHERE_GREATER_THAN);
739 }
740 else {
741 query.append(WHERE_LESSER_THAN);
742 }
743 }
744 }
745
746 query.append(ORDER_BY_CLAUSE);
747
748 for (int i = 0; i < orderByFields.length; i++) {
749 query.append(_ORDER_BY_ENTITY_ALIAS);
750 query.append(orderByFields[i]);
751
752 if ((i + 1) < orderByFields.length) {
753 if (orderByComparator.isAscending() ^ previous) {
754 query.append(ORDER_BY_ASC_HAS_NEXT);
755 }
756 else {
757 query.append(ORDER_BY_DESC_HAS_NEXT);
758 }
759 }
760 else {
761 if (orderByComparator.isAscending() ^ previous) {
762 query.append(ORDER_BY_ASC);
763 }
764 else {
765 query.append(ORDER_BY_DESC);
766 }
767 }
768 }
769 }
770
771 String sql = query.toString();
772
773 Query q = session.createQuery(sql);
774
775 q.setFirstResult(0);
776 q.setMaxResults(2);
777
778 QueryPos qPos = QueryPos.getInstance(q);
779
780 if (uuid != null) {
781 qPos.add(uuid);
782 }
783
784 if (orderByComparator != null) {
785 Object[] values = orderByComparator.getOrderByValues(wikiPageResource);
786
787 for (Object value : values) {
788 qPos.add(value);
789 }
790 }
791
792 List<WikiPageResource> list = q.list();
793
794 if (list.size() == 2) {
795 return list.get(1);
796 }
797 else {
798 return null;
799 }
800 }
801
802
811 public WikiPageResource findByN_T(long nodeId, String title)
812 throws NoSuchPageResourceException, SystemException {
813 WikiPageResource wikiPageResource = fetchByN_T(nodeId, title);
814
815 if (wikiPageResource == null) {
816 StringBundler msg = new StringBundler(6);
817
818 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
819
820 msg.append("nodeId=");
821 msg.append(nodeId);
822
823 msg.append(", title=");
824 msg.append(title);
825
826 msg.append(StringPool.CLOSE_CURLY_BRACE);
827
828 if (_log.isWarnEnabled()) {
829 _log.warn(msg.toString());
830 }
831
832 throw new NoSuchPageResourceException(msg.toString());
833 }
834
835 return wikiPageResource;
836 }
837
838
846 public WikiPageResource fetchByN_T(long nodeId, String title)
847 throws SystemException {
848 return fetchByN_T(nodeId, title, true);
849 }
850
851
859 public WikiPageResource fetchByN_T(long nodeId, String title,
860 boolean retrieveFromCache) throws SystemException {
861 Object[] finderArgs = new Object[] { nodeId, title };
862
863 Object result = null;
864
865 if (retrieveFromCache) {
866 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_N_T,
867 finderArgs, this);
868 }
869
870 if (result == null) {
871 StringBundler query = new StringBundler(3);
872
873 query.append(_SQL_SELECT_WIKIPAGERESOURCE_WHERE);
874
875 query.append(_FINDER_COLUMN_N_T_NODEID_2);
876
877 if (title == null) {
878 query.append(_FINDER_COLUMN_N_T_TITLE_1);
879 }
880 else {
881 if (title.equals(StringPool.BLANK)) {
882 query.append(_FINDER_COLUMN_N_T_TITLE_3);
883 }
884 else {
885 query.append(_FINDER_COLUMN_N_T_TITLE_2);
886 }
887 }
888
889 String sql = query.toString();
890
891 Session session = null;
892
893 try {
894 session = openSession();
895
896 Query q = session.createQuery(sql);
897
898 QueryPos qPos = QueryPos.getInstance(q);
899
900 qPos.add(nodeId);
901
902 if (title != null) {
903 qPos.add(title);
904 }
905
906 List<WikiPageResource> list = q.list();
907
908 result = list;
909
910 WikiPageResource wikiPageResource = null;
911
912 if (list.isEmpty()) {
913 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T,
914 finderArgs, list);
915 }
916 else {
917 wikiPageResource = list.get(0);
918
919 cacheResult(wikiPageResource);
920
921 if ((wikiPageResource.getNodeId() != nodeId) ||
922 (wikiPageResource.getTitle() == null) ||
923 !wikiPageResource.getTitle().equals(title)) {
924 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T,
925 finderArgs, wikiPageResource);
926 }
927 }
928
929 return wikiPageResource;
930 }
931 catch (Exception e) {
932 throw processException(e);
933 }
934 finally {
935 if (result == null) {
936 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_T,
937 finderArgs);
938 }
939
940 closeSession(session);
941 }
942 }
943 else {
944 if (result instanceof List<?>) {
945 return null;
946 }
947 else {
948 return (WikiPageResource)result;
949 }
950 }
951 }
952
953
959 public List<WikiPageResource> findAll() throws SystemException {
960 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
961 }
962
963
975 public List<WikiPageResource> findAll(int start, int end)
976 throws SystemException {
977 return findAll(start, end, null);
978 }
979
980
993 public List<WikiPageResource> findAll(int start, int end,
994 OrderByComparator orderByComparator) throws SystemException {
995 Object[] finderArgs = new Object[] {
996 String.valueOf(start), String.valueOf(end),
997 String.valueOf(orderByComparator)
998 };
999
1000 List<WikiPageResource> list = (List<WikiPageResource>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1001 finderArgs, this);
1002
1003 if (list == null) {
1004 StringBundler query = null;
1005 String sql = null;
1006
1007 if (orderByComparator != null) {
1008 query = new StringBundler(2 +
1009 (orderByComparator.getOrderByFields().length * 3));
1010
1011 query.append(_SQL_SELECT_WIKIPAGERESOURCE);
1012
1013 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1014 orderByComparator);
1015
1016 sql = query.toString();
1017 }
1018 else {
1019 sql = _SQL_SELECT_WIKIPAGERESOURCE;
1020 }
1021
1022 Session session = null;
1023
1024 try {
1025 session = openSession();
1026
1027 Query q = session.createQuery(sql);
1028
1029 if (orderByComparator == null) {
1030 list = (List<WikiPageResource>)QueryUtil.list(q,
1031 getDialect(), start, end, false);
1032
1033 Collections.sort(list);
1034 }
1035 else {
1036 list = (List<WikiPageResource>)QueryUtil.list(q,
1037 getDialect(), start, end);
1038 }
1039 }
1040 catch (Exception e) {
1041 throw processException(e);
1042 }
1043 finally {
1044 if (list == null) {
1045 FinderCacheUtil.removeResult(FINDER_PATH_FIND_ALL,
1046 finderArgs);
1047 }
1048 else {
1049 cacheResult(list);
1050
1051 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs,
1052 list);
1053 }
1054
1055 closeSession(session);
1056 }
1057 }
1058
1059 return list;
1060 }
1061
1062
1068 public void removeByUuid(String uuid) throws SystemException {
1069 for (WikiPageResource wikiPageResource : findByUuid(uuid)) {
1070 remove(wikiPageResource);
1071 }
1072 }
1073
1074
1081 public void removeByN_T(long nodeId, String title)
1082 throws NoSuchPageResourceException, SystemException {
1083 WikiPageResource wikiPageResource = findByN_T(nodeId, title);
1084
1085 remove(wikiPageResource);
1086 }
1087
1088
1093 public void removeAll() throws SystemException {
1094 for (WikiPageResource wikiPageResource : findAll()) {
1095 remove(wikiPageResource);
1096 }
1097 }
1098
1099
1106 public int countByUuid(String uuid) throws SystemException {
1107 Object[] finderArgs = new Object[] { uuid };
1108
1109 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1110 finderArgs, this);
1111
1112 if (count == null) {
1113 StringBundler query = new StringBundler(2);
1114
1115 query.append(_SQL_COUNT_WIKIPAGERESOURCE_WHERE);
1116
1117 if (uuid == null) {
1118 query.append(_FINDER_COLUMN_UUID_UUID_1);
1119 }
1120 else {
1121 if (uuid.equals(StringPool.BLANK)) {
1122 query.append(_FINDER_COLUMN_UUID_UUID_3);
1123 }
1124 else {
1125 query.append(_FINDER_COLUMN_UUID_UUID_2);
1126 }
1127 }
1128
1129 String sql = query.toString();
1130
1131 Session session = null;
1132
1133 try {
1134 session = openSession();
1135
1136 Query q = session.createQuery(sql);
1137
1138 QueryPos qPos = QueryPos.getInstance(q);
1139
1140 if (uuid != null) {
1141 qPos.add(uuid);
1142 }
1143
1144 count = (Long)q.uniqueResult();
1145 }
1146 catch (Exception e) {
1147 throw processException(e);
1148 }
1149 finally {
1150 if (count == null) {
1151 count = Long.valueOf(0);
1152 }
1153
1154 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
1155 finderArgs, count);
1156
1157 closeSession(session);
1158 }
1159 }
1160
1161 return count.intValue();
1162 }
1163
1164
1172 public int countByN_T(long nodeId, String title) throws SystemException {
1173 Object[] finderArgs = new Object[] { nodeId, title };
1174
1175 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_N_T,
1176 finderArgs, this);
1177
1178 if (count == null) {
1179 StringBundler query = new StringBundler(3);
1180
1181 query.append(_SQL_COUNT_WIKIPAGERESOURCE_WHERE);
1182
1183 query.append(_FINDER_COLUMN_N_T_NODEID_2);
1184
1185 if (title == null) {
1186 query.append(_FINDER_COLUMN_N_T_TITLE_1);
1187 }
1188 else {
1189 if (title.equals(StringPool.BLANK)) {
1190 query.append(_FINDER_COLUMN_N_T_TITLE_3);
1191 }
1192 else {
1193 query.append(_FINDER_COLUMN_N_T_TITLE_2);
1194 }
1195 }
1196
1197 String sql = query.toString();
1198
1199 Session session = null;
1200
1201 try {
1202 session = openSession();
1203
1204 Query q = session.createQuery(sql);
1205
1206 QueryPos qPos = QueryPos.getInstance(q);
1207
1208 qPos.add(nodeId);
1209
1210 if (title != null) {
1211 qPos.add(title);
1212 }
1213
1214 count = (Long)q.uniqueResult();
1215 }
1216 catch (Exception e) {
1217 throw processException(e);
1218 }
1219 finally {
1220 if (count == null) {
1221 count = Long.valueOf(0);
1222 }
1223
1224 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_T, finderArgs,
1225 count);
1226
1227 closeSession(session);
1228 }
1229 }
1230
1231 return count.intValue();
1232 }
1233
1234
1240 public int countAll() throws SystemException {
1241 Object[] finderArgs = new Object[0];
1242
1243 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1244 finderArgs, this);
1245
1246 if (count == null) {
1247 Session session = null;
1248
1249 try {
1250 session = openSession();
1251
1252 Query q = session.createQuery(_SQL_COUNT_WIKIPAGERESOURCE);
1253
1254 count = (Long)q.uniqueResult();
1255 }
1256 catch (Exception e) {
1257 throw processException(e);
1258 }
1259 finally {
1260 if (count == null) {
1261 count = Long.valueOf(0);
1262 }
1263
1264 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1265 count);
1266
1267 closeSession(session);
1268 }
1269 }
1270
1271 return count.intValue();
1272 }
1273
1274
1277 public void afterPropertiesSet() {
1278 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1279 com.liferay.portal.util.PropsUtil.get(
1280 "value.object.listener.com.liferay.portlet.wiki.model.WikiPageResource")));
1281
1282 if (listenerClassNames.length > 0) {
1283 try {
1284 List<ModelListener<WikiPageResource>> listenersList = new ArrayList<ModelListener<WikiPageResource>>();
1285
1286 for (String listenerClassName : listenerClassNames) {
1287 listenersList.add((ModelListener<WikiPageResource>)InstanceFactory.newInstance(
1288 listenerClassName));
1289 }
1290
1291 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1292 }
1293 catch (Exception e) {
1294 _log.error(e);
1295 }
1296 }
1297 }
1298
1299 public void destroy() {
1300 EntityCacheUtil.removeCache(WikiPageResourceImpl.class.getName());
1301 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1302 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
1303 }
1304
1305 @BeanReference(type = WikiNodePersistence.class)
1306 protected WikiNodePersistence wikiNodePersistence;
1307 @BeanReference(type = WikiPagePersistence.class)
1308 protected WikiPagePersistence wikiPagePersistence;
1309 @BeanReference(type = WikiPageResourcePersistence.class)
1310 protected WikiPageResourcePersistence wikiPageResourcePersistence;
1311 @BeanReference(type = ResourcePersistence.class)
1312 protected ResourcePersistence resourcePersistence;
1313 @BeanReference(type = UserPersistence.class)
1314 protected UserPersistence userPersistence;
1315 private static final String _SQL_SELECT_WIKIPAGERESOURCE = "SELECT wikiPageResource FROM WikiPageResource wikiPageResource";
1316 private static final String _SQL_SELECT_WIKIPAGERESOURCE_WHERE = "SELECT wikiPageResource FROM WikiPageResource wikiPageResource WHERE ";
1317 private static final String _SQL_COUNT_WIKIPAGERESOURCE = "SELECT COUNT(wikiPageResource) FROM WikiPageResource wikiPageResource";
1318 private static final String _SQL_COUNT_WIKIPAGERESOURCE_WHERE = "SELECT COUNT(wikiPageResource) FROM WikiPageResource wikiPageResource WHERE ";
1319 private static final String _FINDER_COLUMN_UUID_UUID_1 = "wikiPageResource.uuid IS NULL";
1320 private static final String _FINDER_COLUMN_UUID_UUID_2 = "wikiPageResource.uuid = ?";
1321 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(wikiPageResource.uuid IS NULL OR wikiPageResource.uuid = ?)";
1322 private static final String _FINDER_COLUMN_N_T_NODEID_2 = "wikiPageResource.nodeId = ? AND ";
1323 private static final String _FINDER_COLUMN_N_T_TITLE_1 = "wikiPageResource.title IS NULL";
1324 private static final String _FINDER_COLUMN_N_T_TITLE_2 = "wikiPageResource.title = ?";
1325 private static final String _FINDER_COLUMN_N_T_TITLE_3 = "(wikiPageResource.title IS NULL OR wikiPageResource.title = ?)";
1326 private static final String _ORDER_BY_ENTITY_ALIAS = "wikiPageResource.";
1327 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No WikiPageResource exists with the primary key ";
1328 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No WikiPageResource exists with the key {";
1329 private static Log _log = LogFactoryUtil.getLog(WikiPageResourcePersistenceImpl.class);
1330 }