Introduce a TransactionTemplate for automating transaction retries.

Changed a flaky test to use the transaction template to avoid unnecessary breakages.