use of org.hibernate.event.spi.MergeContext in project hibernate-orm by hibernate.
the class MergeContextTest method testMergeToManagedEntityFillFollowedByInvertUsingPutWithSetOperatedOnArg.
@Test
public void testMergeToManagedEntityFillFollowedByInvertUsingPutWithSetOperatedOnArg() {
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);
assertTrue(cache.containsKey(mergeEntity));
assertFalse(cache.containsKey(managedEntity));
assertTrue(cache.invertMap().containsKey(managedEntity));
assertFalse(cache.invertMap().containsKey(mergeEntity));
cache.clear();
checkCacheConsistency(cache, 0);
cache.put(mergeEntity, managedEntity, false);
assertFalse(cache.isOperatedOn(mergeEntity));
checkCacheConsistency(cache, 1);
assertTrue(cache.containsKey(mergeEntity));
assertFalse(cache.containsKey(managedEntity));
}
use of org.hibernate.event.spi.MergeContext in project hibernate-orm by hibernate.
the class MergeContextTest method testManagedEntityAssociatedWithNewAndExistingMergeEntities.
@Test
public void testManagedEntityAssociatedWithNewAndExistingMergeEntities() {
MergeContext cache = new MergeContext(session, new DoNothingEntityCopyObserver());
session.getTransaction().begin();
Simple mergeEntity = new Simple(1);
Simple managedEntity = new Simple(0);
cache.put(mergeEntity, managedEntity);
cache.put(new Simple(1), managedEntity);
}
use of org.hibernate.event.spi.MergeContext in project hibernate-orm by hibernate.
the class MergeContextTest method testMergeToManagedEntityFillFollowedByModifyEntrySet.
@Test
public void testMergeToManagedEntityFillFollowedByModifyEntrySet() {
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.entrySet().iterator();
try {
it.remove();
fail("should have thrown UnsupportedOperationException");
} catch (UnsupportedOperationException ex) {
// expected
}
Map.Entry entry = (Map.Entry) cache.entrySet().iterator().next();
try {
cache.entrySet().remove(entry);
fail("should have thrown UnsupportedOperationException");
} catch (UnsupportedOperationException ex) {
// expected
}
Map.Entry anotherEntry = new Map.Entry() {
private Object key = new Simple(3);
private Object value = 4;
@Override
public Object getKey() {
return key;
}
@Override
public Object getValue() {
return value;
}
@Override
public Object setValue(Object value) {
Object oldValue = this.value;
this.value = value;
return oldValue;
}
};
try {
cache.entrySet().add(anotherEntry);
fail("should have thrown UnsupportedOperationException");
} catch (UnsupportedOperationException ex) {
// expected
}
}
use of org.hibernate.event.spi.MergeContext in project hibernate-orm by hibernate.
the class MergeContextTest method testMergeToManagedEntityFillFollowedByInvert.
@Test
public void testMergeToManagedEntityFillFollowedByInvert() {
MergeContext cache = new MergeContext(session, new DoNothingEntityCopyObserver());
Object mergeEntity = new Simple(1);
Object managedEntity = new Simple(2);
cache.put(mergeEntity, managedEntity);
checkCacheConsistency(cache, 1);
assertTrue(cache.containsKey(mergeEntity));
assertFalse(cache.containsKey(managedEntity));
assertTrue(cache.invertMap().containsKey(managedEntity));
assertFalse(cache.invertMap().containsKey(mergeEntity));
}
use of org.hibernate.event.spi.MergeContext in project hibernate-orm by hibernate.
the class MergeContextTest method testMergeToManagedEntityFillFollowedByModifyValueOfEntrySetElement.
@Test
public void testMergeToManagedEntityFillFollowedByModifyValueOfEntrySetElement() {
MergeContext cache = new MergeContext(session, new DoNothingEntityCopyObserver());
Simple mergeEntity = new Simple(1);
Simple managedEntity = new Simple(0);
cache.put(mergeEntity, managedEntity, true);
Map.Entry entry = (Map.Entry) cache.entrySet().iterator().next();
((Simple) entry.getValue()).setValue(2);
assertEquals(2, managedEntity.getValue());
checkCacheConsistency(cache, 1);
entry = (Map.Entry) cache.entrySet().iterator().next();
assertSame(mergeEntity, entry.getKey());
assertSame(managedEntity, entry.getValue());
}
Aggregations