use of io.shardingjdbc.core.parsing.parser.context.condition.Column in project sharding-jdbc by shardingjdbc.
the class InsertColumnsClauseParser method parse.
/**
* Parse insert columns.
*
* @param insertStatement insert statement
*/
public void parse(final InsertStatement insertStatement) {
Collection<Column> result = new LinkedList<>();
if (lexerEngine.equalAny(Symbol.LEFT_PAREN)) {
String tableName = insertStatement.getTables().getSingleTableName();
Optional<String> generateKeyColumn = shardingRule.getGenerateKeyColumn(tableName);
int count = 0;
do {
lexerEngine.nextToken();
String columnName = SQLUtil.getExactlyValue(lexerEngine.getCurrentToken().getLiterals());
result.add(new Column(columnName, tableName));
lexerEngine.nextToken();
if (generateKeyColumn.isPresent() && generateKeyColumn.get().equalsIgnoreCase(columnName)) {
insertStatement.setGenerateKeyColumnIndex(count);
}
count++;
} while (!lexerEngine.equalAny(Symbol.RIGHT_PAREN) && !lexerEngine.equalAny(Assist.END));
insertStatement.setColumnsListLastPosition(lexerEngine.getCurrentToken().getEndPosition() - lexerEngine.getCurrentToken().getLiterals().length());
lexerEngine.nextToken();
}
insertStatement.getColumns().addAll(result);
}
use of io.shardingjdbc.core.parsing.parser.context.condition.Column in project sharding-jdbc by shardingjdbc.
the class InsertSetClauseParser method parse.
/**
* Parse insert set.
*
* @param insertStatement insert statement
*/
public void parse(final InsertStatement insertStatement) {
if (!lexerEngine.skipIfEqual(getCustomizedInsertKeywords())) {
return;
}
do {
Column column = new Column(SQLUtil.getExactlyValue(lexerEngine.getCurrentToken().getLiterals()), insertStatement.getTables().getSingleTableName());
lexerEngine.nextToken();
lexerEngine.accept(Symbol.EQ);
SQLExpression sqlExpression;
if (lexerEngine.equalAny(Literals.INT)) {
sqlExpression = new SQLNumberExpression(Integer.parseInt(lexerEngine.getCurrentToken().getLiterals()));
} else if (lexerEngine.equalAny(Literals.FLOAT)) {
sqlExpression = new SQLNumberExpression(Double.parseDouble(lexerEngine.getCurrentToken().getLiterals()));
} else if (lexerEngine.equalAny(Literals.CHARS)) {
sqlExpression = new SQLTextExpression(lexerEngine.getCurrentToken().getLiterals());
} else if (lexerEngine.equalAny(DefaultKeyword.NULL)) {
sqlExpression = new SQLIgnoreExpression(DefaultKeyword.NULL.name());
} else if (lexerEngine.equalAny(Symbol.QUESTION)) {
sqlExpression = new SQLPlaceholderExpression(insertStatement.getParametersIndex());
insertStatement.increaseParametersIndex();
} else {
throw new UnsupportedOperationException("");
}
lexerEngine.nextToken();
if (lexerEngine.equalAny(Symbol.COMMA, DefaultKeyword.ON, Assist.END)) {
insertStatement.getConditions().add(new Condition(column, sqlExpression), shardingRule);
} else {
lexerEngine.skipUntil(Symbol.COMMA, DefaultKeyword.ON);
}
} while (lexerEngine.skipIfEqual(Symbol.COMMA));
}
use of io.shardingjdbc.core.parsing.parser.context.condition.Column in project sharding-jdbc by shardingjdbc.
the class InsertValuesClauseParser method parseValues.
private void parseValues(final InsertStatement insertStatement) {
lexerEngine.accept(Symbol.LEFT_PAREN);
List<SQLExpression> sqlExpressions = new LinkedList<>();
do {
sqlExpressions.add(basicExpressionParser.parse(insertStatement));
} while (lexerEngine.skipIfEqual(Symbol.COMMA));
insertStatement.setValuesListLastPosition(lexerEngine.getCurrentToken().getEndPosition() - lexerEngine.getCurrentToken().getLiterals().length());
int count = 0;
for (Column each : insertStatement.getColumns()) {
SQLExpression sqlExpression = sqlExpressions.get(count);
insertStatement.getConditions().add(new Condition(each, sqlExpression), shardingRule);
if (insertStatement.getGenerateKeyColumnIndex() == count) {
insertStatement.setGeneratedKey(createGeneratedKey(each, sqlExpression));
}
count++;
}
lexerEngine.accept(Symbol.RIGHT_PAREN);
}
use of io.shardingjdbc.core.parsing.parser.context.condition.Column in project sharding-jdbc by shardingjdbc.
the class WhereClauseParser method parseBetweenCondition.
private void parseBetweenCondition(final ShardingRule shardingRule, final SQLStatement sqlStatement, final SQLExpression left) {
List<SQLExpression> rights = new LinkedList<>();
rights.add(basicExpressionParser.parse(sqlStatement));
lexerEngine.accept(DefaultKeyword.AND);
rights.add(basicExpressionParser.parse(sqlStatement));
Optional<Column> column = find(sqlStatement.getTables(), left);
if (column.isPresent()) {
sqlStatement.getConditions().add(new Condition(column.get(), rights.get(0), rights.get(1)), shardingRule);
}
}
use of io.shardingjdbc.core.parsing.parser.context.condition.Column in project sharding-jdbc by shardingjdbc.
the class WhereClauseParser method parseInCondition.
private void parseInCondition(final ShardingRule shardingRule, final SQLStatement sqlStatement, final SQLExpression left) {
lexerEngine.accept(Symbol.LEFT_PAREN);
List<SQLExpression> rights = new LinkedList<>();
do {
lexerEngine.skipIfEqual(Symbol.COMMA);
rights.add(basicExpressionParser.parse(sqlStatement));
} while (!lexerEngine.equalAny(Symbol.RIGHT_PAREN));
Optional<Column> column = find(sqlStatement.getTables(), left);
if (column.isPresent()) {
sqlStatement.getConditions().add(new Condition(column.get(), rights), shardingRule);
}
lexerEngine.nextToken();
}
Aggregations