use of io.shardingjdbc.core.parsing.parser.token.GeneratedKeyToken in project sharding-jdbc by shardingjdbc.
the class AbstractInsertParser method appendGenerateKey.
private void appendGenerateKey(final InsertStatement insertStatement) {
String tableName = insertStatement.getTables().getSingleTableName();
Optional<String> generateKeyColumn = shardingRule.getGenerateKeyColumn(tableName);
if (!generateKeyColumn.isPresent() || null != insertStatement.getGeneratedKey()) {
return;
}
ItemsToken columnsToken = new ItemsToken(insertStatement.getColumnsListLastPosition());
columnsToken.getItems().add(generateKeyColumn.get());
insertStatement.getSqlTokens().add(columnsToken);
insertStatement.getSqlTokens().add(new GeneratedKeyToken(insertStatement.getValuesListLastPosition()));
}
use of io.shardingjdbc.core.parsing.parser.token.GeneratedKeyToken in project sharding-jdbc by shardingjdbc.
the class InsertStatement method appendGenerateKeyToken.
/**
* Append generate key token.
*
* @param shardingRule databases and tables sharding rule
*/
public void appendGenerateKeyToken(final ShardingRule shardingRule) {
if (null != generatedKey) {
return;
}
Optional<TableRule> tableRule = shardingRule.tryFindTableRuleByLogicTable(getTables().getSingleTableName());
if (!tableRule.isPresent()) {
return;
}
Optional<GeneratedKeyToken> generatedKeysToken = findGeneratedKeyToken();
if (!generatedKeysToken.isPresent()) {
return;
}
ItemsToken valuesToken = new ItemsToken(generatedKeysToken.get().getBeginPosition());
appendGenerateKeyToken(shardingRule, tableRule.get(), valuesToken);
getSqlTokens().remove(generatedKeysToken.get());
getSqlTokens().add(valuesToken);
}
Aggregations