Cleanup DatabaseBase::query implicit transaction code

* Add DatabaseBase::isTransactableQuery() for checking whether a query could
  benefit from being executed in a transaction.

Change-Id: Ie5b116bc726b47c68459e6525a1bb43b96bd9f30