Package com.trafficparrot.sdk.database
Interface DatabaseConnections
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
The database connections configured in Traffic Parrot's
database-connections.json, from
TrafficParrotServices.databaseConnections().
DataSource dataSource = databaseConnections.dataSource(parameters.getString("connectionId"));
try (Connection connection = dataSource.getConnection()) {
...
}
The connection id comes from the mapping, for example its transformerParameters, as the dataSource
Handlebars helper takes it inline. In a unit test, implement dataSource(java.lang.String) alone, for example over an in-memory
database; the other methods have defaults. Methods added in later versions will have defaults too.-
Method Summary
Modifier and TypeMethodDescriptiondataSource(String connectionId) ADataSourcefor the JDBC connection with thisconnectionIdindatabase-connections.json, for a library that takes one.
-
Method Details
-
dataSource
ADataSourcefor the JDBC connection with thisconnectionIdindatabase-connections.json, for a library that takes one.Each
DataSource.getConnection()reads the file again and today opens a new connection the way thedataSourceHandlebars helper does. A later release may pool them, so close every connection and leave it as you found it (auto-commit, isolation). It fails only with anSQLException: if the JDBC driver is not inlib/external, the database refuses the connection, or the file no longer has a JDBC connection with this id. The message names the connection id and, for a refused connection, the JDBC URL, with passwords masked; the driver's own exception is not attached. The user and password come from the file, soDataSource.getConnection(String, String)is not supported.- Throws:
IllegalArgumentException- if no connection has this id, it is not a JDBC connection, it has nodriverClass, ordatabase-connections.jsonis inconsistent (two connections with one id)UncheckedIOException- ifdatabase-connections.jsoncannot be read or parsedNullPointerException- ifconnectionIdis null
-
connectionIds
- Returns:
- the ids of all connections in
database-connections.json, of every type;dataSource(java.lang.String)accepts only the JDBC ones - Throws:
IllegalArgumentException- ifdatabase-connections.jsonis inconsistent (two connections with one id)UncheckedIOException- ifdatabase-connections.jsoncannot be read or parsedUnsupportedOperationException- if this implementation does not list them, as a test's may not
-