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 if (wikiPageResource.isCachedModel() ||
254 BatchSessionUtil.isEnabled()) {
255 Object staleObject = session.get(WikiPageResourceImpl.class,
256 wikiPageResource.getPrimaryKeyObj());
257
258 if (staleObject != null) {
259 session.evict(staleObject);
260 }
261 }
262
263 session.delete(wikiPageResource);
264
265 session.flush();
266 }
267 catch (Exception e) {
268 throw processException(e);
269 }
270 finally {
271 closeSession(session);
272 }
273
274 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
275
276 WikiPageResourceModelImpl wikiPageResourceModelImpl = (WikiPageResourceModelImpl)wikiPageResource;
277
278 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_T,
279 new Object[] {
280 new Long(wikiPageResourceModelImpl.getOriginalNodeId()),
281
282 wikiPageResourceModelImpl.getOriginalTitle()
283 });
284
285 EntityCacheUtil.removeResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
286 WikiPageResourceImpl.class, wikiPageResource.getPrimaryKey());
287
288 return wikiPageResource;
289 }
290
291 public WikiPageResource updateImpl(
292 com.liferay.portlet.wiki.model.WikiPageResource wikiPageResource,
293 boolean merge) throws SystemException {
294 wikiPageResource = toUnwrappedModel(wikiPageResource);
295
296 boolean isNew = wikiPageResource.isNew();
297
298 WikiPageResourceModelImpl wikiPageResourceModelImpl = (WikiPageResourceModelImpl)wikiPageResource;
299
300 if (Validator.isNull(wikiPageResource.getUuid())) {
301 String uuid = PortalUUIDUtil.generate();
302
303 wikiPageResource.setUuid(uuid);
304 }
305
306 Session session = null;
307
308 try {
309 session = openSession();
310
311 BatchSessionUtil.update(session, wikiPageResource, merge);
312
313 wikiPageResource.setNew(false);
314 }
315 catch (Exception e) {
316 throw processException(e);
317 }
318 finally {
319 closeSession(session);
320 }
321
322 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
323
324 EntityCacheUtil.putResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
325 WikiPageResourceImpl.class, wikiPageResource.getPrimaryKey(),
326 wikiPageResource);
327
328 if (!isNew &&
329 ((wikiPageResource.getNodeId() != wikiPageResourceModelImpl.getOriginalNodeId()) ||
330 !Validator.equals(wikiPageResource.getTitle(),
331 wikiPageResourceModelImpl.getOriginalTitle()))) {
332 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_T,
333 new Object[] {
334 new Long(wikiPageResourceModelImpl.getOriginalNodeId()),
335
336 wikiPageResourceModelImpl.getOriginalTitle()
337 });
338 }
339
340 if (isNew ||
341 ((wikiPageResource.getNodeId() != wikiPageResourceModelImpl.getOriginalNodeId()) ||
342 !Validator.equals(wikiPageResource.getTitle(),
343 wikiPageResourceModelImpl.getOriginalTitle()))) {
344 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T,
345 new Object[] {
346 new Long(wikiPageResource.getNodeId()),
347
348 wikiPageResource.getTitle()
349 }, wikiPageResource);
350 }
351
352 return wikiPageResource;
353 }
354
355 protected WikiPageResource toUnwrappedModel(
356 WikiPageResource wikiPageResource) {
357 if (wikiPageResource instanceof WikiPageResourceImpl) {
358 return wikiPageResource;
359 }
360
361 WikiPageResourceImpl wikiPageResourceImpl = new WikiPageResourceImpl();
362
363 wikiPageResourceImpl.setNew(wikiPageResource.isNew());
364 wikiPageResourceImpl.setPrimaryKey(wikiPageResource.getPrimaryKey());
365
366 wikiPageResourceImpl.setUuid(wikiPageResource.getUuid());
367 wikiPageResourceImpl.setResourcePrimKey(wikiPageResource.getResourcePrimKey());
368 wikiPageResourceImpl.setNodeId(wikiPageResource.getNodeId());
369 wikiPageResourceImpl.setTitle(wikiPageResource.getTitle());
370
371 return wikiPageResourceImpl;
372 }
373
374
382 public WikiPageResource findByPrimaryKey(Serializable primaryKey)
383 throws NoSuchModelException, SystemException {
384 return findByPrimaryKey(((Long)primaryKey).longValue());
385 }
386
387
395 public WikiPageResource findByPrimaryKey(long resourcePrimKey)
396 throws NoSuchPageResourceException, SystemException {
397 WikiPageResource wikiPageResource = fetchByPrimaryKey(resourcePrimKey);
398
399 if (wikiPageResource == null) {
400 if (_log.isWarnEnabled()) {
401 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + resourcePrimKey);
402 }
403
404 throw new NoSuchPageResourceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
405 resourcePrimKey);
406 }
407
408 return wikiPageResource;
409 }
410
411
418 public WikiPageResource fetchByPrimaryKey(Serializable primaryKey)
419 throws SystemException {
420 return fetchByPrimaryKey(((Long)primaryKey).longValue());
421 }
422
423
430 public WikiPageResource fetchByPrimaryKey(long resourcePrimKey)
431 throws SystemException {
432 WikiPageResource wikiPageResource = (WikiPageResource)EntityCacheUtil.getResult(WikiPageResourceModelImpl.ENTITY_CACHE_ENABLED,
433 WikiPageResourceImpl.class, resourcePrimKey, this);
434
435 if (wikiPageResource == null) {
436 Session session = null;
437
438 try {
439 session = openSession();
440
441 wikiPageResource = (WikiPageResource)session.get(WikiPageResourceImpl.class,
442 new Long(resourcePrimKey));
443 }
444 catch (Exception e) {
445 throw processException(e);
446 }
447 finally {
448 if (wikiPageResource != null) {
449 cacheResult(wikiPageResource);
450 }
451
452 closeSession(session);
453 }
454 }
455
456 return wikiPageResource;
457 }
458
459
466 public List<WikiPageResource> findByUuid(String uuid)
467 throws SystemException {
468 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
469 }
470
471
484 public List<WikiPageResource> findByUuid(String uuid, int start, int end)
485 throws SystemException {
486 return findByUuid(uuid, start, end, null);
487 }
488
489
503 public List<WikiPageResource> findByUuid(String uuid, int start, int end,
504 OrderByComparator orderByComparator) throws SystemException {
505 Object[] finderArgs = new Object[] {
506 uuid,
507
508 String.valueOf(start), String.valueOf(end),
509 String.valueOf(orderByComparator)
510 };
511
512 List<WikiPageResource> list = (List<WikiPageResource>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
513 finderArgs, this);
514
515 if (list == null) {
516 Session session = null;
517
518 try {
519 session = openSession();
520
521 StringBundler query = null;
522
523 if (orderByComparator != null) {
524 query = new StringBundler(3 +
525 (orderByComparator.getOrderByFields().length * 3));
526 }
527 else {
528 query = new StringBundler(2);
529 }
530
531 query.append(_SQL_SELECT_WIKIPAGERESOURCE_WHERE);
532
533 if (uuid == null) {
534 query.append(_FINDER_COLUMN_UUID_UUID_1);
535 }
536 else {
537 if (uuid.equals(StringPool.BLANK)) {
538 query.append(_FINDER_COLUMN_UUID_UUID_3);
539 }
540 else {
541 query.append(_FINDER_COLUMN_UUID_UUID_2);
542 }
543 }
544
545 if (orderByComparator != null) {
546 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
547 orderByComparator);
548 }
549
550 String sql = query.toString();
551
552 Query q = session.createQuery(sql);
553
554 QueryPos qPos = QueryPos.getInstance(q);
555
556 if (uuid != null) {
557 qPos.add(uuid);
558 }
559
560 list = (List<WikiPageResource>)QueryUtil.list(q, getDialect(),
561 start, end);
562 }
563 catch (Exception e) {
564 throw processException(e);
565 }
566 finally {
567 if (list == null) {
568 list = new ArrayList<WikiPageResource>();
569 }
570
571 cacheResult(list);
572
573 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
574 list);
575
576 closeSession(session);
577 }
578 }
579
580 return list;
581 }
582
583
596 public WikiPageResource findByUuid_First(String uuid,
597 OrderByComparator orderByComparator)
598 throws NoSuchPageResourceException, SystemException {
599 List<WikiPageResource> list = findByUuid(uuid, 0, 1, orderByComparator);
600
601 if (list.isEmpty()) {
602 StringBundler msg = new StringBundler(4);
603
604 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
605
606 msg.append("uuid=");
607 msg.append(uuid);
608
609 msg.append(StringPool.CLOSE_CURLY_BRACE);
610
611 throw new NoSuchPageResourceException(msg.toString());
612 }
613 else {
614 return list.get(0);
615 }
616 }
617
618
631 public WikiPageResource findByUuid_Last(String uuid,
632 OrderByComparator orderByComparator)
633 throws NoSuchPageResourceException, SystemException {
634 int count = countByUuid(uuid);
635
636 List<WikiPageResource> list = findByUuid(uuid, count - 1, count,
637 orderByComparator);
638
639 if (list.isEmpty()) {
640 StringBundler msg = new StringBundler(4);
641
642 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
643
644 msg.append("uuid=");
645 msg.append(uuid);
646
647 msg.append(StringPool.CLOSE_CURLY_BRACE);
648
649 throw new NoSuchPageResourceException(msg.toString());
650 }
651 else {
652 return list.get(0);
653 }
654 }
655
656
670 public WikiPageResource[] findByUuid_PrevAndNext(long resourcePrimKey,
671 String uuid, OrderByComparator orderByComparator)
672 throws NoSuchPageResourceException, SystemException {
673 WikiPageResource wikiPageResource = findByPrimaryKey(resourcePrimKey);
674
675 Session session = null;
676
677 try {
678 session = openSession();
679
680 WikiPageResource[] array = new WikiPageResourceImpl[3];
681
682 array[0] = getByUuid_PrevAndNext(session, wikiPageResource, uuid,
683 orderByComparator, true);
684
685 array[1] = wikiPageResource;
686
687 array[2] = getByUuid_PrevAndNext(session, wikiPageResource, uuid,
688 orderByComparator, false);
689
690 return array;
691 }
692 catch (Exception e) {
693 throw processException(e);
694 }
695 finally {
696 closeSession(session);
697 }
698 }
699
700 protected WikiPageResource getByUuid_PrevAndNext(Session session,
701 WikiPageResource wikiPageResource, String uuid,
702 OrderByComparator orderByComparator, boolean previous) {
703 StringBundler query = null;
704
705 if (orderByComparator != null) {
706 query = new StringBundler(6 +
707 (orderByComparator.getOrderByFields().length * 6));
708 }
709 else {
710 query = new StringBundler(3);
711 }
712
713 query.append(_SQL_SELECT_WIKIPAGERESOURCE_WHERE);
714
715 if (uuid == null) {
716 query.append(_FINDER_COLUMN_UUID_UUID_1);
717 }
718 else {
719 if (uuid.equals(StringPool.BLANK)) {
720 query.append(_FINDER_COLUMN_UUID_UUID_3);
721 }
722 else {
723 query.append(_FINDER_COLUMN_UUID_UUID_2);
724 }
725 }
726
727 if (orderByComparator != null) {
728 String[] orderByFields = orderByComparator.getOrderByFields();
729
730 if (orderByFields.length > 0) {
731 query.append(WHERE_AND);
732 }
733
734 for (int i = 0; i < orderByFields.length; i++) {
735 query.append(_ORDER_BY_ENTITY_ALIAS);
736 query.append(orderByFields[i]);
737
738 if ((i + 1) < orderByFields.length) {
739 if (orderByComparator.isAscending() ^ previous) {
740 query.append(WHERE_GREATER_THAN_HAS_NEXT);
741 }
742 else {
743 query.append(WHERE_LESSER_THAN_HAS_NEXT);
744 }
745 }
746 else {
747 if (orderByComparator.isAscending() ^ previous) {
748 query.append(WHERE_GREATER_THAN);
749 }
750 else {
751 query.append(WHERE_LESSER_THAN);
752 }
753 }
754 }
755
756 query.append(ORDER_BY_CLAUSE);
757
758 for (int i = 0; i < orderByFields.length; i++) {
759 query.append(_ORDER_BY_ENTITY_ALIAS);
760 query.append(orderByFields[i]);
761
762 if ((i + 1) < orderByFields.length) {
763 if (orderByComparator.isAscending() ^ previous) {
764 query.append(ORDER_BY_ASC_HAS_NEXT);
765 }
766 else {
767 query.append(ORDER_BY_DESC_HAS_NEXT);
768 }
769 }
770 else {
771 if (orderByComparator.isAscending() ^ previous) {
772 query.append(ORDER_BY_ASC);
773 }
774 else {
775 query.append(ORDER_BY_DESC);
776 }
777 }
778 }
779 }
780
781 String sql = query.toString();
782
783 Query q = session.createQuery(sql);
784
785 q.setFirstResult(0);
786 q.setMaxResults(2);
787
788 QueryPos qPos = QueryPos.getInstance(q);
789
790 if (uuid != null) {
791 qPos.add(uuid);
792 }
793
794 if (orderByComparator != null) {
795 Object[] values = orderByComparator.getOrderByValues(wikiPageResource);
796
797 for (Object value : values) {
798 qPos.add(value);
799 }
800 }
801
802 List<WikiPageResource> list = q.list();
803
804 if (list.size() == 2) {
805 return list.get(1);
806 }
807 else {
808 return null;
809 }
810 }
811
812
821 public WikiPageResource findByN_T(long nodeId, String title)
822 throws NoSuchPageResourceException, SystemException {
823 WikiPageResource wikiPageResource = fetchByN_T(nodeId, title);
824
825 if (wikiPageResource == null) {
826 StringBundler msg = new StringBundler(6);
827
828 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
829
830 msg.append("nodeId=");
831 msg.append(nodeId);
832
833 msg.append(", title=");
834 msg.append(title);
835
836 msg.append(StringPool.CLOSE_CURLY_BRACE);
837
838 if (_log.isWarnEnabled()) {
839 _log.warn(msg.toString());
840 }
841
842 throw new NoSuchPageResourceException(msg.toString());
843 }
844
845 return wikiPageResource;
846 }
847
848
856 public WikiPageResource fetchByN_T(long nodeId, String title)
857 throws SystemException {
858 return fetchByN_T(nodeId, title, true);
859 }
860
861
869 public WikiPageResource fetchByN_T(long nodeId, String title,
870 boolean retrieveFromCache) throws SystemException {
871 Object[] finderArgs = new Object[] { nodeId, title };
872
873 Object result = null;
874
875 if (retrieveFromCache) {
876 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_N_T,
877 finderArgs, this);
878 }
879
880 if (result == null) {
881 Session session = null;
882
883 try {
884 session = openSession();
885
886 StringBundler query = new StringBundler(3);
887
888 query.append(_SQL_SELECT_WIKIPAGERESOURCE_WHERE);
889
890 query.append(_FINDER_COLUMN_N_T_NODEID_2);
891
892 if (title == null) {
893 query.append(_FINDER_COLUMN_N_T_TITLE_1);
894 }
895 else {
896 if (title.equals(StringPool.BLANK)) {
897 query.append(_FINDER_COLUMN_N_T_TITLE_3);
898 }
899 else {
900 query.append(_FINDER_COLUMN_N_T_TITLE_2);
901 }
902 }
903
904 String sql = query.toString();
905
906 Query q = session.createQuery(sql);
907
908 QueryPos qPos = QueryPos.getInstance(q);
909
910 qPos.add(nodeId);
911
912 if (title != null) {
913 qPos.add(title);
914 }
915
916 List<WikiPageResource> list = q.list();
917
918 result = list;
919
920 WikiPageResource wikiPageResource = null;
921
922 if (list.isEmpty()) {
923 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T,
924 finderArgs, list);
925 }
926 else {
927 wikiPageResource = list.get(0);
928
929 cacheResult(wikiPageResource);
930
931 if ((wikiPageResource.getNodeId() != nodeId) ||
932 (wikiPageResource.getTitle() == null) ||
933 !wikiPageResource.getTitle().equals(title)) {
934 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T,
935 finderArgs, wikiPageResource);
936 }
937 }
938
939 return wikiPageResource;
940 }
941 catch (Exception e) {
942 throw processException(e);
943 }
944 finally {
945 if (result == null) {
946 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T,
947 finderArgs, new ArrayList<WikiPageResource>());
948 }
949
950 closeSession(session);
951 }
952 }
953 else {
954 if (result instanceof List<?>) {
955 return null;
956 }
957 else {
958 return (WikiPageResource)result;
959 }
960 }
961 }
962
963
969 public List<WikiPageResource> findAll() throws SystemException {
970 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
971 }
972
973
985 public List<WikiPageResource> findAll(int start, int end)
986 throws SystemException {
987 return findAll(start, end, null);
988 }
989
990
1003 public List<WikiPageResource> findAll(int start, int end,
1004 OrderByComparator orderByComparator) throws SystemException {
1005 Object[] finderArgs = new Object[] {
1006 String.valueOf(start), String.valueOf(end),
1007 String.valueOf(orderByComparator)
1008 };
1009
1010 List<WikiPageResource> list = (List<WikiPageResource>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1011 finderArgs, this);
1012
1013 if (list == null) {
1014 Session session = null;
1015
1016 try {
1017 session = openSession();
1018
1019 StringBundler query = null;
1020 String sql = null;
1021
1022 if (orderByComparator != null) {
1023 query = new StringBundler(2 +
1024 (orderByComparator.getOrderByFields().length * 3));
1025
1026 query.append(_SQL_SELECT_WIKIPAGERESOURCE);
1027
1028 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1029 orderByComparator);
1030
1031 sql = query.toString();
1032 }
1033 else {
1034 sql = _SQL_SELECT_WIKIPAGERESOURCE;
1035 }
1036
1037 Query q = session.createQuery(sql);
1038
1039 if (orderByComparator == null) {
1040 list = (List<WikiPageResource>)QueryUtil.list(q,
1041 getDialect(), start, end, false);
1042
1043 Collections.sort(list);
1044 }
1045 else {
1046 list = (List<WikiPageResource>)QueryUtil.list(q,
1047 getDialect(), start, end);
1048 }
1049 }
1050 catch (Exception e) {
1051 throw processException(e);
1052 }
1053 finally {
1054 if (list == null) {
1055 list = new ArrayList<WikiPageResource>();
1056 }
1057
1058 cacheResult(list);
1059
1060 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1061
1062 closeSession(session);
1063 }
1064 }
1065
1066 return list;
1067 }
1068
1069
1075 public void removeByUuid(String uuid) throws SystemException {
1076 for (WikiPageResource wikiPageResource : findByUuid(uuid)) {
1077 remove(wikiPageResource);
1078 }
1079 }
1080
1081
1088 public void removeByN_T(long nodeId, String title)
1089 throws NoSuchPageResourceException, SystemException {
1090 WikiPageResource wikiPageResource = findByN_T(nodeId, title);
1091
1092 remove(wikiPageResource);
1093 }
1094
1095
1100 public void removeAll() throws SystemException {
1101 for (WikiPageResource wikiPageResource : findAll()) {
1102 remove(wikiPageResource);
1103 }
1104 }
1105
1106
1113 public int countByUuid(String uuid) throws SystemException {
1114 Object[] finderArgs = new Object[] { uuid };
1115
1116 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1117 finderArgs, this);
1118
1119 if (count == null) {
1120 Session session = null;
1121
1122 try {
1123 session = openSession();
1124
1125 StringBundler query = new StringBundler(2);
1126
1127 query.append(_SQL_COUNT_WIKIPAGERESOURCE_WHERE);
1128
1129 if (uuid == null) {
1130 query.append(_FINDER_COLUMN_UUID_UUID_1);
1131 }
1132 else {
1133 if (uuid.equals(StringPool.BLANK)) {
1134 query.append(_FINDER_COLUMN_UUID_UUID_3);
1135 }
1136 else {
1137 query.append(_FINDER_COLUMN_UUID_UUID_2);
1138 }
1139 }
1140
1141 String sql = query.toString();
1142
1143 Query q = session.createQuery(sql);
1144
1145 QueryPos qPos = QueryPos.getInstance(q);
1146
1147 if (uuid != null) {
1148 qPos.add(uuid);
1149 }
1150
1151 count = (Long)q.uniqueResult();
1152 }
1153 catch (Exception e) {
1154 throw processException(e);
1155 }
1156 finally {
1157 if (count == null) {
1158 count = Long.valueOf(0);
1159 }
1160
1161 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
1162 finderArgs, count);
1163
1164 closeSession(session);
1165 }
1166 }
1167
1168 return count.intValue();
1169 }
1170
1171
1179 public int countByN_T(long nodeId, String title) throws SystemException {
1180 Object[] finderArgs = new Object[] { nodeId, title };
1181
1182 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_N_T,
1183 finderArgs, this);
1184
1185 if (count == null) {
1186 Session session = null;
1187
1188 try {
1189 session = openSession();
1190
1191 StringBundler query = new StringBundler(3);
1192
1193 query.append(_SQL_COUNT_WIKIPAGERESOURCE_WHERE);
1194
1195 query.append(_FINDER_COLUMN_N_T_NODEID_2);
1196
1197 if (title == null) {
1198 query.append(_FINDER_COLUMN_N_T_TITLE_1);
1199 }
1200 else {
1201 if (title.equals(StringPool.BLANK)) {
1202 query.append(_FINDER_COLUMN_N_T_TITLE_3);
1203 }
1204 else {
1205 query.append(_FINDER_COLUMN_N_T_TITLE_2);
1206 }
1207 }
1208
1209 String sql = query.toString();
1210
1211 Query q = session.createQuery(sql);
1212
1213 QueryPos qPos = QueryPos.getInstance(q);
1214
1215 qPos.add(nodeId);
1216
1217 if (title != null) {
1218 qPos.add(title);
1219 }
1220
1221 count = (Long)q.uniqueResult();
1222 }
1223 catch (Exception e) {
1224 throw processException(e);
1225 }
1226 finally {
1227 if (count == null) {
1228 count = Long.valueOf(0);
1229 }
1230
1231 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_T, finderArgs,
1232 count);
1233
1234 closeSession(session);
1235 }
1236 }
1237
1238 return count.intValue();
1239 }
1240
1241
1247 public int countAll() throws SystemException {
1248 Object[] finderArgs = new Object[0];
1249
1250 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1251 finderArgs, this);
1252
1253 if (count == null) {
1254 Session session = null;
1255
1256 try {
1257 session = openSession();
1258
1259 Query q = session.createQuery(_SQL_COUNT_WIKIPAGERESOURCE);
1260
1261 count = (Long)q.uniqueResult();
1262 }
1263 catch (Exception e) {
1264 throw processException(e);
1265 }
1266 finally {
1267 if (count == null) {
1268 count = Long.valueOf(0);
1269 }
1270
1271 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1272 count);
1273
1274 closeSession(session);
1275 }
1276 }
1277
1278 return count.intValue();
1279 }
1280
1281
1284 public void afterPropertiesSet() {
1285 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1286 com.liferay.portal.util.PropsUtil.get(
1287 "value.object.listener.com.liferay.portlet.wiki.model.WikiPageResource")));
1288
1289 if (listenerClassNames.length > 0) {
1290 try {
1291 List<ModelListener<WikiPageResource>> listenersList = new ArrayList<ModelListener<WikiPageResource>>();
1292
1293 for (String listenerClassName : listenerClassNames) {
1294 listenersList.add((ModelListener<WikiPageResource>)InstanceFactory.newInstance(
1295 listenerClassName));
1296 }
1297
1298 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1299 }
1300 catch (Exception e) {
1301 _log.error(e);
1302 }
1303 }
1304 }
1305
1306 @BeanReference(type = WikiNodePersistence.class)
1307 protected WikiNodePersistence wikiNodePersistence;
1308 @BeanReference(type = WikiPagePersistence.class)
1309 protected WikiPagePersistence wikiPagePersistence;
1310 @BeanReference(type = WikiPageResourcePersistence.class)
1311 protected WikiPageResourcePersistence wikiPageResourcePersistence;
1312 @BeanReference(type = ResourcePersistence.class)
1313 protected ResourcePersistence resourcePersistence;
1314 @BeanReference(type = UserPersistence.class)
1315 protected UserPersistence userPersistence;
1316 private static final String _SQL_SELECT_WIKIPAGERESOURCE = "SELECT wikiPageResource FROM WikiPageResource wikiPageResource";
1317 private static final String _SQL_SELECT_WIKIPAGERESOURCE_WHERE = "SELECT wikiPageResource FROM WikiPageResource wikiPageResource WHERE ";
1318 private static final String _SQL_COUNT_WIKIPAGERESOURCE = "SELECT COUNT(wikiPageResource) FROM WikiPageResource wikiPageResource";
1319 private static final String _SQL_COUNT_WIKIPAGERESOURCE_WHERE = "SELECT COUNT(wikiPageResource) FROM WikiPageResource wikiPageResource WHERE ";
1320 private static final String _FINDER_COLUMN_UUID_UUID_1 = "wikiPageResource.uuid IS NULL";
1321 private static final String _FINDER_COLUMN_UUID_UUID_2 = "wikiPageResource.uuid = ?";
1322 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(wikiPageResource.uuid IS NULL OR wikiPageResource.uuid = ?)";
1323 private static final String _FINDER_COLUMN_N_T_NODEID_2 = "wikiPageResource.nodeId = ? AND ";
1324 private static final String _FINDER_COLUMN_N_T_TITLE_1 = "wikiPageResource.title IS NULL";
1325 private static final String _FINDER_COLUMN_N_T_TITLE_2 = "wikiPageResource.title = ?";
1326 private static final String _FINDER_COLUMN_N_T_TITLE_3 = "(wikiPageResource.title IS NULL OR wikiPageResource.title = ?)";
1327 private static final String _ORDER_BY_ENTITY_ALIAS = "wikiPageResource.";
1328 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No WikiPageResource exists with the primary key ";
1329 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No WikiPageResource exists with the key {";
1330 private static Log _log = LogFactoryUtil.getLog(WikiPageResourcePersistenceImpl.class);
1331 }