Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,26 @@ class MongoCodecEntityPersister extends ThirdPartyCacheEntityPersister<Object> {
mongoCodecSession.addPendingUpdate(new PendingUpdateAdapter(entity, id, obj, entityAccess) {
@Override
void run() {
// Take snapshot of all property values BEFORE the PreUpdate event fires
Map<String, Object> beforeUpdateSnapshot = [:]
if (obj instanceof DirtyCheckable) {
for (PersistentProperty prop : entity.persistentProperties) {
beforeUpdateSnapshot[prop.name] = entityAccess.getProperty(prop.name)
}
}
if (!cancelUpdate(entity, entityAccess)) {
// Compare with snapshot and mark modified properties dirty
if (obj instanceof DirtyCheckable) {
DirtyCheckable dirtyCheckable = (DirtyCheckable) obj
for (PersistentProperty prop : entity.persistentProperties) {
Object oldValue = beforeUpdateSnapshot[prop.name]
Object newValue = entityAccess.getProperty(prop.name)
boolean valueChanged = oldValue != newValue && (oldValue == null || !oldValue.equals(newValue))
if (valueChanged) {
dirtyCheckable.markDirty(prop.name, newValue, oldValue)
}
}
}
updateCaches(entity, obj, id)
addCascadeOperation(new PendingOperationAdapter(entity, id, obj) {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ import org.grails.datastore.mapping.engine.internal.MappingUtils
import org.grails.datastore.mapping.model.EmbeddedPersistentEntity
import org.grails.datastore.mapping.model.PersistentEntity
import org.grails.datastore.mapping.model.PersistentProperty
import org.grails.datastore.mapping.model.config.GormProperties
import org.grails.datastore.mapping.model.types.Association
import org.grails.datastore.mapping.model.types.Embedded
import org.grails.datastore.mapping.model.types.EmbeddedCollection
Expand Down Expand Up @@ -249,12 +248,6 @@ class PersistentEntityCodec extends BsonPersistentEntityCodec {
}

}
else {
// schedule lastUpdated if necessary
if (entity.getPropertyByName(GormProperties.LAST_UPDATED) != null) {
dirtyProperties.add(GormProperties.LAST_UPDATED)
}
}

for (propertyName in dirtyProperties) {
def prop = entity.getPropertyByName(propertyName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
*/
package org.grails.datastore.gorm.mongo

import spock.lang.PendingFeature

import grails.persistence.Entity
import org.apache.grails.data.mongo.core.GrailsDataMongoTckManager
import org.apache.grails.data.testing.tck.base.GrailsDataTckSpec
Expand All @@ -37,7 +35,7 @@ class BeforeUpdatePropertyPersistenceSpec extends GrailsDataTckSpec<GrailsDataMo
manager.domainClasses.addAll([UserWithBeforeUpdate, UserWithBeforeUpdateAndAutoTimestamp])
}

@PendingFeature
@Issue('GRAILS-15139')
void "Test that properties set in beforeUpdate are persisted"() {
given: "A user is created"
def user = new UserWithBeforeUpdate(name: "Fred")
Expand Down Expand Up @@ -92,7 +90,6 @@ class BeforeUpdatePropertyPersistenceSpec extends GrailsDataTckSpec<GrailsDataMo
user.random.length() == 5
}

@PendingFeature
void "Test that multiple updates continue to trigger beforeUpdate"() {
given: "A user is created"
def user = new UserWithBeforeUpdate(name: "Fred")
Expand All @@ -119,8 +116,7 @@ class BeforeUpdatePropertyPersistenceSpec extends GrailsDataTckSpec<GrailsDataMo
user.random.length() == 5
}

@PendingFeature
@Issue('GPMONGODB-XXX')
@Issue('GRAILS-15120')
void "Test that properties set in beforeUpdate with AutoTimestamp are persisted"() {
given: "A user with auto timestamp is created"
def user = new UserWithBeforeUpdateAndAutoTimestamp(name: "Fred")
Expand Down
Loading