Skip to content

Commit

Permalink
Change the custom dirtiness strategy to match what Hibernate expects.…
Browse files Browse the repository at this point in the history
… Active dirty checking in ClosureEventTriggeringInterceptor
  • Loading branch information
jameskleeh committed Oct 21, 2016
1 parent b5e4e9d commit a007266
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class GrailsEntityDirtinessStrategy implements CustomEntityDirtinessStrategy {

@Override
public boolean isDirty(Object entity, EntityPersister persister, Session session) {
cast(entity).hasChanged()
cast(entity).listDirtyPropertyNames().size() > 0
}

@Override
Expand All @@ -36,7 +36,7 @@ class GrailsEntityDirtinessStrategy implements CustomEntityDirtinessStrategy {
@Override
public boolean isDirty(CustomEntityDirtinessStrategy.AttributeInformation attributeInformation) {
String propertyName = attributeInformation.name
dirtyAware.hasChanged(propertyName)
cast(entity).listDirtyPropertyNames().contains(propertyName)
}
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.grails.datastore.gorm.events.ConfigurableApplicationContextEventPublisher;
import org.grails.datastore.gorm.events.ConfigurableApplicationEventPublisher;
import org.grails.datastore.mapping.dirty.checking.DirtyCheckable;
import org.grails.datastore.mapping.engine.event.AbstractPersistenceEvent;
import org.grails.datastore.mapping.model.config.GormProperties;
import org.grails.orm.hibernate.AbstractHibernateDatastore;
Expand Down Expand Up @@ -97,8 +98,10 @@ public void onPreLoad(PreLoadEvent hibernateEvent) {
}

public void onPostLoad(PostLoadEvent hibernateEvent) {
Object entity = hibernateEvent.getEntity();
activateDirtyChecking(entity);
publishEvent(hibernateEvent, new org.grails.datastore.mapping.engine.event.PostLoadEvent(
this.datastore, hibernateEvent.getEntity()));
this.datastore, entity));
}

public boolean onPreInsert(PreInsertEvent hibernateEvent) {
Expand All @@ -109,8 +112,10 @@ public boolean onPreInsert(PreInsertEvent hibernateEvent) {
}

public void onPostInsert(PostInsertEvent hibernateEvent) {
Object entity = hibernateEvent.getEntity();
activateDirtyChecking(entity);
publishEvent(hibernateEvent, new org.grails.datastore.mapping.engine.event.PostInsertEvent(
this.datastore, hibernateEvent.getEntity()));
this.datastore, entity));
}

@Override
Expand All @@ -126,8 +131,10 @@ public boolean onPreUpdate(PreUpdateEvent hibernateEvent) {
}

public void onPostUpdate(PostUpdateEvent hibernateEvent) {
Object entity = hibernateEvent.getEntity();
activateDirtyChecking(entity);
publishEvent(hibernateEvent, new org.grails.datastore.mapping.engine.event.PostUpdateEvent(
this.datastore, hibernateEvent.getEntity()));
this.datastore, entity));
}

public boolean onPreDelete(PreDeleteEvent hibernateEvent) {
Expand Down Expand Up @@ -190,5 +197,10 @@ protected Boolean getAssumedUnsaved() {
return AbstractHibernateGormInstanceApi.getAssumedUnsaved();
}

private void activateDirtyChecking(Object entity) {
if(entity instanceof DirtyCheckable) {
((DirtyCheckable) entity).trackChanges();
}
}

}

0 comments on commit a007266

Please sign in to comment.