Last active
August 29, 2015 14:05
-
-
Save mostlylikeable/637bda7e2172104f1f3b to your computer and use it in GitHub Desktop.
Suppress auto-timestamping in Groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def withAutoTimestampSuppression(entity, closure) { | |
| toggleAutoTimestamp(entity, false) | |
| try { | |
| def result = closure() | |
| return result | |
| } finally { | |
| toggleAutoTimestamp(entity, true) | |
| } | |
| } | |
| void toggleAutoTimestamp(def domainObjectInstance, boolean shouldTimestamp) { | |
| ApplicationContext ctx = ServletContextHolder.servletContext.getAttribute(ApplicationAttributes.APPLICATION_CONTEXT) | |
| ClosureEventTriggeringInterceptor closureInterceptor = ctx.eventTriggeringInterceptor | |
| Datastore datastore = closureInterceptor.datastores.values().first() | |
| EventTriggeringInterceptor interceptor = datastore.eventTriggeringInterceptor | |
| ClosureEventListener listener = interceptor.findEventListener(domainObjectInstance) | |
| listener.shouldTimestamp = shouldTimestamp | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment