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) {
270
270
configuration .setConfigurationFactory (resolveClass (props .getProperty ("configurationFactory" )));
271
271
configuration .setShrinkWhitespacesInSql (booleanValueOf (props .getProperty ("shrinkWhitespacesInSql" ), false ));
272
272
configuration .setDefaultSqlProviderType (resolveClass (props .getProperty ("defaultSqlProviderType" )));
273
+ configuration .setForceRollbackOnClose (booleanValueOf (props .getProperty ("forceRollbackOnClose" ), false ));
273
274
}
274
275
275
276
private void environmentsElement (XNode context ) throws Exception {
Original file line number Diff line number Diff line change @@ -114,6 +114,7 @@ public class Configuration {
114
114
protected boolean useActualParamName = true ;
115
115
protected boolean returnInstanceForEmptyRow ;
116
116
protected boolean shrinkWhitespacesInSql ;
117
+ protected boolean forceRollbackOnClose ;
117
118
118
119
protected String logPrefix ;
119
120
protected Class <? extends Log > logImpl ;
@@ -297,6 +298,26 @@ public void setShrinkWhitespacesInSql(boolean shrinkWhitespacesInSql) {
297
298
this .shrinkWhitespacesInSql = shrinkWhitespacesInSql ;
298
299
}
299
300
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
+
300
321
public String getDatabaseId () {
301
322
return databaseId ;
302
323
}
Original file line number Diff line number Diff line change @@ -257,7 +257,7 @@ public List<BatchResult> flushStatements() {
257
257
@ Override
258
258
public void close () {
259
259
try {
260
- executor .close (isCommitOrRollbackRequired (false ));
260
+ executor .close (isCommitOrRollbackRequired (configuration . isForceRollbackOnClose () ));
261
261
closeCursors ();
262
262
dirty = false ;
263
263
} finally {
Original file line number Diff line number Diff line change 1
1
<?xml version =" 1.0" encoding =" UTF-8" ?>
2
2
<!--
3
3
4
- Copyright 2009-2020 the original author or authors.
4
+ Copyright 2009-2021 the original author or authors.
5
5
6
6
Licensed under the Apache License, Version 2.0 (the "License");
7
7
you may not use this file except in compliance with the License.
56
56
<setting name =" defaultEnumTypeHandler" value =" org.apache.ibatis.type.EnumOrdinalTypeHandler" />
57
57
<setting name =" shrinkWhitespacesInSql" value =" true" />
58
58
<setting name =" defaultSqlProviderType" value =" org.apache.ibatis.builder.XmlConfigBuilderTest$MySqlProvider" />
59
+ <setting name =" forceRollbackOnClose" value =" true" />
59
60
</settings >
60
61
61
62
<typeAliases >
Original file line number Diff line number Diff line change @@ -103,6 +103,7 @@ void shouldSuccessfullyLoadMinimalXMLConfigFile() throws Exception {
103
103
assertThat (config .getTypeHandlerRegistry ().getTypeHandler (RoundingMode .class )).isInstanceOf (EnumTypeHandler .class );
104
104
assertThat (config .isShrinkWhitespacesInSql ()).isFalse ();
105
105
assertThat (config .getDefaultSqlProviderType ()).isNull ();
106
+ assertThat (config .isForceRollbackOnClose ()).isFalse ();
106
107
}
107
108
}
108
109
@@ -200,6 +201,7 @@ void shouldSuccessfullyLoadXMLConfigFile() throws Exception {
200
201
assertThat (config .getConfigurationFactory ().getName ()).isEqualTo (String .class .getName ());
201
202
assertThat (config .isShrinkWhitespacesInSql ()).isTrue ();
202
203
assertThat (config .getDefaultSqlProviderType ().getName ()).isEqualTo (MySqlProvider .class .getName ());
204
+ assertThat (config .isForceRollbackOnClose ()).isTrue ();
203
205
204
206
assertThat (config .getTypeAliasRegistry ().getTypeAliases ().get ("blogauthor" )).isEqualTo (Author .class );
205
207
assertThat (config .getTypeAliasRegistry ().getTypeAliases ().get ("blog" )).isEqualTo (Blog .class );
You can’t perform that action at this time.
0 commit comments