public class JdbcTransactionInterceptor extends Object implements org.aopalliance.intercept.MethodInterceptor
This method interceptor fetches a JDBC transaction from a JDBC
Datasource, opens a transaction and binds the JDBC connection to the current thread
using ThreadLocalManager.bindResource(String, Object)
with the given
datasource as a key.
When the method finishes, the transaction is committed or rolled back and the JDBC connection is unbound from the current thread.
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_THREAD_LOCAL_KEY
The default thread local key, which is used if no other key is configured.
|
Constructor and Description |
---|
JdbcTransactionInterceptor() |
Modifier and Type | Method and Description |
---|---|
String |
getCatalog() |
DataSource |
getDataSource() |
String |
getThreadLocalKey() |
Integer |
getTransactionIsolation() |
Object |
invoke(org.aopalliance.intercept.MethodInvocation invocation) |
boolean |
isPedanticProbe() |
void |
probeDataBase()
This method may be used as an initialization method in order to resolve the database driver and
check the database connection.
|
void |
setCatalog(String catalog) |
void |
setDataSource(DataSource dataSource) |
void |
setPedanticProbe(boolean pedanticProbe) |
void |
setThreadLocalKey(String key) |
void |
setTransactionIsolation(Integer transactionIsolation) |
public static final String DEFAULT_THREAD_LOCAL_KEY
public void probeDataBase()
isPedanticProbe()
is true
,
this method will fail with a DAOException
, when the database connection
is not ready.public Object invoke(org.aopalliance.intercept.MethodInvocation invocation) throws Throwable
invoke
in interface org.aopalliance.intercept.MethodInterceptor
Throwable
public DataSource getDataSource()
public void setDataSource(DataSource dataSource)
dataSource
- the JDBC datasource for retrieving the connection to set.public String getThreadLocalKey()
DEFAULT_THREAD_LOCAL_KEY
.public void setThreadLocalKey(String key)
key
- the key for retrieving the connection to set.
The default value is DEFAULT_THREAD_LOCAL_KEY
.
Configure this property, if you use multiple JDBC datasources.
For clarity, it is recommended to use the JDBC URL of the underlying
datasource for this value.public Integer getTransactionIsolation()
Connection.setTransactionIsolation(int)
public void setTransactionIsolation(Integer transactionIsolation)
transactionIsolation
- the optional transaction isloation level to set.public String getCatalog()
Connection.setCatalog(String)
public void setCatalog(String catalog)
catalog
- the optional catalog to set to newly created connection to setpublic boolean isPedanticProbe()
probeDataBase()
should fail on connection errors.public void setPedanticProbe(boolean pedanticProbe)
pedanticProbe
- Whether probeDataBase()
should fail on connection errors.Copyright © 2016 Clazzes.org. All rights reserved.