removing properties on set null, constructor
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package org.springframework.datastore.graph.neo4j.spi.node;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.*;
|
||||
|
||||
@@ -159,13 +161,19 @@ public aspect Neo4jNodeBacking extends AbstractTypeAnnotatingMixinFields<GraphEn
|
||||
|
||||
private static RelationshipBacked createRelationshipEntity(Class<? extends RelationshipBacked> relationshipType, Relationship rel) {
|
||||
try {
|
||||
final RelationshipBacked relationshipEntity = relationshipType.newInstance();
|
||||
final Constructor<? extends RelationshipBacked> constructor = relationshipType.getDeclaredConstructor();
|
||||
constructor.setAccessible(true);
|
||||
final RelationshipBacked relationshipEntity = constructor.newInstance();
|
||||
relationshipEntity.setUnderlyingRelationship(rel);
|
||||
return relationshipEntity;
|
||||
} catch (InstantiationException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (NoSuchMethodException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new RuntimeException(e.getTargetException());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -121,7 +121,12 @@ public aspect Neo4jRelationshipBacking extends AbstractTypeAnnotatingMixinFields
|
||||
throw new InvalidDataAccessApiUsageException("Please set start node and end node before assigning to other fields.");
|
||||
}
|
||||
String propName = FieldAccessorFactory.getNeo4jPropertyName(f);
|
||||
entity.getUnderlyingRelationship().setProperty(propName, newVal);
|
||||
if (newVal==null) {
|
||||
entity.getUnderlyingRelationship().removeProperty(propName);
|
||||
}
|
||||
else {
|
||||
entity.getUnderlyingRelationship().setProperty(propName, newVal);
|
||||
}
|
||||
log.info("SET " + f + " -> Neo4J simple relationship property [" + propName + "] with value=[" + newVal + "]");
|
||||
return proceed(entity, newVal);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user