mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-08 04:39:00 +08:00
♻️ Refactoring code. 适配最新的 shardingsphere 分库分表策略
This commit is contained in:
1 parent
dd89faff1e
commit
130da074a0
2 files changed
+24
-7
No files matched your search
+7
-1
@@ -5,6 +5,7 @@ package com.pig4cloud.pigx.common.sequence.properties;
|
||||
* @date 2019-05-26
|
||||
*/
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -20,6 +21,11 @@ import org.springframework.stereotype.Component;
|
||||
@ConfigurationProperties(prefix = "pigx.xsequence.db")
|
||||
public class SequenceDbProperties extends BaseSequenceProperties {
|
||||
|
||||
/**
|
||||
* 默认数据库类型
|
||||
*/
|
||||
private DbType dbType = DbType.MYSQL;
|
||||
|
||||
/**
|
||||
* 表名称
|
||||
*/
|
||||
@@ -30,4 +36,4 @@ public class SequenceDbProperties extends BaseSequenceProperties {
|
||||
*/
|
||||
private int retryTimes = 1;
|
||||
|
||||
}
|
||||
}
|
||||
+17
-6
@@ -4,12 +4,14 @@ import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
import com.baomidou.mybatisplus.extension.toolkit.JdbcUtils;
|
||||
import com.pig4cloud.pigx.common.sequence.properties.SequenceDbProperties;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* sql语句提供工厂
|
||||
@@ -22,20 +24,29 @@ import java.util.List;
|
||||
@RequiredArgsConstructor
|
||||
public class SqlProviderFactory {
|
||||
|
||||
private final DruidDataSource druidDataSource;
|
||||
private final Optional<DruidDataSource> druidDataSourceOptional;
|
||||
|
||||
private final SequenceDbProperties dbProperties;
|
||||
|
||||
private final List<SqlProvider> sqlProviders;
|
||||
|
||||
private final Environment environment;
|
||||
|
||||
public SqlProvider getSqlProvider() {
|
||||
String url = druidDataSource.getUrl();
|
||||
// druid 形式 进行降级获取
|
||||
if (StrUtil.isBlank(url)) {
|
||||
url = environment.getProperty("spring.datasource.druid.url");
|
||||
DbType dbType = null;
|
||||
if (druidDataSourceOptional.isPresent()) {
|
||||
String url = druidDataSourceOptional.get().getUrl();
|
||||
// druid 形式 进行降级获取
|
||||
if (StrUtil.isBlank(url)) {
|
||||
url = environment.getProperty("spring.datasource.druid.url");
|
||||
}
|
||||
|
||||
JdbcUtils.getDbType(url);
|
||||
}
|
||||
else {
|
||||
dbType = dbProperties.getDbType();
|
||||
}
|
||||
|
||||
DbType dbType = JdbcUtils.getDbType(url);
|
||||
for (SqlProvider sqlProvider : sqlProviders) {
|
||||
if (sqlProvider.support(dbType)) {
|
||||
return sqlProvider;
|
||||
|
||||
Reference in new issue
Block a user