Search in sources :

Example 1 with SQLType

use of io.shardingjdbc.core.constant.SQLType 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;
}
Also used : SQLExecutionUnit(io.shardingjdbc.core.routing.SQLExecutionUnit) PreparedStatement(java.sql.PreparedStatement) PreparedStatementUnit(io.shardingjdbc.core.executor.type.prepared.PreparedStatementUnit) BatchPreparedStatementUnit(io.shardingjdbc.core.executor.type.batch.BatchPreparedStatementUnit) SQLType(io.shardingjdbc.core.constant.SQLType) LinkedList(java.util.LinkedList)

Example 2 with SQLType

use of io.shardingjdbc.core.constant.SQLType in project sharding-jdbc by shardingjdbc.

the class AbstractNullableShardingTableOnlyTest method dataParameters.

protected static Collection<Object[]> dataParameters(final SQLType... sqlTypes) {
    List<Object[]> result = new LinkedList<>();
    for (SQLType each : sqlTypes) {
        result.addAll(SQLAssertJAXBHelper.getDataParameters("integrate/assert/select_aggregate.xml", each));
        result.addAll(SQLAssertJAXBHelper.getDataParameters("integrate/assert/select_nullable.xml", each));
    }
    return result;
}
Also used : SQLType(io.shardingjdbc.core.constant.SQLType) LinkedList(java.util.LinkedList)

Example 3 with SQLType

use of io.shardingjdbc.core.constant.SQLType 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);
}
Also used : DQLStatement(io.shardingjdbc.core.parsing.parser.sql.dql.DQLStatement) SelectStatement(io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement) InsertStatement(io.shardingjdbc.core.parsing.parser.sql.dml.insert.InsertStatement) DALStatement(io.shardingjdbc.core.parsing.parser.sql.dal.DALStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) ShardingConnection(io.shardingjdbc.core.jdbc.core.connection.ShardingConnection) StatementRoutingEngine(io.shardingjdbc.core.routing.StatementRoutingEngine) SQLExecutionUnit(io.shardingjdbc.core.routing.SQLExecutionUnit) SQLType(io.shardingjdbc.core.constant.SQLType) StatementExecutor(io.shardingjdbc.core.executor.type.statement.StatementExecutor) StatementUnit(io.shardingjdbc.core.executor.type.statement.StatementUnit) LinkedList(java.util.LinkedList) ShardingContext(io.shardingjdbc.core.jdbc.core.ShardingContext)

Aggregations

SQLType (io.shardingjdbc.core.constant.SQLType)3 LinkedList (java.util.LinkedList)3 SQLExecutionUnit (io.shardingjdbc.core.routing.SQLExecutionUnit)2 BatchPreparedStatementUnit (io.shardingjdbc.core.executor.type.batch.BatchPreparedStatementUnit)1 PreparedStatementUnit (io.shardingjdbc.core.executor.type.prepared.PreparedStatementUnit)1 StatementExecutor (io.shardingjdbc.core.executor.type.statement.StatementExecutor)1 StatementUnit (io.shardingjdbc.core.executor.type.statement.StatementUnit)1 ShardingContext (io.shardingjdbc.core.jdbc.core.ShardingContext)1 ShardingConnection (io.shardingjdbc.core.jdbc.core.connection.ShardingConnection)1 DALStatement (io.shardingjdbc.core.parsing.parser.sql.dal.DALStatement)1 InsertStatement (io.shardingjdbc.core.parsing.parser.sql.dml.insert.InsertStatement)1 DQLStatement (io.shardingjdbc.core.parsing.parser.sql.dql.DQLStatement)1 SelectStatement (io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement)1 StatementRoutingEngine (io.shardingjdbc.core.routing.StatementRoutingEngine)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 Statement (java.sql.Statement)1