SpringBoot集成Sharding-JDBC实现分库分表
import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.infra.context.metadata.MetaDataContexts;
import org.apache.shardingsphere.infra.context.runtime.RuntimeContext;
import org.apache.shardingsphere.infra.database.DefaultSchema;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.datanode.DataNode;
import org.apache.shardingsphere.infra.metadata.model.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.model.logic.LogicSchemaMetaData;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.infra.rule.type.DataSourceContainedRule;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.metadata.MetaDataContextsBuilder;
import org.apache.shardingsphere.mode.repository.StandalonePersistRepository;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.apache.shardingsphere.sharding.rule.TableRule;
import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
public class ShardingSphereMockMetaDataContexts implements MetaDataContexts {
private final Map<String, ShardingSphereMetaData> metaDataMap = new HashMap<>();
private final Collection<ShardingSphereRule> rules = new ArrayList<>();
private final Properties props = new Properties();
private final StandalonePersistRepository repository = new StandalonePersistRepository();
private final ConfigurationProperties configurationProperties;
public ShardingSphereMockMetaDataContexts(final Map<String, DataSource> dataSourceMap, final Collection<ShardingSphereRule> rules) {
// 构建ShardingRule
ShardingRule shardingRule = new ShardingRule(
dataSourceMap.keySet().stream().map(dataSource
评论已关闭