public interface DbConnectionFactory
DbConnectionFactory
allocates and deallocates connections
from a database. The concrete implementations of this interface specify a
particular allocation/deallocation policy.
For example, an implementation might use and reuse connections from a persistent pool of connections, while another might dynamically allocate and deallocate connections for each request.
Modifier and Type | Method and Description |
---|---|
void |
destroy()
Deallocate all the resources that may have been allocated to this
database connection factory.
|
Connection |
getConnection()
Retrieve a connection from the given database connection pool.
|
void |
init(String dbUrl,
String dbDriver,
String username,
String password)
Initialize a database factory with the given URL, driver classname, and
database credentials.
|
void |
releaseConnection(Connection connection)
Replace a database connection back in the pool of available connections
for its parent pool.
|
void init(String dbUrl, String dbDriver, String username, String password) throws ClassNotFoundException
Only one init
method should be called.
dbUrl
- the JDBC URL used to retrieve connectionsdbDriver
- a fully qualified class name for the JDBC driver that will
handle this JDBC URLusername
- the name to use to authenticate us with the databasepassword
- the credentials use to authenticate the usernameClassNotFoundException
- if any.void destroy()
Connection getConnection() throws SQLException
Connection
object.IllegalStateException
- If the factory has not been initialized or has been
destroyed.SQLException
- if any.void releaseConnection(Connection connection) throws SQLException
connection
- the connection to releaseIllegalStateException
- If the factory has not been initialized or has been
destroyed.SQLException
- if any.Copyright © 2016. All rights reserved.