Search in sources :

Example 6 with DALStatement

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));
}
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 7 with DALStatement

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));
}
Also used : ShowCreateTableStatement(io.shardingjdbc.core.parsing.parser.dialect.mysql.statement.ShowCreateTableStatement) DALStatement(io.shardingjdbc.core.parsing.parser.sql.dal.DALStatement) ShowCreateTableMergedResult(io.shardingjdbc.core.merger.dal.show.ShowCreateTableMergedResult) Test(org.junit.Test)

Example 8 with DALStatement

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;
}
Also used : SelectStatement(io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement) QueryResult(io.shardingjdbc.core.merger.QueryResult) JDBCQueryResult(io.shardingjdbc.core.merger.JDBCQueryResult) MergeEngine(io.shardingjdbc.core.merger.MergeEngine) DQLStatement(io.shardingjdbc.core.parsing.parser.sql.dql.DQLStatement) ShardingResultSet(io.shardingjdbc.core.jdbc.core.resultset.ShardingResultSet) ResultSet(java.sql.ResultSet) GeneratedKeysResultSet(io.shardingjdbc.core.jdbc.core.resultset.GeneratedKeysResultSet) ShardingResultSet(io.shardingjdbc.core.jdbc.core.resultset.ShardingResultSet) ArrayList(java.util.ArrayList) DALStatement(io.shardingjdbc.core.parsing.parser.sql.dal.DALStatement) JDBCQueryResult(io.shardingjdbc.core.merger.JDBCQueryResult) PreparedStatement(java.sql.PreparedStatement)

Example 9 with DALStatement

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

DALStatement (io.shardingjdbc.core.parsing.parser.sql.dal.DALStatement)9 Test (org.junit.Test)5 ShowDatabasesStatement (io.shardingjdbc.core.parsing.parser.dialect.mysql.statement.ShowDatabasesStatement)3 ShowTablesStatement (io.shardingjdbc.core.parsing.parser.dialect.mysql.statement.ShowTablesStatement)3 SelectStatement (io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement)3 GeneratedKeysResultSet (io.shardingjdbc.core.jdbc.core.resultset.GeneratedKeysResultSet)2 ShardingResultSet (io.shardingjdbc.core.jdbc.core.resultset.ShardingResultSet)2 JDBCQueryResult (io.shardingjdbc.core.merger.JDBCQueryResult)2 MergeEngine (io.shardingjdbc.core.merger.MergeEngine)2 QueryResult (io.shardingjdbc.core.merger.QueryResult)2 ShowCreateTableStatement (io.shardingjdbc.core.parsing.parser.dialect.mysql.statement.ShowCreateTableStatement)2 ShowOtherStatement (io.shardingjdbc.core.parsing.parser.dialect.mysql.statement.ShowOtherStatement)2 DQLStatement (io.shardingjdbc.core.parsing.parser.sql.dql.DQLStatement)2 ResultSet (java.sql.ResultSet)2 ArrayList (java.util.ArrayList)2 DALMergeEngine (io.shardingjdbc.core.merger.dal.DALMergeEngine)1 ShowCreateTableMergedResult (io.shardingjdbc.core.merger.dal.show.ShowCreateTableMergedResult)1 ShowDatabasesMergedResult (io.shardingjdbc.core.merger.dal.show.ShowDatabasesMergedResult)1 ShowOtherMergedResult (io.shardingjdbc.core.merger.dal.show.ShowOtherMergedResult)1 ShowTablesMergedResult (io.shardingjdbc.core.merger.dal.show.ShowTablesMergedResult)1