Search in sources :

Example 1 with IndexToken

use of io.shardingjdbc.core.parsing.parser.token.IndexToken in project sharding-jdbc by shardingjdbc.

the class TableReferencesClauseParser method parseForceIndex.

private void parseForceIndex(final String tableName, final SQLStatement sqlStatement) {
    boolean skipIfForce = lexerEngine.skipIfEqual(MySQLKeyword.FORCE) && this.lexerEngine.skipIfEqual(DefaultKeyword.INDEX);
    if (skipIfForce) {
        lexerEngine.accept(Symbol.LEFT_PAREN);
        do {
            String literals = lexerEngine.getCurrentToken().getLiterals();
            if (shardingRule.isLogicIndex(literals, tableName)) {
                int beginPosition = lexerEngine.getCurrentToken().getEndPosition() - literals.length();
                sqlStatement.getSqlTokens().add(new IndexToken(beginPosition, literals, tableName));
            }
            lexerEngine.nextToken();
        } while (lexerEngine.skipIfEqual(Symbol.COMMA));
        lexerEngine.accept(Symbol.RIGHT_PAREN);
    }
}
Also used : IndexToken(io.shardingjdbc.core.parsing.parser.token.IndexToken)

Example 2 with IndexToken

use of io.shardingjdbc.core.parsing.parser.token.IndexToken in project sharding-jdbc by shardingjdbc.

the class AbstractCreateParser method parseIndex.

private void parseIndex(final DDLStatement ddlStatement) {
    Token currentToken = lexerEngine.getCurrentToken();
    int beginPosition = currentToken.getEndPosition() - currentToken.getLiterals().length();
    String literals = currentToken.getLiterals();
    lexerEngine.skipUntil(DefaultKeyword.ON);
    lexerEngine.nextToken();
    String tableName = lexerEngine.getCurrentToken().getLiterals();
    ddlStatement.getSqlTokens().add(new IndexToken(beginPosition, literals, tableName));
}
Also used : IndexToken(io.shardingjdbc.core.parsing.parser.token.IndexToken) Token(io.shardingjdbc.core.parsing.lexer.token.Token) IndexToken(io.shardingjdbc.core.parsing.parser.token.IndexToken)

Example 3 with IndexToken

use of io.shardingjdbc.core.parsing.parser.token.IndexToken in project sharding-jdbc by shardingjdbc.

the class SQLRewriteEngine method rewrite.

/**
 * rewrite SQL.
 *
 * @param isRewriteLimit is rewrite limit
 * @return SQL builder
 */
public SQLBuilder rewrite(final boolean isRewriteLimit) {
    SQLBuilder result = new SQLBuilder();
    if (sqlTokens.isEmpty()) {
        result.appendLiterals(originalSQL);
        return result;
    }
    int count = 0;
    sortByBeginPosition();
    for (SQLToken each : sqlTokens) {
        if (0 == count) {
            result.appendLiterals(originalSQL.substring(0, each.getBeginPosition()));
        }
        if (each instanceof TableToken) {
            appendTablePlaceholder(result, (TableToken) each, count, sqlTokens);
        } else if (each instanceof SchemaToken) {
            appendSchemaPlaceholder(result, (SchemaToken) each, count, sqlTokens);
        } else if (each instanceof IndexToken) {
            appendIndexPlaceholder(result, (IndexToken) each, count, sqlTokens);
        } else if (each instanceof ItemsToken) {
            appendItemsToken(result, (ItemsToken) each, count, sqlTokens);
        } else if (each instanceof RowCountToken) {
            appendLimitRowCount(result, (RowCountToken) each, count, sqlTokens, isRewriteLimit);
        } else if (each instanceof OffsetToken) {
            appendLimitOffsetToken(result, (OffsetToken) each, count, sqlTokens, isRewriteLimit);
        } else if (each instanceof OrderByToken) {
            appendOrderByToken(result, count, sqlTokens);
        }
        count++;
    }
    return result;
}
Also used : TableToken(io.shardingjdbc.core.parsing.parser.token.TableToken) SQLToken(io.shardingjdbc.core.parsing.parser.token.SQLToken) SchemaToken(io.shardingjdbc.core.parsing.parser.token.SchemaToken) IndexToken(io.shardingjdbc.core.parsing.parser.token.IndexToken) OffsetToken(io.shardingjdbc.core.parsing.parser.token.OffsetToken) ItemsToken(io.shardingjdbc.core.parsing.parser.token.ItemsToken) RowCountToken(io.shardingjdbc.core.parsing.parser.token.RowCountToken) OrderByToken(io.shardingjdbc.core.parsing.parser.token.OrderByToken)

Example 4 with IndexToken

use of io.shardingjdbc.core.parsing.parser.token.IndexToken in project sharding-jdbc by shardingjdbc.

the class AbstractDropParser method parseIndex.

private void parseIndex(final DDLStatement ddlStatement) {
    Token currentToken = lexerEngine.getCurrentToken();
    int beginPosition = currentToken.getEndPosition() - currentToken.getLiterals().length();
    String literals = currentToken.getLiterals();
    lexerEngine.skipUntil(DefaultKeyword.ON);
    if (lexerEngine.skipIfEqual(DefaultKeyword.ON)) {
        tableReferencesClauseParser.parseSingleTableWithoutAlias(ddlStatement);
        ddlStatement.getSqlTokens().add(new IndexToken(beginPosition, literals, ddlStatement.getTables().getSingleTableName()));
    } else {
        ddlStatement.getSqlTokens().add(new IndexToken(beginPosition, literals, ""));
    }
}
Also used : IndexToken(io.shardingjdbc.core.parsing.parser.token.IndexToken) Token(io.shardingjdbc.core.parsing.lexer.token.Token) IndexToken(io.shardingjdbc.core.parsing.parser.token.IndexToken)

Aggregations

IndexToken (io.shardingjdbc.core.parsing.parser.token.IndexToken)4 Token (io.shardingjdbc.core.parsing.lexer.token.Token)2 ItemsToken (io.shardingjdbc.core.parsing.parser.token.ItemsToken)1 OffsetToken (io.shardingjdbc.core.parsing.parser.token.OffsetToken)1 OrderByToken (io.shardingjdbc.core.parsing.parser.token.OrderByToken)1 RowCountToken (io.shardingjdbc.core.parsing.parser.token.RowCountToken)1 SQLToken (io.shardingjdbc.core.parsing.parser.token.SQLToken)1 SchemaToken (io.shardingjdbc.core.parsing.parser.token.SchemaToken)1 TableToken (io.shardingjdbc.core.parsing.parser.token.TableToken)1