Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HHH-8973 - Fix tracking entity modifications to detached entities wit…
…h the modified flags feature.
- Loading branch information
Showing
13 changed files
with
189 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
35 changes: 35 additions & 0 deletions
35
...te-envers/src/main/java/org/hibernate/envers/event/spi/BaseEnversUpdateEventListener.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.envers.event.spi; | ||
|
||
import org.hibernate.envers.boot.internal.EnversService; | ||
import org.hibernate.envers.internal.entities.EntityConfiguration; | ||
|
||
/** | ||
* @author Chris Cranford | ||
*/ | ||
public abstract class BaseEnversUpdateEventListener extends BaseEnversEventListener { | ||
public BaseEnversUpdateEventListener(EnversService enversService) { | ||
super( enversService ); | ||
} | ||
|
||
/** | ||
* Returns whether the entity has {@code withModifiedFlag} features and has no old state, most likely implying | ||
* it was updated in a detached entity state. | ||
* | ||
* @param entityName The associated entity name. | ||
* @param oldState The event old (likely detached) entity state. | ||
* @return {@code true} if the entity is/has been updated in detached state, otherwise {@code false}. | ||
*/ | ||
protected boolean isDetachedEntityUpdate(String entityName, Object[] oldState) { | ||
final EntityConfiguration configuration = getEnversService().getEntitiesConfigurations().get( entityName ); | ||
if ( configuration.getPropertyMapper() != null && oldState == null ) { | ||
return configuration.getPropertyMapper().hasPropertiesWithModifiedFlag(); | ||
} | ||
return false; | ||
} | ||
} |
This file contains 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
40 changes: 40 additions & 0 deletions
40
...envers/src/main/java/org/hibernate/envers/event/spi/EnversPreUpdateEventListenerImpl.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.envers.event.spi; | ||
|
||
import org.hibernate.envers.boot.internal.EnversService; | ||
import org.hibernate.envers.internal.synchronization.AuditProcess; | ||
import org.hibernate.event.spi.PreUpdateEvent; | ||
import org.hibernate.event.spi.PreUpdateEventListener; | ||
|
||
/** | ||
* Envers-specific entity (pre) update event listener. | ||
* | ||
* @author Chris Cranford | ||
*/ | ||
public class EnversPreUpdateEventListenerImpl extends BaseEnversUpdateEventListener implements PreUpdateEventListener { | ||
public EnversPreUpdateEventListenerImpl(EnversService enversService) { | ||
super( enversService ); | ||
} | ||
|
||
@Override | ||
public boolean onPreUpdate(PreUpdateEvent event) { | ||
final String entityName = event.getPersister().getEntityName(); | ||
if ( getEnversService().getEntitiesConfigurations().isVersioned( entityName ) ) { | ||
checkIfTransactionInProgress( event.getSession() ); | ||
if ( isDetachedEntityUpdate( entityName, event.getOldState() ) ) { | ||
final AuditProcess auditProcess = getEnversService().getAuditProcessManager().get( event.getSession() ); | ||
auditProcess.cacheEntityState( | ||
event.getId(), | ||
entityName, | ||
event.getPersister().getDatabaseSnapshot( event.getId(), event.getSession() ) | ||
); | ||
} | ||
} | ||
return false; | ||
} | ||
} |
This file contains 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
23 changes: 23 additions & 0 deletions
23
...rc/main/java/org/hibernate/envers/internal/entities/mapper/ModifiedFlagMapperSupport.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.envers.internal.entities.mapper; | ||
|
||
/** | ||
* Contract for {@link PropertyMapper} implementations to expose whether they contain any property | ||
* that uses {@link org.hibernate.envers.internal.entities.PropertyData#isUsingModifiedFlag()}. | ||
* | ||
* @author Chris Cranford | ||
*/ | ||
public interface ModifiedFlagMapperSupport { | ||
/** | ||
* Returns whether the associated {@link PropertyMapper} has any properties that use | ||
* the {@code witModifiedFlag} feature. | ||
* | ||
* @return {@code true} if a property uses {@code withModifiedFlag}, otherwise {@code false}. | ||
*/ | ||
boolean hasPropertiesWithModifiedFlag(); | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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