forked from hibernate/hibernate-orm
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EntityTrackingRevisionListener extension
- Loading branch information
1 parent
110c3a4
commit 19bde34
Showing
22 changed files
with
289 additions
and
49 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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,16 +26,21 @@ | |
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import javax.persistence.EntityManager; | ||
|
||
import org.junit.Test; | ||
|
||
import org.hibernate.envers.RevisionType; | ||
import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; | ||
import org.hibernate.envers.test.Priority; | ||
import org.hibernate.envers.test.entities.manytomany.MapOwnedEntity; | ||
import org.hibernate.envers.test.entities.manytomany.MapOwningEntity; | ||
import org.hibernate.envers.test.tools.NotificationCheckRevisionListener; | ||
import org.hibernate.envers.test.tools.TestTools; | ||
|
||
import static org.hibernate.envers.test.tools.NotificationCheckRevisionListener.expectNotification; | ||
|
||
/** | ||
* @author Adam Warski (adam at warski dot org) | ||
*/ | ||
|
@@ -51,7 +56,12 @@ protected Class<?>[] getAnnotatedClasses() { | |
return new Class[] { MapOwningEntity.class, MapOwnedEntity.class }; | ||
} | ||
|
||
@Test | ||
@Override | ||
protected void addConfigOptions(Map options) { | ||
options.put( "org.hibernate.envers.revision_listener", NotificationCheckRevisionListener.class.getName() ); | ||
} | ||
|
||
@Test | ||
@Priority(10) | ||
public void initData() { | ||
EntityManager em = getEntityManager(); | ||
|
@@ -72,7 +82,14 @@ public void initData() { | |
em.persist(ing1); | ||
em.persist(ing2); | ||
|
||
expectNotification( MapOwnedEntity.class, ed1.getId(), ed1, RevisionType.ADD ); | ||
expectNotification( MapOwnedEntity.class, ed2.getId(), ed2, RevisionType.ADD ); | ||
expectNotification( MapOwningEntity.class, ing1.getId(), ing1, RevisionType.ADD ); | ||
expectNotification( MapOwningEntity.class, ing2.getId(), ing2, RevisionType.ADD ); | ||
expectNotification( MapOwningEntity.class, ing2.getId(), TestTools.makeMap( "2", ed2 ), RevisionType.MOD ); | ||
|
||
em.getTransaction().commit(); | ||
NotificationCheckRevisionListener.checkAllExpectedNotificationsProcessed(); | ||
|
||
// Revision 2 (ing1: adding two mappings, ing2: replacing an existing mapping) | ||
|
||
|
@@ -88,7 +105,15 @@ public void initData() { | |
|
||
ing2.getReferences().put("2", ed1); | ||
|
||
expectNotification( MapOwningEntity.class, ing1.getId(), TestTools.makeMap( "1", ed1, "2", ed1 ), RevisionType.MOD ); | ||
expectNotification( MapOwningEntity.class, ing1.getId(), ing1, RevisionType.MOD ); | ||
expectNotification( MapOwnedEntity.class, ed1.getId(), ed1, RevisionType.MOD ); | ||
expectNotification( MapOwningEntity.class, ing2.getId(), TestTools.makeMap( "2", ed1 ), RevisionType.MOD ); | ||
expectNotification( MapOwningEntity.class, ing2.getId(), ing2, RevisionType.MOD ); | ||
expectNotification( MapOwnedEntity.class, ed2.getId(), ed2, RevisionType.MOD ); | ||
|
||
em.getTransaction().commit(); | ||
NotificationCheckRevisionListener.checkAllExpectedNotificationsProcessed(); | ||
|
||
// No revision (ing1: adding an existing mapping, ing2: removing a non existing mapping) | ||
em.getTransaction().begin(); | ||
|
@@ -101,6 +126,7 @@ public void initData() { | |
ing2.getReferences().remove("3"); | ||
|
||
em.getTransaction().commit(); | ||
NotificationCheckRevisionListener.checkAllExpectedNotificationsProcessed(); | ||
|
||
// Revision 3 (ing1: clearing, ing2: replacing with a new map) | ||
em.getTransaction().begin(); | ||
|
@@ -112,7 +138,16 @@ public void initData() { | |
ing2.setReferences(new HashMap<String, MapOwnedEntity>()); | ||
ing2.getReferences().put("1", ed2); | ||
|
||
expectNotification( MapOwningEntity.class, ing2.getId(), ing2, RevisionType.MOD ); | ||
expectNotification( MapOwnedEntity.class, ed1.getId(), ed1, RevisionType.MOD ); | ||
expectNotification( MapOwningEntity.class, ing1.getId(), TestTools.makeMap(), RevisionType.MOD ); | ||
expectNotification( MapOwningEntity.class, ing1.getId(), ing1, RevisionType.MOD ); | ||
expectNotification( MapOwningEntity.class, ing2.getId(), TestTools.makeMap( "1", ed2 ), RevisionType.MOD ); | ||
expectNotification( MapOwnedEntity.class, ed2.getId(),ed2, RevisionType.MOD ); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
adamw
|
||
|
||
em.getTransaction().commit(); | ||
NotificationCheckRevisionListener.checkAllExpectedNotificationsProcessed(); | ||
|
||
// | ||
|
||
ed1_id = ed1.getId(); | ||
|
Oops, something went wrong.
Maybe wrap the parameters in an object so that more fields can be added there in a backward-compatible way in the future.