Search in sources :

Example 1 with MetacatRenameTablePostEvent

use of com.netflix.metacat.common.server.events.MetacatRenameTablePostEvent in project metacat by Netflix.

the class TableServiceImpl method rename.

@Override
public void rename(@Nonnull final QualifiedName oldName, @Nonnull final QualifiedName newName, final boolean isMView) {
    validate(oldName);
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    final ConnectorTableService service = connectorManager.getTableService(oldName.getCatalogName());
    final TableDto oldTable = get(oldName, true).orElseThrow(() -> new TableNotFoundException(oldName));
    if (oldTable != null) {
        //Ignore if the operation is not supported, so that we can at least go ahead and save the user metadata
        eventBus.postSync(new MetacatRenameTablePreEvent(oldName, metacatRequestContext, this, newName));
        try {
            log.info("Renaming {} {} to {}", isMView ? "view" : "table", oldName, newName);
            final ConnectorContext connectorContext = converterUtil.toConnectorContext(metacatRequestContext);
            service.rename(connectorContext, oldName, newName);
        } catch (UnsupportedOperationException ignored) {
        }
        userMetadataService.renameDefinitionMetadataKey(oldName, newName);
        tagService.rename(oldName, newName.getTableName());
        final TableDto dto = get(newName, true).orElseThrow(() -> new IllegalStateException("should exist"));
        eventBus.postAsync(new MetacatRenameTablePostEvent(oldName, metacatRequestContext, this, oldTable, dto));
    }
}
Also used : TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) ConnectorTableService(com.netflix.metacat.common.server.connectors.ConnectorTableService) MetacatRenameTablePreEvent(com.netflix.metacat.common.server.events.MetacatRenameTablePreEvent) ConnectorContext(com.netflix.metacat.common.server.connectors.ConnectorContext) TableDto(com.netflix.metacat.common.dto.TableDto) MetacatRenameTablePostEvent(com.netflix.metacat.common.server.events.MetacatRenameTablePostEvent)

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 TableNotFoundException (com.netflix.metacat.common.server.connectors.exception.TableNotFoundException)1 MetacatRenameTablePostEvent (com.netflix.metacat.common.server.events.MetacatRenameTablePostEvent)1 MetacatRenameTablePreEvent (com.netflix.metacat.common.server.events.MetacatRenameTablePreEvent)1