| |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
Helper class that provides static methods to obtain connections from JNDI and close connections if necessary. Has support for thread-bound connections, e.g. for use with DataSourceTransactionManager.
Note: The getDataSourceFromJndi methods are targetted at applications that do not use a BeanFactory resp. an ApplicationContext. With the latter, it is preferable to preconfigure your beans or even JdbcTemplate instances in the factory: JndiObjectFactoryBean can be used to fetch a DataSource from JNDI and give the DataSource bean reference to other beans. Switching to another DataSource is just a matter of configuration then: You can even replace the definition of the FactoryBean with a non-JNDI DataSource!
| Method Summary | |
static void | applyTransactionTimeout(Statement stmt, DataSource ds)Apply the current transaction timeout, if any, to the given JDBC Statement object. |
static void | closeConnectionIfNecessary(Connection con, DataSource ds)Close the given connection if necessary, i.e. |
(package private) static Connection | getCloseSuppressingConnectionProxy(Connection source)Wrap the given connection with a proxy that delegates every method call to it but suppresses close calls. |
static Connection | getConnection(DataSource ds)Get a connection from the given DataSource. |
static Connection | getConnection(DataSource ds, boolean allowSynchronization) |
static DataSource | getDataSourceFromJndi(String jndiName)Look up the specified DataSource in JNDI, assuming that the lookup occurs in a J2EE container, i.e. |
static DataSource | getDataSourceFromJndi(String jndiName, boolean inContainer)Look up the specified DataSource in JNDI, explicitly specifying if the lookup occurs in a J2EE container. |
| Method Detail |
public static void applyTransactionTimeout(Statement stmt, DataSource ds)
throws java.sql.SQLException
public static void closeConnectionIfNecessary(Connection con, DataSource ds)
throws CannotCloseJdbcConnectionException
static Connection getCloseSuppressingConnectionProxy(Connection source)
public static Connection getConnection(DataSource ds)
throws CannotGetJdbcConnectionException
Is aware of a respective connection bound to the current thread, for example when using DataSourceTransactionManager. Will bind a Connection to the thread if transaction synchronization is active (e.g. if in a JTA transaction).
public static Connection getConnection(DataSource ds, boolean allowSynchronization)
throws CannotGetJdbcConnectionException
public static DataSource getDataSourceFromJndi(String jndiName)
throws CannotGetJdbcConnectionException
Use getDataSourceFromJndi(jndiName,false) in case of a custom JNDI name.
public static DataSource getDataSourceFromJndi(String jndiName, boolean inContainer)
throws CannotGetJdbcConnectionException
| |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||