Search in sources :

Example 11 with MergeContext

use of org.hibernate.event.spi.MergeContext in project hibernate-orm by hibernate.

the class MergeContextTest method testMergeToManagedEntityFillFollowedByIterateEntrySet.

@Test
public void testMergeToManagedEntityFillFollowedByIterateEntrySet() {
    MergeContext cache = new MergeContext(session, new DoNothingEntityCopyObserver());
    Object mergeEntity = new Simple(1);
    Object managedEntity = new Simple(2);
    cache.put(mergeEntity, managedEntity, true);
    checkCacheConsistency(cache, 1);
    Iterator it = cache.entrySet().iterator();
    assertTrue(it.hasNext());
    Map.Entry entry = (Map.Entry) it.next();
    assertSame(mergeEntity, entry.getKey());
    assertSame(managedEntity, entry.getValue());
    assertFalse(it.hasNext());
}
Also used : Iterator(java.util.Iterator) MergeContext(org.hibernate.event.spi.MergeContext) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 12 with MergeContext

use of org.hibernate.event.spi.MergeContext in project hibernate-orm by hibernate.

the class MergeContextTest method testMergeToManagedEntityFillFollowedByModifyValues.

@Test
public void testMergeToManagedEntityFillFollowedByModifyValues() {
    MergeContext cache = new MergeContext(session, new DoNothingEntityCopyObserver());
    Object mergeEntity = new Simple(1);
    Object managedEntity = new Simple(2);
    cache.put(mergeEntity, managedEntity, true);
    Iterator it = cache.values().iterator();
    try {
        it.remove();
        fail("should have thrown UnsupportedOperationException");
    } catch (UnsupportedOperationException ex) {
    // expected
    }
    try {
        cache.values().remove(managedEntity);
        fail("should have thrown UnsupportedOperationException");
    } catch (UnsupportedOperationException ex) {
    // expected
    }
    Object newmanagedEntity = new Simple(3);
    try {
        cache.values().add(newmanagedEntity);
        fail("should have thrown UnsupportedOperationException");
    } catch (UnsupportedOperationException ex) {
    // expected
    }
}
Also used : Iterator(java.util.Iterator) MergeContext(org.hibernate.event.spi.MergeContext) Test(org.junit.Test)

Example 13 with MergeContext

use of org.hibernate.event.spi.MergeContext in project hibernate-orm by hibernate.

the class MergeContextTest method testMergeToManagedEntityFillFollowedByModifyKeys.

@Test
public void testMergeToManagedEntityFillFollowedByModifyKeys() {
    MergeContext cache = new MergeContext(session, new DoNothingEntityCopyObserver());
    Object mergeEntity = new Simple(1);
    Object managedEntity = new Simple(2);
    cache.put(mergeEntity, managedEntity, true);
    Iterator it = cache.keySet().iterator();
    try {
        it.remove();
        fail("should have thrown UnsupportedOperationException");
    } catch (UnsupportedOperationException ex) {
    // expected
    }
    try {
        cache.keySet().remove(mergeEntity);
        fail("should have thrown UnsupportedOperationException");
    } catch (UnsupportedOperationException ex) {
    // expected
    }
    Object newmanagedEntity = new Simple(3);
    try {
        cache.keySet().add(newmanagedEntity);
        fail("should have thrown UnsupportedOperationException");
    } catch (UnsupportedOperationException ex) {
    // expected
    }
}
Also used : Iterator(java.util.Iterator) MergeContext(org.hibernate.event.spi.MergeContext) Test(org.junit.Test)

Example 14 with MergeContext

use of org.hibernate.event.spi.MergeContext in project hibernate-orm by hibernate.

the class MergeContextTest method testReplaceManagedEntity.

@Test
public void testReplaceManagedEntity() {
    MergeContext cache = new MergeContext(session, new DoNothingEntityCopyObserver());
    Simple mergeEntity = new Simple(1);
    Simple managedEntity = new Simple(0);
    cache.put(mergeEntity, managedEntity);
    Simple managedEntityNew = new Simple(0);
    try {
        cache.put(mergeEntity, managedEntityNew);
    } catch (IllegalArgumentException ex) {
    // expected; cannot replace the managed entity result for a particular merge entity.
    }
}
Also used : MergeContext(org.hibernate.event.spi.MergeContext) Test(org.junit.Test)

Aggregations

MergeContext (org.hibernate.event.spi.MergeContext)14 Test (org.junit.Test)13 HashMap (java.util.HashMap)5 Iterator (java.util.Iterator)4 Map (java.util.Map)4 EntityCopyObserver (org.hibernate.event.spi.EntityCopyObserver)1