Search in sources :

Example 1 with GeneratedKey

use of io.shardingjdbc.core.parsing.parser.context.GeneratedKey in project sharding-jdbc by shardingjdbc.

the class InsertStatement method appendGenerateKeyToken.

private void appendGenerateKeyToken(final ShardingRule shardingRule, final TableRule tableRule, final ItemsToken valuesToken) {
    if (0 == getParametersIndex()) {
        Number generatedKey = shardingRule.generateKey(tableRule.getLogicTable());
        valuesToken.getItems().add(generatedKey.toString());
        getConditions().add(new Condition(new Column(tableRule.getGenerateKeyColumn(), tableRule.getLogicTable()), new SQLNumberExpression(generatedKey)), shardingRule);
        this.generatedKey = new GeneratedKey(tableRule.getLogicTable(), -1, generatedKey);
    } else {
        valuesToken.getItems().add(Symbol.QUESTION.getLiterals());
        getConditions().add(new Condition(new Column(tableRule.getGenerateKeyColumn(), tableRule.getLogicTable()), new SQLPlaceholderExpression(getParametersIndex())), shardingRule);
        generatedKey = new GeneratedKey(tableRule.getGenerateKeyColumn(), getParametersIndex(), null);
    }
}
Also used : Condition(io.shardingjdbc.core.parsing.parser.context.condition.Condition) SQLNumberExpression(io.shardingjdbc.core.parsing.parser.expression.SQLNumberExpression) GeneratedKey(io.shardingjdbc.core.parsing.parser.context.GeneratedKey) Column(io.shardingjdbc.core.parsing.parser.context.condition.Column) SQLPlaceholderExpression(io.shardingjdbc.core.parsing.parser.expression.SQLPlaceholderExpression)

Aggregations

GeneratedKey (io.shardingjdbc.core.parsing.parser.context.GeneratedKey)1 Column (io.shardingjdbc.core.parsing.parser.context.condition.Column)1 Condition (io.shardingjdbc.core.parsing.parser.context.condition.Condition)1 SQLNumberExpression (io.shardingjdbc.core.parsing.parser.expression.SQLNumberExpression)1 SQLPlaceholderExpression (io.shardingjdbc.core.parsing.parser.expression.SQLPlaceholderExpression)1