[Database] Added onTransactionPreCommitOrIdle() function.

* Also fixed case where onTransactionIdle() could start uncommitted
  transactions if there was no transanction and DBO_TRX was set.

Change-Id: I0bf6171fac692cf3d6e04011321bed075f58724b
(cherry picked from commit 75b16dfb5f6be93c9729dd0b8c1e5d4639880503)