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);
}
}
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));
}
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;
}
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, ""));
}
}
Aggregations