CORE-1195 Restore auto-commit on close.

- Only adjust auto-commit in `AbstractDatabase.setConnection(DatabaseConnection)` if the current auto-commit mode isn't what's required
- If the auto-commit mode is adjusted, store what it used to be
- When `close()` is called, if a previous auto-commit mode was stored, restore the connection to it
- Added unit tests to ensure the auto-commit mode is only changed if it has to be, and that, if it's changed, it's restored on `close()`