feat: 3.2.0
1. 获取表的分区数量,兼容oracle 和 sqlserver
This commit is contained in:
parent
8c58aca247
commit
158ca87c72
@ -60,7 +60,7 @@ public class EasyRetryTemplateAutoConfiguration {
|
|||||||
return new SqlSessionTemplate(sqlSessionFactory);
|
return new SqlSessionTemplate(sqlSessionFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static List<String> TABLES = Arrays.asList("retry_task", "retry_dead_letter");
|
private static final List<String> TABLES = Arrays.asList("retry_task", "retry_dead_letter");
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public MybatisPlusInterceptor mybatisPlusInterceptor(Environment environment) {
|
public MybatisPlusInterceptor mybatisPlusInterceptor(Environment environment) {
|
||||||
|
@ -13,5 +13,4 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|||||||
*/
|
*/
|
||||||
public interface DistributedLockMapper extends BaseMapper<DistributedLock> {
|
public interface DistributedLockMapper extends BaseMapper<DistributedLock> {
|
||||||
|
|
||||||
int updateTest(DistributedLock lock);
|
|
||||||
}
|
}
|
||||||
|
@ -18,10 +18,4 @@
|
|||||||
id, name, lock_until, locked_at, locked_by, create_dt, update_dt
|
id, name, lock_until, locked_at, locked_by, create_dt, update_dt
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
<update id="updateTest">
|
|
||||||
update distributed_lock set locked_by = #{lockedBy},
|
|
||||||
lock_until = #{lockUntil},
|
|
||||||
locked_at = #{lockedAt}
|
|
||||||
where name = #{name} and lock_until <![CDATA[ <= ]]> #{lockedAt}
|
|
||||||
</update>
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
@ -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.AccessTemplate;
|
||||||
import com.aizuda.easy.retry.template.datasource.access.ConfigAccess;
|
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.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.SequenceAllocMapper;
|
||||||
import com.aizuda.easy.retry.template.datasource.persistence.mapper.ServerNodeMapper;
|
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.persistence.po.*;
|
||||||
|
import com.aizuda.easy.retry.template.datasource.utils.DbUtils;
|
||||||
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusProperties;
|
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusProperties;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import org.slf4j.helpers.MessageFormatter;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Lazy;
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.jdbc.BadSqlGrammarException;
|
import org.springframework.jdbc.BadSqlGrammarException;
|
||||||
@ -40,7 +42,10 @@ import org.springframework.util.CollectionUtils;
|
|||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
|
import java.sql.DatabaseMetaData;
|
||||||
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.text.MessageFormat;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -73,6 +78,8 @@ public class GroupConfigServiceImpl implements GroupConfigService {
|
|||||||
private JdbcTemplate jdbcTemplate;
|
private JdbcTemplate jdbcTemplate;
|
||||||
@Autowired
|
@Autowired
|
||||||
private MybatisPlusProperties mybatisPlusProperties;
|
private MybatisPlusProperties mybatisPlusProperties;
|
||||||
|
@Autowired
|
||||||
|
private RetryTaskMapper retryTaskMapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
@ -334,6 +341,7 @@ public class GroupConfigServiceImpl implements GroupConfigService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Integer> getTablePartitionList() {
|
public List<Integer> getTablePartitionList() {
|
||||||
|
|
||||||
DataSource dataSource = jdbcTemplate.getDataSource();
|
DataSource dataSource = jdbcTemplate.getDataSource();
|
||||||
Connection connection = null;
|
Connection connection = null;
|
||||||
try {
|
try {
|
||||||
@ -341,14 +349,23 @@ public class GroupConfigServiceImpl implements GroupConfigService {
|
|||||||
String catalog = connection.getCatalog();
|
String catalog = connection.getCatalog();
|
||||||
String schema = connection.getSchema();
|
String schema = connection.getSchema();
|
||||||
|
|
||||||
String tablePrefix = Optional.ofNullable(mybatisPlusProperties.getGlobalConfig().getDbConfig().getTablePrefix()).orElse(StrUtil.EMPTY);
|
DbTypeEnum dbType = DbUtils.getDbType();
|
||||||
// https://gitee.com/aizuda/easy-retry/issues/I8DAMH
|
if (DbTypeEnum.ORACLE.getDb().equals(dbType.getDb())) {
|
||||||
String sql = MessageFormatter.arrayFormat("SELECT table_name\n"
|
catalog = Optional.ofNullable(catalog).orElse(StrUtil.EMPTY).toUpperCase();
|
||||||
+ "FROM information_schema.tables\n"
|
schema = Optional.ofNullable(schema).orElse(StrUtil.EMPTY).toUpperCase();
|
||||||
+ "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();
|
|
||||||
|
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<String> tableList = new ArrayList<>();
|
||||||
|
while (tables.next()) {
|
||||||
|
String tableName = tables.getString("TABLE_NAME");
|
||||||
|
tableList.add(tableName);
|
||||||
|
}
|
||||||
|
|
||||||
List<String> tableList = jdbcTemplate.queryForList(sql, String.class);
|
|
||||||
return tableList.stream().map(ReUtil::getFirstNumber).filter(i ->
|
return tableList.stream().map(ReUtil::getFirstNumber).filter(i ->
|
||||||
!Objects.isNull(i) && i <= systemProperties.getTotalPartition()).distinct()
|
!Objects.isNull(i) && i <= systemProperties.getTotalPartition()).distinct()
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
Loading…
Reference in New Issue
Block a user