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