Empty ResultSet returns Collection with single Null element

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Empty ResultSet returns Collection with single Null element

srini_n
This post has NOT been accepted by the mailing list yet.
I have an out param (jdbcType=CURSOR, javaType=java.sql.ResultSet, mode=OUT) that is mapped to a resultMap. When the resultset is empty, a Collection with a single null element is returned. Hence we are having to not only check for CollectionUtils.isEmpty but also check if the first element is not null and is undesirable.

Reviewing the default ResultSetHandler and ResultHandler implementations;

  private void callResultHandler(ResultHandler<?> resultHandler, DefaultResultContext resultContext, Object rowValue) {
    resultContext.nextResultObject(rowValue);
    <strong>((ResultHandler)resultHandler).handleResult(resultContext);</strong>
  }

  public void handleResult(ResultContext<? extends Object> context) {
    list.add(context.getResultObject());
  }

it appears that we may have to add check in the handleResult to not add to list if "context.getResultObject()" returns null.

  public void handleResult(ResultContext<? extends Object> context) {
    if (context.getResultObject() != null)
                     list.add(context.getResultObject());
  }

I could override the handleResult method but i thought this should be a central fix into the framework. Thoughts?
Loading...