| 1. |
What Is Another Way To Make A Transaction Method That Not Use The Transactional Annotation In Grails? |
|
Answer» USING the ".withTransaction" method Example: Account.with TRANSACTION { status -> def source = Account.get(params.from) def dest = Account.get(params.to) int amount = params.amount.to INTEGER() if (source.active) { source.balance -= amount if (dest.active) { dest.amount += amount } else { status.setRollbackOnly() } } } Using the ".withTransaction" method Example: Account.with Transaction { status -> def source = Account.get(params.from) def dest = Account.get(params.to) int amount = params.amount.to Integer() if (source.active) { source.balance -= amount if (dest.active) { dest.amount += amount } else { status.setRollbackOnly() } } } |
|