54
54
@ AutoConfigureAfter (name = {"mybatisAutoConfiguration" , "mybatisPlusAutoConfiguration" })
55
55
public class DttMybatisAutoConfiguration implements InitializingBean {
56
56
private static final String [] MYBATIS_PROP_PREFIX = {"mybatis-plus.type-aliases-package" , "mybatis.type-aliases-package" };
57
- private static final String [] shardingSphereBeans = {"shardingSphereAutoConfiguration" , "org.apache.shardingsphere.spring.boot.ShardingSphereAutoConfiguration" };
57
+ private static final String [] SHARDING_SPHERE_BEANS = {"shardingSphereAutoConfiguration" , "org.apache.shardingsphere.spring.boot.ShardingSphereAutoConfiguration" };
58
58
private final Logger logger = LoggerFactory .getLogger (this .getClass ());
59
59
/**
60
60
* The type aliases map of mybatis
@@ -76,6 +76,7 @@ public class DttMybatisAutoConfiguration implements InitializingBean {
76
76
*/
77
77
private final DefaultDttMybatisInterceptor defaultDttMybatisInterceptor ;
78
78
private final DttMybatisOrmSupportProperties dttMybatisOrmSupportProperties ;
79
+ private Boolean shardingSphereEnable = false ;
79
80
80
81
public DttMybatisAutoConfiguration (JdbcTemplate jdbcTemplate ,
81
82
DttProperties dttProperties ,
@@ -97,22 +98,18 @@ public DttMybatisAutoConfiguration(JdbcTemplate jdbcTemplate,
97
98
98
99
@ Override
99
100
public void afterPropertiesSet () {
100
- if (dttMybatisOrmSupportProperties .getIsEnable ().equals (false ) || isShardingSphereEnable () ) return ;
101
-
101
+ if (dttMybatisOrmSupportProperties .getIsEnable ().equals (false )) return ;
102
+ this . shardingSphereEnable = isShardingSphereEnable ();
102
103
sqlSessionFactories .forEach (sqlSessionFactory -> {
103
104
Configuration configuration = sqlSessionFactory .getConfiguration ();
104
105
if (ObjectUtils .isNotEmpty (configuration ) && !configuration .getInterceptors ().contains (defaultDttMybatisInterceptor )) {
105
106
configuration .addInterceptor (defaultDttMybatisInterceptor );
106
107
}
107
108
});
108
-
109
- if (logger .isInfoEnabled ()) {
110
- logger .info ("Loading..., " +
111
- "DTT is judging the existence of all tables for caching, it's will take a few seconds," +
112
- "if you want to disable dtt-mybatis-orm-support," +
113
- "please set 'alphahub.dtt.mybatis-orm-support.is-enable' to 'false'." );
109
+ if (logger .isInfoEnabled () && shardingSphereEnable .equals (false )) {
110
+ logger .info ("DTT is judging the existence of all tables for caching, it's will take a few seconds," +
111
+ "if you want to disable dtt-mybatis-orm-support, please set 'alphahub.dtt.mybatis-orm-support.is-enable' to 'false'." );
114
112
}
115
-
116
113
for (String mybatisPropPrefix : MYBATIS_PROP_PREFIX ) {
117
114
String property = SpringUtil .getProperty (mybatisPropPrefix );
118
115
if (StringUtils .isBlank (property )) continue ;
@@ -124,7 +121,9 @@ public void afterPropertiesSet() {
124
121
actWrapper .setDomainName (com .baomidou .mybatisplus .core .toolkit .StringUtils .firstToLowerCase (value .getSimpleName ()));
125
122
actWrapper .setDomainClass (value );
126
123
String tableName = com .baomidou .mybatisplus .core .toolkit .StringUtils .camelToUnderline (value .getSimpleName ());
127
- actWrapper .setTableNotExists (isTableNotExists (tableName ));
124
+ if (shardingSphereEnable .equals (false )) {
125
+ actWrapper .setTableNotExists (isTableNotExists (tableName ));
126
+ }
128
127
return actWrapper ;
129
128
})));
130
129
this .typeAliasesMap .putAll (classConcurrentMap );
@@ -138,7 +137,7 @@ public void afterPropertiesSet() {
138
137
* @return if enable return true
139
138
* @see <a href="https://shardingsphere.apache.org/document/5.1.2/cn/user-manual/shardingsphere-jdbc/spring-boot-starter/">ShardingSphere Auto-Configuration</a>
140
139
*/
141
- public boolean isShardingSphereEnable () {
140
+ protected boolean isShardingSphereEnable () {
142
141
boolean isShardingSphereEnable = false ;
143
142
try {
144
143
Class <?> shardingSphereDriver = Class .forName ("org.apache.shardingsphere.driver.ShardingSphereDriver" );
@@ -148,7 +147,7 @@ public boolean isShardingSphereEnable() {
148
147
} catch (Exception e ) {
149
148
// No dump
150
149
}
151
- for (String shardingSphereBean : shardingSphereBeans ) {
150
+ for (String shardingSphereBean : SHARDING_SPHERE_BEANS ) {
152
151
try {
153
152
if (ObjectUtils .isNotEmpty (applicationContext .getBean (shardingSphereBean )))
154
153
isShardingSphereEnable = true ;
0 commit comments