File tree Expand file tree Collapse file tree 5 files changed +27
-2
lines changed
main/java/org/apache/ibatis
test/java/org/apache/ibatis/builder Expand file tree Collapse file tree 5 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -270,6 +270,7 @@ private void settingsElement(Properties props) {
270270 configuration .setConfigurationFactory (resolveClass (props .getProperty ("configurationFactory" )));
271271 configuration .setShrinkWhitespacesInSql (booleanValueOf (props .getProperty ("shrinkWhitespacesInSql" ), false ));
272272 configuration .setDefaultSqlProviderType (resolveClass (props .getProperty ("defaultSqlProviderType" )));
273+ configuration .setForceRollbackOnClose (booleanValueOf (props .getProperty ("forceRollbackOnClose" ), false ));
273274 }
274275
275276 private void environmentsElement (XNode context ) throws Exception {
Original file line number Diff line number Diff line change @@ -114,6 +114,7 @@ public class Configuration {
114114 protected boolean useActualParamName = true ;
115115 protected boolean returnInstanceForEmptyRow ;
116116 protected boolean shrinkWhitespacesInSql ;
117+ protected boolean forceRollbackOnClose ;
117118
118119 protected String logPrefix ;
119120 protected Class <? extends Log > logImpl ;
@@ -297,6 +298,26 @@ public void setShrinkWhitespacesInSql(boolean shrinkWhitespacesInSql) {
297298 this .shrinkWhitespacesInSql = shrinkWhitespacesInSql ;
298299 }
299300
301+ /**
302+ * Whether force rollback on session close.
303+ *
304+ * @return if return {@code true}, execute force rollback
305+ * @since 3.5.8
306+ */
307+ public boolean isForceRollbackOnClose () {
308+ return forceRollbackOnClose ;
309+ }
310+
311+ /**
312+ * Set whether force rollback on session close.
313+ *
314+ * @param forceRollbackOnClose if set {@code true}, execute force rollback
315+ * @since 3.5.8
316+ */
317+ public void setForceRollbackOnClose (boolean forceRollbackOnClose ) {
318+ this .forceRollbackOnClose = forceRollbackOnClose ;
319+ }
320+
300321 public String getDatabaseId () {
301322 return databaseId ;
302323 }
Original file line number Diff line number Diff line change @@ -257,7 +257,7 @@ public List<BatchResult> flushStatements() {
257257 @ Override
258258 public void close () {
259259 try {
260- executor .close (isCommitOrRollbackRequired (false ));
260+ executor .close (isCommitOrRollbackRequired (configuration . isForceRollbackOnClose () ));
261261 closeCursors ();
262262 dirty = false ;
263263 } finally {
Original file line number Diff line number Diff line change 11<?xml version =" 1.0" encoding =" UTF-8" ?>
22<!--
33
4- Copyright 2009-2020 the original author or authors.
4+ Copyright 2009-2021 the original author or authors.
55
66 Licensed under the Apache License, Version 2.0 (the "License");
77 you may not use this file except in compliance with the License.
5656 <setting name =" defaultEnumTypeHandler" value =" org.apache.ibatis.type.EnumOrdinalTypeHandler" />
5757 <setting name =" shrinkWhitespacesInSql" value =" true" />
5858 <setting name =" defaultSqlProviderType" value =" org.apache.ibatis.builder.XmlConfigBuilderTest$MySqlProvider" />
59+ <setting name =" forceRollbackOnClose" value =" true" />
5960 </settings >
6061
6162 <typeAliases >
Original file line number Diff line number Diff line change @@ -103,6 +103,7 @@ void shouldSuccessfullyLoadMinimalXMLConfigFile() throws Exception {
103103 assertThat (config .getTypeHandlerRegistry ().getTypeHandler (RoundingMode .class )).isInstanceOf (EnumTypeHandler .class );
104104 assertThat (config .isShrinkWhitespacesInSql ()).isFalse ();
105105 assertThat (config .getDefaultSqlProviderType ()).isNull ();
106+ assertThat (config .isForceRollbackOnClose ()).isFalse ();
106107 }
107108 }
108109
@@ -200,6 +201,7 @@ void shouldSuccessfullyLoadXMLConfigFile() throws Exception {
200201 assertThat (config .getConfigurationFactory ().getName ()).isEqualTo (String .class .getName ());
201202 assertThat (config .isShrinkWhitespacesInSql ()).isTrue ();
202203 assertThat (config .getDefaultSqlProviderType ().getName ()).isEqualTo (MySqlProvider .class .getName ());
204+ assertThat (config .isForceRollbackOnClose ()).isTrue ();
203205
204206 assertThat (config .getTypeAliasRegistry ().getTypeAliases ().get ("blogauthor" )).isEqualTo (Author .class );
205207 assertThat (config .getTypeAliasRegistry ().getTypeAliases ().get ("blog" )).isEqualTo (Blog .class );
You can’t perform that action at this time.
0 commit comments