예제 #1
0
파일: Query.java 프로젝트: aaberg/sql2o
 public <T> T executeAndFetchFirst(ResultSetHandlerFactory<T> resultSetHandlerFactory) {
   // if sql2o moves to java 7 at some point, this could be much cleaner using try-with-resources
   ResultSetIterable<T> iterable = null;
   try {
     iterable = executeAndFetchLazy(resultSetHandlerFactory);
     Iterator<T> iterator = iterable.iterator();
     return iterator.hasNext() ? iterator.next() : null;
   } finally {
     if (iterable != null) {
       iterable.close();
     }
   }
 }
예제 #2
0
파일: Query.java 프로젝트: aaberg/sql2o
  public <T> List<T> executeAndFetch(ResultSetHandlerFactory<T> factory) {
    List<T> list = new ArrayList<>();

    // if sql2o moves to java 7 at some point, this could be much cleaner using try-with-resources
    ResultSetIterable<T> iterable = null;
    try {
      iterable = executeAndFetchLazy(factory);
      for (T item : iterable) {
        list.add(item);
      }
    } finally {
      if (iterable != null) {
        iterable.close();
      }
    }

    return list;
  }