ErrorCase.java 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package com.trs.example;
  2. import com.trs.TRSWCMBaseTest;
  3. import com.trs.components.wcm.content.persistent.Document;
  4. import com.trs.components.wcm.content.persistent.Documents;
  5. import com.trs.infra.common.WCMException;
  6. import com.trs.infra.persistent.WCMFilter;
  7. public class ErrorCase extends TRSWCMBaseTest {
  8. public void errorOnWCMFilter() throws WCMException {
  9. // 错误代码1,带了关键字Where和Select
  10. WCMFilter filter1 = new WCMFilter("", "Where DocId>=1", "",
  11. "Select DocTitle,DocId,CrUser");
  12. // 错误代码2:Where和Order反了
  13. WCMFilter filter2 = new WCMFilter("", "DocId desc", "DocId>=1",
  14. " DocTitle,DocId,CrUser");
  15. // 错误代码3:需要提取的字段没有在Select中
  16. WCMFilter filter3 = new WCMFilter("", "DocId>=1 and DocId<=10",
  17. "DocId desc", "DocId,CrUser");
  18. Documents documents = Documents.openWCMObjs(null, filter3);
  19. for (int i = 0, nSize = documents.size(); i < nSize; i++) {
  20. Document document = (Document) documents.getAt(i);
  21. // 这时取出的Title肯定为Null,虽然文档有标题,Filter没有指定
  22. System.out.println("Doctitle:" + document.getTitle());
  23. }// END For
  24. // 错误代码4:指定的字段在元素对应的表中不存在,读取集合的时候老没有出现结果,但是后台有异常
  25. WCMFilter filter4 = new WCMFilter("", "DocId>=1 and DocId<=10",
  26. "DocId desc", "DocTitle2,DocId,CrUser");
  27. documents = Documents.openWCMObjs(null, filter4);
  28. for (int i = 0, nSize = documents.size(); i < nSize; i++) {
  29. Document document = (Document) documents.getAt(i);
  30. if(document == null){
  31. // 永远是走到这个逻辑上
  32. System.out.println("WCMFilter设置错误???");
  33. continue;
  34. }
  35. // 永远走不到这个逻辑
  36. System.out.println("Doctitle:" + document.getTitle());
  37. }// END For
  38. }
  39. public void queryById() throws WCMException {
  40. /*
  41. * 低效方法1:通过集合获取
  42. */
  43. }
  44. }