An important aspect of Spring Python is its non-invasive nature. This was demonstrated in great detail in the chapter that introduced aspect oriented programming. Spring Python provides a convenient, non-intrusive method interceptor that allows the demarcation of existing code.
This solves the problem mentioned earlier, where neither editing existing source code nor tangling our business logic with transaction management are acceptable.
Let's start with an alternative version of
Bank
class that has no transaction demarcation.class Bank(object): def __init__(self, connectionFactory): self.factory = connectionFactory: self.dt = DatabaseTemplate(self.factory) def balance(self, act): return self.dt.queryForObject(""" SELECT BALANCE FROM ACCOUNT WHERE ACCOUNT_NUM = ?""", (act,), types.FloatType) def withdraw(self, amt, act): if (self.balance(act) > amt...