Permalink
Browse files

do not invalidate instances after migration

  • Loading branch information...
DirkMahler committed Nov 2, 2018
1 parent 9ba149e commit 812317b61809a064f939c1465569fde4362fa4e9
@@ -358,7 +358,6 @@ private CompositeObject createByExample(Class<?> type, Class<?>[] types, Map<Pri
if (migrationStrategy != null) {
migrationStrategy.migrate(instance, migratedInstance.as(targetType));
}
entityInstanceManager.closeInstance(instance);
return migratedInstance;
}
@@ -51,7 +51,7 @@
public CompositeObject add(Class<?> newType, Class<?>... newTypes) {
TypeMetadataSet<EntityTypeMetadata<EntityMetadata>> types = getDiscriminators(newType, newTypes);
Set<EntityDiscriminator> newDiscriminators = new HashSet<>(metadataProvider.getEntityDiscriminators(types));
Entity entity = invalidateInstance(entityInstanceManager);
Entity entity = removeInstance(entityInstanceManager);
Set<EntityDiscriminator> entityDiscriminators = datastoreEntityManager.getEntityDiscriminators(entity);
newDiscriminators.removeAll(entityDiscriminators);
datastoreEntityManager.addDiscriminators(types, entity, newDiscriminators);
@@ -62,7 +62,7 @@ public CompositeObject add(Class<?> newType, Class<?>... newTypes) {
public CompositeObject remove(Class<?> obsoleteType, Class<?>... obsoleteTypes) {
TypeMetadataSet<EntityTypeMetadata<EntityMetadata>> types = getDiscriminators(obsoleteType, obsoleteTypes);
Set<EntityDiscriminator> obsoleteDiscriminators = new HashSet<>(metadataProvider.getEntityDiscriminators(types));
Entity entity = invalidateInstance(entityInstanceManager);
Entity entity = removeInstance(entityInstanceManager);
Set<EntityDiscriminator> entityDiscriminators = datastoreEntityManager.getEntityDiscriminators(entity);
obsoleteDiscriminators.retainAll(entityDiscriminators);
datastoreEntityManager.removeDiscriminators(types, entity, obsoleteDiscriminators);
@@ -78,10 +78,9 @@ public CompositeObject remove(Class<?> obsoleteType, Class<?>... obsoleteTypes)
return typeMetadata;
}
private Entity invalidateInstance(AbstractInstanceManager<EntityId, Entity> entityInstanceManager) {
private Entity removeInstance(AbstractInstanceManager<EntityId, Entity> entityInstanceManager) {
Entity entity = entityInstanceManager.getDatastoreType(instance);
entityInstanceManager.removeInstance(instance);
entityInstanceManager.closeInstance(instance);
return entity;
}
@@ -43,6 +43,7 @@ public void downCast() {
xoManager.currentTransaction().begin();
B b = xoManager.migrate(a, B.class);
assertThat(a == b, equalTo(false));
assertThat(a.getValue(), equalTo("Value"));
assertThat(b.getValue(), equalTo("Value"));
xoManager.currentTransaction().commit();
xoManager.close();
@@ -101,6 +102,7 @@ public void addType() {
CompositeObject compositeObject = xoManager.migrate(a).add(C.class);
assertThat(compositeObject, instanceOf(A.class));
assertThat(compositeObject, instanceOf(C.class));
assertThat(a.getValue(), equalTo("Value"));
assertThat(compositeObject.as(A.class).getValue(), equalTo("Value"));
xoManager.currentTransaction().commit();
xoManager.close();
@@ -117,6 +119,7 @@ public void removeType() {
A a = xoManager.migrate(compositeObject).remove(C.class).as(A.class);
assertThat(a, instanceOf(A.class));
assertThat(a, not(instanceOf(C.class)));
assertThat(compositeObject.getId(), equalTo(((CompositeObject)a).getId()));
assertThat(a.getValue(), equalTo("Value"));
xoManager.currentTransaction().commit();
xoManager.close();

0 comments on commit 812317b

Please sign in to comment.