Mandarax查询之后判断ResultSet中是否存在answer的方法

类别:Java 点击:0 评论:0 推荐:

注意到在mandarax自己提供的crm例子中有:

 public Discount getDiscount() {
  try {
   return (result == null) ? null : (Discount) result.getResult(Discount.class,QUERY_VARIABLE);
  }
  catch (InferenceException x) {
   return null;
  }
 }
但是实际上这并不能完全说明问题,还应该类似JDBC,采用:
if(result != null && result.next)
    return (Discount) result.getResult(Discount.class,QUERY_VARIABLE)

当然在mandarax的manual中,还是很清楚的说明了这一点,只是今天很生动的体会了这一点,即使判断了
result != null,在result.getResult(..)的时候,仍然throw exception:

java.lang.NullPointerException
        at org.mandarax.reference.ResolutionInferenceEngine$2.getResult(ResolutionInferenceEngine.java:328)
        at _publish._P_0hehe._index__jsp._jspService(_index__jsp.java:584)
        at com.caucho.jsp.JavaPage.service(JavaPage.java:75)
        at com.caucho.jsp.Page.subservice(Page.java:506)
        at com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:182)
        at com.airinbox.album.AlbumServletFilter.doFilter(Unknown Source)
        at com.airinbox.album.AlbumServletFilter.doFilter(Unknown Source)
        at com.caucho.server.http.FilterChainFilter.doFilter(FilterChainFilter.java:88)
        at com.caucho.server.http.Invocation.service(Invocation.java:315)
        at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:135)
        at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:246)
        at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:163)
        at com.caucho.server.TcpConnection.run(TcpConnection.java:139)
        at java.lang.Thread.run(Thread.java:595)

本文地址:http://com.8s8s.com/it/it13974.htm