/** * The type converter factory to use. * * @param config The system configuration * @return The type converter factory */ @Bean public TypeConverterFactory typeConverterFactory(final Config config) { return new TypeConverterFactory(config); }
/** * Converter utility bean. * * @param dozerTypeConverter The Dozer type converter to use. * @return The converter util instance */ @Bean public ConverterUtil converterUtil(final DozerTypeConverter dozerTypeConverter) { return new ConverterUtil(dozerTypeConverter); }
/** * The dozer type converter to use. * * @param typeConverterFactory The type converter factory to use * @return type converter */ @Bean public DozerTypeConverter dozerTypeConverter(final TypeConverterFactory typeConverterFactory) { return new DozerTypeConverter(typeConverterFactory); }
/** * {@inheritDoc} */ @Override public String convertTo(final Type source, final String destination) { final ConnectorTypeConverter typeConverter; try { typeConverter = this.typeConverterFactory.get(MetacatContextManager.getContext().getDataTypeContext()); } catch (final Exception e) { throw new IllegalStateException("Unable to get a type converter", e); } return typeConverter.fromMetacatType(source); }
@Override protected void configure() { mapping(FieldDto.class, FieldInfo.class) .fields("type", "type", FieldsMappingOptions.customConverterId("typeConverter")) .fields("partition_key", "partitionKey", FieldsMappingOptions.copyByReference()) .fields("source_type", "sourceType", FieldsMappingOptions.copyByReference()); mapping(TableDto.class, TableInfo.class) .fields("name", "name", FieldsMappingOptions.copyByReference()); mapping(DatabaseDto.class, DatabaseInfo.class) .fields("name", "name", FieldsMappingOptions.copyByReference()); mapping(PartitionDto.class, PartitionInfo.class) .fields("name", "name", FieldsMappingOptions.copyByReference()); mapping(AuditDto.class, AuditInfo.class); mapping(ViewDto.class, ViewInfo.class); mapping(StorageDto.class, StorageInfo.class); } };
/** * Returns the right type converter based on the context. * * @param context context * @return type converter */ public ConnectorTypeConverter get(@Nullable final String context) { if (context == null) { return this.getDefaultConverter(); } final ConnectorTypeConverter result = this.registry.get(context); if (result == null) { throw new IllegalArgumentException("No handler for " + context); } return result; }
/** * Calls the connector table service create method. * @param name table name * @param tableInfo table object */ public void create(final QualifiedName name, final TableInfo tableInfo) { final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext(); final ConnectorTableService service = connectorManager.getTableService(name); final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext); service.create(connectorRequestContext, tableInfo); }
/** * Installs the plugins. * * @param connectorPlugin service plugin */ private void installPlugin(final ConnectorPlugin connectorPlugin) { this.connectorManager.addPlugin(connectorPlugin); this.typeConverterFactory.register(connectorPlugin.getType(), connectorPlugin.getTypeConverter()); } }
private TableInfo getTableInfo(final QualifiedName name) { return converterUtil.fromTableDto(this.tableService.get(name, GetTableServiceParameters.builder().includeInfo(true) .useCache(true).build()).orElseThrow(() -> new TableNotFoundException(name) )); } }
/** * {@inheritDoc} */ @Override public Type convertFrom(final String source, final Type destination) { final ConnectorTypeConverter typeConverter; try { typeConverter = this.typeConverterFactory.get(MetacatContextManager.getContext().getDataTypeContext()); } catch (final Exception e) { throw new IllegalStateException("Unable to get a type converter", e); } return typeConverter.toMetacatType(source); } }
@Override protected void configure() { mapping(FieldDto.class, FieldInfo.class) .fields("type", "type", FieldsMappingOptions.customConverterId("typeConverter")) .fields("partition_key", "partitionKey", FieldsMappingOptions.copyByReference()) .fields("source_type", "sourceType", FieldsMappingOptions.copyByReference()); mapping(TableDto.class, TableInfo.class) .fields("name", "name", FieldsMappingOptions.copyByReference()); mapping(DatabaseDto.class, DatabaseInfo.class) .fields("name", "name", FieldsMappingOptions.copyByReference()); mapping(PartitionDto.class, PartitionInfo.class) .fields("name", "name", FieldsMappingOptions.copyByReference()); mapping(AuditDto.class, AuditInfo.class); mapping(ViewDto.class, ViewInfo.class); mapping(StorageDto.class, StorageInfo.class); } };
/** * Returns the right type converter based on the context. * * @param context context * @return type converter */ public ConnectorTypeConverter get(@Nullable final String context) { if (context == null) { return this.getDefaultConverter(); } final ConnectorTypeConverter result = this.registry.get(context); if (result == null) { throw new IllegalArgumentException("No handler for " + context); } return result; }
/** * Calls the connector table service exists method. * @param name table name * @return true, if the object exists. */ public boolean exists(final QualifiedName name) { final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext(); final ConnectorTableService service = connectorManager.getTableService(name); final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext); return service.exists(connectorRequestContext, name); } }
/** * {@inheritDoc} */ @Override public String convertTo(final Type source, final String destination) { final ConnectorTypeConverter typeConverter; try { typeConverter = this.typeConverterFactory.get(MetacatContextManager.getContext().getDataTypeContext()); } catch (final Exception e) { throw new IllegalStateException("Unable to get a type converter", e); } return typeConverter.fromMetacatType(source); }
/** * * Returns table if <code>useCache</code> is true and object exists in the cache. If <code>useCache</code> is false * or object does not exists in the cache, it is retrieved from the store. * @param name table name * @param useCache true, if table can be retrieved from cache * @return table dto */ @Cacheable(key = "'table.' + #name", condition = "#useCache") public TableInfo get(final QualifiedName name, final boolean useCache) { final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext(); final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext); final ConnectorTableService service = connectorManager.getTableService(name); return service.get(connectorRequestContext, name); }
/** * {@inheritDoc} */ @Override public Type convertFrom(final String source, final Type destination) { final ConnectorTypeConverter typeConverter; try { typeConverter = this.typeConverterFactory.get(MetacatContextManager.getContext().getDataTypeContext()); } catch (final Exception e) { throw new IllegalStateException("Unable to get a type converter", e); } return typeConverter.toMetacatType(source); } }
/** * Calls the connector table service delete method. * @param name table name */ @CacheEvict(key = "'table.' + #name") public void delete(final QualifiedName name) { final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext(); final ConnectorTableService service = connectorManager.getTableService(name); log.info("Drop table {}", name); final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext); service.delete(connectorRequestContext, name); }
/** * Calls the connector table service rename method. * @param oldName old table name * @param newName new table name * @param isMView true, if the object is a view */ @CacheEvict(key = "'table.' + #oldName") public void rename( final QualifiedName oldName, final QualifiedName newName, final boolean isMView ) { final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext(); final ConnectorTableService service = connectorManager.getTableService(oldName); try { log.info("Renaming {} {} to {}", isMView ? "view" : "table", oldName, newName); final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext); service.rename(connectorRequestContext, oldName, newName); } catch (UnsupportedOperationException ignored) { } }
/** * Calls the connector table service update method. * @param name table name * @param tableInfo table object */ @CacheEvict(key = "'table.' + #name") public void update(final QualifiedName name, final TableInfo tableInfo) { final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext(); final ConnectorTableService service = connectorManager.getTableService(name); try { log.info("Updating table {}", name); final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext); service.update(connectorRequestContext, tableInfo); } catch (UnsupportedOperationException ignored) { //Ignore if the operation is not supported, so that we can at least go ahead and save the user metadata. log.debug("Catalog {} does not support the table update operation.", name.getCatalogName()); } }
/** * {@inheritDoc} */ @Override public Integer count(final QualifiedName name) { Integer result = 0; if (tableService.exists(name)) { final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext(); final ConnectorPartitionService service = connectorManager.getPartitionService(name); final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext); result = service.getPartitionCount(connectorRequestContext, name, this.getTableInfo(name)); } return result; }