use of io.shardingjdbc.core.routing.SQLExecutionUnit in project sharding-jdbc by shardingjdbc.
the class DatabaseHintSQLRouter method route.
@Override
public // TODO insert SQL need parse gen key
SQLRouteResult route(final String logicSQL, final List<Object> parameters, final SQLStatement sqlStatement) {
SQLRouteResult result = new SQLRouteResult(sqlStatement);
RoutingResult routingResult = new DatabaseHintRoutingEngine(shardingRule.getDataSourceNames(), (HintShardingStrategy) shardingRule.getDefaultDatabaseShardingStrategy()).route();
for (TableUnit each : routingResult.getTableUnits().getTableUnits()) {
result.getExecutionUnits().add(new SQLExecutionUnit(each.getDataSourceName(), logicSQL));
}
if (showSQL) {
SQLLogger.logSQL(logicSQL, sqlStatement, result.getExecutionUnits(), parameters);
}
return result;
}
use of io.shardingjdbc.core.routing.SQLExecutionUnit in project sharding-jdbc by shardingjdbc.
the class StatementExecutorTest method createStatementUnits.
private Collection<StatementUnit> createStatementUnits(final String sql, final Statement statement, final String dataSource) {
Collection<StatementUnit> result = new LinkedList<>();
SQLBuilder sqlBuilder = new SQLBuilder();
sqlBuilder.appendLiterals(sql);
result.add(new StatementUnit(new SQLExecutionUnit(dataSource, sqlBuilder.toSQL(Collections.<String, String>emptyMap(), null)), statement));
return result;
}
use of io.shardingjdbc.core.routing.SQLExecutionUnit in project sharding-jdbc by shardingjdbc.
the class ShardingPreparedStatement method route.
private Collection<PreparedStatementUnit> route() throws SQLException {
Collection<PreparedStatementUnit> result = new LinkedList<>();
routeResult = routingEngine.route(getParameters());
for (SQLExecutionUnit each : routeResult.getExecutionUnits()) {
SQLType sqlType = routeResult.getSqlStatement().getType();
Collection<PreparedStatement> preparedStatements;
if (SQLType.DDL == sqlType) {
preparedStatements = generatePreparedStatementForDDL(each);
} else {
preparedStatements = Collections.singletonList(generatePreparedStatement(each));
}
routedStatements.addAll(preparedStatements);
for (PreparedStatement preparedStatement : preparedStatements) {
replaySetParameter(preparedStatement);
result.add(new PreparedStatementUnit(each, preparedStatement));
}
}
return result;
}
use of io.shardingjdbc.core.routing.SQLExecutionUnit in project sharding-jdbc by shardingjdbc.
the class ShardingPreparedStatement method routeBatch.
private List<BatchPreparedStatementUnit> routeBatch() throws SQLException {
List<BatchPreparedStatementUnit> result = new ArrayList<>();
routeResult = routingEngine.route(getParameters());
for (SQLExecutionUnit each : routeResult.getExecutionUnits()) {
BatchPreparedStatementUnit batchStatementUnit = getPreparedBatchStatement(each);
replaySetParameter(batchStatementUnit.getStatement());
result.add(batchStatementUnit);
}
return result;
}
use of io.shardingjdbc.core.routing.SQLExecutionUnit in project sharding-jdbc by shardingjdbc.
the class ExecuteEventListenerTest method assertSQLException.
@Test(expected = SQLException.class)
public void assertSQLException() throws Exception {
Statement statement = mock(Statement.class);
when(statement.getConnection()).thenReturn(mock(Connection.class));
executorEngine.executeStatement(SQLType.DQL, Collections.singleton(new StatementUnit(new SQLExecutionUnit("ds_0", "select ..."), statement)), new ExecuteCallback<Integer>() {
@Override
public Integer execute(final BaseStatementUnit baseStatementUnit) throws Exception {
throw new SQLException();
}
});
}
Aggregations