I have a service that is communicating to another machine. Since it's a simple Controller method Grails automatically grabs a DB connection from the pool while my controller is communicating with the other server. I'd like to prevent it from doing that, and manually open up the database connection when I'm ready so that it doesn't suck up a connection during a long period like doing network calls. How do I prevent Grails from automatically grabbing a connection from the pool in a controller method?
When you create a controller it has the Transactional
annotation on it, something like:
@Transactional(readOnly=true)
class FooController { ..
If you remove that annotation (and any method level annotations) then Grails will no longer connect to the database to start the transaction.
Open Session In View should not come into play since we use a lazy init approach for obtaining the connection with OSIV
Note my answer above assumes you are using a recent version of Grails (2.3.x or above)
Updated
For MongoDB you can disable automatically connection for all controllers by defining the following bean (which overrides the default) in grails-app/conf/spring/resources.groovy
:
mongoPersistenceInterceptor(org.codehaus.groovy.grails.support.NullPersistentContextInterceptor)
However there is no way to disable on a per controller basis at the moment
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With