in metacat-metadata-mysql/src/main/java/com/netflix/metacat/metadata/mysql/MysqlUserMetadataService.java [589:650]
public void saveDefinitionMetadata(
@Nonnull final QualifiedName name,
@Nonnull final String userId,
@Nonnull final Optional<ObjectNode> metadata, final boolean merge)
throws InvalidMetadataException {
final Optional<ObjectNode> existingData =
config.isDefinitionMetadataSelectForUpdateEnabled()
? getDefinitionMetadataForUpdate(name) : getDefinitionMetadata(name);
metadataPreMergeInterceptor.onWrite(
this,
name,
existingData,
metadata
);
final int count;
if (existingData.isPresent() && metadata.isPresent()) {
ObjectNode merged = existingData.get();
if (merge) {
metacatJson.mergeIntoPrimary(merged, metadata.get());
} else {
merged = metadata.get();
}
//apply interceptor to change the object node
this.metadataInterceptor.onWrite(this, name, merged);
String query;
if (name.isPartitionDefinition()) {
throwIfPartitionDefinitionMetadataDisabled();
query = SQL.UPDATE_PARTITION_DEFINITION_METADATA;
} else {
query = SQL.UPDATE_DEFINITION_METADATA;
}
count = executeUpdateForKey(
query,
merged.toString(),
userId,
name.toString());
} else {
// apply interceptor to change the object node
if (metadata.isPresent()) {
this.metadataInterceptor.onWrite(this, name, metadata.get());
}
String queryToExecute;
if (name.isPartitionDefinition()) {
throwIfPartitionDefinitionMetadataDisabled();
queryToExecute = SQL.INSERT_PARTITION_DEFINITION_METADATA;
} else {
queryToExecute = SQL.INSERT_DEFINITION_METADATA;
}
count = metadata.map(jsonNodes -> executeUpdateForKey(
queryToExecute,
jsonNodes.toString(),
userId,
userId,
name.toString()
)).orElse(1);
}
if (count != 1) {
throw new IllegalStateException("Expected one row to be insert or update for " + name);
}
}