MetadataExtractor { public Metadata extract(JdbcConnectivity configuration) throws ClassNotFoundException, SQLException { Class<?> jdbcDriverClass = Class.forName(configuration.getDriver()); isOracle = isOracle(jdbcDriverClass); isDB2 = isDB2(jdbcDriverClass); useLabel = !isDB2; if ((isOracle || isDB2) && configuration.getSchemaName() == null) { configuration.setSchemaName(configuration.getUser().toUpperCase()); if (log.isInfoEnabled()) { log.info(" Schema is null, we force it to :\"" + configuration.getSchemaName() + "\""); } } Connection connection = getDatabaseConnection(configuration); try { return extract(configuration, connection); } finally { if (connection != null) { connection.close(); } } }  Metadata extract(JdbcConnectivity configuration); Metadata extract(Connection connection); Metadata extract(JdbcConnectivity jdbcConnectivity, Connection connection);  }
@Test public void noTable() throws ClassNotFoundException, SQLException, JAXBException, IOException { EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(); EmbeddedDatabase embeddedDatabase = builder.setType(EmbeddedDatabaseType.H2).build(); Metadata meta = extractor.extract(embeddedDatabase.getConnection()); assertThat(countTables(meta)).isZero(); assertThat(countColumns(meta)).isZero(); assertThat(countPrimaryKeys(meta)).isZero(); assertThat(countImportedKeys(meta)).isZero(); assertThat(countIndexes(meta)).isZero(); assertThat(countEnums(meta)).isZero(); embeddedDatabase.shutdown(); }
@Test public void minimal() throws ClassNotFoundException, SQLException, JAXBException, IOException { EmbeddedDatabase embeddedDatabase = createMinimalEmbeddedDatabase(MINIMAL_SCRIPT); Metadata meta = extractor.extract(embeddedDatabase.getConnection()); assertThat(countTables(meta)).isEqualTo(6); assertThat(countColumns(meta)).isEqualTo(29); assertThat(countPrimaryKeys(meta)).isEqualTo(9); assertThat(countImportedKeys(meta)).isEqualTo(4); assertThat(countIndexes(meta)).isEqualTo(13); assertThat(countEnums(meta)).isZero(); embeddedDatabase.shutdown(); }
@Test public void outputIsSameAsInput() throws ClassNotFoundException, SQLException, XmlMappingException, IOException { EmbeddedDatabase embeddedDatabase = createMinimalEmbeddedDatabase(ALL_RELATIONS_SCRIPT); Metadata meta = extractor.extract(embeddedDatabase.getConnection()); assertThat(countTables(meta)).isEqualTo(18); assertThat(countColumns(meta)).isEqualTo(49); assertThat(countPrimaryKeys(meta)).isEqualTo(18); assertThat(countIndexes(meta)).isEqualTo(21); assertThat(countEnums(meta)).isEqualTo(3); File tempFile = File.createTempFile(getClass().getName(), ".xml"); tempFile.deleteOnExit(); loader.write(meta, tempFile); Metadata loadedMeta = loader.load(tempFile); assertThat(countTables(meta)).isEqualTo(countTables(loadedMeta)); assertThat(countColumns(meta)).isEqualTo(countColumns(loadedMeta)); assertThat(countPrimaryKeys(meta)).isEqualTo(countPrimaryKeys(loadedMeta)); assertThat(countIndexes(meta)).isEqualTo(countIndexes(loadedMeta)); assertThat(countEnums(meta)).isEqualTo(countEnums(loadedMeta)); embeddedDatabase.shutdown(); }