| java.lang.Object org.apache.lucene.store.jdbc.datasource.TransactionAwareDataSourceProxy
TransactionAwareDataSourceProxy | public class TransactionAwareDataSourceProxy implements DataSource(Code) | | 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 on ThreadLocal
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
org.apache.lucene.store.jdbc.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.
author: kimchy See Also: DataSourceUtils See Also: org.apache.lucene.store.DirectoryTemplate |
TransactionAwareDataSourceProxy | public TransactionAwareDataSourceProxy(DataSource dataSource)(Code) | | Create the data source with the given data source to wrap.
|
getTargetDataSource | public DataSource getTargetDataSource()(Code) | | Returns the targe data source.
|
getTransactionAwareConnectionProxy | protected Connection getTransactionAwareConnectionProxy(Connection target, DataSource dataSource, boolean controllsConnection)(Code) | | A simple helper that return the Jdbc Connection wrapped in our proxy.
|
|
|