what you're suggesting is this:
if (batchingEnabled) {
   transaction = batchContainer.getBatchTransaction();
   if (transaction == null) 
      return tm.getTransaction()
} else {
   return tm.getTransaction();
}

Both versions are correct, I prefer the one I wrote because it's more concise.