Commit fd619a6a authored by terrymanu's avatar terrymanu
Browse files

SQLJudgeEngine Lexer => LexerEngine

parent 555769ea
Loading
Loading
Loading
Loading
+7 −6
Original line number Diff line number Diff line
@@ -17,8 +17,9 @@

package io.shardingjdbc.core.parsing;

import io.shardingjdbc.core.parsing.lexer.Lexer;
import io.shardingjdbc.core.parsing.lexer.analyzer.Dictionary;
import io.shardingjdbc.core.constant.DatabaseType;
import io.shardingjdbc.core.parsing.lexer.LexerEngine;
import io.shardingjdbc.core.parsing.lexer.LexerEngineFactory;
import io.shardingjdbc.core.parsing.lexer.dialect.mysql.MySQLKeyword;
import io.shardingjdbc.core.parsing.lexer.token.Assist;
import io.shardingjdbc.core.parsing.lexer.token.DefaultKeyword;
@@ -50,10 +51,10 @@ public final class SQLJudgeEngine {
     * @return SQL statement
     */
    public SQLStatement judge() {
        Lexer lexer = new Lexer(sql, new Dictionary());
        lexer.nextToken();
        LexerEngine lexerEngine = LexerEngineFactory.newInstance(DatabaseType.MySQL, sql);
        lexerEngine.nextToken();
        while (true) {
            TokenType tokenType = lexer.getCurrentToken().getType();
            TokenType tokenType = lexerEngine.getCurrentToken().getType();
            if (tokenType instanceof Keyword) {
                if (DefaultKeyword.SELECT == tokenType) {
                    return new SelectStatement();
@@ -75,7 +76,7 @@ public final class SQLJudgeEngine {
            if (tokenType instanceof Assist && Assist.END == tokenType) {
                throw new SQLParsingException("Unsupported SQL statement: [%s]", sql);
            }
            lexer.nextToken();
            lexerEngine.nextToken();
        }
    }
}
+14 −2
Original line number Diff line number Diff line
package io.shardingjdbc.server.packet.command;

import io.shardingjdbc.core.constant.SQLType;
import io.shardingjdbc.core.exception.ShardingJdbcException;
import io.shardingjdbc.core.parsing.SQLJudgeEngine;
import io.shardingjdbc.core.parsing.parser.sql.SQLStatement;
import io.shardingjdbc.server.DataSourceManager;
import io.shardingjdbc.server.constant.ColumnType;
import io.shardingjdbc.server.constant.StatusFlag;
@@ -40,8 +43,17 @@ public final class ComQueryPacket extends AbstractCommandPacket {
        try (
                Connection conn = DataSourceManager.getInstance().getDataSource().getConnection();
                Statement statement = conn.createStatement()) {
            SQLStatement sqlStatement = new SQLJudgeEngine(sql).judge();
            ResultSet resultSet;
            if (SQLType.DQL == sqlStatement.getType()) {
                resultSet = statement.executeQuery(sql);
            } else if (SQLType.DML == sqlStatement.getType() || SQLType.DDL == sqlStatement.getType()) {
                statement.executeUpdate(sql);
                resultSet = statement.getResultSet();
            } else {
                statement.execute(sql);
            ResultSet resultSet = statement.getResultSet();
                resultSet = statement.getResultSet();
            }
            if (null == resultSet) {
                result.add(new OKPacket(++currentSequenceId, 0, 0, StatusFlag.SERVER_STATUS_AUTOCOMMIT.getValue(), 0, ""));
                return result;