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 1e3f0cd99..5b64013fd 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,14 +1,11 @@ package org.springframework.datastore.graph.neo4j.spi.node; import java.lang.reflect.Field; +import java.lang.reflect.Modifier; import java.util.*; import org.aspectj.lang.reflect.FieldSignature; -import org.neo4j.graphdb.GraphDatabaseService; -import org.neo4j.graphdb.Node; -import org.neo4j.graphdb.NotInTransactionException; -import org.neo4j.graphdb.Relationship; -import org.neo4j.graphdb.RelationshipType; +import org.neo4j.graphdb.*; import org.neo4j.kernel.EmbeddedGraphDatabase; import org.neo4j.util.GraphDatabaseUtil; import org.springframework.beans.factory.annotation.Autowired; @@ -149,6 +146,24 @@ public aspect Neo4jNodeBacking extends AbstractTypeAnnotatingMixinFields(); this.dirty.put(f,previousValue); } +/* + public R NodeBacked.relateTo(N node, Class relationshipType, String type) { + Relationship rel = this.getUnderlyingNode().createRelationshipTo(node.getUnderlyingNode(), DynamicRelationshipType.withName(type)); + return relationshipEntityInstantiator.createEntityFromState(rel, relationshipType); + } +*/ + public RelationshipBacked NodeBacked.relateTo(NodeBacked node, Class relationshipType, String type) { + Relationship rel = this.getUnderlyingNode().createRelationshipTo(node.getUnderlyingNode(), DynamicRelationshipType.withName(type)); + try { + final RelationshipBacked relationshipEntity = relationshipType.newInstance(); + relationshipEntity.setUnderlyingRelationship(rel); + return relationshipEntity; + } catch (InstantiationException e) { + throw new RuntimeException(e); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } private Iterable> NodeBacked.eachDirty() { return this.dirty!=null ? this.dirty.entrySet() : Collections.emptyMap().entrySet(); @@ -174,6 +189,7 @@ public aspect Neo4jNodeBacking extends AbstractTypeAnnotatingMixinFields entry, Field field) { final Object nodeValue = getNodePropertyOrRelationship(field, entity).value; final Object previousValue = entry.getValue(); @@ -256,6 +274,7 @@ public aspect Neo4jNodeBacking extends AbstractTypeAnnotatingMixinFields