0
votes

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
}
2

2 Answers

1
votes

Transactions are implemented by the database (Oracle in your case), not by spring. Spring hides it very well behind many classes but essentially it just calls JDBC connection methods (setAutoCommit, commit and rollback) at the right times.

What data you see inside a transaction (no matter if it is part of your application or someone's else) depends on transaction isolation level (google it ;)

0
votes

If multiple copies of my application receive requests to perform database operations on the same datasource, will the operations still be transactional?

The transactional behavior is not controlled by the datasource itself. The datasource is responsible to produce connections while the TransactionManager is responsible to manage transaction boundaries. If you propagate the transaction to all operations, then the TransactionManager will delimit them into the same transaction. In fact, it's possible to have distributed transactions (using two phase commit) over distinct datasources.

If another programmer connects to the same data source using a different library, will the operations performed here still be transactional?

The client cannot control the service provider transaction.