use of io.shardingjdbc.core.executor.type.batch.BatchPreparedStatementUnit in project sharding-jdbc by shardingjdbc.
the class ShardingPreparedStatement method addBatch.
@Override
public void addBatch() throws SQLException {
try {
for (BatchPreparedStatementUnit each : routeBatch()) {
each.getStatement().addBatch();
each.mapAddBatchCount(parameterSets.size());
}
parameterSets.add(getParameters());
} finally {
currentResultSet = null;
clearParameters();
}
}
use of io.shardingjdbc.core.executor.type.batch.BatchPreparedStatementUnit in project sharding-jdbc by shardingjdbc.
the class ShardingPreparedStatement method getPreparedBatchStatement.
private BatchPreparedStatementUnit getPreparedBatchStatement(final SQLExecutionUnit sqlExecutionUnit) throws SQLException {
Optional<BatchPreparedStatementUnit> preparedBatchStatement = Iterators.tryFind(batchStatementUnits.iterator(), new Predicate<BatchPreparedStatementUnit>() {
@Override
public boolean apply(final BatchPreparedStatementUnit input) {
return Objects.equals(input.getSqlExecutionUnit(), sqlExecutionUnit);
}
});
if (preparedBatchStatement.isPresent()) {
return preparedBatchStatement.get();
}
BatchPreparedStatementUnit result = new BatchPreparedStatementUnit(sqlExecutionUnit, generatePreparedStatement(sqlExecutionUnit));
batchStatementUnits.add(result);
return result;
}
use of io.shardingjdbc.core.executor.type.batch.BatchPreparedStatementUnit 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.executor.type.batch.BatchPreparedStatementUnit 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;
}
Aggregations