Every JDBC service instance keeps its own database connection and
uses it to access the database. It can be useful in some cases to be able
to share a connection between different JDBC service instances in order to
let the statements executed from different services be done within a single
transaction.
If a service invoker can share a connection between different
JDBC service instances, the JDBC services in the external definition files
should uses a connection alias (a tag in the services definition file). The
JDBCServicesConnectionManager must then manage the establishment and release
of the connection. When the service invoker requests a connection to the JDBC
service instance, the request is passed to the JDBCServicesConnectionManager
as follows:
- If there is an already-existing connection to the same database URL with
the specified connection alias, then this connection is returned to the service
invoker, and a counter that keeps the number of services using that connection
is incremented.
- If a connection with these properties does not exist, then the connection
is requested either from the DriverManager or from the connection pool (if
defined), and is returned to the service invoker. The JDBCServicesConnectionManager
will keep information about this new connections for future requests.
Whenever an service invoker closes the connection being used by a
JDBC service instance, the JDBCServicesConnectionManager checks whether this
connection is being used by other instances, and it will only close the connection
or release it to the connection pool if no instance is still using it.