use of io.shardingjdbc.core.executor.type.prepared.PreparedStatementUnit in project sharding-jdbc by shardingjdbc.
the class ShardingPreparedStatement method executeQuery.
@Override
public ResultSet executeQuery() throws SQLException {
ResultSet result;
try {
Collection<PreparedStatementUnit> preparedStatementUnits = route();
List<ResultSet> resultSets = new PreparedStatementExecutor(getConnection().getShardingContext().getExecutorEngine(), routeResult.getSqlStatement().getType(), preparedStatementUnits, getParameters()).executeQuery();
List<QueryResult> queryResults = new ArrayList<>(resultSets.size());
for (ResultSet each : resultSets) {
queryResults.add(new JDBCQueryResult(each));
}
MergeEngine mergeEngine = MergeEngineFactory.newInstance(connection.getShardingContext().getShardingRule(), queryResults, routeResult.getSqlStatement());
result = new ShardingResultSet(resultSets, mergeEngine.merge(), this);
} finally {
clearBatch();
}
currentResultSet = result;
return result;
}
use of io.shardingjdbc.core.executor.type.prepared.PreparedStatementUnit 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.executor.type.prepared.PreparedStatementUnit 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;
}
Aggregations