Search in sources :

Example 1 with DDLStatement

use of io.shardingjdbc.core.parsing.parser.sql.ddl.DDLStatement 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 DDLStatement

use of io.shardingjdbc.core.parsing.parser.sql.ddl.DDLStatement in project sharding-jdbc by shardingjdbc.

the class AbstractCreateParser method parse.

@Override
public DDLStatement parse() {
    lexerEngine.nextToken();
    lexerEngine.skipAll(getSkippedKeywordsBetweenCreateIndexAndKeyword());
    lexerEngine.skipAll(getSkippedKeywordsBetweenCreateAndKeyword());
    DDLStatement result = new DDLStatement();
    if (lexerEngine.skipIfEqual(DefaultKeyword.INDEX)) {
        lexerEngine.skipAll(getSkippedKeywordsBetweenCreateIndexAndIndexName());
        parseIndex(result);
    } else if (lexerEngine.skipIfEqual(DefaultKeyword.TABLE)) {
        lexerEngine.skipAll(getSkippedKeywordsBetweenCreateTableAndTableName());
    } else {
        throw new SQLParsingException("Can't support other CREATE grammar unless CREATE TABLE, CREATE INDEX.");
    }
    tableReferencesClauseParser.parseSingleTableWithoutAlias(result);
    return result;
}
Also used : SQLParsingException(io.shardingjdbc.core.parsing.parser.exception.SQLParsingException) DDLStatement(io.shardingjdbc.core.parsing.parser.sql.ddl.DDLStatement)

Example 3 with DDLStatement

use of io.shardingjdbc.core.parsing.parser.sql.ddl.DDLStatement in project sharding-jdbc by shardingjdbc.

the class AbstractDropParser method parse.

@Override
public DDLStatement parse() {
    lexerEngine.nextToken();
    lexerEngine.skipAll(getSkippedKeywordsBetweenDropAndTable());
    DDLStatement result = new DDLStatement();
    if (lexerEngine.skipIfEqual(DefaultKeyword.INDEX)) {
        lexerEngine.skipAll(getSkippedKeywordsBetweenDropIndexAndIndexName());
        parseIndex(result);
    } else if (lexerEngine.skipIfEqual(DefaultKeyword.TABLE)) {
        lexerEngine.skipAll(getSkippedKeywordsBetweenDropTableAndTableName());
        tableReferencesClauseParser.parseSingleTableWithoutAlias(result);
    } else {
        throw new SQLParsingException("Can't support other DROP grammar unless DROP TABLE, DROP INDEX.");
    }
    return result;
}
Also used : SQLParsingException(io.shardingjdbc.core.parsing.parser.exception.SQLParsingException) DDLStatement(io.shardingjdbc.core.parsing.parser.sql.ddl.DDLStatement)

Example 4 with DDLStatement

use of io.shardingjdbc.core.parsing.parser.sql.ddl.DDLStatement in project sharding-jdbc by shardingjdbc.

the class AbstractTruncateParser method parse.

@Override
public DDLStatement parse() {
    lexerEngine.nextToken();
    lexerEngine.skipIfEqual(DefaultKeyword.TABLE);
    lexerEngine.skipAll(getSkippedKeywordsBetweenTruncateTableAndTableName());
    DDLStatement result = new DDLStatement();
    tableReferencesClauseParser.parseSingleTableWithoutAlias(result);
    return result;
}
Also used : DDLStatement(io.shardingjdbc.core.parsing.parser.sql.ddl.DDLStatement)

Example 5 with DDLStatement

use of io.shardingjdbc.core.parsing.parser.sql.ddl.DDLStatement in project sharding-jdbc by shardingjdbc.

the class AbstractAlterParser method parse.

@Override
public DDLStatement parse() {
    lexerEngine.nextToken();
    lexerEngine.unsupportedIfNotSkip(DefaultKeyword.TABLE);
    lexerEngine.skipAll(getSkippedKeywordsBetweenAlterTableAndTableName());
    DDLStatement result = new DDLStatement();
    tableReferencesClauseParser.parseSingleTableWithoutAlias(result);
    return result;
}
Also used : DDLStatement(io.shardingjdbc.core.parsing.parser.sql.ddl.DDLStatement)

Aggregations

DDLStatement (io.shardingjdbc.core.parsing.parser.sql.ddl.DDLStatement)5 SQLParsingException (io.shardingjdbc.core.parsing.parser.exception.SQLParsingException)2 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 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