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.getOriginalNodeId()),
269
270 wikiPageResourceModelImpl.getOriginalTitle()
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 Session session = null;
505
506 try {
507 session = openSession();
508
509 StringBundler query = null;
510
511 if (orderByComparator != null) {
512 query = new StringBundler(3 +
513 (orderByComparator.getOrderByFields().length * 3));
514 }
515 else {
516 query = new StringBundler(2);
517 }
518
519 query.append(_SQL_SELECT_WIKIPAGERESOURCE_WHERE);
520
521 if (uuid == null) {
522 query.append(_FINDER_COLUMN_UUID_UUID_1);
523 }
524 else {
525 if (uuid.equals(StringPool.BLANK)) {
526 query.append(_FINDER_COLUMN_UUID_UUID_3);
527 }
528 else {
529 query.append(_FINDER_COLUMN_UUID_UUID_2);
530 }
531 }
532
533 if (orderByComparator != null) {
534 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
535 orderByComparator);
536 }
537
538 String sql = query.toString();
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 list = new ArrayList<WikiPageResource>();
557 }
558
559 cacheResult(list);
560
561 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
562 list);
563
564 closeSession(session);
565 }
566 }
567
568 return list;
569 }
570
571
584 public WikiPageResource findByUuid_First(String uuid,
585 OrderByComparator orderByComparator)
586 throws NoSuchPageResourceException, SystemException {
587 List<WikiPageResource> list = findByUuid(uuid, 0, 1, orderByComparator);
588
589 if (list.isEmpty()) {
590 StringBundler msg = new StringBundler(4);
591
592 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
593
594 msg.append("uuid=");
595 msg.append(uuid);
596
597 msg.append(StringPool.CLOSE_CURLY_BRACE);
598
599 throw new NoSuchPageResourceException(msg.toString());
600 }
601 else {
602 return list.get(0);
603 }
604 }
605
606
619 public WikiPageResource findByUuid_Last(String uuid,
620 OrderByComparator orderByComparator)
621 throws NoSuchPageResourceException, SystemException {
622 int count = countByUuid(uuid);
623
624 List<WikiPageResource> list = findByUuid(uuid, count - 1, count,
625 orderByComparator);
626
627 if (list.isEmpty()) {
628 StringBundler msg = new StringBundler(4);
629
630 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
631
632 msg.append("uuid=");
633 msg.append(uuid);
634
635 msg.append(StringPool.CLOSE_CURLY_BRACE);
636
637 throw new NoSuchPageResourceException(msg.toString());
638 }
639 else {
640 return list.get(0);
641 }
642 }
643
644
658 public WikiPageResource[] findByUuid_PrevAndNext(long resourcePrimKey,
659 String uuid, OrderByComparator orderByComparator)
660 throws NoSuchPageResourceException, SystemException {
661 WikiPageResource wikiPageResource = findByPrimaryKey(resourcePrimKey);
662
663 Session session = null;
664
665 try {
666 session = openSession();
667
668 WikiPageResource[] array = new WikiPageResourceImpl[3];
669
670 array[0] = getByUuid_PrevAndNext(session, wikiPageResource, uuid,
671 orderByComparator, true);
672
673 array[1] = wikiPageResource;
674
675 array[2] = getByUuid_PrevAndNext(session, wikiPageResource, uuid,
676 orderByComparator, false);
677
678 return array;
679 }
680 catch (Exception e) {
681 throw processException(e);
682 }
683 finally {
684 closeSession(session);
685 }
686 }
687
688 protected WikiPageResource getByUuid_PrevAndNext(Session session,
689 WikiPageResource wikiPageResource, String uuid,
690 OrderByComparator orderByComparator, boolean previous) {
691 StringBundler query = null;
692
693 if (orderByComparator != null) {
694 query = new StringBundler(6 +
695 (orderByComparator.getOrderByFields().length * 6));
696 }
697 else {
698 query = new StringBundler(3);
699 }
700
701 query.append(_SQL_SELECT_WIKIPAGERESOURCE_WHERE);
702
703 if (uuid == null) {
704 query.append(_FINDER_COLUMN_UUID_UUID_1);
705 }
706 else {
707 if (uuid.equals(StringPool.BLANK)) {
708 query.append(_FINDER_COLUMN_UUID_UUID_3);
709 }
710 else {
711 query.append(_FINDER_COLUMN_UUID_UUID_2);
712 }
713 }
714
715 if (orderByComparator != null) {
716 String[] orderByFields = orderByComparator.getOrderByFields();
717
718 if (orderByFields.length > 0) {
719 query.append(WHERE_AND);
720 }
721
722 for (int i = 0; i < orderByFields.length; i++) {
723 query.append(_ORDER_BY_ENTITY_ALIAS);
724 query.append(orderByFields[i]);
725
726 if ((i + 1) < orderByFields.length) {
727 if (orderByComparator.isAscending() ^ previous) {
728 query.append(WHERE_GREATER_THAN_HAS_NEXT);
729 }
730 else {
731 query.append(WHERE_LESSER_THAN_HAS_NEXT);
732 }
733 }
734 else {
735 if (orderByComparator.isAscending() ^ previous) {
736 query.append(WHERE_GREATER_THAN);
737 }
738 else {
739 query.append(WHERE_LESSER_THAN);
740 }
741 }
742 }
743
744 query.append(ORDER_BY_CLAUSE);
745
746 for (int i = 0; i < orderByFields.length; i++) {
747 query.append(_ORDER_BY_ENTITY_ALIAS);
748 query.append(orderByFields[i]);
749
750 if ((i + 1) < orderByFields.length) {
751 if (orderByComparator.isAscending() ^ previous) {
752 query.append(ORDER_BY_ASC_HAS_NEXT);
753 }
754 else {
755 query.append(ORDER_BY_DESC_HAS_NEXT);
756 }
757 }
758 else {
759 if (orderByComparator.isAscending() ^ previous) {
760 query.append(ORDER_BY_ASC);
761 }
762 else {
763 query.append(ORDER_BY_DESC);
764 }
765 }
766 }
767 }
768
769 String sql = query.toString();
770
771 Query q = session.createQuery(sql);
772
773 q.setFirstResult(0);
774 q.setMaxResults(2);
775
776 QueryPos qPos = QueryPos.getInstance(q);
777
778 if (uuid != null) {
779 qPos.add(uuid);
780 }
781
782 if (orderByComparator != null) {
783 Object[] values = orderByComparator.getOrderByValues(wikiPageResource);
784
785 for (Object value : values) {
786 qPos.add(value);
787 }
788 }
789
790 List<WikiPageResource> list = q.list();
791
792 if (list.size() == 2) {
793 return list.get(1);
794 }
795 else {
796 return null;
797 }
798 }
799
800
809 public WikiPageResource findByN_T(long nodeId, String title)
810 throws NoSuchPageResourceException, SystemException {
811 WikiPageResource wikiPageResource = fetchByN_T(nodeId, title);
812
813 if (wikiPageResource == null) {
814 StringBundler msg = new StringBundler(6);
815
816 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
817
818 msg.append("nodeId=");
819 msg.append(nodeId);
820
821 msg.append(", title=");
822 msg.append(title);
823
824 msg.append(StringPool.CLOSE_CURLY_BRACE);
825
826 if (_log.isWarnEnabled()) {
827 _log.warn(msg.toString());
828 }
829
830 throw new NoSuchPageResourceException(msg.toString());
831 }
832
833 return wikiPageResource;
834 }
835
836
844 public WikiPageResource fetchByN_T(long nodeId, String title)
845 throws SystemException {
846 return fetchByN_T(nodeId, title, true);
847 }
848
849
857 public WikiPageResource fetchByN_T(long nodeId, String title,
858 boolean retrieveFromCache) throws SystemException {
859 Object[] finderArgs = new Object[] { nodeId, title };
860
861 Object result = null;
862
863 if (retrieveFromCache) {
864 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_N_T,
865 finderArgs, this);
866 }
867
868 if (result == null) {
869 Session session = null;
870
871 try {
872 session = openSession();
873
874 StringBundler query = new StringBundler(3);
875
876 query.append(_SQL_SELECT_WIKIPAGERESOURCE_WHERE);
877
878 query.append(_FINDER_COLUMN_N_T_NODEID_2);
879
880 if (title == null) {
881 query.append(_FINDER_COLUMN_N_T_TITLE_1);
882 }
883 else {
884 if (title.equals(StringPool.BLANK)) {
885 query.append(_FINDER_COLUMN_N_T_TITLE_3);
886 }
887 else {
888 query.append(_FINDER_COLUMN_N_T_TITLE_2);
889 }
890 }
891
892 String sql = query.toString();
893
894 Query q = session.createQuery(sql);
895
896 QueryPos qPos = QueryPos.getInstance(q);
897
898 qPos.add(nodeId);
899
900 if (title != null) {
901 qPos.add(title);
902 }
903
904 List<WikiPageResource> list = q.list();
905
906 result = list;
907
908 WikiPageResource wikiPageResource = null;
909
910 if (list.isEmpty()) {
911 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T,
912 finderArgs, list);
913 }
914 else {
915 wikiPageResource = list.get(0);
916
917 cacheResult(wikiPageResource);
918
919 if ((wikiPageResource.getNodeId() != nodeId) ||
920 (wikiPageResource.getTitle() == null) ||
921 !wikiPageResource.getTitle().equals(title)) {
922 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T,
923 finderArgs, wikiPageResource);
924 }
925 }
926
927 return wikiPageResource;
928 }
929 catch (Exception e) {
930 throw processException(e);
931 }
932 finally {
933 if (result == null) {
934 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T,
935 finderArgs, new ArrayList<WikiPageResource>());
936 }
937
938 closeSession(session);
939 }
940 }
941 else {
942 if (result instanceof List<?>) {
943 return null;
944 }
945 else {
946 return (WikiPageResource)result;
947 }
948 }
949 }
950
951
957 public List<WikiPageResource> findAll() throws SystemException {
958 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
959 }
960
961
973 public List<WikiPageResource> findAll(int start, int end)
974 throws SystemException {
975 return findAll(start, end, null);
976 }
977
978
991 public List<WikiPageResource> findAll(int start, int end,
992 OrderByComparator orderByComparator) throws SystemException {
993 Object[] finderArgs = new Object[] {
994 String.valueOf(start), String.valueOf(end),
995 String.valueOf(orderByComparator)
996 };
997
998 List<WikiPageResource> list = (List<WikiPageResource>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
999 finderArgs, this);
1000
1001 if (list == null) {
1002 Session session = null;
1003
1004 try {
1005 session = openSession();
1006
1007 StringBundler query = null;
1008 String sql = null;
1009
1010 if (orderByComparator != null) {
1011 query = new StringBundler(2 +
1012 (orderByComparator.getOrderByFields().length * 3));
1013
1014 query.append(_SQL_SELECT_WIKIPAGERESOURCE);
1015
1016 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1017 orderByComparator);
1018
1019 sql = query.toString();
1020 }
1021 else {
1022 sql = _SQL_SELECT_WIKIPAGERESOURCE;
1023 }
1024
1025 Query q = session.createQuery(sql);
1026
1027 if (orderByComparator == null) {
1028 list = (List<WikiPageResource>)QueryUtil.list(q,
1029 getDialect(), start, end, false);
1030
1031 Collections.sort(list);
1032 }
1033 else {
1034 list = (List<WikiPageResource>)QueryUtil.list(q,
1035 getDialect(), start, end);
1036 }
1037 }
1038 catch (Exception e) {
1039 throw processException(e);
1040 }
1041 finally {
1042 if (list == null) {
1043 list = new ArrayList<WikiPageResource>();
1044 }
1045
1046 cacheResult(list);
1047
1048 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1049
1050 closeSession(session);
1051 }
1052 }
1053
1054 return list;
1055 }
1056
1057
1063 public void removeByUuid(String uuid) throws SystemException {
1064 for (WikiPageResource wikiPageResource : findByUuid(uuid)) {
1065 remove(wikiPageResource);
1066 }
1067 }
1068
1069
1076 public void removeByN_T(long nodeId, String title)
1077 throws NoSuchPageResourceException, SystemException {
1078 WikiPageResource wikiPageResource = findByN_T(nodeId, title);
1079
1080 remove(wikiPageResource);
1081 }
1082
1083
1088 public void removeAll() throws SystemException {
1089 for (WikiPageResource wikiPageResource : findAll()) {
1090 remove(wikiPageResource);
1091 }
1092 }
1093
1094
1101 public int countByUuid(String uuid) throws SystemException {
1102 Object[] finderArgs = new Object[] { uuid };
1103
1104 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1105 finderArgs, this);
1106
1107 if (count == null) {
1108 Session session = null;
1109
1110 try {
1111 session = openSession();
1112
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 Query q = session.createQuery(sql);
1132
1133 QueryPos qPos = QueryPos.getInstance(q);
1134
1135 if (uuid != null) {
1136 qPos.add(uuid);
1137 }
1138
1139 count = (Long)q.uniqueResult();
1140 }
1141 catch (Exception e) {
1142 throw processException(e);
1143 }
1144 finally {
1145 if (count == null) {
1146 count = Long.valueOf(0);
1147 }
1148
1149 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
1150 finderArgs, count);
1151
1152 closeSession(session);
1153 }
1154 }
1155
1156 return count.intValue();
1157 }
1158
1159
1167 public int countByN_T(long nodeId, String title) throws SystemException {
1168 Object[] finderArgs = new Object[] { nodeId, title };
1169
1170 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_N_T,
1171 finderArgs, this);
1172
1173 if (count == null) {
1174 Session session = null;
1175
1176 try {
1177 session = openSession();
1178
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 Query q = session.createQuery(sql);
1200
1201 QueryPos qPos = QueryPos.getInstance(q);
1202
1203 qPos.add(nodeId);
1204
1205 if (title != null) {
1206 qPos.add(title);
1207 }
1208
1209 count = (Long)q.uniqueResult();
1210 }
1211 catch (Exception e) {
1212 throw processException(e);
1213 }
1214 finally {
1215 if (count == null) {
1216 count = Long.valueOf(0);
1217 }
1218
1219 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_T, finderArgs,
1220 count);
1221
1222 closeSession(session);
1223 }
1224 }
1225
1226 return count.intValue();
1227 }
1228
1229
1235 public int countAll() throws SystemException {
1236 Object[] finderArgs = new Object[0];
1237
1238 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1239 finderArgs, this);
1240
1241 if (count == null) {
1242 Session session = null;
1243
1244 try {
1245 session = openSession();
1246
1247 Query q = session.createQuery(_SQL_COUNT_WIKIPAGERESOURCE);
1248
1249 count = (Long)q.uniqueResult();
1250 }
1251 catch (Exception e) {
1252 throw processException(e);
1253 }
1254 finally {
1255 if (count == null) {
1256 count = Long.valueOf(0);
1257 }
1258
1259 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1260 count);
1261
1262 closeSession(session);
1263 }
1264 }
1265
1266 return count.intValue();
1267 }
1268
1269
1272 public void afterPropertiesSet() {
1273 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1274 com.liferay.portal.util.PropsUtil.get(
1275 "value.object.listener.com.liferay.portlet.wiki.model.WikiPageResource")));
1276
1277 if (listenerClassNames.length > 0) {
1278 try {
1279 List<ModelListener<WikiPageResource>> listenersList = new ArrayList<ModelListener<WikiPageResource>>();
1280
1281 for (String listenerClassName : listenerClassNames) {
1282 listenersList.add((ModelListener<WikiPageResource>)InstanceFactory.newInstance(
1283 listenerClassName));
1284 }
1285
1286 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1287 }
1288 catch (Exception e) {
1289 _log.error(e);
1290 }
1291 }
1292 }
1293
1294 public void destroy() {
1295 EntityCacheUtil.removeCache(WikiPageResourceImpl.class.getName());
1296 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1297 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
1298 }
1299
1300 @BeanReference(type = WikiNodePersistence.class)
1301 protected WikiNodePersistence wikiNodePersistence;
1302 @BeanReference(type = WikiPagePersistence.class)
1303 protected WikiPagePersistence wikiPagePersistence;
1304 @BeanReference(type = WikiPageResourcePersistence.class)
1305 protected WikiPageResourcePersistence wikiPageResourcePersistence;
1306 @BeanReference(type = ResourcePersistence.class)
1307 protected ResourcePersistence resourcePersistence;
1308 @BeanReference(type = UserPersistence.class)
1309 protected UserPersistence userPersistence;
1310 private static final String _SQL_SELECT_WIKIPAGERESOURCE = "SELECT wikiPageResource FROM WikiPageResource wikiPageResource";
1311 private static final String _SQL_SELECT_WIKIPAGERESOURCE_WHERE = "SELECT wikiPageResource FROM WikiPageResource wikiPageResource WHERE ";
1312 private static final String _SQL_COUNT_WIKIPAGERESOURCE = "SELECT COUNT(wikiPageResource) FROM WikiPageResource wikiPageResource";
1313 private static final String _SQL_COUNT_WIKIPAGERESOURCE_WHERE = "SELECT COUNT(wikiPageResource) FROM WikiPageResource wikiPageResource WHERE ";
1314 private static final String _FINDER_COLUMN_UUID_UUID_1 = "wikiPageResource.uuid IS NULL";
1315 private static final String _FINDER_COLUMN_UUID_UUID_2 = "wikiPageResource.uuid = ?";
1316 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(wikiPageResource.uuid IS NULL OR wikiPageResource.uuid = ?)";
1317 private static final String _FINDER_COLUMN_N_T_NODEID_2 = "wikiPageResource.nodeId = ? AND ";
1318 private static final String _FINDER_COLUMN_N_T_TITLE_1 = "wikiPageResource.title IS NULL";
1319 private static final String _FINDER_COLUMN_N_T_TITLE_2 = "wikiPageResource.title = ?";
1320 private static final String _FINDER_COLUMN_N_T_TITLE_3 = "(wikiPageResource.title IS NULL OR wikiPageResource.title = ?)";
1321 private static final String _ORDER_BY_ENTITY_ALIAS = "wikiPageResource.";
1322 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No WikiPageResource exists with the primary key ";
1323 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No WikiPageResource exists with the key {";
1324 private static Log _log = LogFactoryUtil.getLog(WikiPageResourcePersistenceImpl.class);
1325 }