Search in sources :

Example 1 with DALStatement

use of io.shardingjdbc.core.parsing.parser.sql.dal.DALStatement in project sharding-jdbc by shardingjdbc.

the class ParsingSQLRouter method route.

private RoutingResult route(final List<Object> parameters, final SQLStatement sqlStatement) {
    Collection<String> tableNames = sqlStatement.getTables().getTableNames();
    RoutingEngine routingEngine;
    if (sqlStatement instanceof UseStatement) {
        routingEngine = new IgnoreRoutingEngine();
    } else if (sqlStatement instanceof DDLStatement) {
        routingEngine = new TableBroadcastRoutingEngine(shardingRule, sqlStatement);
    } else if (sqlStatement instanceof ShowDatabasesStatement || sqlStatement instanceof ShowTablesStatement) {
        routingEngine = new DatabaseBroadcastRoutingEngine(shardingRule);
    } else if (sqlStatement instanceof DALStatement) {
        routingEngine = new UnicastRoutingEngine(shardingRule, sqlStatement);
    } else if (tableNames.isEmpty() && sqlStatement instanceof SelectStatement) {
        routingEngine = new UnicastRoutingEngine(shardingRule, sqlStatement);
    } else if (tableNames.isEmpty()) {
        routingEngine = new DatabaseBroadcastRoutingEngine(shardingRule);
    } else if (1 == tableNames.size() || shardingRule.isAllBindingTables(tableNames) || shardingRule.isAllInDefaultDataSource(tableNames)) {
        routingEngine = new StandardRoutingEngine(shardingRule, parameters, tableNames.iterator().next(), sqlStatement);
    } else {
        // TODO config for cartesian set
        routingEngine = new ComplexRoutingEngine(shardingRule, parameters, tableNames, sqlStatement);
    }
    return routingEngine.route();
}
Also used : ComplexRoutingEngine(io.shardingjdbc.core.routing.type.complex.ComplexRoutingEngine) IgnoreRoutingEngine(io.shardingjdbc.core.routing.type.ignore.IgnoreRoutingEngine) DDLStatement(io.shardingjdbc.core.parsing.parser.sql.ddl.DDLStatement) DatabaseBroadcastRoutingEngine(io.shardingjdbc.core.routing.type.broadcast.DatabaseBroadcastRoutingEngine) ShowDatabasesStatement(io.shardingjdbc.core.parsing.parser.dialect.mysql.statement.ShowDatabasesStatement) StandardRoutingEngine(io.shardingjdbc.core.routing.type.standard.StandardRoutingEngine) TableBroadcastRoutingEngine(io.shardingjdbc.core.routing.type.broadcast.TableBroadcastRoutingEngine) SelectStatement(io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement) UnicastRoutingEngine(io.shardingjdbc.core.routing.type.unicast.UnicastRoutingEngine) UseStatement(io.shardingjdbc.core.parsing.parser.dialect.mysql.statement.UseStatement) ComplexRoutingEngine(io.shardingjdbc.core.routing.type.complex.ComplexRoutingEngine) DatabaseBroadcastRoutingEngine(io.shardingjdbc.core.routing.type.broadcast.DatabaseBroadcastRoutingEngine) RoutingEngine(io.shardingjdbc.core.routing.type.RoutingEngine) IgnoreRoutingEngine(io.shardingjdbc.core.routing.type.ignore.IgnoreRoutingEngine) UnicastRoutingEngine(io.shardingjdbc.core.routing.type.unicast.UnicastRoutingEngine) StandardRoutingEngine(io.shardingjdbc.core.routing.type.standard.StandardRoutingEngine) TableBroadcastRoutingEngine(io.shardingjdbc.core.routing.type.broadcast.TableBroadcastRoutingEngine) ShowTablesStatement(io.shardingjdbc.core.parsing.parser.dialect.mysql.statement.ShowTablesStatement) DALStatement(io.shardingjdbc.core.parsing.parser.sql.dal.DALStatement)

Example 2 with DALStatement

use of io.shardingjdbc.core.parsing.parser.sql.dal.DALStatement 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 3 with DALStatement

use of io.shardingjdbc.core.parsing.parser.sql.dal.DALStatement in project sharding-jdbc by shardingjdbc.

