use of io.shardingjdbc.core.parsing.parser.sql.dal.DALStatement in project sharding-jdbc by shardingjdbc.
the class ParsingSQLRouter method route.
private RoutingResult route(final List<Object> parameters, final SQLStatement sqlStatement) {
Collection<String> tableNames = sqlStatement.getTables().getTableNames();
RoutingEngine routingEngine;
if (sqlStatement instanceof UseStatement) {
routingEngine = new IgnoreRoutingEngine();
} else if (sqlStatement instanceof DDLStatement) {
routingEngine = new TableBroadcastRoutingEngine(shardingRule, sqlStatement);
} else if (sqlStatement instanceof ShowDatabasesStatement || sqlStatement instanceof ShowTablesStatement) {
routingEngine = new DatabaseBroadcastRoutingEngine(shardingRule);
} else if (sqlStatement instanceof DALStatement) {
routingEngine = new UnicastRoutingEngine(shardingRule, sqlStatement);
} else if (tableNames.isEmpty() && sqlStatement instanceof SelectStatement) {
routingEngine = new UnicastRoutingEngine(shardingRule, sqlStatement);
} else if (tableNames.isEmpty()) {
routingEngine = new DatabaseBroadcastRoutingEngine(shardingRule);
} else if (1 == tableNames.size() || shardingRule.isAllBindingTables(tableNames) || shardingRule.isAllInDefaultDataSource(tableNames)) {
routingEngine = new StandardRoutingEngine(shardingRule, parameters, tableNames.iterator().next(), sqlStatement);
} else {
// TODO config for cartesian set
routingEngine = new ComplexRoutingEngine(shardingRule, parameters, tableNames, sqlStatement);
}
return routingEngine.route();
}
use of io.shardingjdbc.core.parsing.parser.sql.dal.DALStatement in project sharding-jdbc by shardingjdbc.
the class ShardingStatement method getResultSet.
@Override
public ResultSet getResultSet() throws SQLException {
if (null != currentResultSet) {
return currentResultSet;
}
if (1 == routedStatements.size() && routeResult.getSqlStatement() instanceof DQLStatement) {
currentResultSet = routedStatements.iterator().next().getResultSet();
return currentResultSet;
}
List<ResultSet> resultSets = new ArrayList<>(routedStatements.size());
List<QueryResult> queryResults = new ArrayList<>(routedStatements.size());
for (Statement each : routedStatements) {
ResultSet resultSet = each.getResultSet();
resultSets.add(resultSet);
queryResults.add(new JDBCQueryResult(resultSet));
}
if (routeResult.getSqlStatement() instanceof SelectStatement || routeResult.getSqlStatement() instanceof DALStatement) {
MergeEngine mergeEngine = MergeEngineFactory.newInstance(connection.getShardingContext().getShardingRule(), queryResults, routeResult.getSqlStatement());
currentResultSet = new ShardingResultSet(resultSets, mergeEngine.merge(), this);
}
return currentResultSet;
}
use of io.shardingjdbc.core.parsing.parser.sql.dal.DALStatement in project sharding-jdbc by shardingjdbc.
the class DALMergeEngineTest method assertMergeForShowOtherStatement.
@Test
public void assertMergeForShowOtherStatement() throws SQLException {
DALStatement dalStatement = new ShowOtherStatement();
DALMergeEngine dalMergeEngine = new DALMergeEngine(null, queryResults, dalStatement);
assertThat(dalMergeEngine.merge(), instanceOf(ShowOtherMergedResult.class));
}
use of io.shardingjdbc.core.parsing.parser.sql.dal.DALStatement in project sharding-jdbc by shardingjdbc.
the class DALMergeEngineTest method assertMergeForShowDatabasesStatement.
@Test
public void assertMergeForShowDatabasesStatement() throws SQLException {
DALStatement dalStatement = new ShowDatabasesStatement();
DALMergeEngine dalMergeEngine = new DALMergeEngine(null, queryResults, dalStatement);
assertThat(dalMergeEngine.merge(), instanceOf(ShowDatabasesMergedResult.class));
}
use of io.shardingjdbc.core.parsing.parser.sql.dal.DALStatement in project sharding-jdbc by shardingjdbc.
the class MergeEngineFactoryTest method assertNewInstanceWithDALStatement.
@Test
public void assertNewInstanceWithDALStatement() throws SQLException {
SQLStatement dalStatement = new DALStatement();
assertThat(MergeEngineFactory.newInstance(null, queryResults, dalStatement), instanceOf(DALMergeEngine.class));
}
Aggregations