Search in sources :

Example 1 with SQLExecutionUnit

use of com.dangdang.ddframe.rdb.sharding.router.SQLExecutionUnit in project sharding-jdbc by dangdangdotcom.

the class ShardingPreparedStatement method routeSQL.

private List<PreparedStatementExecutorWrapper> routeSQL() throws SQLException {
    List<PreparedStatementExecutorWrapper> result = new ArrayList<>();
    SQLRouteResult sqlRouteResult = preparedSQLRouter.route(getParameters());
    MergeContext mergeContext = sqlRouteResult.getMergeContext();
    setMergeContext(mergeContext);
    setGeneratedKeyContext(sqlRouteResult.getGeneratedKeyContext());
    for (SQLExecutionUnit each : sqlRouteResult.getExecutionUnits()) {
        PreparedStatement preparedStatement = (PreparedStatement) getStatement(getShardingConnection().getConnection(each.getDataSource(), sqlRouteResult.getSqlStatementType()), each.getSql());
        replayMethodsInvocation(preparedStatement);
        getParameters().replayMethodsInvocation(preparedStatement);
        result.add(wrap(preparedStatement, each));
    }
    return result;
}
Also used : SQLRouteResult(com.dangdang.ddframe.rdb.sharding.router.SQLRouteResult) PreparedStatementExecutorWrapper(com.dangdang.ddframe.rdb.sharding.executor.wrapper.PreparedStatementExecutorWrapper) ArrayList(java.util.ArrayList) SQLExecutionUnit(com.dangdang.ddframe.rdb.sharding.router.SQLExecutionUnit) PreparedStatement(java.sql.PreparedStatement) MergeContext(com.dangdang.ddframe.rdb.sharding.parser.result.merger.MergeContext)

Example 2 with SQLExecutionUnit

use of com.dangdang.ddframe.rdb.sharding.router.SQLExecutionUnit in project sharding-jdbc by dangdangdotcom.

the class ShardingStatement method generateExecutor.

private StatementExecutor generateExecutor(final String sql) throws SQLException {
    StatementExecutor result = new StatementExecutor(shardingConnection.getShardingContext().getExecutorEngine());
    SQLRouteResult sqlRouteResult = shardingConnection.getShardingContext().getSqlRouteEngine().route(sql);
    generatedKeyContext = sqlRouteResult.getGeneratedKeyContext();
    mergeContext = sqlRouteResult.getMergeContext();
    for (SQLExecutionUnit each : sqlRouteResult.getExecutionUnits()) {
        Statement statement = getStatement(shardingConnection.getConnection(each.getDataSource(), sqlRouteResult.getSqlStatementType()), each.getSql());
        replayMethodsInvocation(statement);
        result.addStatement(new StatementExecutorWrapper(statement, each));
    }
    return result;
}
Also used : SQLRouteResult(com.dangdang.ddframe.rdb.sharding.router.SQLRouteResult) Statement(java.sql.Statement) SQLExecutionUnit(com.dangdang.ddframe.rdb.sharding.router.SQLExecutionUnit) StatementExecutor(com.dangdang.ddframe.rdb.sharding.executor.StatementExecutor) StatementExecutorWrapper(com.dangdang.ddframe.rdb.sharding.executor.wrapper.StatementExecutorWrapper)

Aggregations

SQLExecutionUnit (com.dangdang.ddframe.rdb.sharding.router.SQLExecutionUnit)2 SQLRouteResult (com.dangdang.ddframe.rdb.sharding.router.SQLRouteResult)2 StatementExecutor (com.dangdang.ddframe.rdb.sharding.executor.StatementExecutor)1 PreparedStatementExecutorWrapper (com.dangdang.ddframe.rdb.sharding.executor.wrapper.PreparedStatementExecutorWrapper)1 StatementExecutorWrapper (com.dangdang.ddframe.rdb.sharding.executor.wrapper.StatementExecutorWrapper)1 MergeContext (com.dangdang.ddframe.rdb.sharding.parser.result.merger.MergeContext)1 PreparedStatement (java.sql.PreparedStatement)1 Statement (java.sql.Statement)1 ArrayList (java.util.ArrayList)1