use of com.netflix.metacat.common.server.events.MetacatDeleteTablePreEvent in project metacat by Netflix.
the class TableServiceImpl method deleteAndReturn.
@Override
public TableDto deleteAndReturn(@Nonnull final QualifiedName name, final boolean isMView) {
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
eventBus.postSync(new MetacatDeleteTablePreEvent(name, metacatRequestContext, this));
validate(name);
final ConnectorTableService service = connectorManager.getTableService(name.getCatalogName());
final Optional<TableDto> oTable = get(name, true);
if (oTable.isPresent()) {
log.info("Drop table {}", name);
final ConnectorContext connectorContext = converterUtil.toConnectorContext(metacatRequestContext);
service.delete(connectorContext, name);
}
final TableDto tableDto = oTable.orElseGet(() -> {
// If the table doesn't exist construct a blank copy we can use to delete the definitionMetadata and tags
final TableDto t = new TableDto();
t.setName(name);
return t;
});
// Delete the metadata. Type doesn't matter since we discard the result
log.info("Deleting user metadata for table {}", name);
userMetadataService.deleteMetadatas(metacatRequestContext.getUserName(), Lists.newArrayList(tableDto));
log.info("Deleting tags for table {}", name);
tagService.delete(name, false);
eventBus.postAsync(new MetacatDeleteTablePostEvent(name, metacatRequestContext, this, tableDto));
return tableDto;
}
Aggregations