Switching to using 'with db_api.transaction()'

Change-Id: I80eba89e4c748e8c17c3f93f657f844c0e72e8a6