Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ private void settingsElement(Properties props) {
configuration.setConfigurationFactory(resolveClass(props.getProperty("configurationFactory")));
configuration.setShrinkWhitespacesInSql(booleanValueOf(props.getProperty("shrinkWhitespacesInSql"), false));
configuration.setDefaultSqlProviderType(resolveClass(props.getProperty("defaultSqlProviderType")));
configuration.setForceRollbackOnClose(booleanValueOf(props.getProperty("forceRollbackOnClose"), false));
}

private void environmentsElement(XNode context) throws Exception {
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/org/apache/ibatis/session/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public class Configuration {
protected boolean useActualParamName = true;
protected boolean returnInstanceForEmptyRow;
protected boolean shrinkWhitespacesInSql;
protected boolean forceRollbackOnClose;

protected String logPrefix;
protected Class<? extends Log> logImpl;
Expand Down Expand Up @@ -297,6 +298,26 @@ public void setShrinkWhitespacesInSql(boolean shrinkWhitespacesInSql) {
this.shrinkWhitespacesInSql = shrinkWhitespacesInSql;
}

/**
* Whether force rollback on session close.
*
* @return if return {@code true}, execute force rollback
* @since 3.5.8
*/
public boolean isForceRollbackOnClose() {
return forceRollbackOnClose;
}

/**
* Set whether force rollback on session close.
*
* @param forceRollbackOnClose if set {@code true}, execute force rollback
* @since 3.5.8
*/
public void setForceRollbackOnClose(boolean forceRollbackOnClose) {
this.forceRollbackOnClose = forceRollbackOnClose;
}

public String getDatabaseId() {
return databaseId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public List<BatchResult> flushStatements() {
@Override
public void close() {
try {
executor.close(isCommitOrRollbackRequired(false));
executor.close(isCommitOrRollbackRequired(configuration.isForceRollbackOnClose()));
closeCursors();
dirty = false;
} finally {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--

Copyright 2009-2020 the original author or authors.
Copyright 2009-2021 the original author or authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -56,6 +56,7 @@
<setting name="defaultEnumTypeHandler" value="org.apache.ibatis.type.EnumOrdinalTypeHandler"/>
<setting name="shrinkWhitespacesInSql" value="true"/>
<setting name="defaultSqlProviderType" value="org.apache.ibatis.builder.XmlConfigBuilderTest$MySqlProvider"/>
<setting name="forceRollbackOnClose" value="true"/>
</settings>

<typeAliases>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ void shouldSuccessfullyLoadMinimalXMLConfigFile() throws Exception {
assertThat(config.getTypeHandlerRegistry().getTypeHandler(RoundingMode.class)).isInstanceOf(EnumTypeHandler.class);
assertThat(config.isShrinkWhitespacesInSql()).isFalse();
assertThat(config.getDefaultSqlProviderType()).isNull();
assertThat(config.isForceRollbackOnClose()).isFalse();
}
}

Expand Down Expand Up @@ -200,6 +201,7 @@ void shouldSuccessfullyLoadXMLConfigFile() throws Exception {
assertThat(config.getConfigurationFactory().getName()).isEqualTo(String.class.getName());
assertThat(config.isShrinkWhitespacesInSql()).isTrue();
assertThat(config.getDefaultSqlProviderType().getName()).isEqualTo(MySqlProvider.class.getName());
assertThat(config.isForceRollbackOnClose()).isTrue();

assertThat(config.getTypeAliasRegistry().getTypeAliases().get("blogauthor")).isEqualTo(Author.class);
assertThat(config.getTypeAliasRegistry().getTypeAliases().get("blog")).isEqualTo(Blog.class);
Expand Down