Skip to content

Commit

Permalink
Merge pull request #912 from nieqiurong/support_dataBaseId
Browse files Browse the repository at this point in the history
Support configuration databaseId.
  • Loading branch information
kazuki43zoo committed Nov 21, 2023
2 parents 0129834 + 6f90947 commit bda974b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,11 @@ public static class CoreConfiguration {
*/
private Properties variables;

/**
* Specifies the database identify value for switching query to use.
*/
private String databaseId;

public Boolean getSafeRowBoundsEnabled() {
return safeRowBoundsEnabled;
}
Expand Down Expand Up @@ -657,6 +662,14 @@ public void setDefaultEnumTypeHandler(Class<? extends TypeHandler> defaultEnumTy
this.defaultEnumTypeHandler = defaultEnumTypeHandler;
}

public String getDatabaseId() {
return databaseId;
}

public void setDatabaseId(String databaseId) {
this.databaseId = databaseId;
}

public void applyTo(Configuration target) {
PropertyMapper mapper = PropertyMapper.get().alwaysApplyingWhenNonNull();
mapper.from(getSafeRowBoundsEnabled()).to(target::setSafeRowBoundsEnabled);
Expand Down Expand Up @@ -690,6 +703,7 @@ public void applyTo(Configuration target) {
mapper.from(getDefaultSqlProviderType()).to(target::setDefaultSqlProviderType);
mapper.from(getConfigurationFactory()).to(target::setConfigurationFactory);
mapper.from(getDefaultEnumTypeHandler()).to(target::setDefaultEnumTypeHandler);
mapper.from(getDatabaseId()).to(target::setDatabaseId);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ void testWithDefaultCoreConfiguration() {
.getTypeHandler(JdbcType.class).getClass()).isEqualTo(EnumTypeHandler.class);
assertThat(context.getBean(SqlSessionFactory.class).getConfiguration().getConfigurationFactory()).isNull();
assertThat(context.getBean(SqlSessionFactory.class).getConfiguration().getVariables()).hasToString("{}");
assertThat(context.getBean(SqlSessionFactory.class).getConfiguration().getDatabaseId()).isNull();
});
}

Expand Down Expand Up @@ -196,7 +197,7 @@ void testWithCustomizeCoreConfiguration() {
"mybatis.configuration.default-sql-provider-type:org.mybatis.spring.boot.autoconfigure.MybatisPropertiesTest$MySqlProvider",
"mybatis.configuration.defaultEnumTypeHandler:org.apache.ibatis.type.EnumOrdinalTypeHandler",
"mybatis.configuration.configuration-factory:org.mybatis.spring.boot.autoconfigure.MybatisPropertiesTest$MyConfigurationFactory",
"mybatis.configuration.variables.key1:value1", "mybatis.configuration.variables.key2:value2")
"mybatis.configuration.variables.key1:value1", "mybatis.configuration.variables.key2:value2", "mybatis.configuration.database-id:mysql")
.run(context -> {
assertThat(context.getBean(SqlSessionFactory.class).getConfiguration().getDefaultStatementTimeout())
.isEqualTo(2000);
Expand Down Expand Up @@ -230,6 +231,8 @@ void testWithCustomizeCoreConfiguration() {
.isEqualTo(MyConfigurationFactory.class);
assertThat(context.getBean(SqlSessionFactory.class).getConfiguration().getVariables())
.hasToString("{key1=value1, key2=value2}");
assertThat(context.getBean(SqlSessionFactory.class).getConfiguration().getDatabaseId())
.hasToString("mysql");
}));
}

Expand All @@ -246,7 +249,7 @@ void checkProperties() {
"sqlFragments", "typeHandlerRegistry", "mapperRegistry", "interceptors", "cacheNames", "incompleteResultMaps",
"typeAliasRegistry", "incompleteMethods", "proxyFactory", "resultMaps", "defaultScriptingLanguageInstance",
"parameterMaps", "keyGenerators", "parameterMapNames", "caches", "mappedStatementNames", "objectWrapperFactory",
"objectFactory", "databaseId", "incompleteStatements", "resultMapNames", "defaultScriptingLanuageInstance",
"objectFactory", "incompleteStatements", "resultMapNames", "defaultScriptingLanuageInstance",
"keyGeneratorNames", "environment", "mappedStatements", "languageRegistry", "incompleteCacheRefs"));
assertThat(mybatisCoreConfigurationProperties).isEmpty();
}
Expand Down

0 comments on commit bda974b

Please sign in to comment.