From 158ca87c7291351a6a9f438e687419f5248bf458 Mon Sep 17 00:00:00 2001 From: byteblogs168 <598092184@qq.com> Date: Fri, 29 Mar 2024 17:00:24 +0800 Subject: [PATCH] =?UTF-8?q?feat:=203.2.0=201.=20=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E8=A1=A8=E7=9A=84=E5=88=86=E5=8C=BA=E6=95=B0=E9=87=8F=EF=BC=8C?= =?UTF-8?q?=E5=85=BC=E5=AE=B9oracle=20=E5=92=8C=20sqlserver?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EasyRetryTemplateAutoConfiguration.java | 2 +- .../mapper/DistributedLockMapper.java | 1 - .../template/mapper/DistributedLockMapper.xml | 6 ---- .../service/impl/GroupConfigServiceImpl.java | 33 ++++++++++++++----- 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/easy-retry-datasource/easy-retry-datasource-template/src/main/java/com/aizuda/easy/retry/template/datasource/config/EasyRetryTemplateAutoConfiguration.java b/easy-retry-datasource/easy-retry-datasource-template/src/main/java/com/aizuda/easy/retry/template/datasource/config/EasyRetryTemplateAutoConfiguration.java index 575df10fa..67893125d 100644 --- a/easy-retry-datasource/easy-retry-datasource-template/src/main/java/com/aizuda/easy/retry/template/datasource/config/EasyRetryTemplateAutoConfiguration.java +++ b/easy-retry-datasource/easy-retry-datasource-template/src/main/java/com/aizuda/easy/retry/template/datasource/config/EasyRetryTemplateAutoConfiguration.java @@ -60,7 +60,7 @@ public class EasyRetryTemplateAutoConfiguration { return new SqlSessionTemplate(sqlSessionFactory); } - private final static List TABLES = Arrays.asList("retry_task", "retry_dead_letter"); + private static final List TABLES = Arrays.asList("retry_task", "retry_dead_letter"); @Bean public MybatisPlusInterceptor mybatisPlusInterceptor(Environment environment) { diff --git a/easy-retry-datasource/easy-retry-datasource-template/src/main/java/com/aizuda/easy/retry/template/datasource/persistence/mapper/DistributedLockMapper.java b/easy-retry-datasource/easy-retry-datasource-template/src/main/java/com/aizuda/easy/retry/template/datasource/persistence/mapper/DistributedLockMapper.java index 42ca47391..f245a8a50 100644 --- a/easy-retry-datasource/easy-retry-datasource-template/src/main/java/com/aizuda/easy/retry/template/datasource/persistence/mapper/DistributedLockMapper.java +++ b/easy-retry-datasource/easy-retry-datasource-template/src/main/java/com/aizuda/easy/retry/template/datasource/persistence/mapper/DistributedLockMapper.java @@ -13,5 +13,4 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; */ public interface DistributedLockMapper extends BaseMapper { - int updateTest(DistributedLock lock); } diff --git a/easy-retry-datasource/easy-retry-datasource-template/src/main/resources/template/mapper/DistributedLockMapper.xml b/easy-retry-datasource/easy-retry-datasource-template/src/main/resources/template/mapper/DistributedLockMapper.xml index 366d73e95..646adda0d 100644 --- a/easy-retry-datasource/easy-retry-datasource-template/src/main/resources/template/mapper/DistributedLockMapper.xml +++ b/easy-retry-datasource/easy-retry-datasource-template/src/main/resources/template/mapper/DistributedLockMapper.xml @@ -18,10 +18,4 @@ id, name, lock_until, locked_at, locked_by, create_dt, update_dt - - update distributed_lock set locked_by = #{lockedBy}, - lock_until = #{lockUntil}, - locked_at = #{lockedAt} - where name = #{name} and lock_until #{lockedAt} - diff --git a/easy-retry-server/easy-retry-server-web/src/main/java/com/aizuda/easy/retry/server/web/service/impl/GroupConfigServiceImpl.java b/easy-retry-server/easy-retry-server-web/src/main/java/com/aizuda/easy/retry/server/web/service/impl/GroupConfigServiceImpl.java index 5b3e1deda..0a55b3dc4 100644 --- a/easy-retry-server/easy-retry-server-web/src/main/java/com/aizuda/easy/retry/server/web/service/impl/GroupConfigServiceImpl.java +++ b/easy-retry-server/easy-retry-server-web/src/main/java/com/aizuda/easy/retry/server/web/service/impl/GroupConfigServiceImpl.java @@ -21,15 +21,17 @@ import com.aizuda.easy.retry.server.web.util.UserSessionUtils; import com.aizuda.easy.retry.template.datasource.access.AccessTemplate; import com.aizuda.easy.retry.template.datasource.access.ConfigAccess; import com.aizuda.easy.retry.template.datasource.access.TaskAccess; +import com.aizuda.easy.retry.template.datasource.enums.DbTypeEnum; +import com.aizuda.easy.retry.template.datasource.persistence.mapper.RetryTaskMapper; import com.aizuda.easy.retry.template.datasource.persistence.mapper.SequenceAllocMapper; import com.aizuda.easy.retry.template.datasource.persistence.mapper.ServerNodeMapper; import com.aizuda.easy.retry.template.datasource.persistence.po.*; +import com.aizuda.easy.retry.template.datasource.utils.DbUtils; import com.baomidou.mybatisplus.autoconfigure.MybatisPlusProperties; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO; import com.google.common.collect.Lists; -import org.slf4j.helpers.MessageFormatter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.jdbc.BadSqlGrammarException; @@ -40,7 +42,10 @@ import org.springframework.util.CollectionUtils; import javax.sql.DataSource; import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.ResultSet; import java.sql.SQLException; +import java.text.MessageFormat; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; @@ -73,6 +78,8 @@ public class GroupConfigServiceImpl implements GroupConfigService { private JdbcTemplate jdbcTemplate; @Autowired private MybatisPlusProperties mybatisPlusProperties; + @Autowired + private RetryTaskMapper retryTaskMapper; @Override @Transactional @@ -334,6 +341,7 @@ public class GroupConfigServiceImpl implements GroupConfigService { @Override public List getTablePartitionList() { + DataSource dataSource = jdbcTemplate.getDataSource(); Connection connection = null; try { @@ -341,14 +349,23 @@ public class GroupConfigServiceImpl implements GroupConfigService { String catalog = connection.getCatalog(); String schema = connection.getSchema(); - String tablePrefix = Optional.ofNullable(mybatisPlusProperties.getGlobalConfig().getDbConfig().getTablePrefix()).orElse(StrUtil.EMPTY); - // https://gitee.com/aizuda/easy-retry/issues/I8DAMH - String sql = MessageFormatter.arrayFormat("SELECT table_name\n" - + "FROM information_schema.tables\n" - + "WHERE table_name LIKE '{}retry_task_%' AND (table_schema = '{}' OR table_schema = '{}' OR table_catalog = '{}' OR table_catalog = '{}')", - new Object[]{tablePrefix, schema, catalog, schema, catalog}).getMessage(); + DbTypeEnum dbType = DbUtils.getDbType(); + if (DbTypeEnum.ORACLE.getDb().equals(dbType.getDb())) { + catalog = Optional.ofNullable(catalog).orElse(StrUtil.EMPTY).toUpperCase(); + schema = Optional.ofNullable(schema).orElse(StrUtil.EMPTY).toUpperCase(); + } + + DatabaseMetaData metaData = connection.getMetaData(); + String tablePrefix = Optional.ofNullable(mybatisPlusProperties.getGlobalConfig().getDbConfig().getTablePrefix()).orElse(StrUtil.EMPTY); + ResultSet tables = metaData.getTables(catalog.toUpperCase(), schema.toUpperCase(), MessageFormat.format("{0}retry_task_%", tablePrefix), new String[]{"TABLE"}); + + // 输出表名 + List tableList = new ArrayList<>(); + while (tables.next()) { + String tableName = tables.getString("TABLE_NAME"); + tableList.add(tableName); + } - List tableList = jdbcTemplate.queryForList(sql, String.class); return tableList.stream().map(ReUtil::getFirstNumber).filter(i -> !Objects.isNull(i) && i <= systemProperties.getTotalPartition()).distinct() .collect(Collectors.toList());