Given all of the DB operations I'm performing on an Oracle datasource (using JDBCTemplate) are executed using a transaction template that uses a Spring Datasource TransactionManager,
- If multiple copies of my application receive requests to perform database operations on the same datasource, will the operations still be transactional?
- If another programmer connects to the same data source using a different library, will the operations performed here still be transactional?
To illustrate what exactly it is I'm doing:
val txTemplate = new TransactionTemplate(txManager, txAttribute)
txTemplate.execute(func)
where func is the function that performs the actual calls to JDBCtemplate, txManager is the transaction manager, and txAttribute is a DefaultTransactionAttribute where I define isolation, propagation, timeouts etc.
The transaction manager is a singleton defined in Spring that takes my datasource as an argument.
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<constructor-arg ref="dataSource"/>
</bean>
<bean id="dataSource" class="oracle.jdbc.pool.OracleConnectionPoolDataSource">
...
</bean>
Note:
As I am writing this in Scala, I have implicits defined that wrap the function func inside a TransactionCallback like so:
implicit def txCallbackImplicit[T](func: => T): TransactionCallback[T] = {
new TransactionCallback[T] {
def doInTransaction(status: TransactionStatus) = func.asInstanceOf[T]
}
}
So, txTemplate.execute(func) is actually callingtxTemplate.execute(new TransactionalCallBack[T] {...}`. This allows me to declare a method as transactional like so:
def foo = transactional() {
//jdbcTemplate operations
}
Aucun commentaire:
Enregistrer un commentaire