open method
Opens the component.
correlationId
(optional) transaction id to trace execution through call chain.
Implementation
@override
Future open(String? correlationId) async {
var options = await connectionResolver_.resolve(correlationId);
logger_.debug(correlationId, "Connecting to Postgres");
try {
var settings = this._composeSettings();
options.addAll(settings);
// Try to connect
var connection = PostgreSQLConnection(
options['host'], options['port'], options['database'],
username: options['user'],
password: options['password'],
timeoutInSeconds: options['connectionTimeoutMillis']);
await connection.open();
// set idleTimeoutMillis
await connection.query(
"SET SESSION idle_in_transaction_session_timeout = '" +
options['idleTimeoutMillis'].toString() +
"'");
connection_ = connection;
databaseName_ = connection_!.databaseName;
} catch (ex) {
throw new ConnectionException(
correlationId, "CONNECT_FAILED", "Connection to Postgres failed")
.withCause(ex);
}
}