Skip to content
Permalink
Browse files

Merge ebbec92 into 03619bf

  • Loading branch information
RaigorJiang committed Nov 19, 2019
2 parents 03619bf + ebbec92 commit 6c55c0bafa1ec6e60ec5f4a0ab952ff439c33a96
@@ -102,6 +102,9 @@ private static RoutingEngine getDALRoutingEngine(final ShardingRule shardingRule
if (sqlStatement instanceof SetStatement || sqlStatement instanceof ResetParameterStatement || sqlStatement instanceof ShowDatabasesStatement) {
return new DatabaseBroadcastRoutingEngine(shardingRule);
}
if (!tableNames.isEmpty() && !shardingRule.tableRuleExists(tableNames) && shardingRule.hasDefaultDataSourceName()) {
return new DefaultDatabaseRoutingEngine(shardingRule, tableNames);
}
if (!tableNames.isEmpty()) {
return new UnicastRoutingEngine(shardingRule, tableNames);
}
@@ -22,6 +22,8 @@
import org.apache.shardingsphere.core.preprocessor.statement.SQLStatementContext;
import org.apache.shardingsphere.sql.parser.sql.statement.SQLStatement;
import org.apache.shardingsphere.sql.parser.sql.statement.dal.DALStatement;
import org.apache.shardingsphere.sql.parser.sql.statement.dal.dialect.mysql.ShowColumnsStatement;
import org.apache.shardingsphere.sql.parser.sql.statement.dal.dialect.mysql.ShowCreateTableStatement;
import org.apache.shardingsphere.sql.parser.sql.statement.dal.dialect.mysql.ShowDatabasesStatement;
import org.apache.shardingsphere.sql.parser.sql.statement.dal.dialect.postgresql.SetStatement;
import org.apache.shardingsphere.sql.parser.sql.statement.dcl.DCLStatement;
@@ -237,4 +239,47 @@ public void assertNewInstanceForTableRuleNotExists() {
RoutingEngine actual = RoutingEngineFactory.newInstance(shardingRule, shardingSphereMetaData, sqlStatementContext, shardingConditions);
assertThat(actual, instanceOf(UnicastRoutingEngine.class));
}

@Test
public void assertNewInstanceForShowCreateTableWithTableRule() {
DALStatement dalStatement = mock(ShowCreateTableStatement.class);
when(sqlStatementContext.getSqlStatement()).thenReturn(dalStatement);
when(shardingRule.tableRuleExists(tableNames)).thenReturn(true);
tableNames.add("table_1");
RoutingEngine actual = RoutingEngineFactory.newInstance(shardingRule, shardingSphereMetaData, sqlStatementContext, shardingConditions);
assertThat(actual, instanceOf(UnicastRoutingEngine.class));
}

@Test
public void assertNewInstanceForShowCreateTableWithDefaultDataSource() {
DALStatement dalStatement = mock(ShowCreateTableStatement.class);
when(sqlStatementContext.getSqlStatement()).thenReturn(dalStatement);
when(shardingRule.tableRuleExists(tableNames)).thenReturn(false);
when(shardingRule.hasDefaultDataSourceName()).thenReturn(true);
tableNames.add("table_1");
RoutingEngine actual = RoutingEngineFactory.newInstance(shardingRule, shardingSphereMetaData, sqlStatementContext, shardingConditions);
assertThat(actual, instanceOf(DefaultDatabaseRoutingEngine.class));
}

@Test
public void assertNewInstanceForShowColumnsWithTableRule() {
DALStatement dalStatement = mock(ShowColumnsStatement.class);
when(sqlStatementContext.getSqlStatement()).thenReturn(dalStatement);
when(shardingRule.tableRuleExists(tableNames)).thenReturn(true);
tableNames.add("table_1");
RoutingEngine actual = RoutingEngineFactory.newInstance(shardingRule, shardingSphereMetaData, sqlStatementContext, shardingConditions);
assertThat(actual, instanceOf(UnicastRoutingEngine.class));
}

@Test
public void assertNewInstanceForShowColumnsWithDefaultDataSource() {
DALStatement dalStatement = mock(ShowColumnsStatement.class);
when(sqlStatementContext.getSqlStatement()).thenReturn(dalStatement);
when(shardingRule.tableRuleExists(tableNames)).thenReturn(false);
when(shardingRule.hasDefaultDataSourceName()).thenReturn(true);
tableNames.add("table_1");
RoutingEngine actual = RoutingEngineFactory.newInstance(shardingRule, shardingSphereMetaData, sqlStatementContext, shardingConditions);
assertThat(actual, instanceOf(DefaultDatabaseRoutingEngine.class));
}

}

0 comments on commit 6c55c0b

Please sign in to comment.
You can’t perform that action at this time.