I was not able to successfully get a link to save () methods during plugin / application initialization; I do not know why. Instead, I decided to create a listener for hibernation events after inserting, updating, and deleting. This post from Sean Hartsock regarding the audit audit plugin was ideal for this.
Here's the gist of the listener:
class MyListener implements PostInsertEventListener, PostUpdateEventListener, PostDeleteEventListener, Initializable { public void onPostInsert(final PostInsertEvent event) {
Then in * GrailsPlugin.groovy:
def doWithApplicationContext = { applicationContext -> // add the event listeners for reindexing on change def listeners = applicationContext.sessionFactory.eventListeners def listener = new MyListener() ['postInsert', 'postUpdate', 'postDelete'].each({ addEventTypeListener(listeners, listener, it) }) } // copied from http://hartsock.blogspot.com/2008/04/inside-hibernate-events-and-audit.html private addEventTypeListener(listeners, listener, type) { def typeProperty = "${type}EventListeners" def typeListeners = listeners."${typeProperty}" def expandedTypeListeners = new Object[typeListeners.length + 1] System.arraycopy(typeListeners, 0, expandedTypeListeners, 0, typeListeners.length) expandedTypeListeners[-1] = listener listeners."${typeProperty}" = expandedTypeListeners }
Pretty simple at the end of the day ...
mbrevoort
source share