@Override
protected Supplier<Future<Connection>> createConnectionSupplier(final Config config,
final Supplier<Future<NettyChannel>> channelSupplier) {
final EncodingRegistry encoding = new EncodingRegistry(config.loadCustomEncodings(), config.charset());
final Marshallers marshallers = new Marshallers(encoding);
final Unmarshallers unmarshallers = new Unmarshallers(config.charset());
final QueryResultExchange queryResultExchange = new QueryResultExchange(encoding, unmarshallers);
final InitSSLExchange initSSLExchange = new InitSSLExchange(marshallers, unmarshallers);
final StartupExchange startup = new StartupExchange(marshallers, unmarshallers);
return () -> {
final PrepareStatementExchange preparedStatementCache = new PrepareStatementExchange(marshallers, unmarshallers);
final ExtendedExchange extendedExchange = new ExtendedExchange(marshallers, unmarshallers,
preparedStatementCache);
return channelSupplier.get().flatMap(channel -> initSSLExchange.apply(config.ssl()).run(channel)
.flatMap(ssl -> initSSLHandler.apply(config.host(), config.port(), ssl, channel))
.flatMap(v -> startup.apply(config.charset(), config.user(), config.password(), config.database())
.run(channel)
.map(backendKeyData -> new io.trane.ndbc.postgres.Connection(
channel, marshallers,
config.queryTimeout(), config.scheduler(),
channelSupplier, backendKeyData,
new SimpleQueryExchange(queryResultExchange, marshallers, unmarshallers),
new SimpleExecuteExchange(marshallers, unmarshallers),
new ExtendedQueryExchange(queryResultExchange, extendedExchange),
new ExtendedQueryStreamExchange(marshallers, unmarshallers, preparedStatementCache,
queryResultExchange),
new ExtendedExecuteExchange(extendedExchange, unmarshallers)))));
};
}
}