diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/DbTypeUtil.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/DbTypeUtil.java index 99c045f6..88c7c85f 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/DbTypeUtil.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/DbTypeUtil.java @@ -24,7 +24,6 @@ import org.apache.ibatis.datasource.unpooled.UnpooledDataSource; import javax.sql.DataSource; import java.lang.reflect.Method; import java.sql.Connection; -import java.sql.SQLException; import java.util.regex.Pattern; /** @@ -66,19 +65,10 @@ public class DbTypeUtil { } } - Connection connection = null; - try { - connection = dataSource.getConnection(); + try (Connection connection = dataSource.getConnection()) { return connection.getMetaData().getURL(); } catch (Exception e) { throw FlexExceptions.wrap(e, LocalizedFormats.DATASOURCE_JDBC_URL); - } finally { - if (connection != null) { - try { - connection.close(); - } catch (SQLException e) { //ignore - } - } } } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/handler/FastjsonTypeHandler.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/handler/FastjsonTypeHandler.java index 31cdb154..f2cc6d04 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/handler/FastjsonTypeHandler.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/handler/FastjsonTypeHandler.java @@ -22,6 +22,7 @@ import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.util.Arrays; import java.util.Collection; +import java.util.Objects; /** * @author michael @@ -96,10 +97,10 @@ public class FastjsonTypeHandler extends BaseJsonTypeHandler { } else { if (this.ownerType != null) { if (this.ownerType.equals(that.ownerType)) { - return this.rawType != null ? this.rawType.equals(that.rawType) : that.rawType == null; + return Objects.equals(this.rawType, that.rawType); } } else if (that.ownerType == null) { - return this.rawType != null ? this.rawType.equals(that.rawType) : that.rawType == null; + return Objects.equals(this.rawType, that.rawType); } return false; diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/row/Db.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/row/Db.java index 9c735c7b..60f10af8 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/row/Db.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/row/Db.java @@ -127,9 +127,7 @@ public class Db { * @param batchSize 每次提交的数据量 */ public static int[] insertBatch(String schema, String tableName, Collection rows, int batchSize) { - return executeBatch(rows, batchSize, RowMapper.class, (mapper, row) -> { - mapper.insert(schema, tableName, row); - }); + return executeBatch(rows, batchSize, RowMapper.class, (mapper, row) -> mapper.insert(schema, tableName, row)); } /** @@ -140,9 +138,7 @@ public class Db { * @param batchSize 每次提交的数据量 */ public static int[] insertBatch(String tableName, Collection rows, int batchSize) { - return executeBatch(rows, batchSize, RowMapper.class, (mapper, row) -> { - mapper.insert(null, tableName, row); - }); + return executeBatch(rows, batchSize, RowMapper.class, (mapper, row) -> mapper.insert(null, tableName, row)); } /** diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfo.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfo.java index 2e8af126..936a3145 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfo.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfo.java @@ -976,7 +976,7 @@ public class TableInfo { public List getDefaultQueryColumn() { return Arrays.stream(defaultQueryColumns) - .map(name -> columnQueryMapping.get(name)) + .map(columnQueryMapping::get) .collect(Collectors.toList()); } diff --git a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/AccountSqlTester.java b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/AccountSqlTester.java index ff8bbb35..7b2b9cf9 100644 --- a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/AccountSqlTester.java +++ b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/AccountSqlTester.java @@ -70,12 +70,7 @@ public class AccountSqlTester { .where(ACCOUNT01.ID.ge(100)) .and(ACCOUNT.SEX.eq(1)); - TableManager.setDynamicTableProcessor(new DynamicTableProcessor() { - @Override - public String process(String tableName) { - return tableName + "_01"; - } - }); + TableManager.setDynamicTableProcessor(tableName -> tableName + "_01"); TableManager.setDynamicTableProcessor(original -> original + "_01"); System.out.println(query.toSQL()); diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/DataSourceDecipherTester.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/DataSourceDecipherTester.java index f72d49e6..00040c3f 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/DataSourceDecipherTester.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/DataSourceDecipherTester.java @@ -36,16 +36,13 @@ public class DataSourceDecipherTester { dataSource.setUsername("root123"); dataSource.setPassword("123456---0000"); - DataSourceManager.setDecipher(new DataSourceDecipher() { - @Override - public String decrypt(DataSourceProperty property, String value) { - if (property == DataSourceProperty.USERNAME) { - return value.substring(0, 4); - } else if (property == DataSourceProperty.PASSWORD) { - return value.substring(0, 6); - } - return value; + DataSourceManager.setDecipher((property, value) -> { + if (property == DataSourceProperty.USERNAME) { + return value.substring(0, 4); + } else if (property == DataSourceProperty.PASSWORD) { + return value.substring(0, 6); } + return value; }); MybatisFlexBootstrap.getInstance() diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/EntityTestStarter.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/EntityTestStarter.java index 4afa97a8..193665ed 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/EntityTestStarter.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/EntityTestStarter.java @@ -176,18 +176,15 @@ public class EntityTestStarter { // Page paginate = accountMapper.paginateAs(Page.of(1, 10), asWrapper, ArticleDTO01.class); // System.out.println(paginate); - Db.tx(new Supplier() { - @Override - public Boolean get() { - Cursor accounts = accountMapper.selectCursorByQuery(asWrapper); - System.out.println(accounts.isOpen()); - for (Account account : accounts) { - System.out.println(accounts.isOpen()); - System.out.println(account); - } - System.out.println(accounts.isOpen()); - return true; + Db.tx(() -> { + Cursor accounts1 = accountMapper.selectCursorByQuery(asWrapper); + System.out.println(accounts1.isOpen()); + for (Account account : accounts1) { + System.out.println(accounts1.isOpen()); + System.out.println(account); } + System.out.println(accounts1.isOpen()); + return true; }); // Cursor accounts = accountMapper.selectCursorByQuery(asWrapper); diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/MultiDataSourceTester.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/MultiDataSourceTester.java index ca727ca8..037d2846 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/MultiDataSourceTester.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/MultiDataSourceTester.java @@ -59,14 +59,11 @@ public class MultiDataSourceTester { MessageCollector collector = new ConsoleMessageCollector(); AuditManager.setMessageCollector(collector); - Db.tx(new Supplier() { - @Override - public Boolean get() { - Db.selectAll(null, "tb_account"); - DataSourceKey.use("ds2"); - Db.selectAll(null, "tb_account"); - return true; - } + Db.tx(() -> { + Db.selectAll(null, "tb_account"); + DataSourceKey.use("ds2"); + Db.selectAll(null, "tb_account"); + return true; }); diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/TenantManagerTester.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/TenantManagerTester.java index 67b03cb8..14c51a8d 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/TenantManagerTester.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/TenantManagerTester.java @@ -47,12 +47,7 @@ public class TenantManagerTester { AuditManager.setMessageCollector(new ConsoleMessageCollector()); //配置 tenantFactory - TenantManager.setTenantFactory(new TenantFactory() { - @Override - public Object[] getTenantIds() { - return new Object[]{1}; - } - }); + TenantManager.setTenantFactory(() -> new Object[]{1}); TenantAccountMapper mapper = MybatisFlexBootstrap.getInstance().getMapper(TenantAccountMapper.class); List tenantAccounts = TenantManager.withoutTenantCondition(mapper::selectAll); diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/MyConfigurationCustomizer.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/MyConfigurationCustomizer.java index 49982073..542b9b77 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/MyConfigurationCustomizer.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/MyConfigurationCustomizer.java @@ -50,12 +50,9 @@ public class MyConfigurationCustomizer implements ConfigurationCustomizer, MyBat @Override public void customize(FlexGlobalConfig globalConfig) { - DataSourceDecipher decipher = new DataSourceDecipher() { - @Override - public String decrypt(DataSourceProperty property, String value) { - System.out.println(">>>>>> decipher.decrypt"); - return value; - } + DataSourceDecipher decipher = (property, value) -> { + System.out.println(">>>>>> decipher.decrypt"); + return value; }; DataSourceManager.setDecipher(decipher);