use of io.shardingjdbc.core.rewrite.SQLBuilder 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.rewrite.SQLBuilder in project sharding-jdbc by shardingjdbc.
the class ParsingSQLRouter method route.
@Override
public SQLRouteResult route(final String logicSQL, final List<Object> parameters, final SQLStatement sqlStatement) {
SQLRouteResult result = new SQLRouteResult(sqlStatement);
if (sqlStatement instanceof InsertStatement && null != ((InsertStatement) sqlStatement).getGeneratedKey()) {
processGeneratedKey(parameters, (InsertStatement) sqlStatement, result);
}
RoutingResult routingResult = route(parameters, sqlStatement);
SQLRewriteEngine rewriteEngine = new SQLRewriteEngine(shardingRule, logicSQL, databaseType, sqlStatement);
boolean isSingleRouting = routingResult.isSingleRouting();
if (sqlStatement instanceof SelectStatement && null != ((SelectStatement) sqlStatement).getLimit()) {
processLimit(parameters, (SelectStatement) sqlStatement, isSingleRouting);
}
SQLBuilder sqlBuilder = rewriteEngine.rewrite(!isSingleRouting);
if (routingResult instanceof CartesianRoutingResult) {
for (CartesianDataSource cartesianDataSource : ((CartesianRoutingResult) routingResult).getRoutingDataSources()) {
for (CartesianTableReference cartesianTableReference : cartesianDataSource.getRoutingTableReferences()) {
result.getExecutionUnits().add(new SQLExecutionUnit(cartesianDataSource.getDataSource(), rewriteEngine.generateSQL(cartesianTableReference, sqlBuilder)));
}
}
} else {
for (TableUnit each : routingResult.getTableUnits().getTableUnits()) {
result.getExecutionUnits().add(new SQLExecutionUnit(each.getDataSourceName(), rewriteEngine.generateSQL(each, sqlBuilder)));
}
}
if (showSQL) {
SQLLogger.logSQL(logicSQL, sqlStatement, result.getExecutionUnits(), parameters);
}
return result;
}
use of io.shardingjdbc.core.rewrite.SQLBuilder 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.rewrite.SQLBuilder 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