DatabaseInfoRetriever extends AbstractRetriever { void retrieveServerInfo() { final MutableDatabaseInfo dbInfo = catalog.getDatabaseInfo(); if (dbInfo == null) { return; } final InformationSchemaViews informationSchemaViews = getRetrieverConnection().getInformationSchemaViews(); if (!informationSchemaViews.hasQuery(SERVER_INFORMATION)) { LOGGER.log(Level.INFO, "Not retrieving server information, since this was not requested"); LOGGER.log(Level.FINE, "Server information SQL statement was not provided"); return; } final Query serverInfoSql = informationSchemaViews.getQuery(SERVER_INFORMATION); final Connection connection = getDatabaseConnection(); try (final Statement statement = connection.createStatement(); final MetadataResultSet results = new MetadataResultSet(serverInfoSql, statement, new IncludeAll())) { results.setDescription("retrieveServerInfo"); while (results.next()) { final String propertyName = results.getString("NAME"); if (isBlank(propertyName)) { continue; } final String propertyValue = results.getString("VALUE"); final String propertyDescription = results.getString("DESCRIPTION"); LOGGER.log( Level.FINER, new StringFormat( "Retrieving server information property: %s=%s", propertyName, propertyValue)); final Property serverInfoProperty = new ImmutableServerInfoProperty(propertyName, propertyValue, propertyDescription); dbInfo.addServerInfo(serverInfoProperty); } } catch (final Exception e) { LOGGER.log(Level.WARNING, "Could not retrieve server information", e); } } DatabaseInfoRetriever(
      final RetrieverConnection retrieverConnection,
      final MutableCatalog catalog,
      final SchemaCrawlerOptions options);   }
@Test @DisplayName("Retrieve server info") public void serverInfo(final TestContext testContext, final Connection connection) throws Exception { assertThat(catalog.getDatabaseInfo().getServerInfo(), is(empty())); final String name = "TEST Server Info Property - Name"; final String description = "TEST Server Info Property - Description"; final String value = "TEST Server Info Property - Value"; final InformationSchemaViews informationSchemaViews = InformationSchemaViewsBuilder.builder() .withSql( InformationSchemaKey.SERVER_INFORMATION, String.format( "SELECT '%s' AS NAME, '%s' AS DESCRIPTION, '%s' AS VALUE " + "FROM INFORMATION_SCHEMA.SYSTEM_TYPEINFO", name, description, value)) .toOptions(); final SchemaRetrievalOptionsBuilder schemaRetrievalOptionsBuilder = SchemaRetrievalOptionsBuilder.builder().withInformationSchemaViews(informationSchemaViews); final SchemaRetrievalOptions schemaRetrievalOptions = schemaRetrievalOptionsBuilder.toOptions(); final RetrieverConnection retrieverConnection = new RetrieverConnection(connection, schemaRetrievalOptions); final SchemaCrawlerOptions options = SchemaCrawlerOptionsBuilder.newSchemaCrawlerOptions(); final DatabaseInfoRetriever databaseInfoRetriever = new DatabaseInfoRetriever(retrieverConnection, catalog, options); databaseInfoRetriever.retrieveServerInfo(); final List<Property> serverInfo = new ArrayList<>(catalog.getDatabaseInfo().getServerInfo()); assertThat(serverInfo, hasSize(1)); final Property serverInfoProperty = serverInfo.get(0); assertThat(serverInfoProperty, is(new ImmutableServerInfoProperty(name, value, description))); assertThat(serverInfoProperty.getDescription(), is(description)); }