void findDirty()

in grails-datastore-gorm-hibernate/src/main/groovy/org/grails/orm/hibernate/dirty/GrailsEntityDirtinessStrategy.groovy [91:141]


    void findDirty(Object entity, EntityPersister persister, Session session, CustomEntityDirtinessStrategy.DirtyCheckContext dirtyCheckContext) {
        Status status = getStatus(session, entity)
        if(entity instanceof DirtyCheckable) {
            dirtyCheckContext.doDirtyChecking(
                    new CustomEntityDirtinessStrategy.AttributeChecker() {
                        @Override
                        boolean isDirty(CustomEntityDirtinessStrategy.AttributeInformation attributeInformation) {
                            String propertyName = attributeInformation.name
                            if(status != null) {
                                if(status == Status.MANAGED) {
                                    // perform dirty check
                                    DirtyCheckable dirtyCheckable = cast(entity)
                                    if(GormProperties.LAST_UPDATED == propertyName) {
                                        return dirtyCheckable.hasChanged()
                                    }
                                    else {
                                        if(dirtyCheckable.hasChanged(propertyName)) {
                                            return true
                                        }
                                        else {
                                            PersistentEntity gormEntity = GormEnhancer.findEntity(Hibernate.getClass(entity))
                                            PersistentProperty prop = gormEntity.getPropertyByName(attributeInformation.name)
                                            if(prop instanceof Embedded) {
                                                def val = prop.reader.read(entity)
                                                if( val instanceof DirtyCheckable ) {
                                                    return ((DirtyCheckable)val).hasChanged()
                                                }
                                                else {
                                                    return false
                                                }
                                            }
                                            else {
                                                return false
                                            }
                                        }
                                    }
                                }
                                else {
                                    // either deleted or in a state that cannot be regarded as dirty
                                    return false
                                }
                            }
                            else {
                                // a new object not within the session
                                return true
                            }
                        }
                    }
            )
        }
    }