বুধবার, ১৪ ডিসেম্বর, ২০১১

Declarative Transaction Management

Declarative transaction management means that you don’t write transaction management code in
your beans at all; instead, you configure the beans to be transactional. We can therefore take the
DefaultBankService from Listing 16-8 and specify in the bean configuration that we want the
transfer method to be transactional. The simplest way to achieve this is to use a proxy: the proxy will
intercept all method calls, and if the method name is included in the transactional configuration, the
proxy will act as around advice. It will begin the transaction before the call to the target method and
execute the target method in a try / catch block. If the target method finishes normally, the proxy
commits the transaction; if the target method throws a runtime exception, the proxy performs a roll-
back. To do all this work, the proxy will use the configured PlatformTransactionManager. This is the
core concept of declarative transaction management; the differences are in the way we can create
the proxy. Let’s begin with the legacy way, using the TransactionProxyFactoryBean.

1 টি মন্তব্য: