未验证 提交 3fd291a9 编写于 作者: L Liang Zhang 提交者: GitHub

rename ShardingSchema to ShardingSphereSchema (#5514)

上级 eac2fd32
......@@ -31,7 +31,7 @@ import org.apache.shardingsphere.orchestration.core.configcenter.ConfigCenter;
import org.apache.shardingsphere.orchestration.core.facade.ShardingOrchestrationFacade;
import org.apache.shardingsphere.orchestration.core.metadatacenter.event.MetaDataChangedEvent;
import org.apache.shardingsphere.orchestration.core.registrycenter.event.DisabledStateChangedEvent;
import org.apache.shardingsphere.orchestration.core.registrycenter.schema.OrchestrationShardingSchema;
import org.apache.shardingsphere.orchestration.core.registrycenter.schema.OrchestrationSchema;
import org.apache.shardingsphere.shardingjdbc.jdbc.core.datasource.ShardingSphereDataSource;
import org.apache.shardingsphere.shardingjdbc.orchestration.internal.util.DataSourceConverter;
import org.apache.shardingsphere.underlying.common.config.DataSourceConfiguration;
......@@ -143,11 +143,11 @@ public class OrchestrationShardingSphereDataSource extends AbstractOrchestration
*/
@Subscribe
public synchronized void renew(final DisabledStateChangedEvent disabledStateChangedEvent) {
OrchestrationShardingSchema shardingSchema = disabledStateChangedEvent.getShardingSchema();
if (DefaultSchema.LOGIC_NAME.equals(shardingSchema.getSchemaName())) {
OrchestrationSchema orchestrationSchema = disabledStateChangedEvent.getOrchestrationSchema();
if (DefaultSchema.LOGIC_NAME.equals(orchestrationSchema.getSchemaName())) {
for (ShardingSphereRule each : dataSource.getRuntimeContext().getRules()) {
if (each instanceof MasterSlaveRule) {
((MasterSlaveRule) each).updateDisabledDataSourceNames(shardingSchema.getDataSourceName(), disabledStateChangedEvent.isDisabled());
((MasterSlaveRule) each).updateDisabledDataSourceNames(orchestrationSchema.getDataSourceName(), disabledStateChangedEvent.isDisabled());
}
}
}
......
......@@ -31,7 +31,7 @@ import org.apache.shardingsphere.orchestration.core.common.event.DataSourceChang
import org.apache.shardingsphere.orchestration.core.common.event.PropertiesChangedEvent;
import org.apache.shardingsphere.orchestration.core.common.event.ShardingRuleChangedEvent;
import org.apache.shardingsphere.orchestration.core.registrycenter.event.DisabledStateChangedEvent;
import org.apache.shardingsphere.orchestration.core.registrycenter.schema.OrchestrationShardingSchema;
import org.apache.shardingsphere.orchestration.core.registrycenter.schema.OrchestrationSchema;
import org.apache.shardingsphere.shardingjdbc.api.yaml.YamlShardingSphereDataSourceFactory;
import org.apache.shardingsphere.shardingjdbc.jdbc.core.datasource.ShardingSphereDataSource;
import org.apache.shardingsphere.underlying.common.config.DataSourceConfiguration;
......@@ -167,7 +167,7 @@ public final class OrchestrationShardingSphereDataSourceTest {
}
private DisabledStateChangedEvent getDisabledStateChangedEvent() {
OrchestrationShardingSchema shardingSchema = new OrchestrationShardingSchema("logic_db.ds_s");
return new DisabledStateChangedEvent(shardingSchema, true);
OrchestrationSchema orchestrationSchema = new OrchestrationSchema("logic_db.ds_s");
return new DisabledStateChangedEvent(orchestrationSchema, true);
}
}
......@@ -19,7 +19,7 @@ package org.apache.shardingsphere.orchestration.core.registrycenter;
import com.google.common.base.Joiner;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.orchestration.core.registrycenter.schema.OrchestrationShardingSchema;
import org.apache.shardingsphere.orchestration.core.registrycenter.schema.OrchestrationSchema;
/**
* RegistryCenter node.
......@@ -70,7 +70,7 @@ public final class RegistryCenterNode {
* @param dataSourceNodeFullPath data source node full path
* @return orchestration sharding schema
*/
public OrchestrationShardingSchema getOrchestrationShardingSchema(final String dataSourceNodeFullPath) {
return new OrchestrationShardingSchema(dataSourceNodeFullPath.replace(getDataSourcesNodeFullRootPath() + '/', ""));
public OrchestrationSchema getOrchestrationShardingSchema(final String dataSourceNodeFullPath) {
return new OrchestrationSchema(dataSourceNodeFullPath.replace(getDataSourcesNodeFullRootPath() + '/', ""));
}
}
......@@ -20,7 +20,7 @@ package org.apache.shardingsphere.orchestration.core.registrycenter.event;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.orchestration.core.common.event.ShardingOrchestrationEvent;
import org.apache.shardingsphere.orchestration.core.registrycenter.schema.OrchestrationShardingSchema;
import org.apache.shardingsphere.orchestration.core.registrycenter.schema.OrchestrationSchema;
/**
* Disabled state event.
......@@ -29,7 +29,7 @@ import org.apache.shardingsphere.orchestration.core.registrycenter.schema.Orches
@Getter
public final class DisabledStateChangedEvent implements ShardingOrchestrationEvent {
private final OrchestrationShardingSchema shardingSchema;
private final OrchestrationSchema orchestrationSchema;
private final boolean disabled;
}
......@@ -24,7 +24,7 @@ import org.apache.shardingsphere.orchestration.core.common.listener.PostSharding
import org.apache.shardingsphere.orchestration.core.registrycenter.event.DisabledStateChangedEvent;
import org.apache.shardingsphere.orchestration.core.registrycenter.RegistryCenterNode;
import org.apache.shardingsphere.orchestration.core.registrycenter.RegistryCenterNodeStatus;
import org.apache.shardingsphere.orchestration.core.registrycenter.schema.OrchestrationShardingSchema;
import org.apache.shardingsphere.orchestration.core.registrycenter.schema.OrchestrationSchema;
import java.util.Collections;
......@@ -45,7 +45,7 @@ public final class DataSourceStateChangedListener extends PostShardingCenterRepo
return new DisabledStateChangedEvent(getShardingSchema(event.getKey()), isDataSourceDisabled(event));
}
private OrchestrationShardingSchema getShardingSchema(final String dataSourceNodeFullPath) {
private OrchestrationSchema getShardingSchema(final String dataSourceNodeFullPath) {
return registryCenterNode.getOrchestrationShardingSchema(dataSourceNodeFullPath);
}
......
......@@ -25,17 +25,17 @@ import org.apache.shardingsphere.underlying.common.database.DefaultSchema;
import java.util.List;
/**
* Orchestration sharding schema.
* Orchestration schema.
*/
@RequiredArgsConstructor
@Getter
public final class OrchestrationShardingSchema {
public final class OrchestrationSchema {
private final String schemaName;
private final String dataSourceName;
public OrchestrationShardingSchema(final String value) {
public OrchestrationSchema(final String value) {
if (value.contains(".")) {
List<String> values = Splitter.on(".").splitToList(value);
schemaName = values.get(0);
......
......@@ -35,7 +35,7 @@ public final class OrchestrationShardingSchemaGroup {
*
* @param orchestrationShardingSchema orchestration sharding schema
*/
public void add(final OrchestrationShardingSchema orchestrationShardingSchema) {
public void add(final OrchestrationSchema orchestrationShardingSchema) {
String schemaName = orchestrationShardingSchema.getSchemaName();
if (!schemaGroup.containsKey(schemaName)) {
schemaGroup.put(schemaName, new LinkedList<>());
......
......@@ -20,7 +20,7 @@ package org.apache.shardingsphere.orchestration.core.registrycenter.listener;
import org.apache.shardingsphere.orchestration.center.RegistryCenterRepository;
import org.apache.shardingsphere.orchestration.center.listener.DataChangedEvent;
import org.apache.shardingsphere.orchestration.center.listener.DataChangedEvent.ChangedType;
import org.apache.shardingsphere.orchestration.core.registrycenter.schema.OrchestrationShardingSchema;
import org.apache.shardingsphere.orchestration.core.registrycenter.schema.OrchestrationSchema;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -45,8 +45,8 @@ public final class DataSourceStateChangedListenerTest {
@Test
public void assertCreateShardingOrchestrationEvent() {
OrchestrationShardingSchema expected = new OrchestrationShardingSchema("master_slave_db", "slave_ds_0");
OrchestrationSchema expected = new OrchestrationSchema("master_slave_db", "slave_ds_0");
DataChangedEvent dataChangedEvent = new DataChangedEvent("/test/registry/datasources/master_slave_db.slave_ds_0", "disabled", ChangedType.UPDATED);
assertThat(dataSourceStateChangedListener.createShardingOrchestrationEvent(dataChangedEvent).getShardingSchema().getSchemaName(), is(expected.getSchemaName()));
assertThat(dataSourceStateChangedListener.createShardingOrchestrationEvent(dataChangedEvent).getOrchestrationSchema().getSchemaName(), is(expected.getSchemaName()));
}
}
......@@ -30,8 +30,8 @@ public final class OrchestrationShardingSchemaGroupTest {
@Test
public void assertAddWithExistedSchemaName() {
OrchestrationShardingSchemaGroup actual = new OrchestrationShardingSchemaGroup();
actual.add(new OrchestrationShardingSchema("test_0.ds_0"));
actual.add(new OrchestrationShardingSchema("test_0.ds_1"));
actual.add(new OrchestrationSchema("test_0.ds_0"));
actual.add(new OrchestrationSchema("test_0.ds_1"));
assertThat(actual.getDataSourceNames("test_0").size(), is(2));
assertTrue(actual.getDataSourceNames("test_0").contains("ds_0"));
assertTrue(actual.getDataSourceNames("test_0").contains("ds_1"));
......@@ -40,8 +40,8 @@ public final class OrchestrationShardingSchemaGroupTest {
@Test
public void assertAddWithoutExistedSchemaName() {
OrchestrationShardingSchemaGroup actual = new OrchestrationShardingSchemaGroup();
actual.add(new OrchestrationShardingSchema("test_0.ds_0"));
actual.add(new OrchestrationShardingSchema("test_1.ds_1"));
actual.add(new OrchestrationSchema("test_0.ds_0"));
actual.add(new OrchestrationSchema("test_1.ds_1"));
assertThat(actual.getDataSourceNames("test_0").size(), is(1));
assertTrue(actual.getDataSourceNames("test_0").contains("ds_0"));
assertThat(actual.getDataSourceNames("test_1").size(), is(1));
......
......@@ -27,14 +27,14 @@ public final class OrchestrationShardingSchemaTest {
@Test
public void assertNewOrchestrationSchemaWithDataSourceNameOnly() {
OrchestrationShardingSchema actual = new OrchestrationShardingSchema("test_ds");
OrchestrationSchema actual = new OrchestrationSchema("test_ds");
assertThat(actual.getSchemaName(), is(DefaultSchema.LOGIC_NAME));
assertThat(actual.getDataSourceName(), is("test_ds"));
}
@Test
public void assertNewOrchestrationSchemaWithSchemaNameAndDataSourceName() {
OrchestrationShardingSchema actual = new OrchestrationShardingSchema("test_schema.test_ds");
OrchestrationSchema actual = new OrchestrationSchema("test_schema.test_ds");
assertThat(actual.getSchemaName(), is("test_schema"));
assertThat(actual.getDataSourceName(), is("test_ds"));
}
......
......@@ -31,7 +31,7 @@ import org.apache.shardingsphere.shardingproxy.backend.response.query.QueryRespo
import org.apache.shardingsphere.shardingproxy.backend.response.update.UpdateResponse;
import org.apache.shardingsphere.shardingproxy.backend.schema.LogicSchema;
import org.apache.shardingsphere.shardingproxy.backend.schema.LogicSchemas;
import org.apache.shardingsphere.shardingproxy.backend.schema.impl.ShardingSchema;
import org.apache.shardingsphere.shardingproxy.backend.schema.impl.ShardingSphereSchema;
import org.apache.shardingsphere.shardingproxy.context.ShardingProxyContext;
import org.apache.shardingsphere.sql.parser.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.sql.parser.binder.type.TableAvailable;
......@@ -90,7 +90,7 @@ public final class JDBCDatabaseCommunicationEngine implements DatabaseCommunicat
}
response = executeEngine.execute(executionContext);
// TODO refresh non-sharding table meta data
if (logicSchema instanceof ShardingSchema) {
if (logicSchema instanceof ShardingSphereSchema) {
logicSchema.refreshTableMetaData(executionContext.getSqlStatementContext());
}
return merge(executionContext.getSqlStatementContext());
......
......@@ -23,7 +23,7 @@ import org.apache.shardingsphere.shadow.rewrite.judgement.ShadowJudgementEngine;
import org.apache.shardingsphere.shadow.rewrite.judgement.impl.PreparedJudgementEngine;
import org.apache.shardingsphere.shardingproxy.backend.schema.LogicSchema;
import org.apache.shardingsphere.shardingproxy.backend.schema.impl.ShadowSchema;
import org.apache.shardingsphere.shardingproxy.backend.schema.impl.ShardingSchema;
import org.apache.shardingsphere.shardingproxy.backend.schema.impl.ShardingSphereSchema;
import org.apache.shardingsphere.shardingproxy.context.ShardingProxyContext;
import org.apache.shardingsphere.sql.parser.binder.SQLStatementContextFactory;
import org.apache.shardingsphere.sql.parser.binder.metadata.schema.SchemaMetaData;
......@@ -69,7 +69,7 @@ public final class PreparedStatementExecutorWrapper implements JDBCExecutorWrapp
@Override
public ExecutionContext route(final String sql) {
if (logicSchema instanceof ShardingSchema) {
if (logicSchema instanceof ShardingSphereSchema) {
return doShardingRoute(sql);
}
if (logicSchema instanceof ShadowSchema) {
......
......@@ -23,7 +23,7 @@ import org.apache.shardingsphere.shadow.rewrite.judgement.ShadowJudgementEngine;
import org.apache.shardingsphere.shadow.rewrite.judgement.impl.SimpleJudgementEngine;
import org.apache.shardingsphere.shardingproxy.backend.schema.LogicSchema;
import org.apache.shardingsphere.shardingproxy.backend.schema.impl.ShadowSchema;
import org.apache.shardingsphere.shardingproxy.backend.schema.impl.ShardingSchema;
import org.apache.shardingsphere.shardingproxy.backend.schema.impl.ShardingSphereSchema;
import org.apache.shardingsphere.shardingproxy.context.ShardingProxyContext;
import org.apache.shardingsphere.sql.parser.binder.SQLStatementContextFactory;
import org.apache.shardingsphere.sql.parser.binder.metadata.schema.SchemaMetaData;
......@@ -66,7 +66,7 @@ public final class StatementExecutorWrapper implements JDBCExecutorWrapper {
@Override
public ExecutionContext route(final String sql) {
if (logicSchema instanceof ShardingSchema) {
if (logicSchema instanceof ShardingSphereSchema) {
return doShardingRoute(sql);
}
if (logicSchema instanceof ShadowSchema) {
......
......@@ -24,7 +24,7 @@ import org.apache.shardingsphere.api.config.shadow.ShadowRuleConfiguration;
import org.apache.shardingsphere.api.config.sharding.ShardingRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.EncryptRuleConfiguration;
import org.apache.shardingsphere.shardingproxy.backend.schema.impl.ShadowSchema;
import org.apache.shardingsphere.shardingproxy.backend.schema.impl.ShardingSchema;
import org.apache.shardingsphere.shardingproxy.backend.schema.impl.ShardingSphereSchema;
import org.apache.shardingsphere.shardingproxy.backend.schema.impl.TransparentSchema;
import org.apache.shardingsphere.shardingproxy.config.yaml.YamlDataSourceParameter;
import org.apache.shardingsphere.underlying.common.config.RuleConfiguration;
......@@ -52,20 +52,20 @@ public final class LogicSchemaFactory {
public static LogicSchema newInstance(final String schemaName, final Map<String, Map<String, YamlDataSourceParameter>> schemaDataSources,
final Collection<RuleConfiguration> ruleConfigurations) throws SQLException {
if (ruleConfigurations.size() > 1) {
return new ShardingSchema(schemaName, schemaDataSources.get(schemaName), ruleConfigurations);
return new ShardingSphereSchema(schemaName, schemaDataSources.get(schemaName), ruleConfigurations);
}
if (ruleConfigurations.isEmpty()) {
return new TransparentSchema(schemaName, schemaDataSources.get(schemaName));
}
RuleConfiguration ruleConfiguration = ruleConfigurations.iterator().next();
if (ruleConfiguration instanceof ShardingRuleConfiguration) {
return new ShardingSchema(schemaName, schemaDataSources.get(schemaName), Collections.singleton(ruleConfiguration));
return new ShardingSphereSchema(schemaName, schemaDataSources.get(schemaName), Collections.singleton(ruleConfiguration));
}
if (ruleConfiguration instanceof MasterSlaveRuleConfiguration) {
return new ShardingSchema(schemaName, schemaDataSources.get(schemaName), Collections.singleton(ruleConfiguration));
return new ShardingSphereSchema(schemaName, schemaDataSources.get(schemaName), Collections.singleton(ruleConfiguration));
}
if (ruleConfiguration instanceof EncryptRuleConfiguration) {
return new ShardingSchema(schemaName, schemaDataSources.get(schemaName), Collections.singleton(ruleConfiguration));
return new ShardingSphereSchema(schemaName, schemaDataSources.get(schemaName), Collections.singleton(ruleConfiguration));
}
if (ruleConfiguration instanceof ShadowRuleConfiguration) {
return new ShadowSchema(schemaName, schemaDataSources.get(schemaName), (ShadowRuleConfiguration) ruleConfiguration);
......
......@@ -23,7 +23,7 @@ import org.apache.shardingsphere.core.rule.MasterSlaveRule;
import org.apache.shardingsphere.orchestration.core.common.event.ShardingRuleChangedEvent;
import org.apache.shardingsphere.orchestration.core.facade.ShardingOrchestrationFacade;
import org.apache.shardingsphere.orchestration.core.registrycenter.event.DisabledStateChangedEvent;
import org.apache.shardingsphere.orchestration.core.registrycenter.schema.OrchestrationShardingSchema;
import org.apache.shardingsphere.orchestration.core.registrycenter.schema.OrchestrationSchema;
import org.apache.shardingsphere.shardingproxy.backend.schema.LogicSchema;
import org.apache.shardingsphere.shardingproxy.backend.schema.LogicSchemas;
import org.apache.shardingsphere.shardingproxy.config.yaml.YamlDataSourceParameter;
......@@ -43,11 +43,11 @@ import java.util.Map;
import java.util.Optional;
/**
* Sharding schema.
* ShardingSphere schema.
*/
public final class ShardingSchema extends LogicSchema {
public final class ShardingSphereSchema extends LogicSchema {
public ShardingSchema(final String name, final Map<String, YamlDataSourceParameter> dataSources, final Collection<RuleConfiguration> ruleConfigurations) throws SQLException {
public ShardingSphereSchema(final String name, final Map<String, YamlDataSourceParameter> dataSources, final Collection<RuleConfiguration> ruleConfigurations) throws SQLException {
super(name, dataSources, ShardingSphereRulesBuilder.build(ruleConfigurations, dataSources.keySet()));
}
......@@ -71,11 +71,11 @@ public final class ShardingSchema extends LogicSchema {
*/
@Subscribe
public synchronized void renew(final DisabledStateChangedEvent disabledStateChangedEvent) {
OrchestrationShardingSchema shardingSchema = disabledStateChangedEvent.getShardingSchema();
if (getName().equals(shardingSchema.getSchemaName())) {
OrchestrationSchema orchestrationSchema = disabledStateChangedEvent.getOrchestrationSchema();
if (getName().equals(orchestrationSchema.getSchemaName())) {
for (ShardingSphereRule each : getRules()) {
if (each instanceof MasterSlaveRule) {
((MasterSlaveRule) each).updateDisabledDataSourceNames(shardingSchema.getDataSourceName(), disabledStateChangedEvent.isDisabled());
((MasterSlaveRule) each).updateDisabledDataSourceNames(orchestrationSchema.getDataSourceName(), disabledStateChangedEvent.isDisabled());
}
}
}
......
......@@ -18,7 +18,7 @@
package org.apache.shardingsphere.shardingproxy.backend.response.query;
import org.apache.shardingsphere.core.rule.ShardingRule;
import org.apache.shardingsphere.shardingproxy.backend.schema.impl.ShardingSchema;
import org.apache.shardingsphere.shardingproxy.backend.schema.impl.ShardingSphereSchema;
import org.apache.shardingsphere.sql.parser.binder.metadata.column.ColumnMetaData;
import org.apache.shardingsphere.sql.parser.binder.metadata.index.IndexMetaData;
import org.apache.shardingsphere.sql.parser.binder.metadata.schema.SchemaMetaData;
......@@ -125,8 +125,8 @@ public final class QueryHeaderTest {
assertTrue(header.isAutoIncrement());
}
private ShardingSchema getShardingSchema() {
ShardingSchema result = mock(ShardingSchema.class);
private ShardingSphereSchema getShardingSchema() {
ShardingSphereSchema result = mock(ShardingSphereSchema.class);
ColumnMetaData columnMetaData = new ColumnMetaData("order_id", Types.INTEGER, "int", true, false, false);
SchemaMetaData schemaMetaData = mock(SchemaMetaData.class);
when(schemaMetaData.get("t_logic_order")).thenReturn(new TableMetaData(Collections.singletonList(columnMetaData), Collections.singletonList(new IndexMetaData("order_id"))));
......
......@@ -23,13 +23,13 @@ import lombok.NoArgsConstructor;
import lombok.Setter;
/**
* Sharding schema DTO.
* ShardingSphere schema DTO.
*/
@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
public final class ShardingSchemaDTO {
public final class ShardingSphereSchemaDTO {
private String name;
......
......@@ -17,17 +17,17 @@
package org.apache.shardingsphere.ui.web.controller;
import org.apache.shardingsphere.ui.common.dto.ShardingSchemaDTO;
import org.apache.shardingsphere.ui.common.dto.ShardingSphereSchemaDTO;
import org.apache.shardingsphere.ui.servcie.ShardingSchemaService;
import org.apache.shardingsphere.ui.web.response.ResponseResult;
import org.apache.shardingsphere.ui.web.response.ResponseResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.Map;
......@@ -38,7 +38,7 @@ import java.util.Map;
@RequestMapping("/api/schema")
public final class ShardingSchemaController {
@Autowired
@Resource
private ShardingSchemaService shardingSchemaService;
/**
......@@ -54,19 +54,20 @@ public final class ShardingSchemaController {
/**
* Add schema configuration.
*
* @param shardingSchema sharding schema DTO.
* @param schemaDTO schema DTO
* @return response result
*/
@RequestMapping(value = "", method = RequestMethod.POST)
public ResponseResult addSchema(final @RequestBody ShardingSchemaDTO shardingSchema) {
shardingSchemaService.addSchemaConfiguration(shardingSchema.getName(), shardingSchema.getRuleConfiguration(), shardingSchema.getDataSourceConfiguration());
public ResponseResult addSchema(final @RequestBody ShardingSphereSchemaDTO schemaDTO) {
shardingSchemaService.addSchemaConfiguration(schemaDTO.getName(), schemaDTO.getRuleConfiguration(), schemaDTO.getDataSourceConfiguration());
return ResponseResultUtil.success();
}
/**
* Delete schema configuration
* Delete schema configuration.
*
* @param schemaName schema name
* @return
* @return response result
*/
@RequestMapping(value = "/{schemaName}", method = RequestMethod.DELETE)
public ResponseResult deleteSchema(@PathVariable("schemaName") final String schemaName) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册