Search in sources :

Example 6 with SQLStatement

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

the class SQLParsingEngine method parse.

/**
 * Parse SQL.
 *
 * @return parsed SQL statement
 */
public SQLStatement parse() {
    SQLStatement cachedSQLStatement = ParsingResultCache.getInstance().getSQLStatement(sql);
    if (null != cachedSQLStatement) {
        return cachedSQLStatement;
    }
    LexerEngine lexerEngine = LexerEngineFactory.newInstance(dbType, sql);
    lexerEngine.nextToken();
    return SQLParserFactory.newInstance(dbType, lexerEngine.getCurrentToken().getType(), shardingRule, lexerEngine).parse();
}
Also used : LexerEngine(io.shardingjdbc.core.parsing.lexer.LexerEngine) SQLStatement(io.shardingjdbc.core.parsing.parser.sql.SQLStatement)

Example 7 with SQLStatement

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

the class MergeEngineFactoryTest method assertNewInstanceWithDALStatement.

@Test
public void assertNewInstanceWithDALStatement() throws SQLException {
    SQLStatement dalStatement = new DALStatement();
    assertThat(MergeEngineFactory.newInstance(null, queryResults, dalStatement), instanceOf(DALMergeEngine.class));
}
Also used : DALStatement(io.shardingjdbc.core.parsing.parser.sql.dal.DALStatement) DALMergeEngine(io.shardingjdbc.core.merger.dal.DALMergeEngine) SQLStatement(io.shardingjdbc.core.parsing.parser.sql.SQLStatement) Test(org.junit.Test)

Example 8 with SQLStatement

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

the class MergeEngineFactoryTest method assertNewInstanceWithSelectStatement.

@Test
public void assertNewInstanceWithSelectStatement() throws SQLException {
    SQLStatement selectStatement = new SelectStatement();
    assertThat(MergeEngineFactory.newInstance(null, queryResults, selectStatement), instanceOf(DQLMergeEngine.class));
}
Also used : SelectStatement(io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement) DQLMergeEngine(io.shardingjdbc.core.merger.dql.DQLMergeEngine) SQLStatement(io.shardingjdbc.core.parsing.parser.sql.SQLStatement) Test(org.junit.Test)

Example 9 with SQLStatement

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

the class MasterSlaveStatement method execute.

@Override
public boolean execute(final String sql, final String[] columnNames) throws SQLException {
    boolean result = false;
    SQLStatement sqlStatement = new SQLJudgeEngine(sql).judge();
    for (Connection each : connection.getConnections(sqlStatement.getType())) {
        Statement statement = each.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability);
        routedStatements.add(statement);
        result = statement.execute(sql, columnNames);
    }
    return result;
}
Also used : SQLJudgeEngine(io.shardingjdbc.core.parsing.SQLJudgeEngine) Statement(java.sql.Statement) SQLStatement(io.shardingjdbc.core.parsing.parser.sql.SQLStatement) Connection(java.sql.Connection) MasterSlaveConnection(io.shardingjdbc.core.jdbc.core.connection.MasterSlaveConnection) SQLStatement(io.shardingjdbc.core.parsing.parser.sql.SQLStatement)

Example 10 with SQLStatement

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

the class MasterSlaveStatement method execute.

@Override
public boolean execute(final String sql) throws SQLException {
    boolean result = false;
    SQLStatement sqlStatement = new SQLJudgeEngine(sql).judge();
    for (Connection each : connection.getConnections(sqlStatement.getType())) {
        Statement statement = each.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability);
        routedStatements.add(statement);
        result = statement.execute(sql);
    }
    return result;
}
Also used : SQLJudgeEngine(io.shardingjdbc.core.parsing.SQLJudgeEngine) Statement(java.sql.Statement) SQLStatement(io.shardingjdbc.core.parsing.parser.sql.SQLStatement) Connection(java.sql.Connection) MasterSlaveConnection(io.shardingjdbc.core.jdbc.core.connection.MasterSlaveConnection) SQLStatement(io.shardingjdbc.core.parsing.parser.sql.SQLStatement)

Aggregations

SQLStatement (io.shardingjdbc.core.parsing.parser.sql.SQLStatement)16 Connection (java.sql.Connection)10 Statement (java.sql.Statement)10 MasterSlaveConnection (io.shardingjdbc.core.jdbc.core.connection.MasterSlaveConnection)9 SQLJudgeEngine (io.shardingjdbc.core.parsing.SQLJudgeEngine)9 InsertStatement (io.shardingjdbc.core.parsing.parser.sql.dml.insert.InsertStatement)3 Test (org.junit.Test)3 SQLParsingEngine (io.shardingjdbc.core.parsing.SQLParsingEngine)2 DatabaseProtocolPacket (io.shardingjdbc.proxy.transport.common.packet.DatabaseProtocolPacket)2 DALMergeEngine (io.shardingjdbc.core.merger.dal.DALMergeEngine)1 DQLMergeEngine (io.shardingjdbc.core.merger.dql.DQLMergeEngine)1 LexerEngine (io.shardingjdbc.core.parsing.lexer.LexerEngine)1 DALStatement (io.shardingjdbc.core.parsing.parser.sql.dal.DALStatement)1 SelectStatement (io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement)1 ColumnDefinition41Packet (io.shardingjdbc.proxy.transport.mysql.packet.command.text.query.ColumnDefinition41Packet)1 EofPacket (io.shardingjdbc.proxy.transport.mysql.packet.generic.EofPacket)1 ErrPacket (io.shardingjdbc.proxy.transport.mysql.packet.generic.ErrPacket)1 OKPacket (io.shardingjdbc.proxy.transport.mysql.packet.generic.OKPacket)1 SQLException (java.sql.SQLException)1 LinkedList (java.util.LinkedList)1