Skip to content

Commit a29befb

Browse files
committed
注释完善
1 parent e0a50ff commit a29befb

4 files changed

Lines changed: 49 additions & 10 deletions

File tree

src/main/java/io/sqlman/spring/JdbcManagerConfiguration.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import io.sqlman.SqlDialectSupport;
44
import io.sqlman.SqlScriptResolver;
55
import io.sqlman.SqlSourceProvider;
6+
import io.sqlman.SqlVersionManager;
67
import io.sqlman.manager.JdbcIsolation;
78
import io.sqlman.manager.JdbcVersionManager;
89
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
@@ -42,21 +43,19 @@ public class JdbcManagerConfiguration {
4243
private SqlDialectSupport dialectSupport;
4344

4445
@Bean
45-
@ConditionalOnMissingBean
46+
@ConditionalOnMissingBean(SqlVersionManager.class)
4647
@ConditionalOnProperty(prefix = "sqlman", name = "enabled", havingValue = "true", matchIfMissing = true)
47-
public JdbcVersionManager sqlmanBasicVersionManager(ApplicationContext applicationContext) throws Exception {
48-
Map<String, DataSource> dataSources = applicationContext.getBeansOfType(DataSource.class);
49-
if (dataSources.isEmpty()) {
48+
public JdbcVersionManager sqlmanBasicVersionManager(ApplicationContext applicationContext) {
49+
Map<String, DataSource> map = applicationContext.getBeansOfType(DataSource.class);
50+
if (map.isEmpty()) {
5051
throw new IllegalStateException("no dataSource found in application context");
5152
}
52-
DataSource dataSource = dataSources.size() == 1 ? dataSources.values().iterator().next() : dataSources.get(properties.getDataSource());
53+
DataSource dataSource = map.size() == 1 ? map.values().iterator().next() : map.get(properties.getDataSource());
5354
if (dataSource == null) {
5455
throw new IllegalStateException("no dataSource found in application context named: " + properties.getDataSource());
5556
}
5657
JdbcIsolation jdbcIsolation = properties.getJdbcIsolation();
57-
JdbcVersionManager jdbcVersionManager = new JdbcVersionManager(dataSource, jdbcIsolation, scriptProvider, scriptResolver, dialectSupport);
58-
jdbcVersionManager.upgrade();
59-
return jdbcVersionManager;
58+
return new JdbcVersionManager(dataSource, jdbcIsolation, scriptProvider, scriptResolver, dialectSupport);
6059
}
6160

6261
}

src/main/resources/META-INF/spring.factories

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
66
io.sqlman.spring.dialect.MySQLDialectConfiguration,\
77
io.sqlman.spring.dialect.SQLiteDialectConfiguration,\
88
io.sqlman.spring.dialect.OracleDialectConfiguration,\
9-
io.sqlman.spring.dialect.SQLServerDialectConfiguration
9+
io.sqlman.spring.dialect.SQLServerDialectConfiguration

src/test/java/io/sqlman/spring/SqlmanTestApplication.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
package io.sqlman.spring;
22

3+
import io.sqlman.*;
4+
import io.sqlman.manager.JdbcVersionManager;
5+
import io.sqlman.provider.ClasspathSourceProvider;
6+
import io.sqlman.resolver.DruidScriptResolver;
7+
import io.sqlman.strategy.StandardNamingStrategy;
8+
import io.sqlman.support.MySQLDialectSupport;
39
import org.springframework.boot.SpringApplication;
410
import org.springframework.boot.autoconfigure.SpringBootApplication;
11+
import org.springframework.context.ApplicationContext;
12+
import org.springframework.context.annotation.Bean;
13+
14+
import javax.sql.DataSource;
15+
import java.sql.SQLException;
516

617
/**
718
* Sqlman测试应用
@@ -16,4 +27,32 @@ public static void main(String... args) {
1627
SpringApplication.run(SqlmanTestApplication.class);
1728
}
1829

30+
@Bean
31+
public SqlNamingStrategy sqlNamingStrategy() {
32+
return new StandardNamingStrategy();
33+
}
34+
35+
@Bean
36+
public SqlSourceProvider sqlSourceProvider() {
37+
return new ClasspathSourceProvider();
38+
}
39+
40+
@Bean
41+
public SqlScriptResolver sqlScriptResolver() {
42+
return new DruidScriptResolver();
43+
}
44+
45+
@Bean
46+
public SqlDialectSupport sqlDialectSupport() {
47+
return new MySQLDialectSupport();
48+
}
49+
50+
@Bean
51+
public SqlVersionManager sqlVersionManager(ApplicationContext applicationContext) throws SQLException {
52+
DataSource dataSource = applicationContext.getBean(DataSource.class);
53+
JdbcVersionManager jdbcVersionManager = new JdbcVersionManager(dataSource);
54+
jdbcVersionManager.upgrade();
55+
return jdbcVersionManager;
56+
}
57+
1958
}

src/test/resources/application.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ sqlman:
1717
location: sqlman/**/*.sql
1818
provider: classpath
1919
resolver: druid
20+
dialect: MySQL
2021
dialect:
2122
table: SQLMAN_VERSION
22-
type: Oracle
23+
type: MySQL

0 commit comments

Comments
 (0)