use of io.shardingjdbc.core.parsing.parser.sql.dal.DALStatement 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));
}
use of io.shardingjdbc.core.parsing.parser.sql.dal.DALStatement in project sharding-jdbc by shardingjdbc.
the class DALMergeEngineTest method assertMergeForShowCreateTableStatement.
@Test
public void assertMergeForShowCreateTableStatement() throws SQLException {
DALStatement dalStatement = new ShowCreateTableStatement();
DALMergeEngine dalMergeEngine = new DALMergeEngine(null, queryResults, dalStatement);
assertThat(dalMergeEngine.merge(), instanceOf(ShowCreateTableMergedResult.class));
}
use of io.shardingjdbc.core.parsing.parser.sql.dal.DALStatement in project sharding-jdbc by shardingjdbc.
the class ShardingPreparedStatement 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 (PreparedStatement 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;
}
use of io.shardingjdbc.core.parsing.parser.sql.dal.DALStatement 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();
}
Aggregations