This repository was archived by the owner on Mar 13, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 72
Reset embedded dirty checking #169
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,8 @@ import org.hibernate.Session | |
| import org.hibernate.engine.spi.SessionImplementor | ||
| import org.hibernate.engine.spi.Status | ||
| import org.hibernate.persister.entity.EntityPersister | ||
| import org.slf4j.Logger | ||
| import org.slf4j.LoggerFactory | ||
|
|
||
| /** | ||
| * A class to customize Hibernate dirtiness based on Grails {@link DirtyCheckable} interface | ||
|
|
@@ -42,6 +44,8 @@ import org.hibernate.persister.entity.EntityPersister | |
| @CompileStatic | ||
| class GrailsEntityDirtinessStrategy implements CustomEntityDirtinessStrategy { | ||
|
|
||
| protected static final Logger LOG = LoggerFactory.getLogger(GrailsEntityDirtinessStrategy.class) | ||
|
|
||
| @Override | ||
| boolean canDirtyCheck(Object entity, EntityPersister persister, Session session) { | ||
| return entity instanceof DirtyCheckable | ||
|
|
@@ -56,6 +60,30 @@ class GrailsEntityDirtinessStrategy implements CustomEntityDirtinessStrategy { | |
| void resetDirty(Object entity, EntityPersister persister, Session session) { | ||
| if (canDirtyCheck(entity, persister, session)) { | ||
| cast(entity).trackChanges() | ||
| try { | ||
| PersistentEntity persistentEntity = GormEnhancer.findEntity(Hibernate.getClass(entity)) | ||
| if (persistentEntity != null) { | ||
| resetDirtyEmbeddedObjects(persistentEntity, entity, persister, session) | ||
| } | ||
| } catch (IllegalStateException e) { | ||
| if (LOG.isDebugEnabled()) { | ||
| LOG.debug(e.message, e) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private void resetDirtyEmbeddedObjects(PersistentEntity persistentEntity, | ||
| Object entity, | ||
| EntityPersister persister, | ||
| Session session) { | ||
|
|
||
| if (DirtyCheckingSupport.areEmbeddedDirty(persistentEntity, entity)) { | ||
| final associations = persistentEntity.getEmbedded() | ||
| for (Embedded a in associations) { | ||
| final value = a.reader.read(entity) | ||
| resetDirty(value, persister, session) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the value is |
||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we swallowing the exception here and logging at
debuglevel?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this PR, we are recursively resetting the
$changedPropertiesof embedded objects. In cases where the embedded object is not a PersistentEntity the recursion will break, andIllegalStateExceptionis thrown as: