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.executor.kernel.ExecutorEngine;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.optimize.context.OptimizerContext;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.metadata.MetaDataContextsBuilder;
import org.apache.shardingsphere.mode.repository.RepositoryType;
import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
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.executor.kernel.ExecutorEngine;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.optimize.context.OptimizerContext;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.metadata.MetaDataContextsBuilder;
import org.apache.shardingsphere.mode.repository.RepositoryType;
// 示例代码省略
// 创建ShardingSphere数据源
public DataSource createDataSource() {
// 省略原有的ShardingSphere配置和规则配置
// ...
// 构建MetaDataContexts
MetaDataContexts metaDataContexts = new MetaDataContextsBuilder(
mock(MetaDataContexts.class),
mock(ShardingSphereRuleMetaData.class),
mock(ExecutorEngine.class),
mock(ConfigurationProperties.class),
Collections.emptyMap()).build();
// 构建ContextManager
ContextManager contextManager = new ContextManager(
mock(MetaDataContexts.class),
mock(RuntimeContext.class),
mock(OptimizerContext.class),
mock(ServerVersion.class),
mock(ExecutorEngine.class));
// 省略其他配置和创建DataSource的代码
// ...
评论已关闭