<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def commit(self, timeout=None, metadata=None, credentials=None):
 """Commits the transaction."""

        if not self._common_commit():
            return

        new_metadata = self._dg.add_login_metadata(metadata)
        try:
            self._dc.commit_or_abort(self._ctx, timeout=timeout,
                                     metadata=new_metadata,
                                     credentials=credentials)
        except Exception as error:
            if util.is_jwt_expired(error):
                self._dg.retry_login()
                new_metadata = self._dg.add_login_metadata(metadata)
                try:
                    self._dc.commit_or_abort(self._ctx, timeout=timeout,
                                             metadata=new_metadata,
                                             credentials=credentials)
                except Exception as error:
                    return self._common_except_commit(error)

            self._common_except_commit(error)