Skip to content

Commit

Permalink
for apache#2900, Rename ShardingDataSourceMetaData to ShardingSphereM…
Browse files Browse the repository at this point in the history
…etaData
  • Loading branch information
terrymanu committed Aug 21, 2019
1 parent 86c0fc1 commit 6402b25
Show file tree
Hide file tree
Showing 20 changed files with 88 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.core.metadata.datasource.ShardingDataSourceMetaData;
import org.apache.shardingsphere.core.metadata.datasource.ShardingSphereDataSourceMetaData;
import org.apache.shardingsphere.core.metadata.table.ShardingTableMetaData;

/**
Expand All @@ -31,7 +31,7 @@
@Getter
public final class ShardingSphereMetaData {

private final ShardingDataSourceMetaData dataSource;
private final ShardingSphereDataSourceMetaData dataSource;

private final ShardingTableMetaData table;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@
import java.util.concurrent.ConcurrentHashMap;

/**
* Sharding data source meta data.
* ShardingSphere data source meta data.
*
* @author panjuan
*/
public final class ShardingDataSourceMetaData {
public final class ShardingSphereDataSourceMetaData {

private final Map<String, DataSourceMetaData> dataSourceMetaDataMap;

public ShardingDataSourceMetaData(final Map<String, String> dataSourceURLs, final ShardingRule shardingRule, final DatabaseType databaseType) {
public ShardingSphereDataSourceMetaData(final Map<String, String> dataSourceURLs, final ShardingRule shardingRule, final DatabaseType databaseType) {
dataSourceMetaDataMap = getDataSourceMetaDataMap(dataSourceURLs, shardingRule, databaseType);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@

import static org.junit.Assert.assertEquals;

public class ShardingDataSourceMetaDataTest {
public final class ShardingSphereDataSourceMetaDataTest {

private ShardingDataSourceMetaData masterSlaveShardingDataSourceMetaData;
private ShardingSphereDataSourceMetaData dataSourceMetaDataForMasterSlave;

private ShardingDataSourceMetaData shardingDataSourceMetaData;
private ShardingSphereDataSourceMetaData dataSourceMetaDataForSharding;

@Before
public void setUp() {
Expand All @@ -48,11 +48,11 @@ public void setUp() {
masterSlaveShardingDataSourceURLs.put("slave_0", "jdbc:mysql://127.0.0.2:3306/slave_0");
masterSlaveShardingDataSourceURLs.put("slave_1", "jdbc:mysql://127.0.0.2:3306/slave_1");
masterSlaveShardingDataSourceURLs.put("slave_2", "jdbc:mysql://127.0.0.2:3307/slave_2");
masterSlaveShardingDataSourceMetaData = new ShardingDataSourceMetaData(masterSlaveShardingDataSourceURLs, getMasterSlaveShardingRule(), DatabaseTypes.getActualDatabaseType("MySQL"));
dataSourceMetaDataForMasterSlave = new ShardingSphereDataSourceMetaData(masterSlaveShardingDataSourceURLs, getMasterSlaveShardingRule(), DatabaseTypes.getActualDatabaseType("MySQL"));
Map<String, String> shardingDataSourceURLs = new LinkedHashMap<>();
shardingDataSourceURLs.put("ds_0", "jdbc:mysql://127.0.0.1:3306/db_0");
shardingDataSourceURLs.put("ds_1", "jdbc:mysql://127.0.0.1:3306/db_1");
shardingDataSourceMetaData = new ShardingDataSourceMetaData(shardingDataSourceURLs, getShardingRule(), DatabaseTypes.getActualDatabaseType("MySQL"));
dataSourceMetaDataForSharding = new ShardingSphereDataSourceMetaData(shardingDataSourceURLs, getShardingRule(), DatabaseTypes.getActualDatabaseType("MySQL"));
}

private ShardingRule getMasterSlaveShardingRule() {
Expand All @@ -74,21 +74,21 @@ private ShardingRule getShardingRule() {

@Test
public void assertGetAllInstanceDataSourceNamesForMasterSlaveShardingRule() {
assertEquals(masterSlaveShardingDataSourceMetaData.getAllInstanceDataSourceNames(), Lists.newArrayList("ms_0", "ms_2"));
assertEquals(dataSourceMetaDataForMasterSlave.getAllInstanceDataSourceNames(), Lists.newArrayList("ms_0", "ms_2"));
}

@Test
public void assertGetAllInstanceDataSourceNamesForShardingRule() {
assertEquals(shardingDataSourceMetaData.getAllInstanceDataSourceNames(), Lists.newArrayList("ds_1"));
assertEquals(dataSourceMetaDataForSharding.getAllInstanceDataSourceNames(), Lists.newArrayList("ds_1"));
}

@Test
public void assertGetActualSchemaNameForMasterSlaveShardingRule() {
assertEquals(masterSlaveShardingDataSourceMetaData.getActualDataSourceMetaData("ms_0").getSchemaName(), "master_0");
assertEquals(dataSourceMetaDataForMasterSlave.getActualDataSourceMetaData("ms_0").getSchemaName(), "master_0");
}

@Test
public void assertGetActualSchemaNameForShardingRule() {
assertEquals(shardingDataSourceMetaData.getActualDataSourceMetaData("ds_0").getSchemaName(), "db_0");
assertEquals(dataSourceMetaDataForSharding.getActualDataSourceMetaData("ds_0").getSchemaName(), "db_0");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.google.common.base.Optional;
import lombok.SneakyThrows;
import org.apache.shardingsphere.core.execute.ShardingExecuteEngine;
import org.apache.shardingsphere.core.metadata.datasource.ShardingDataSourceMetaData;
import org.apache.shardingsphere.core.metadata.datasource.ShardingSphereDataSourceMetaData;
import org.apache.shardingsphere.core.metadata.table.TableMetaData;
import org.apache.shardingsphere.core.rule.ShardingRule;
import org.apache.shardingsphere.core.rule.TableRule;
Expand All @@ -42,17 +42,17 @@
*/
public final class TableMetaDataInitializer {

private final ShardingDataSourceMetaData shardingDataSourceMetaData;
private final ShardingSphereDataSourceMetaData dataSourceMetaData;

private final TableMetaDataConnectionManager connectionManager;

private final TableMetaDataLoader tableMetaDataLoader;

public TableMetaDataInitializer(final ShardingDataSourceMetaData shardingDataSourceMetaData, final ShardingExecuteEngine executeEngine,
public TableMetaDataInitializer(final ShardingSphereDataSourceMetaData dataSourceMetaData, final ShardingExecuteEngine executeEngine,
final TableMetaDataConnectionManager connectionManager, final int maxConnectionsSizePerQuery, final boolean isCheckingMetaData) {
this.shardingDataSourceMetaData = shardingDataSourceMetaData;
this.dataSourceMetaData = dataSourceMetaData;
this.connectionManager = connectionManager;
tableMetaDataLoader = new TableMetaDataLoader(shardingDataSourceMetaData, executeEngine, connectionManager, maxConnectionsSizePerQuery, isCheckingMetaData);
tableMetaDataLoader = new TableMetaDataLoader(dataSourceMetaData, executeEngine, connectionManager, maxConnectionsSizePerQuery, isCheckingMetaData);
}

/**
Expand Down Expand Up @@ -102,7 +102,7 @@ private Map<String, TableMetaData> loadDefaultTables(final ShardingRule sharding

private Collection<String> getAllTableNames(final String dataSourceName) throws SQLException {
Collection<String> result = new LinkedHashSet<>();
DataSourceMetaData dataSourceMetaData = shardingDataSourceMetaData.getActualDataSourceMetaData(dataSourceName);
DataSourceMetaData dataSourceMetaData = this.dataSourceMetaData.getActualDataSourceMetaData(dataSourceName);
String catalog = null == dataSourceMetaData ? null : dataSourceMetaData.getSchemaName();
try (Connection connection = connectionManager.getConnection(dataSourceName);
ResultSet resultSet = connection.getMetaData().getTables(catalog, getCurrentSchemaName(connection), null, new String[]{"TABLE"})) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.apache.shardingsphere.core.execute.ShardingExecuteEngine;
import org.apache.shardingsphere.core.execute.ShardingExecuteGroup;
import org.apache.shardingsphere.core.execute.ShardingGroupExecuteCallback;
import org.apache.shardingsphere.core.metadata.datasource.ShardingDataSourceMetaData;
import org.apache.shardingsphere.core.metadata.datasource.ShardingSphereDataSourceMetaData;
import org.apache.shardingsphere.core.metadata.table.ColumnMetaData;
import org.apache.shardingsphere.core.metadata.table.TableMetaData;
import org.apache.shardingsphere.core.rule.DataNode;
Expand Down Expand Up @@ -52,7 +52,7 @@
@RequiredArgsConstructor
public final class TableMetaDataLoader {

private final ShardingDataSourceMetaData shardingDataSourceMetaData;
private final ShardingSphereDataSourceMetaData dataSourceMetaData;

private final ShardingExecuteEngine executeEngine;

Expand Down Expand Up @@ -82,7 +82,7 @@ private List<TableMetaData> load(final Map<String, List<DataNode>> dataNodeGroup
@Override
public Collection<TableMetaData> execute(final Collection<DataNode> dataNodes, final boolean isTrunkThread, final Map<String, Object> shardingExecuteDataMap) throws SQLException {
String dataSourceName = dataNodes.iterator().next().getDataSourceName();
DataSourceMetaData dataSourceMetaData = shardingDataSourceMetaData.getActualDataSourceMetaData(dataSourceName);
DataSourceMetaData dataSourceMetaData = TableMetaDataLoader.this.dataSourceMetaData.getActualDataSourceMetaData(dataSourceName);
String catalog = null == dataSourceMetaData ? null : dataSourceMetaData.getSchemaName();
return load(shardingDataSourceNames.getRawMasterDataSourceName(dataSourceName), catalog, dataNodes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.google.common.base.Preconditions;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.core.metadata.datasource.ShardingDataSourceMetaData;
import org.apache.shardingsphere.core.metadata.datasource.ShardingSphereDataSourceMetaData;
import org.apache.shardingsphere.core.optimize.api.statement.OptimizedStatement;
import org.apache.shardingsphere.core.optimize.sharding.statement.dml.ShardingConditionOptimizedStatement;
import org.apache.shardingsphere.core.parse.sql.statement.SQLStatement;
Expand Down Expand Up @@ -59,11 +59,11 @@ public final class RoutingEngineFactory {
* Create new instance of routing engine.
*
* @param shardingRule sharding rule
* @param shardingDataSourceMetaData sharding data source meta data
* @param dataSourceMetaData data source meta data of ShardingSphere
* @param optimizedStatement optimized statement
* @return new instance of routing engine
*/
public static RoutingEngine newInstance(final ShardingRule shardingRule, final ShardingDataSourceMetaData shardingDataSourceMetaData, final OptimizedStatement optimizedStatement) {
public static RoutingEngine newInstance(final ShardingRule shardingRule, final ShardingSphereDataSourceMetaData dataSourceMetaData, final OptimizedStatement optimizedStatement) {
SQLStatement sqlStatement = optimizedStatement.getSQLStatement();
Collection<String> tableNames = optimizedStatement.getTables().getTableNames();
if (sqlStatement instanceof TCLStatement) {
Expand All @@ -76,7 +76,7 @@ public static RoutingEngine newInstance(final ShardingRule shardingRule, final S
return getDALRoutingEngine(shardingRule, sqlStatement, tableNames);
}
if (sqlStatement instanceof DCLStatement) {
return getDCLRoutingEngine(shardingRule, optimizedStatement, shardingDataSourceMetaData);
return getDCLRoutingEngine(shardingRule, optimizedStatement, dataSourceMetaData);
}
if (shardingRule.isAllInDefaultDataSource(tableNames)) {
return new DefaultDatabaseRoutingEngine(shardingRule, tableNames);
Expand Down Expand Up @@ -105,9 +105,9 @@ private static RoutingEngine getDALRoutingEngine(final ShardingRule shardingRule
return new DataSourceGroupBroadcastRoutingEngine(shardingRule);
}

private static RoutingEngine getDCLRoutingEngine(final ShardingRule shardingRule, final OptimizedStatement optimizedStatement, final ShardingDataSourceMetaData shardingDataSourceMetaData) {
private static RoutingEngine getDCLRoutingEngine(final ShardingRule shardingRule, final OptimizedStatement optimizedStatement, final ShardingSphereDataSourceMetaData dataSourceMetaData) {
return isGrantForSingleTable(optimizedStatement)
? new TableBroadcastRoutingEngine(shardingRule, optimizedStatement) : new InstanceBroadcastRoutingEngine(shardingRule, shardingDataSourceMetaData);
? new TableBroadcastRoutingEngine(shardingRule, optimizedStatement) : new InstanceBroadcastRoutingEngine(shardingRule, dataSourceMetaData);
}

private static boolean isGrantForSingleTable(final OptimizedStatement optimizedStatement) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package org.apache.shardingsphere.core.route.type.broadcast;

import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.core.metadata.datasource.ShardingDataSourceMetaData;
import org.apache.shardingsphere.core.metadata.datasource.ShardingSphereDataSourceMetaData;
import org.apache.shardingsphere.core.route.type.RoutingEngine;
import org.apache.shardingsphere.core.route.type.RoutingResult;
import org.apache.shardingsphere.core.route.type.RoutingUnit;
Expand All @@ -34,13 +34,13 @@ public final class InstanceBroadcastRoutingEngine implements RoutingEngine {

private final ShardingRule shardingRule;

private final ShardingDataSourceMetaData shardingDataSourceMetaData;
private final ShardingSphereDataSourceMetaData dataSourceMetaData;

@Override
public RoutingResult route() {
RoutingResult result = new RoutingResult();
for (String each : shardingRule.getShardingDataSourceNames().getDataSourceNames()) {
if (shardingDataSourceMetaData.getAllInstanceDataSourceNames().contains(each)) {
if (dataSourceMetaData.getAllInstanceDataSourceNames().contains(each)) {
result.getRoutingUnits().add(new RoutingUnit(each));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.apache.shardingsphere.api.config.sharding.strategy.InlineShardingStrategyConfiguration;
import org.apache.shardingsphere.core.database.DatabaseTypes;
import org.apache.shardingsphere.core.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.core.metadata.datasource.ShardingDataSourceMetaData;
import org.apache.shardingsphere.core.metadata.datasource.ShardingSphereDataSourceMetaData;
import org.apache.shardingsphere.core.metadata.table.ColumnMetaData;
import org.apache.shardingsphere.core.metadata.table.ShardingTableMetaData;
import org.apache.shardingsphere.core.metadata.table.TableMetaData;
Expand All @@ -48,19 +48,19 @@ public abstract class AbstractSQLRouteTest {

protected final SQLRouteResult assertRoute(final String sql, final List<Object> parameters) {
ShardingRule shardingRule = createShardingRule();
ShardingSphereMetaData metaData = new ShardingSphereMetaData(buildShardingDataSourceMetaData(), buildShardingTableMetaData());
ShardingSphereMetaData metaData = new ShardingSphereMetaData(buildDataSourceMetaData(), buildShardingTableMetaData());
SQLParseEngine parseEngine = new SQLParseEngine(DatabaseTypes.getActualDatabaseType("MySQL"));
PreparedStatementRoutingEngine engine = new PreparedStatementRoutingEngine(sql, shardingRule, metaData, DatabaseTypes.getActualDatabaseType("MySQL"), parseEngine);
SQLRouteResult result = engine.route(parameters);
assertThat(result.getRoutingResult().getRoutingUnits().size(), is(1));
return result;
}

private ShardingDataSourceMetaData buildShardingDataSourceMetaData() {
private ShardingSphereDataSourceMetaData buildDataSourceMetaData() {
Map<String, String> shardingDataSourceURLs = new LinkedHashMap<>();
shardingDataSourceURLs.put("ds_0", "jdbc:mysql://127.0.0.1:3306/actual_db");
shardingDataSourceURLs.put("ds_1", "jdbc:mysql://127.0.0.1:3306/actual_db");
return new ShardingDataSourceMetaData(shardingDataSourceURLs, createShardingRule(), DatabaseTypes.getActualDatabaseType("MySQL"));
return new ShardingSphereDataSourceMetaData(shardingDataSourceURLs, createShardingRule(), DatabaseTypes.getActualDatabaseType("MySQL"));
}

private ShardingRule createShardingRule() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.apache.shardingsphere.core.constant.properties.ShardingPropertiesConstant;
import org.apache.shardingsphere.core.execute.metadata.TableMetaDataInitializer;
import org.apache.shardingsphere.core.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.core.metadata.datasource.ShardingDataSourceMetaData;
import org.apache.shardingsphere.core.metadata.datasource.ShardingSphereDataSourceMetaData;
import org.apache.shardingsphere.core.metadata.table.ShardingTableMetaData;
import org.apache.shardingsphere.core.rule.ShardingRule;
import org.apache.shardingsphere.shardingjdbc.jdbc.core.datasource.metadata.CachedDatabaseMetaData;
Expand Down Expand Up @@ -69,9 +69,9 @@ private DatabaseMetaData createCachedDatabaseMetaData(final Map<String, DataSour
}

private ShardingSphereMetaData createMetaData(final Map<String, DataSource> dataSourceMap, final ShardingRule shardingRule, final DatabaseType databaseType) throws SQLException {
ShardingDataSourceMetaData shardingDataSourceMetaData = new ShardingDataSourceMetaData(getDataSourceURLs(dataSourceMap), shardingRule, databaseType);
ShardingTableMetaData shardingTableMetaData = new ShardingTableMetaData(getTableMetaDataInitializer(dataSourceMap, shardingDataSourceMetaData).load(shardingRule));
return new ShardingSphereMetaData(shardingDataSourceMetaData, shardingTableMetaData);
ShardingSphereDataSourceMetaData dataSourceMetaData = new ShardingSphereDataSourceMetaData(getDataSourceURLs(dataSourceMap), shardingRule, databaseType);
ShardingTableMetaData shardingTableMetaData = new ShardingTableMetaData(getTableMetaDataInitializer(dataSourceMap, dataSourceMetaData).load(shardingRule));
return new ShardingSphereMetaData(dataSourceMetaData, shardingTableMetaData);
}

private Map<String, String> getDataSourceURLs(final Map<String, DataSource> dataSourceMap) throws SQLException {
Expand All @@ -88,8 +88,8 @@ private String getDataSourceURL(final DataSource dataSource) throws SQLException
}
}

private TableMetaDataInitializer getTableMetaDataInitializer(final Map<String, DataSource> dataSourceMap, final ShardingDataSourceMetaData shardingDataSourceMetaData) {
return new TableMetaDataInitializer(shardingDataSourceMetaData, getExecuteEngine(), new JDBCTableMetaDataConnectionManager(dataSourceMap),
private TableMetaDataInitializer getTableMetaDataInitializer(final Map<String, DataSource> dataSourceMap, final ShardingSphereDataSourceMetaData dataSourceMetaData) {
return new TableMetaDataInitializer(dataSourceMetaData, getExecuteEngine(), new JDBCTableMetaDataConnectionManager(dataSourceMap),
this.getProps().<Integer>getValue(ShardingPropertiesConstant.MAX_CONNECTIONS_SIZE_PER_QUERY),
this.getProps().<Boolean>getValue(ShardingPropertiesConstant.CHECK_TABLE_METADATA_ENABLED));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@
import org.apache.shardingsphere.shardingproxy.backend.response.query.QueryHeader;
import org.apache.shardingsphere.shardingproxy.backend.response.query.QueryResponse;
import org.apache.shardingsphere.shardingproxy.backend.response.update.UpdateResponse;
import org.apache.shardingsphere.shardingproxy.backend.schema.EncryptSchema;
import org.apache.shardingsphere.shardingproxy.backend.schema.LogicSchema;
import org.apache.shardingsphere.shardingproxy.backend.schema.LogicSchemas;
import org.apache.shardingsphere.shardingproxy.backend.schema.ShardingSchema;
import org.apache.shardingsphere.shardingproxy.backend.schema.impl.EncryptSchema;
import org.apache.shardingsphere.shardingproxy.backend.schema.impl.ShardingSchema;
import org.apache.shardingsphere.spi.database.DatabaseType;
import org.apache.shardingsphere.transaction.core.TransactionType;

Expand Down
Loading

0 comments on commit 6402b25

Please sign in to comment.