From c92390388d148d9f5542fa435b9078c5a3c19a10 Mon Sep 17 00:00:00 2001 From: Michael Hunger Date: Mon, 6 Sep 2010 10:22:56 +0200 Subject: [PATCH] removing properties on set null, constructor --- .../datastore/graph/neo4j/spi/node/Neo4jNodeBacking.aj | 10 +++++++++- .../neo4j/spi/relationship/Neo4jRelationshipBacking.aj | 7 ++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/springframework/datastore/graph/neo4j/spi/node/Neo4jNodeBacking.aj b/src/main/java/org/springframework/datastore/graph/neo4j/spi/node/Neo4jNodeBacking.aj index 28bb6102a..81ea66846 100644 --- a/src/main/java/org/springframework/datastore/graph/neo4j/spi/node/Neo4jNodeBacking.aj +++ b/src/main/java/org/springframework/datastore/graph/neo4j/spi/node/Neo4jNodeBacking.aj @@ -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 relationshipType, Relationship rel) { try { - final RelationshipBacked relationshipEntity = relationshipType.newInstance(); + final Constructor 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()); } } diff --git a/src/main/java/org/springframework/datastore/graph/neo4j/spi/relationship/Neo4jRelationshipBacking.aj b/src/main/java/org/springframework/datastore/graph/neo4j/spi/relationship/Neo4jRelationshipBacking.aj index b7817fe8b..7cd51a5f6 100644 --- a/src/main/java/org/springframework/datastore/graph/neo4j/spi/relationship/Neo4jRelationshipBacking.aj +++ b/src/main/java/org/springframework/datastore/graph/neo4j/spi/relationship/Neo4jRelationshipBacking.aj @@ -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); }