Interface JdbcConnectionFactory
- All Known Implementing Classes:
JdbcConnection
public interface JdbcConnectionFactory
A consistent interface for creating JDBC connections.
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidclose()Releases any resources held by the factory itself (does nothing by default).default voidcloseConnection(Connection connection) Releases a connection obtained fromcreateConnection()(closes it by default).Returns a connection to use; factories fromwrap(Connection)return the same connection on every call.static JdbcConnectionFactoryReturns a factory that opens a new connection on each call by instantiating the namedDriverclass.static JdbcConnectionFactoryReturns a factory that opens a new connection on each call by instantiating the namedDriverclass, passing the properties plus the credentials asuserandpassword.static JdbcConnectionFactorywrap(Connection connection) Returns a factory that always hands out the given connection;closeConnection(Connection)leaves it open andclose()closes it.static JdbcConnectionFactorywrap(DataSource dataSource) Returns a factory that obtains each connection fromdataSource.getConnection().static JdbcConnectionFactorywrap(DataSource dataSource, String username, String password) Returns a factory that obtains each connection fromdataSource.getConnection(username, password).
-
Method Details
-
createConnection
Returns a connection to use; factories fromwrap(Connection)return the same connection on every call.- Throws:
SQLException
-
closeConnection
Releases a connection obtained fromcreateConnection()(closes it by default).- Throws:
SQLException
-
close
default void close()Releases any resources held by the factory itself (does nothing by default). -
wrap
Returns a factory that always hands out the given connection;closeConnection(Connection)leaves it open andclose()closes it. -
wrap
Returns a factory that obtains each connection fromdataSource.getConnection(). -
wrap
Returns a factory that obtains each connection fromdataSource.getConnection(username, password). -
wrap
static JdbcConnectionFactory wrap(String driverClassName, String url, String username, String password) Returns a factory that opens a new connection on each call by instantiating the namedDriverclass. -
wrap
static JdbcConnectionFactory wrap(String driverClassName, String url, Properties properties, String username, String password) Returns a factory that opens a new connection on each call by instantiating the namedDriverclass, passing the properties plus the credentials asuserandpassword.
-