From aae4be683f86b613928619b645a1a4f1e525c5a6 Mon Sep 17 00:00:00 2001 From: David Montag Date: Tue, 10 Aug 2010 13:28:52 +0200 Subject: [PATCH] Added tests for erroneous arguments/uses of properties and constructor, e.g. outside of tx, or circular refs. Does not include any checks of fields on construction or anything like that. --- .../graph/neo4j/Neo4jNodeBacking.aj | 74 +++++++++++-------- .../test/graph/Neo4jGraphPersistenceTest.java | 59 +++++++++++++-- 2 files changed, 97 insertions(+), 36 deletions(-) diff --git a/src/main/java/org/springframework/persistence/graph/neo4j/Neo4jNodeBacking.aj b/src/main/java/org/springframework/persistence/graph/neo4j/Neo4jNodeBacking.aj index ab79dc804..c0aaaecdf 100644 --- a/src/main/java/org/springframework/persistence/graph/neo4j/Neo4jNodeBacking.aj +++ b/src/main/java/org/springframework/persistence/graph/neo4j/Neo4jNodeBacking.aj @@ -10,9 +10,12 @@ import org.neo4j.graphdb.Direction; import org.neo4j.graphdb.DynamicRelationshipType; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Node; +import org.neo4j.graphdb.NotInTransactionException; import org.neo4j.graphdb.RelationshipType; import org.neo4j.util.GraphDatabaseUtil; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.dao.InvalidDataAccessApiUsageException; +import org.springframework.dao.InvalidDataAccessResourceUsageException; import org.springframework.persistence.graph.GraphEntity; import org.springframework.persistence.graph.Relationship; import org.springframework.persistence.support.AbstractTypeAnnotatingMixinFields; @@ -59,15 +62,19 @@ public aspect Neo4jNodeBacking extends AbstractTypeAnnotatingMixinFields Neo4J simple node property [" + propName + "] with value=[" + newVal + "]"); - return null; - } - - // Look for a relationship - if (isNeo4jRelationshipField(f)) { - RelationshipInfo relInfo = RelationshipInfo.forField(f); - graphEntityFieldSet(entity, (NodeBacked) newVal, relInfo); + try { + FieldSignature fieldSignature=(FieldSignature) thisJoinPoint.getSignature(); + Field f = fieldSignature.getField(); + // TODO fix arrays + if (f.getType().isPrimitive() || f.getType().equals(String.class)) { + String propName = getNeo4jPropertyName(f); + entity.getUnderlyingNode().setProperty(propName, newVal); + log.info("SET " + f + " -> Neo4J simple node property [" + propName + "] with value=[" + newVal + "]"); + return null; + } + + // Look for a relationship + if (isNeo4jRelationshipField(f)) { + RelationshipInfo relInfo = RelationshipInfo.forField(f); + graphEntityFieldSet(entity, (NodeBacked) newVal, relInfo); - log.info("SET " + f + " -> Neo4J relationship with value=[" + newVal + "]"); - return null; - } - else { - log.info("Ignored SET " + f + ": " + f.getType().getName() + " not primitive or GraphEntity"); - return proceed(entity, newVal); + log.info("SET " + f + " -> Neo4J relationship with value=[" + newVal + "]"); + return null; + } + else { + log.info("Ignored SET " + f + ": " + f.getType().getName() + " not primitive or GraphEntity"); + return proceed(entity, newVal); + } + } catch(NotInTransactionException e) { + throw new InvalidDataAccessResourceUsageException("Not in a Neo4j transaction.", e); } } @@ -179,10 +190,13 @@ public aspect Neo4jNodeBacking extends AbstractTypeAnnotatingMixinFields