@Subscribe public void metacatCreateDatabasePostEventHandler(MetacatCreateDatabasePostEvent event) { DatabaseDto dto = event.getDto(); ElasticSearchDoc doc = new ElasticSearchDoc( dto.getName().toString(), dto, event.getMetacatContext().getUserName(), false); es.save(database.name(), doc.getId(), doc.toJsonString()); }
@Override public void create(QualifiedName name, DatabaseDto dto) { Session session = validateAndGetSession(name); log.info("Creating schema {}", name); metadataManager.createSchema(session, new ConnectorSchemaMetadata(name.getDatabaseName())); if (dto != null && dto.getDefinitionMetadata() != null) { log.info("Saving user metadata for schema {}", name); userMetadataService.saveDefinitionMetadata( name, session.getUser(), Optional.of(dto.getDefinitionMetadata()), true); } }
@Override public void update(QualifiedName name, DatabaseDto dto) { Session session = validateAndGetSession(name); log.info("Updating schema {}", name); try { metadataManager.updateSchema(session, new ConnectorSchemaMetadata(name.getDatabaseName())); } catch (PrestoException e) { if (e.getErrorCode() != StandardErrorCode.NOT_SUPPORTED.toErrorCode()) { throw e; } } if (dto != null && dto.getDefinitionMetadata() != null) { log.info("Saving user metadata for schema {}", name); userMetadataService.saveDefinitionMetadata( name, session.getUser(), Optional.of(dto.getDefinitionMetadata()), true); } }
@Override public DatabaseDto get(QualifiedName name, boolean includeUserMetadata) { Session session = validateAndGetSession(name); MetacatCatalogConfig config = metacatConnectorManager.getCatalogConfig(name.getCatalogName()); QualifiedTablePrefix spec = new QualifiedTablePrefix(name.getCatalogName(), name.getDatabaseName()); List<QualifiedTableName> tableNames = metadataManager.listTables(session, spec); List<QualifiedTableName> viewNames = Collections.emptyList(); if (config.isIncludeViewsWithTables()) { // TODO JdbcMetadata returns ImmutableList.of() for views. We should change it to fetch // views. viewNames = metadataManager.listViews(session, spec); } // Check to see if schema exists if (tableNames.isEmpty() && viewNames.isEmpty()) { if (!exists(name)) { throw new SchemaNotFoundException(name.getDatabaseName()); } } ConnectorSchemaMetadata schema = metadataManager.getSchema(session); DatabaseDto dto = new DatabaseDto(); dto.setType(metacatConnectorManager.getCatalogConfig(name).getType()); dto.setName(name); dto.setUri(schema.getUri()); dto.setMetadata(schema.getMetadata()); dto.setTables( Stream.concat(tableNames.stream(), viewNames.stream()) .map(QualifiedTableName::getTableName) .sorted(String.CASE_INSENSITIVE_ORDER) .collect(Collectors.toList())); if (includeUserMetadata) { log.info("Populate user metadata for schema {}", name); userMetadataService.populateMetadata(dto); } return dto; }
@Subscribe public void metacatDeleteDatabasePostEventHandler(MetacatDeleteDatabasePostEvent event) { DatabaseDto dto = event.getDto(); es.softDelete(database.name(), dto.getName().toString(), event.getMetacatContext()); }