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();
}
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;
}
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;
}
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;
}
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;
}
Aggregations