From e04b8fd5e9177ea8fdf2096e42c2744f01f1aa68 Mon Sep 17 00:00:00 2001 From: Kazuki Shimizu Date: Sun, 12 Jul 2015 23:42:16 +0900 Subject: [PATCH] #437: Polishing some logics and comments * modify to use Cursor.class.isAssignableFrom(Class) * modfiy to use ExceptionFactory.wrapException(String,Exception) * modify copyright year --- .../org/apache/ibatis/binding/MapperMethod.java | 3 ++- .../ibatis/cursor/defaults/DefaultCursor.java | 17 ++++++++++++++--- .../ibatis/submitted/cursor_nested/CreateDB.sql | 2 +- .../ibatis/submitted/cursor_nested/Mapper.xml | 2 +- .../submitted/cursor_nested/mybatis-config.xml | 2 +- .../ibatis/submitted/cursor_simple/CreateDB.sql | 2 +- .../ibatis/submitted/cursor_simple/Mapper.xml | 2 +- .../submitted/cursor_simple/mybatis-config.xml | 2 +- 8 files changed, 22 insertions(+), 10 deletions(-) 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 @@