rdbms: avoid throwing exceptions in Database::close() on reconnect
The check caused problems in reconnect() calls from rollback()
triggered by LBFactory::rollbackMasterChanges(). Since callbacks
are suppressed at that time, handleSessionLoss() does not consume
all of them, so the the call to open() triggered a close() call
that would error out since the callbacks are still there.
Only do that check if a connection was present beforehand.
Check for callback suppression before trying commit() too.
Also make writesOrCallbacksPending() check trxEndCallbacks.
Bug: T188875
Change-Id: Ia46d30d75132358a0b4f60e847937013781c1daa