I’m porting a class from plain JDBC to use Spring. Part of this class consists of a block that find the most recent row, updates a field, and selects it into an object to be processed later. This block should only be executed by one thread on one machine at a time to make sure no two threads process the same row. We’ve been handling mutual exclusion by locking the table, but as part of the move to Spring would like to use the transaction management provided.
Is the DataSourceTransactionManager powerful enough to provide mutual exclusion in the case where our code is accessing the database from multiple machines?
DataSourceTransactionManagermakes use of thesetAutoCommitmethod onjava.sql.Connection. That in turn controls the transactional behaviour on the database server. The transaction itself resides in the database.So yes, what you want to do shouldn’t be a problem.