Search in sources :

Example 1 with DQLStatement

use of io.shardingjdbc.core.parsing.parser.sql.dql.DQLStatement in project sharding-jdbc by shardingjdbc.

the class ShardingStatement method getResultSet.

@Override
public ResultSet getResultSet() throws SQLException {
    if (null != currentResultSet) {
        return currentResultSet;
    }
    if (1 == routedStatements.size() && routeResult.getSqlStatement() instanceof DQLStatement) {
        currentResultSet = routedStatements.iterator().next().getResultSet();
        return currentResultSet;
    }
    List<ResultSet> resultSets = new ArrayList<>(routedStatements.size());
    List<QueryResult> queryResults = new ArrayList<>(routedStatements.size());
    for (Statement each : routedStatements) {
        ResultSet resultSet = each.getResultSet();
        resultSets.add(resultSet);
        queryResults.add(new JDBCQueryResult(resultSet));
    }
    if (routeResult.getSqlStatement() instanceof SelectStatement || routeResult.getSqlStatement() instanceof DALStatement) {
        MergeEngine mergeEngine = MergeEngineFactory.newInstance(connection.getShardingContext().getShardingRule(), queryResults, routeResult.getSqlStatement());
        currentResultSet = new ShardingResultSet(resultSets, mergeEngine.merge(), this);
    }
    return currentResultSet;
}
Also used : SelectStatement(io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement) QueryResult(io.shardingjdbc.core.merger.QueryResult) JDBCQueryResult(io.shardingjdbc.core.merger.JDBCQueryResult) MergeEngine(io.shardingjdbc.core.merger.MergeEngine) DQLStatement(io.shardingjdbc.core.parsing.parser.sql.dql.DQLStatement) 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) ShardingResultSet(io.shardingjdbc.core.jdbc.core.resultset.ShardingResultSet) ResultSet(java.sql.ResultSet) GeneratedKeysResultSet(io.shardingjdbc.core.jdbc.core.resultset.GeneratedKeysResultSet) ShardingResultSet(io.shardingjdbc.core.jdbc.core.resultset.ShardingResultSet) ArrayList(java.util.ArrayList) DALStatement(io.shardingjdbc.core.parsing.parser.sql.dal.DALStatement) JDBCQueryResult(io.shardingjdbc.core.merger.JDBCQueryResult)

Example 2 with DQLStatement

use of io.shardingjdbc.core.parsing.parser.sql.dql.DQLStatement in project sharding-jdbc by shardingjdbc.

the class ShardingPreparedStatement method getResultSet.

@Override
public ResultSet getResultSet() throws SQLException {
    if (null != currentResultSet) {
        return currentResultSet;
    }
    if (1 == routedStatements.size() && routeResult.getSqlStatement() instanceof DQLStatement) {
        currentResultSet = routedStatements.iterator().next().getResultSet();
        return currentResultSet;
    }
    List<ResultSet> resultSets = new ArrayList<>(routedStatements.size());
    List<QueryResult> queryResults = new ArrayList<>(routedStatements.size());
    for (PreparedStatement each : routedStatements) {
        ResultSet resultSet = each.getResultSet();
        resultSets.add(resultSet);
        queryResults.add(new JDBCQueryResult(resultSet));
    }
    if (routeResult.getSqlStatement() instanceof SelectStatement || routeResult.getSqlStatement() instanceof DALStatement) {
        MergeEngine mergeEngine = MergeEngineFactory.newInstance(connection.getShardingContext().getShardingRule(), queryResults, routeResult.getSqlStatement());
        currentResultSet = new ShardingResultSet(resultSets, mergeEngine.merge(), this);
    }
    return currentResultSet;
}
Also used : SelectStatement(io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement) QueryResult(io.shardingjdbc.core.merger.QueryResult) JDBCQueryResult(io.shardingjdbc.core.merger.JDBCQueryResult) MergeEngine(io.shardingjdbc.core.merger.MergeEngine) DQLStatement(io.shardingjdbc.core.parsing.parser.sql.dql.DQLStatement) ShardingResultSet(io.shardingjdbc.core.jdbc.core.resultset.ShardingResultSet) ResultSet(java.sql.ResultSet) GeneratedKeysResultSet(io.shardingjdbc.core.jdbc.core.resultset.GeneratedKeysResultSet) ShardingResultSet(io.shardingjdbc.core.jdbc.core.resultset.ShardingResultSet) ArrayList(java.util.ArrayList) DALStatement(io.shardingjdbc.core.parsing.parser.sql.dal.DALStatement) JDBCQueryResult(io.shardingjdbc.core.merger.JDBCQueryResult) PreparedStatement(java.sql.PreparedStatement)

Aggregations

GeneratedKeysResultSet (io.shardingjdbc.core.jdbc.core.resultset.GeneratedKeysResultSet)2 ShardingResultSet (io.shardingjdbc.core.jdbc.core.resultset.ShardingResultSet)2 JDBCQueryResult (io.shardingjdbc.core.merger.JDBCQueryResult)2 MergeEngine (io.shardingjdbc.core.merger.MergeEngine)2 QueryResult (io.shardingjdbc.core.merger.QueryResult)2 DALStatement (io.shardingjdbc.core.parsing.parser.sql.dal.DALStatement)2 DQLStatement (io.shardingjdbc.core.parsing.parser.sql.dql.DQLStatement)2 SelectStatement (io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement)2 ResultSet (java.sql.ResultSet)2 ArrayList (java.util.ArrayList)2 InsertStatement (io.shardingjdbc.core.parsing.parser.sql.dml.insert.InsertStatement)1 PreparedStatement (java.sql.PreparedStatement)1 Statement (java.sql.Statement)1