'Prepare the current transaction in progress for two phase commit.
If no transaction is in progress, this method raises an
:exc:`~sqlalchemy.exc.InvalidRequestError`.
Only root transactions of two phase sessions can be prepared. If the
current transaction is not such, an
:exc:`~sqlalchemy.exc.InvalidRequestError` is raised.'

def prepare(self):

    if (self.transaction is None):
        if (not self.autocommit):
            self.begin()
        else:
            raise sa_exc.InvalidRequestError('No    transaction    is    begun.')
    self.transaction.prepare()