the class DALMergeEngineTest method assertMergeForShowOtherStatement.

@Test
public void assertMergeForShowOtherStatement() throws SQLException {
    DALStatement dalStatement = new ShowOtherStatement();
    DALMergeEngine dalMergeEngine = new DALMergeEngine(null, queryResults, dalStatement);
    assertThat(dalMergeEngine.merge(), instanceOf(ShowOtherMergedResult.class));
}
Also used : ShowOtherStatement(io.shardingjdbc.core.parsing.parser.dialect.mysql.statement.ShowOtherStatement) DALStatement(io.shardingjdbc.core.parsing.parser.sql.dal.DALStatement) ShowOtherMergedResult(io.shardingjdbc.core.merger.dal.show.ShowOtherMergedResult) Test(org.junit.Test)

Example 4 with DALStatement

use of io.shardingjdbc.core.parsing.parser.sql.dal.DALStatement in project sharding-jdbc by shardingjdbc.

the class DALMergeEngineTest method assertMergeForShowDatabasesStatement.

@Test
public void assertMergeForShowDatabasesStatement() throws SQLException {
    DALStatement dalStatement = new ShowDatabasesStatement();
    DALMergeEngine dalMergeEngine = new DALMergeEngine(null, queryResults, dalStatement);
    assertThat(dalMergeEngine.merge(), instanceOf(ShowDatabasesMergedResult.class));
}
Also used : ShowDatabasesStatement(io.shardingjdbc.core.parsing.parser.dialect.mysql.statement.ShowDatabasesStatement) DALStatement(io.shardingjdbc.core.parsing.parser.sql.dal.DALStatement) ShowDatabasesMergedResult(io.shardingjdbc.core.merger.dal.show.ShowDatabasesMergedResult) Test(org.junit.Test)

Example 5 with DALStatement

use of io.shardingjdbc.core.parsing.parser.sql.dal.DALStatement in project sharding-jdbc by shardingjdbc.

the class MergeEngineFactoryTest method assertNewInstanceWithDALStatement.

@Test
public void assertNewInstanceWithDALStatement() throws SQLException {
    SQLStatement dalStatement = new DALStatement();
    assertThat(MergeEngineFactory.newInstance(null, queryResults, dalStatement), instanceOf(DALMergeEngine.class));
}
Also used : DALStatement(io.shardingjdbc.core.parsing.parser.sql.dal.DALStatement) DALMergeEngine(io.shardingjdbc.core.merger.dal.DALMergeEngine) SQLStatement(io.shardingjdbc.core.parsing.parser.sql.SQLStatement) Test(org.junit.Test)

Aggregations

DALStatement (io.shardingjdbc.core.parsing.parser.sql.dal.DALStatement)9 Test (org.junit.Test)5 ShowDatabasesStatement (io.shardingjdbc.core.parsing.parser.dialect.mysql.statement.ShowDatabasesStatement)3 ShowTablesStatement (io.shardingjdbc.core.parsing.parser.dialect.mysql.statement.ShowTablesStatement)3 SelectStatement (io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement)3 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 ShowCreateTableStatement (io.shardingjdbc.core.parsing.parser.dialect.mysql.statement.ShowCreateTableStatement)2 ShowOtherStatement (io.shardingjdbc.core.parsing.parser.dialect.mysql.statement.ShowOtherStatement)2 DQLStatement (io.shardingjdbc.core.parsing.parser.sql.dql.DQLStatement)2 ResultSet (java.sql.ResultSet)2 ArrayList (java.util.ArrayList)2 DALMergeEngine (io.shardingjdbc.core.merger.dal.DALMergeEngine)1 ShowCreateTableMergedResult (io.shardingjdbc.core.merger.dal.show.ShowCreateTableMergedResult)1 ShowDatabasesMergedResult (io.shardingjdbc.core.merger.dal.show.ShowDatabasesMergedResult)1 ShowOtherMergedResult (io.shardingjdbc.core.merger.dal.show.ShowOtherMergedResult)1 ShowTablesMergedResult (io.shardingjdbc.core.merger.dal.show.ShowTablesMergedResult)1