Skip to content

Commit 400d128

Browse files
committed
1 parent 391c72e commit 400d128

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

src/main/java/org/apache/ibatis/session/SqlSession.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.apache.ibatis.session;
22

3+
import org.apache.ibatis.executor.BatchResult;
4+
35
import java.sql.Connection;
46
import java.util.List;
57
import java.util.Map;
@@ -48,6 +50,8 @@ public interface SqlSession {
4850

4951
void rollback(boolean force);
5052

53+
public List<BatchResult> flushStatements();
54+
5155
void close();
5256

5357
void clearCache();

src/main/java/org/apache/ibatis/session/SqlSessionManager.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package org.apache.ibatis.session;
22

3+
import org.apache.ibatis.exceptions.ExceptionFactory;
4+
import org.apache.ibatis.executor.BatchResult;
5+
import org.apache.ibatis.executor.ErrorContext;
36
import org.apache.ibatis.reflection.ExceptionUtil;
47

58
import java.io.InputStream;
@@ -235,6 +238,12 @@ public void rollback(boolean force) {
235238
sqlSession.rollback(force);
236239
}
237240

241+
public List<BatchResult> flushStatements() {
242+
final SqlSession sqlSession = localSqlSession.get();
243+
if (sqlSession == null) throw new SqlSessionException("Error: Cannot rollback. No managed session is started.");
244+
return sqlSession.flushStatements();
245+
}
246+
238247
public void close() {
239248
final SqlSession sqlSession = localSqlSession.get();
240249
if (sqlSession == null) throw new SqlSessionException("Error: Cannot close. No managed session is started.");

src/main/java/org/apache/ibatis/session/defaults/DefaultSqlSession.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.apache.ibatis.exceptions.ExceptionFactory;
44
import org.apache.ibatis.exceptions.TooManyResultsException;
5+
import org.apache.ibatis.executor.BatchResult;
56
import org.apache.ibatis.executor.Executor;
67
import org.apache.ibatis.executor.ErrorContext;
78
import org.apache.ibatis.executor.result.DefaultMapResultHandler;
@@ -164,6 +165,16 @@ public void rollback(boolean force) {
164165
}
165166
}
166167

168+
public List<BatchResult> flushStatements() {
169+
try {
170+
return executor.flushStatements();
171+
} catch (Exception e) {
172+
throw ExceptionFactory.wrapException("Error flushing statements. Cause: " + e, e);
173+
} finally {
174+
ErrorContext.instance().reset();
175+
}
176+
}
177+
167178
public void close() {
168179
try {
169180
executor.close(isCommitOrRollbackRequired(false));

0 commit comments

Comments
 (0)