@Test @DisplayName("Retrieve primary keys from data dictionary") public void primaryKeysFromDataDictionary(final Connection connection) throws Exception { final InformationSchemaViews informationSchemaViews = InformationSchemaViewsBuilder.builder() .withSql( InformationSchemaKey.PRIMARY_KEYS, "SELECT * FROM INFORMATION_SCHEMA.SYSTEM_PRIMARYKEYS") .toOptions(); final SchemaRetrievalOptionsBuilder schemaRetrievalOptionsBuilder = SchemaRetrievalOptionsBuilder.builder(); schemaRetrievalOptionsBuilder .with(primaryKeysRetrievalStrategy, data_dictionary_all) .withInformationSchemaViews(informationSchemaViews); final SchemaRetrievalOptions schemaRetrievalOptions = schemaRetrievalOptionsBuilder.toOptions(); final RetrieverConnection retrieverConnection = new RetrieverConnection(connection, schemaRetrievalOptions); final SchemaCrawlerOptions options = SchemaCrawlerOptionsBuilder.newSchemaCrawlerOptions(); final PrimaryKeyRetriever primaryKeyRetriever = new PrimaryKeyRetriever(retrieverConnection, catalog, options); primaryKeyRetriever.retrievePrimaryKeys(catalog.getAllTables()); final Collection<Table> tables = catalog.getTables(); assertThat(tables, hasSize(19)); for (final Table table : tables) { if (!Arrays.asList( "Global Counts", "AUTHORSLIST", "BOOKAUTHORS", "PUBLICATIONWRITERS", "SALES", "SALESDATA") .contains(table.getName())) { assertThat( "Did not find primary key for " + table.getFullName(), table.getPrimaryKey(), is(not(nullValue()))); } } }
void retrievePrimaryKeys(final NamedObjectList<MutableTable> allTables) throws SQLException { requireNonNull(allTables, "No tables provided"); switch (getRetrieverConnection().get(primaryKeysRetrievalStrategy)) { case data_dictionary_all: LOGGER.log(Level.INFO, "Retrieving primary keys, using fast data dictionary retrieval"); retrievePrimaryKeysFromDataDictionary(allTables); break; case metadata: LOGGER.log(Level.INFO, "Retrieving primary keys"); retrievePrimaryKeysFromMetadata(allTables); break; default: break; } }
PrimaryKeyRetriever extends AbstractRetriever { void retrievePrimaryKeys(final NamedObjectList<MutableTable> allTables) throws SQLException { requireNonNull(allTables, "No tables provided"); switch (getRetrieverConnection().get(primaryKeysRetrievalStrategy)) { case data_dictionary_all: LOGGER.log(Level.INFO, "Retrieving primary keys, using fast data dictionary retrieval"); retrievePrimaryKeysFromDataDictionary(allTables); break; case metadata: LOGGER.log(Level.INFO, "Retrieving primary keys"); retrievePrimaryKeysFromMetadata(allTables); break; default: break; } } }
PrimaryKeyRetriever extends AbstractRetriever { void retrievePrimaryKeys(final NamedObjectList<MutableTable> allTables) throws SQLException { requireNonNull(allTables, "No tables provided"); switch (getRetrieverConnection().get(primaryKeysRetrievalStrategy)) { case data_dictionary_all: LOGGER.log(Level.INFO, "Retrieving primary keys, using fast data dictionary retrieval"); retrievePrimaryKeysFromDataDictionary(allTables); break; case metadata: LOGGER.log(Level.INFO, "Retrieving primary keys"); retrievePrimaryKeysFromMetadata(allTables); break; default: break; } } PrimaryKeyRetriever(
      final RetrieverConnection retrieverConnection,
      final MutableCatalog catalog,
      final SchemaCrawlerOptions options); }
PrimaryKeyRetriever extends AbstractRetriever { void retrievePrimaryKeys(final NamedObjectList<MutableTable> allTables) throws SQLException { requireNonNull(allTables, "No tables provided"); switch (getRetrieverConnection().get(primaryKeysRetrievalStrategy)) { case data_dictionary_all: LOGGER.log(Level.INFO, "Retrieving primary keys, using fast data dictionary retrieval"); retrievePrimaryKeysFromDataDictionary(allTables); break; case metadata: LOGGER.log(Level.INFO, "Retrieving primary keys"); retrievePrimaryKeysFromMetadata(allTables); break; default: break; } } PrimaryKeyRetriever(
      final RetrieverConnection retrieverConnection,
      final MutableCatalog catalog,
      final SchemaCrawlerOptions options);  }
PrimaryKeyRetriever extends AbstractRetriever { void retrievePrimaryKeys(final NamedObjectList<MutableTable> allTables) throws SQLException { requireNonNull(allTables, "No tables provided"); switch (getRetrieverConnection().get(primaryKeysRetrievalStrategy)) { case data_dictionary_all: LOGGER.log(Level.INFO, "Retrieving primary keys, using fast data dictionary retrieval"); retrievePrimaryKeysFromDataDictionary(allTables); break; case metadata: LOGGER.log(Level.INFO, "Retrieving primary keys"); retrievePrimaryKeysFromMetadata(allTables); break; default: break; } } PrimaryKeyRetriever(
      final RetrieverConnection retrieverConnection,
      final MutableCatalog catalog,
      final SchemaCrawlerOptions options);   }