use of io.shardingjdbc.core.routing.SQLExecutionUnit in project sharding-jdbc by shardingjdbc.
the class BatchPreparedStatementExecutorTest method createPreparedStatementUnits.
private Collection<BatchPreparedStatementUnit> createPreparedStatementUnits(final String sql, final PreparedStatement preparedStatement, final String dataSource, final int addBatchTimes) {
Collection<BatchPreparedStatementUnit> result = new LinkedList<>();
SQLBuilder sqlBuilder = new SQLBuilder();
sqlBuilder.appendLiterals(sql);
BatchPreparedStatementUnit batchPreparedStatementUnit = new BatchPreparedStatementUnit(new SQLExecutionUnit(dataSource, sqlBuilder.toSQL(Collections.<String, String>emptyMap(), null)), preparedStatement);
for (int i = 0; i < addBatchTimes; i++) {
batchPreparedStatementUnit.mapAddBatchCount(i);
}
result.add(batchPreparedStatementUnit);
return result;
}
use of io.shardingjdbc.core.routing.SQLExecutionUnit in project sharding-jdbc by shardingjdbc.
the class PreparedStatementExecutorTest method createPreparedStatementUnits.
private Collection<PreparedStatementUnit> createPreparedStatementUnits(final String sql, final PreparedStatement preparedStatement, final String dataSource) {
Collection<PreparedStatementUnit> result = new LinkedList<>();
SQLBuilder sqlBuilder = new SQLBuilder();
sqlBuilder.appendLiterals(sql);
result.add(new PreparedStatementUnit(new SQLExecutionUnit(dataSource, sqlBuilder.toSQL(Collections.<String, String>emptyMap(), null)), preparedStatement));
return result;
}
use of io.shardingjdbc.core.routing.SQLExecutionUnit in project sharding-jdbc by shardingjdbc.
the class ShardingStatement method generateExecutor.
private StatementExecutor generateExecutor(final String sql) throws SQLException {
clearPrevious();
ShardingContext shardingContext = connection.getShardingContext();
routeResult = new StatementRoutingEngine(shardingContext.getShardingRule(), shardingContext.getDatabaseType(), shardingContext.isShowSQL()).route(sql);
Collection<StatementUnit> statementUnits = new LinkedList<>();
for (SQLExecutionUnit each : routeResult.getExecutionUnits()) {
Collection<Connection> connections;
SQLType sqlType = routeResult.getSqlStatement().getType();
if (SQLType.DDL == sqlType) {
connections = connection.getConnectionsForDDL(each.getDataSource());
} else {
connections = Collections.singletonList(connection.getConnection(each.getDataSource(), routeResult.getSqlStatement().getType()));
}
for (Connection connection : connections) {
Statement statement = connection.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability);
replayMethodsInvocation(statement);
statementUnits.add(new StatementUnit(each, statement));
routedStatements.add(statement);
}
}
return new StatementExecutor(connection.getShardingContext().getExecutorEngine(), routeResult.getSqlStatement().getType(), statementUnits);
}
Aggregations