Search in sources :

Example 1 with ShowTablesStatement

use of io.shardingjdbc.core.parsing.parser.dialect.mysql.statement.ShowTablesStatement 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 ShowTablesStatement

use of io.shardingjdbc.core.parsing.parser.dialect.mysql.statement.ShowTablesStatement in project sharding-jdbc by shardingjdbc.

the class DALMergeEngineTest method assertMergeForShowShowTablesStatement.

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

Example 3 with ShowTablesStatement

use of io.shardingjdbc.core.parsing.parser.dialect.mysql.statement.ShowTablesStatement in project sharding-jdbc by shardingjdbc.

the class MySQLShowParser method parse.

@Override
public DALStatement parse() {
    lexerEngine.nextToken();
    lexerEngine.skipIfEqual(DefaultKeyword.FULL);
    if (lexerEngine.equalAny(MySQLKeyword.DATABASES)) {
        return new ShowDatabasesStatement();
    }
    if (lexerEngine.skipIfEqual(MySQLKeyword.TABLES)) {
        DALStatement result = new ShowTablesStatement();
        if (lexerEngine.equalAny(DefaultKeyword.FROM, DefaultKeyword.IN)) {
            int beginPosition = lexerEngine.getCurrentToken().getEndPosition() - lexerEngine.getCurrentToken().getLiterals().length();
            lexerEngine.nextToken();
            lexerEngine.nextToken();
            result.getSqlTokens().add(new RemoveToken(beginPosition, lexerEngine.getCurrentToken().getEndPosition()));
        }
        return result;
    }
    if (lexerEngine.skipIfEqual(MySQLKeyword.COLUMNS, MySQLKeyword.FIELDS)) {
        DALStatement result = new ShowColumnsStatement();
        lexerEngine.skipIfEqual(DefaultKeyword.FROM, DefaultKeyword.IN);
        tableReferencesClauseParser.parseSingleTableWithoutAlias(result);
        if (lexerEngine.skipIfEqual(DefaultKeyword.FROM, DefaultKeyword.IN)) {
            int beginPosition = lexerEngine.getCurrentToken().getEndPosition() - lexerEngine.getCurrentToken().getLiterals().length();
            result.getSqlTokens().add(new SchemaToken(beginPosition, lexerEngine.getCurrentToken().getLiterals(), result.getTables().getSingleTableName()));
        }
        return result;
    }
    if (lexerEngine.skipIfEqual(DefaultKeyword.CREATE) && lexerEngine.skipIfEqual(DefaultKeyword.TABLE)) {
        DALStatement result = new ShowCreateTableStatement();
        tableReferencesClauseParser.parseSingleTableWithoutAlias(result);
        return result;
    }
    return new ShowOtherStatement();
}
Also used : ShowCreateTableStatement(io.shardingjdbc.core.parsing.parser.dialect.mysql.statement.ShowCreateTableStatement) ShowOtherStatement(io.shardingjdbc.core.parsing.parser.dialect.mysql.statement.ShowOtherStatement) ShowTablesStatement(io.shardingjdbc.core.parsing.parser.dialect.mysql.statement.ShowTablesStatement) ShowColumnsStatement(io.shardingjdbc.core.parsing.parser.dialect.mysql.statement.ShowColumnsStatement) ShowDatabasesStatement(io.shardingjdbc.core.parsing.parser.dialect.mysql.statement.ShowDatabasesStatement) DALStatement(io.shardingjdbc.core.parsing.parser.sql.dal.DALStatement) RemoveToken(io.shardingjdbc.core.parsing.parser.token.RemoveToken) SchemaToken(io.shardingjdbc.core.parsing.parser.token.SchemaToken)

Aggregations

ShowTablesStatement (io.shardingjdbc.core.parsing.parser.dialect.mysql.statement.ShowTablesStatement)3 DALStatement (io.shardingjdbc.core.parsing.parser.sql.dal.DALStatement)3 ShowDatabasesStatement (io.shardingjdbc.core.parsing.parser.dialect.mysql.statement.ShowDatabasesStatement)2 ShowTablesMergedResult (io.shardingjdbc.core.merger.dal.show.ShowTablesMergedResult)1 ShowColumnsStatement (io.shardingjdbc.core.parsing.parser.dialect.mysql.statement.ShowColumnsStatement)1 ShowCreateTableStatement (io.shardingjdbc.core.parsing.parser.dialect.mysql.statement.ShowCreateTableStatement)1 ShowOtherStatement (io.shardingjdbc.core.parsing.parser.dialect.mysql.statement.ShowOtherStatement)1 UseStatement (io.shardingjdbc.core.parsing.parser.dialect.mysql.statement.UseStatement)1 DDLStatement (io.shardingjdbc.core.parsing.parser.sql.ddl.DDLStatement)1 SelectStatement (io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement)1 RemoveToken (io.shardingjdbc.core.parsing.parser.token.RemoveToken)1 SchemaToken (io.shardingjdbc.core.parsing.parser.token.SchemaToken)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 Test (org.junit.Test)1