Skip to content

Commit 74fb583

Browse files
author
Weasley
committed
Optimize the logic for deducing database name
1 parent a3b6569 commit 74fb583

File tree

173 files changed

+23
-17
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

173 files changed

+23
-17
lines changed

dtt-spring-boot-starter-tests/dtt-spring-boot-2-x/src/main/resources/application-mysql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ mybatis-plus:
2222

2323
alphahub:
2424
dtt:
25-
is-enable: off
25+
is-enable: on
2626
banner-mode: ON
2727
show-sql: off
2828
mybatis-orm-support:

dtt-spring-boot-starter/src/main/java/cn/alphahub/dtt/plus/framework/InitDttClient.java

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,14 @@ public ContextWrapper contextWrapper(@Qualifier("commentParserClient") Map<Parse
146146
*/
147147
@Bean
148148
public DatabaseProperty databaseProperty(DataSource dataSource,
149-
DataSourceProperties dataSourceProperties,
150149
JdbcTemplate jdbcTemplate,
151-
DatabaseHandler databaseHandler
150+
DatabaseHandler databaseHandler,
151+
DataSourceProperties dataSourceProperties
152152
) {
153153
DatabaseProperty property = new DatabaseProperty();
154154
property.setDatabaseType(databaseHandler.getDbType());
155155
String databaseName = "";
156-
if (databaseHandler.getDbType() == DatabaseType.ORACLE)
157-
databaseName = dataSourceProperties.getUsername();
156+
if (databaseHandler.getDbType() == DatabaseType.ORACLE) databaseName = dataSourceProperties.getUsername();
158157
if (databaseHandler.getDbType() == DatabaseType.DB2) {
159158
try {
160159
databaseName = jdbcTemplate.queryForObject("SELECT CURRENT SERVER FROM SYSIBM.SYSDUMMY1", String.class);
@@ -167,17 +166,24 @@ public DatabaseProperty databaseProperty(DataSource dataSource,
167166
}
168167
try {
169168
@SuppressWarnings({"all"}) DatabaseMetaData metaData = dataSource.getConnection().getMetaData();
170-
property.setDatabaseVersion(metaData.getDatabaseProductVersion());
171-
property.setIntDatabaseVersion(metaData.getDatabaseMajorVersion());
172169
ResultSet result = metaData.getCatalogs();
173170
String dataURL = metaData.getURL();
174-
while (result.next()) {
175-
String databaseNameTemp = result.getString(1);
176-
if (org.apache.commons.lang3.StringUtils.isNotBlank(databaseNameTemp)
177-
&& !databaseHandler.getDbType().name().equalsIgnoreCase(databaseNameTemp)
178-
&& dataURL.contains(databaseNameTemp)) {
179-
databaseName = databaseNameTemp;
180-
break;
171+
property.setDatabaseVersion(metaData.getDatabaseProductVersion());
172+
property.setIntDatabaseVersion(metaData.getDatabaseMajorVersion());
173+
String currentCatalogName = metaData.getConnection().getCatalog();
174+
if (org.apache.commons.lang3.StringUtils.isNotBlank(currentCatalogName)
175+
&& !databaseHandler.getDbType().name().equalsIgnoreCase(currentCatalogName)
176+
&& dataURL.contains(currentCatalogName)) {
177+
databaseName = currentCatalogName;
178+
} else {
179+
while (result.next()) {
180+
String databaseNameTemp = result.getString(1);
181+
if (org.apache.commons.lang3.StringUtils.isNotBlank(databaseNameTemp)
182+
&& !databaseHandler.getDbType().name().equalsIgnoreCase(databaseNameTemp)
183+
&& dataURL.contains(databaseNameTemp)) {
184+
databaseName = databaseNameTemp;
185+
break;
186+
}
181187
}
182188
}
183189
} catch (SQLException e) {

embedded-db/derby/db.lck

0 Bytes
Binary file not shown.

embedded-db/derby/log/log.ctrl

0 Bytes
Binary file not shown.

embedded-db/derby/log/log1.dat

-1 MB
Binary file not shown.

embedded-db/derby/log/log2.dat

-1 MB
Binary file not shown.

embedded-db/derby/log/log3.dat

-1 MB
Binary file not shown.

embedded-db/derby/log/log4.dat

0 Bytes
Binary file not shown.

embedded-db/derby/log/logmirror.ctrl

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c101.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c111.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c121.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c130.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c141.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1770.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1790.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c17d0.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c17e0.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c17f0.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1810.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1830.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1840.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1890.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c18c0.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c18d0.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c18e0.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c18f0.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1900.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1920.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1940.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1950.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1960.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c19b0.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c19f0.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1a00.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1a20.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1a30.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1a50.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1a60.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1a70.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1b00.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1b20.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1b40.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1b50.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1b60.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1b70.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1b80.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1bb0.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1bd0.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1c20.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1c30.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1c70.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1c80.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1ca0.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1cb0.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1ce0.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1d20.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1d30.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1d40.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1d60.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1d90.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1da0.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1dc0.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1df0.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1e20.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1e30.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1e60.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1e70.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1e80.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1e90.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1ea0.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1ee0.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1ef0.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1f20.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1f40.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1f60.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1f70.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1f90.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1fe0.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c1ff0.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c20.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c2000.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c2010.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c2030.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c2050.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c2070.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c2090.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c20d0.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c20e0.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c2110.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c2130.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c2140.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c2150.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c2160.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c21a0.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c21c0.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c21d0.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c21f0.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c2230.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c2250.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c2270.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c2280.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c22c0.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c22d0.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c22e0.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c22f0.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c2330.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c2350.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c2360.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c2370.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c2380.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c23b0.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c23d0.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c2400.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c2410.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c2440.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c2450.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c2490.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c24a0.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c24e0.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c2500.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c2520.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c2530.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c2540.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c2560.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c25a0.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c25b0.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c25c0.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c25e0.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c25f0.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c2640.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c2650.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c2670.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c26a0.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c26c0.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c26d1.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c31.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c400.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c41.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c411.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c421.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c51.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c60.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c71.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c81.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/c90.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/ca1.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/cb1.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/cf0.dat

0 Bytes
Binary file not shown.

embedded-db/derby/seg0/d11a0.dat

-4 KB
Binary file not shown.

embedded-db/derby/seg0/d11e1.dat

-4 KB
Binary file not shown.

embedded-db/derby/seg0/d1760.dat

-32 KB
Binary file not shown.

embedded-db/derby/seg0/d17c1.dat

-4 KB
Binary file not shown.

embedded-db/derby/seg0/d1ae0.dat

-4 KB
Binary file not shown.

embedded-db/derby/seg0/d1c10.dat

-4 KB
Binary file not shown.

embedded-db/derby/seg0/d1c60.dat

-4 KB
Binary file not shown.

embedded-db/derby/seg0/d610.dat

-4 KB
Binary file not shown.

embedded-db/derby/seg0/d751.dat

-4 KB
Binary file not shown.

embedded-db/derby/seg0/d770.dat

-4 KB
Binary file not shown.

embedded-db/derby/seg0/d7d1.dat

-4 KB
Binary file not shown.

embedded-db/derby/seg0/d8c0.dat

-32 KB
Binary file not shown.

embedded-db/derby/seg0/d8f1.dat

-4 KB
Binary file not shown.

embedded-db/derby/seg0/da30.dat

-4 KB
Binary file not shown.

embedded-db/derby/seg0/da71.dat

-4 KB
Binary file not shown.

embedded-db/derby/seg0/dc50.dat

-32 KB
Binary file not shown.

embedded-db/derby/seg0/dc81.dat

-4 KB
Binary file not shown.

embedded-db/derby/seg0/ddf0.dat

-4 KB
Binary file not shown.

embedded-db/derby/seg0/de61.dat

-4 KB
Binary file not shown.

embedded-db/derby/seg0/de90.dat

-32 KB
Binary file not shown.

embedded-db/derby/seg0/def1.dat

-4 KB
Binary file not shown.

embedded-db/h2.mv.db

-2.61 MB
Binary file not shown.

embedded-db/hsqldb.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#HSQL Database Engine 2.6.0
2-
#Thu Aug 25 15:39:03 CST 2022
2+
#Sat Oct 08 16:09:42 CST 2022
33
version=2.6.0
44
modified=no
5-
tx_timestamp=37184
5+
tx_timestamp=46357

embedded-db/hsqldb.script

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ SET FILES NIO TRUE
2828
SET FILES NIO SIZE 256
2929
SET FILES LOG TRUE
3030
SET FILES LOG SIZE 50
31-
SET FILES CHECK 37184
31+
SET FILES CHECK 46357
3232
SET DATABASE COLLATION "SQL_TEXT" PAD SPACE
3333
CREATE USER SA PASSWORD DIGEST 'd41d8cd98f00b204e9800998ecf8427e'
3434
ALTER USER SA SET LOCAL TRUE

0 commit comments

Comments
 (0)