SpringSource/spring-scala — pull request #6 by hekonsek (2013-01-14 21:38:55+00:00)
Title: Pattern matching style handlers for TransactionSynchronizationManager

Hi,

What about a little patch that would make possible to handle TransactionSynchronization using pattern matching instead of anonymous inner classes?

// Ugly Scala
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter(){
override def afterCompletion(status: Int) {
if(status == COMMITTED) emailService.sendUserNotification(...)
}
})

// Pretty Scala
TransactionSynchronizationManager.registerSynchronization {
case AfterCompletionEvent(status) => if(status == COMMITTED) emailService.sendUserNotification(...)
}

Using Partial Functions for callbacks is much more "scalish" than relaying on anonymous inner classes.