diff --git a/src/main/java/org/apache/ibatis/binding/MapperMethod.java b/src/main/java/org/apache/ibatis/binding/MapperMethod.java index 69526229260..570b98db5ec 100644 --- a/src/main/java/org/apache/ibatis/binding/MapperMethod.java +++ b/src/main/java/org/apache/ibatis/binding/MapperMethod.java @@ -35,6 +35,7 @@ * @author Clinton Begin * @author Eduardo Macarron * @author Lasse Voss + * @author Kazuki Shimizu */ public class MapperMethod { @@ -245,7 +246,7 @@ public MethodSignature(Configuration configuration, Method method) { this.returnType = method.getReturnType(); this.returnsVoid = void.class.equals(this.returnType); this.returnsMany = (configuration.getObjectFactory().isCollection(this.returnType) || this.returnType.isArray()); - this.returnsCursor = Cursor.class.equals(this.returnType); + this.returnsCursor = Cursor.class.isAssignableFrom(this.returnType); this.mapKey = getMapKey(method); this.returnsMap = (this.mapKey != null); this.hasNamedParameters = hasNamedParams(method); diff --git a/src/main/java/org/apache/ibatis/cursor/defaults/DefaultCursor.java b/src/main/java/org/apache/ibatis/cursor/defaults/DefaultCursor.java index 30c86afd7bb..c2ce922c5ee 100644 --- a/src/main/java/org/apache/ibatis/cursor/defaults/DefaultCursor.java +++ b/src/main/java/org/apache/ibatis/cursor/defaults/DefaultCursor.java @@ -16,6 +16,8 @@ package org.apache.ibatis.cursor.defaults; import org.apache.ibatis.cursor.Cursor; +import org.apache.ibatis.exceptions.ExceptionFactory; +import org.apache.ibatis.executor.ErrorContext; import org.apache.ibatis.executor.resultset.DefaultResultSetHandler; import org.apache.ibatis.executor.resultset.ResultSetWrapper; import org.apache.ibatis.mapping.ResultMap; @@ -31,6 +33,7 @@ /** * @author Guillaume Darmont / guillaume@dropinocean.com + * @author Kazuki Shimizu */ public class DefaultCursor implements Cursor { @@ -111,7 +114,7 @@ protected T fetchNextObjectFromDatabase() { opened = true; resultSetHandler.handleRowValues(rsw, resultMap, objectWrapperResultHandler, RowBounds.DEFAULT, null); } catch (SQLException e) { - throw new RuntimeException(e); + ExceptionFactory.wrapException("Error fetching next object from database at the DefaultCursor.", e); } T next = objectWrapperResultHandler.result; @@ -160,7 +163,11 @@ public CursorIterator() { @Override public boolean hasNext() { if (object == null) { - object = fetchNextUsingRowBound(); + try { + object = fetchNextUsingRowBound(); + } finally { + ErrorContext.instance().reset(); + } } return object != null; } @@ -171,7 +178,11 @@ public T next() { T next = object; if (next == null) { - next = fetchNextUsingRowBound(); + try { + next = fetchNextUsingRowBound(); + } finally { + ErrorContext.instance().reset(); + } } if (next != null) { diff --git a/src/test/java/org/apache/ibatis/submitted/cursor_nested/CreateDB.sql b/src/test/java/org/apache/ibatis/submitted/cursor_nested/CreateDB.sql index ecf8f675cf9..575425d6465 100644 --- a/src/test/java/org/apache/ibatis/submitted/cursor_nested/CreateDB.sql +++ b/src/test/java/org/apache/ibatis/submitted/cursor_nested/CreateDB.sql @@ -1,6 +1,6 @@ -- --- Copyright 2009-2012 The MyBatis Team +-- Copyright 2009-2015 The MyBatis Team -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. diff --git a/src/test/java/org/apache/ibatis/submitted/cursor_nested/Mapper.xml b/src/test/java/org/apache/ibatis/submitted/cursor_nested/Mapper.xml index 0e0e35d2d44..c06321f9942 100644 --- a/src/test/java/org/apache/ibatis/submitted/cursor_nested/Mapper.xml +++ b/src/test/java/org/apache/ibatis/submitted/cursor_nested/Mapper.xml @@ -1,6 +1,6 @@