rdbms: clean up session/transaction loss logic in Database
* Refactor the code to be less cluttered, moving some logic
to reconnect(), which is now named replaceLostConnection()
* Handle the case of a second connection loss on query retry
* Make canRecoverFromDisconnect() check for temporary tables
* Do not clear session-level variables on deadlock errors
since only the transaction is lost, not the whole session
* Make sure any empty transaction is destroyed on deadlock
* Attempt reconnection *before* triggering the transaction
callbacks since some of them might want to use the database
* Define wasConnectionError() for postgres
* Remove unused return value from handleSessionLoss()
Change-Id: Ic1dcab03f087ce310637210e8e9bc0771e44f045