StandardDialect implements Dialect, SequenceSupport, IdentityColumnSupport, TriggerSupport { @Override public <Z, D extends Database<Z>> ConnectionProperties getConnectionProperties(D database, Decoder decoder) throws SQLException { final String password = database.getCredentials().decodePassword(decoder); try (Connection connection = database.connect(decoder)) { DatabaseMetaData metaData = connection.getMetaData(); String url = metaData.getURL(); if (url == null) { throw new UnsupportedOperationException(); } Matcher matcher = this.urlPattern.matcher(url); if (!matcher.find()) { throw new UnsupportedOperationException(url); } final String host = matcher.group("host"); final String port = matcher.group("port"); final String databaseName = matcher.group("database"); final String user = metaData.getUserName(); return new ConnectionProperties() { @Override public String getHost() { return host; } @Override public String getPort() { return port; } @Override public String getDatabase() { return databaseName; } @Override public String getUser() { return user; } @Override public String getPassword() { return password; } }; } }  @Override String getTruncateTableSQL(TableProperties properties); @Override String getCreateForeignKeyConstraintSQL(ForeignKeyConstraint key); @Override String getDropForeignKeyConstraintSQL(ForeignKeyConstraint key); @Override String getCreateUniqueConstraintSQL(UniqueConstraint constraint); @Override String getDropUniqueConstraintSQL(UniqueConstraint constraint); @Override boolean isSelectForUpdate(String sql); @Override List<String> getDefaultSchemas(DatabaseMetaData metaData); @Override SequenceSupport getSequenceSupport(); @Override String parseSequence(String sql); @Override int getColumnType(ColumnProperties properties); @Override Collection<SequenceProperties> getSequences(DatabaseMetaData metaData, SequencePropertiesFactory factory); @Override String getNextSequenceValueSQL(SequenceProperties sequence); @Override String getAlterSequenceSQL(SequenceProperties sequence, long value); @Override IdentityColumnSupport getIdentityColumnSupport(); @Override String parseInsertTable(String sql); @Override String getAlterIdentityColumnSQL(TableProperties table, ColumnProperties column, long value); @Override String evaluateCurrentDate(String sql, java.sql.Date date); @Override String evaluateCurrentTime(String sql, java.sql.Time time); @Override String evaluateCurrentTimestamp(String sql, java.sql.Timestamp timestamp); @Override String evaluateRand(String sql); @Override boolean indicatesFailure(SQLException e); @Override boolean indicatesFailure(XAException e); @Override DumpRestoreSupport getDumpRestoreSupport(); @Override TriggerSupport getTriggerSupport(); @Override String getCreateTriggerSQL(String name, TableProperties table, TriggerEvent event, String action); @Override String getDropTriggerSQL(String name, TableProperties table); @Override String getTriggerRowAlias(TriggerTime time); @Override String getCreateSchemaSQL(String schema); @Override String getDropSchemaSQL(String schema); @Override Collection<QualifiedName> getTables(DatabaseMetaData metaData, QualifiedNameFactory factory); @Override Map<String, ColumnProperties> getColumns(DatabaseMetaData metaData, QualifiedName table, ColumnPropertiesFactory factory); @Override UniqueConstraint getPrimaryKey(DatabaseMetaData metaData, QualifiedName table, UniqueConstraintFactory factory); @Override Collection<ForeignKeyConstraint> getForeignKeyConstraints(DatabaseMetaData metaData, QualifiedName table, ForeignKeyConstraintFactory factory); @Override Collection<UniqueConstraint> getUniqueConstraints(DatabaseMetaData metaData, QualifiedName table, UniqueConstraint primaryKey, UniqueConstraintFactory factory); @Override Collection<String> getIdentityColumns(Collection<ColumnProperties> columns); @Override Map<Integer, Entry<String, Integer>> getTypes(DatabaseMetaData metaData); @Override IdentifierNormalizer createIdentifierNormalizer(DatabaseMetaData metaData); @Override QualifiedNameFactory createQualifiedNameFactory(DatabaseMetaData metaData, IdentifierNormalizer normalizer); @Override ColumnPropertiesFactory createColumnPropertiesFactory(IdentifierNormalizer normalizer); @Override SequencePropertiesFactory createSequencePropertiesFactory(QualifiedNameFactory factory); @Override ForeignKeyConstraintFactory createForeignKeyConstraintFactory(QualifiedNameFactory factory); @Override UniqueConstraintFactory createUniqueConstraintFactory(IdentifierNormalizer normalizer); @Override boolean isValid(Connection connection); @Override ConnectionProperties getConnectionProperties(D database, Decoder decoder);  }
@Test public void getConnectionProperties() throws SQLException { Database<Void> database = mock(Database.class); Credentials credentials = mock(Credentials.class); Decoder decoder = mock(Decoder.class); Connection connection = mock(Connection.class); DatabaseMetaData metaData = mock(DatabaseMetaData.class); String host = "myhost"; String port = "1234"; String databaseName = "mydb"; String user = "user"; String password = "password"; when(database.getCredentials()).thenReturn(credentials); when(credentials.getUser()).thenReturn(user); when(credentials.decodePassword(decoder)).thenReturn(password); when(database.connect(decoder)).thenReturn(connection); when(connection.getMetaData()).thenReturn(metaData); when(metaData.getURL()).thenReturn(String.format("jdbc:%s: when(metaData.getUserName()).thenReturn(user); ConnectionProperties properties = this.dialect.getConnectionProperties(database, decoder); assertEquals(host, properties.getHost()); assertEquals(port, properties.getPort()); assertEquals(databaseName, properties.getDatabase()); assertSame(user, properties.getUser()); assertSame(password, properties.getPassword()); when(metaData.getURL()).thenReturn(String.format("jdbc:%s:%s?loginTimeout=0&socketTimeout=0&prepareThreshold=5&unknownLength=2147483647&tcpKeepAlive=false&binaryTransfer=true", this.factory.getId(), databaseName)); properties = this.dialect.getConnectionProperties(database, decoder); assertNull(properties.getHost()); assertNull(properties.getPort()); assertEquals(databaseName, properties.getDatabase()); assertSame(user, properties.getUser()); assertSame(password, properties.getPassword()); }