Search in sources :

Example 1 with TableBroadcastRoutingEngine

use of io.shardingjdbc.core.routing.type.broadcast.TableBroadcastRoutingEngine 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)

Aggregations

ShowDatabasesStatement (io.shardingjdbc.core.parsing.parser.dialect.mysql.statement.ShowDatabasesStatement)1 ShowTablesStatement (io.shardingjdbc.core.parsing.parser.dialect.mysql.statement.ShowTablesStatement)1 UseStatement (io.shardingjdbc.core.parsing.parser.dialect.mysql.statement.UseStatement)1 DALStatement (io.shardingjdbc.core.parsing.parser.sql.dal.DALStatement)1 DDLStatement (io.shardingjdbc.core.parsing.parser.sql.ddl.DDLStatement)1 SelectStatement (io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement)1 RoutingEngine (io.shardingjdbc.core.routing.type.RoutingEngine)1 DatabaseBroadcastRoutingEngine (io.shardingjdbc.core.routing.type.broadcast.DatabaseBroadcastRoutingEngine)1 TableBroadcastRoutingEngine (io.shardingjdbc.core.routing.type.broadcast.TableBroadcastRoutingEngine)1 ComplexRoutingEngine (io.shardingjdbc.core.routing.type.complex.ComplexRoutingEngine)1 IgnoreRoutingEngine (io.shardingjdbc.core.routing.type.ignore.IgnoreRoutingEngine)1 StandardRoutingEngine (io.shardingjdbc.core.routing.type.standard.StandardRoutingEngine)1 UnicastRoutingEngine (io.shardingjdbc.core.routing.type.unicast.UnicastRoutingEngine)1