Skip to content

Commit

Permalink
Minor refactor in InsertClauseShardingConditionEngine (apache#29304)
Browse files Browse the repository at this point in the history
  • Loading branch information
strongduanmu authored Dec 6, 2023
1 parent c99d91e commit 885c439
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,10 @@ private void appendGeneratedKeyConditions(final InsertStatementContext sqlStatem
Optional<GeneratedKeyContext> generatedKey = sqlStatementContext.getGeneratedKeyContext();
String tableName = sqlStatementContext.getSqlStatement().getTable().getTableName().getIdentifier().getValue();
if (generatedKey.isPresent() && generatedKey.get().isGenerated() && shardingRule.findTableRule(tableName).isPresent()) {
String schemaName =
sqlStatementContext.getTablesContext().getSchemaName().orElseGet(() -> new DatabaseTypeRegistry(sqlStatementContext.getDatabaseType()).getDefaultSchemaName(database.getName()));
generatedKey.get().getGeneratedValues()
.addAll(shardingRule.generateKeys(new KeyGenerateContext(database.getName(), schemaName, tableName, generatedKey.get().getColumnName()), sqlStatementContext.getValueListCount()));
String schemaName = sqlStatementContext.getTablesContext().getSchemaName()
.orElseGet(() -> new DatabaseTypeRegistry(sqlStatementContext.getDatabaseType()).getDefaultSchemaName(database.getName()));
KeyGenerateContext keyGenerateContext = new KeyGenerateContext(database.getName(), schemaName, tableName, generatedKey.get().getColumnName());
generatedKey.get().getGeneratedValues().addAll(shardingRule.generateKeys(keyGenerateContext, sqlStatementContext.getValueListCount()));
generatedKey.get().setSupportAutoIncrement(shardingRule.isSupportAutoIncrement(tableName));
if (shardingRule.findShardingColumn(generatedKey.get().getColumnName(), tableName).isPresent()) {
appendGeneratedKeyCondition(generatedKey.get(), tableName, shardingConditions);
Expand Down

0 comments on commit 885c439

Please sign in to comment.