import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.DefaultSchema;
import org.apache.shardingsphere.infra.datanode.DataNode;
import org.apache.shardingsphere.infra.metadata.model.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.model.logic.LogicTableMetaData;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.infra.rule.type.DataNodeRoutedRule;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.mode.metadata.PersistMetaData;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.apache.shardingsphere.sharding.rule.TableRule;
import org.apache.shardingsphere.sharding.strategy.keygen.KeyGeneratorRow;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
public class DistributedPrimaryKeyMetaDataFixture {
public static MetaDataContexts getDistributedPrimaryKeyMetaData() {
// 构建ShardingSphereMetaData
ShardingSphereMetaData metaData = new ShardingSphereMetaData(
"ds0",
Collections.singletonMap("t_order", new LogicTableMetaData(
Collections.singletonList(new DataNode("ds0", "t_order_0")),
new TableRule(Collections.singletonList("ds0"), "t_order")
)),
new ConfigurationProperties(new Properties())
);
// 构建ShardingSphereRule
ShardingSphereRule rule = new ShardingSphereRule() {
@Override
public Collection<DataNodeRoutedRule> getDataNodeRoutedRules() {
return Collections.emptyList();
}
@Override
public Collection<ShardingSphereRule> getRules() {
return Collections.emptyList();
}
@Override
public DefaultSchema getDefaultSchema() {
return new DefaultSchema("ds0");
}
@Override
public String getType() {
return "SHARDING";
}
};
// 构建PersistMetaData
PersistMetaData persistMetaData = new PersistMetaData("ds0", new HashMap<>());
评论已关闭