Reputation: 19
created a plugin that would intercept all method call to grails-services method that would call another method(not in the same service) after the original method completed.
I added the following code in doWithDynamicMethods.
for (serviceClass in application.serviceClasses){
serviceClass.metaClass.invokeMethod = { String name, args ->
//execute the original method
def metaMethod = delegate.metaClass.getMetaMethod(name, args)
def result = metaMethod.invoke(delegate, args)
//execute additional method on other bean
def otherbean.doSomething(Object object)
return result
}
}
Everything works and otherbean.doSomething() is called everytime, but then i realize that if any exception thrown when by otherbean.doSomething(), the database changes that done in the original method is not rollback.
It seems that the scope of the transaction only covers the original method only and committed as soon as original method call is complete.
Is there any way to execute the original method and additional method in the same transaction?
note : otherbean is not grails service
Upvotes: 1
Views: 154