O'Reilly logo

Spring Python 1.1 by Greg Lee Turnquist

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Simplify by using @transactional

Spring Python solves these problems with its TransactionTemplate. This utility class makes it easy to wrap business methods with transactional functionality that solves all of the problems listed earlier. Spring Python makes it easy to wrap our existing business functions with the TransactionTemplate using its @transactional decorator.

  1. First, let's take our simple transfer function, and put into a Bank class.
    from springpython.database.core import * from springpython.database.factory import * class Bank(object): def __init__(self, connectionFactory): self.factory = connectionFactory self.dt = DatabaseTemplate(self.factory) def transfer(self, transfer_amt, source_act, target_act): self.dt.execute(""" update ACCOUNT ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required