|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.lucene.store.jdbc.datasource.TransactionAwareDataSourceProxy
public class TransactionAwareDataSourceProxy
Proxy for a target DataSource, adding awareness of local managed transactions. Similar to a transactional JNDI DataSource as provided by a J2EE server.
Encapsulates both a simple transaction manager based onThreadLocal
and a DataSource that supports it. Should be used when no tranasction
managers are used (like JTA or Spring) in order to get simpler support for transactions.
It is by no means aimed at replacing the usage of a proper transaction manager, but is provided
for a simple implementation of transactions for JdbcDirectory
(resulting in better performance), and integration with an existing DataSource code.
Wraps the created Jdbc Connection with a ConnectionProxy, which
will only close the target connection if it is controlled by it.
The most outer Connection within the context of a thread, is the controlling
connection. Each inner Connection that will be retrieved using this data source
will return the same connection, and each call to close the connection on inner connection
will be disregarded. Commiting a connection should be done only on the outer most connection.
A set of simple utilities are provided in the DataSourceUtils for simpler management of
the DataSource, and special care is taken if the DataSource uses the
ConnectionProxy (such is the case with this data soruce). For example, the
DataSourceUtils.commitConnectionIfPossible(java.sql.Connection) and
DataSourceUtils.rollbackConnectionIfPossible(java.sql.Connection) will only call commit/rollback
if the Connection was created by this data source (otherwise, in a managed environment, it
will be called on the actual transaction managed, or it will be using AOP).
Note, that all the code that interacts with the database within the Jdbc Store package does not
commit / rollbacks the connection. It only executes it's statements, and if something goes wrong
throws an exception. The responsiblity for transaction management is with the calling code, and the
TransactionAwareDataSourceProxy is there to help non managed transaction management.
DataSourceUtils,
DirectoryTemplate| Constructor Summary | |
|---|---|
TransactionAwareDataSourceProxy(DataSource dataSource)
Create the data source with the given data source to wrap. |
|
| Method Summary | ||
|---|---|---|
Connection |
getConnection()
Creates or returns an alreay created connection. |
|
Connection |
getConnection(String username,
String password)
Not supported. |
|
int |
getLoginTimeout()
|
|
PrintWriter |
getLogWriter()
|
|
DataSource |
getTargetDataSource()
Returns the targe data source. |
|
protected Connection |
getTransactionAwareConnectionProxy(Connection target,
DataSource dataSource,
boolean controllsConnection)
A simple helper that return the Jdbc Connection wrapped in our proxy. |
|
boolean |
isWrapperFor(Class<?> iface)
|
|
void |
setLoginTimeout(int seconds)
|
|
void |
setLogWriter(PrintWriter out)
|
|
|
unwrap(Class<T> iface)
|
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public TransactionAwareDataSourceProxy(DataSource dataSource)
| Method Detail |
|---|
public DataSource getTargetDataSource()
public int getLoginTimeout()
throws SQLException
getLoginTimeout in interface DataSourceSQLException
public void setLoginTimeout(int seconds)
throws SQLException
setLoginTimeout in interface DataSourceSQLException
public PrintWriter getLogWriter()
throws SQLException
getLogWriter in interface DataSourceSQLException
public void setLogWriter(PrintWriter out)
throws SQLException
setLogWriter in interface DataSourceSQLException
public Connection getConnection(String username,
String password)
throws SQLException
getConnection in interface DataSourceSQLException
public Connection getConnection()
throws SQLException
close
method was not called yet, the ori connection will be returned (and will be a "not controlled"
connection, which means that any call to close will be a no op).
Consider using DataSourceUtils.getConnection(javax.sql.DataSource) and
DataSourceUtils.releaseConnection(java.sql.Connection) for simpler usage.
getConnection in interface DataSourceSQLException
protected Connection getTransactionAwareConnectionProxy(Connection target,
DataSource dataSource,
boolean controllsConnection)
Connection wrapped in our proxy.
public <T> T unwrap(Class<T> iface)
throws SQLException
SQLException
public boolean isWrapperFor(Class<?> iface)
throws SQLException
SQLException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||