Search in sources :

Example 1 with MetacatDeleteTablePreEvent

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;
}
Also used : MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) ConnectorTableService(com.netflix.metacat.common.server.connectors.ConnectorTableService) MetacatDeleteTablePostEvent(com.netflix.metacat.common.server.events.MetacatDeleteTablePostEvent) ConnectorContext(com.netflix.metacat.common.server.connectors.ConnectorContext) TableDto(com.netflix.metacat.common.dto.TableDto) MetacatDeleteTablePreEvent(com.netflix.metacat.common.server.events.MetacatDeleteTablePreEvent)

Aggregations

MetacatRequestContext (com.netflix.metacat.common.MetacatRequestContext)1 TableDto (com.netflix.metacat.common.dto.TableDto)1 ConnectorContext (com.netflix.metacat.common.server.connectors.ConnectorContext)1 ConnectorTableService (com.netflix.metacat.common.server.connectors.ConnectorTableService)1 MetacatDeleteTablePostEvent (com.netflix.metacat.common.server.events.MetacatDeleteTablePostEvent)1 MetacatDeleteTablePreEvent (com.netflix.metacat.common.server.events.MetacatDeleteTablePreEvent)1