some TODOs and suggestions for further development

This commit is contained in:
Michael Hunger
2010-08-09 09:59:18 +02:00
parent b9f71bdebc
commit e9078059ee
4 changed files with 114 additions and 60 deletions

View File

@@ -1,44 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>datastore-graph</name>
<comment/>
<projects/>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
</buildCommand>
<buildCommand>
<name>org.maven.ide.eclipse.maven2Builder</name>
</buildCommand>
<buildCommand>
<name>org.eclipse.ajdt.core.ajbuilder</name>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
</buildCommand>
<buildCommand>
<name>org.eclipse.ajdt.core.ajbuilder</name>
<arguments>
<dictionary>
<key>aspectPath</key>
<value>org.springframework.aspects</value>
</dictionary>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.core.springbuilder</name>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.maven.ide.eclipse.maven2Nature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.ajdt.ui.ajnature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>com.springsource.sts.roo.core.nature</nature>
<nature>org.springframework.ide.eclipse.core.springnature</nature>
</natures>
</projectDescription>
<name>datastore-graph</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.maven.ide.eclipse.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.ajdt.core.ajbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.ajdt.core.ajbuilder</name>
<arguments>
<dictionary>
<key>aspectPath</key>
<value>org.springframework.aspects</value>
</dictionary>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.core.springbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.maven.ide.eclipse.maven2Nature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.ajdt.ui.ajnature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>com.springsource.sts.roo.core.nature</nature>
<nature>org.springframework.ide.eclipse.core.springnature</nature>
</natures>
</projectDescription>

View File

@@ -104,9 +104,9 @@ public aspect Neo4jNodeBacking extends AbstractTypeAnnotatingMixinFields<GraphEn
FieldSignature fieldSignature=(FieldSignature) thisJoinPoint.getSignature();
Field f = fieldSignature.getField();
// TODO fix arrays
// TODO fix arrays, TODO serialize other types as byte[] or string (for indexing, querying) via Annotation
if (f.getType().isPrimitive() || f.getType().equals(String.class)) {
String propName = getNeo4jPropertyName(thisJoinPoint.getSignature());
String propName = getNeo4jPropertyName(f);
log.info("GET " + f + " <- Neo4J simple node property [" + propName + "]");
return entity.getUnderlyingNode().getProperty(propName, null);
}
@@ -118,7 +118,7 @@ public aspect Neo4jNodeBacking extends AbstractTypeAnnotatingMixinFields<GraphEn
if (me == null) {
throw new IllegalStateException("Entity must have a backing Node");
}
org.neo4j.graphdb.Relationship singleRelationship = getRelationship(me, fieldSignature);
org.neo4j.graphdb.Relationship singleRelationship = getRelationship(me, f);
// TODO is this correct
// [mh] i assume only for null
@@ -137,10 +137,10 @@ public aspect Neo4jNodeBacking extends AbstractTypeAnnotatingMixinFields<GraphEn
}
private org.neo4j.graphdb.Relationship getRelationship(Node me, FieldSignature f) {
Relationship r = f.getField().getAnnotation(Relationship.class);
private org.neo4j.graphdb.Relationship getRelationship(Node me, Field field) {
Relationship r = field.getAnnotation(Relationship.class);
if (r == null) {
RelationshipType type=DynamicRelationshipType.withName(getNeo4jPropertyName((Signature)f));
RelationshipType type=DynamicRelationshipType.withName(getNeo4jPropertyName(field));
return me.getSingleRelationship(type, Direction.OUTGOING);
}
RelationshipType type = DynamicRelationshipType.withName(r.type());
@@ -154,7 +154,7 @@ public aspect Neo4jNodeBacking extends AbstractTypeAnnotatingMixinFields<GraphEn
Field f = fieldSignature.getField();
// TODO fix arrays
if (f.getType().isPrimitive() || f.getType().equals(String.class)) {
String propName = getNeo4jPropertyName(thisJoinPoint.getSignature());
String propName = getNeo4jPropertyName(f);
entity.getUnderlyingNode().setProperty(propName, newVal);
log.info("SET " + f + " -> Neo4J simple node property [" + propName + "] with value=[" + newVal + "]");
return null;
@@ -162,12 +162,10 @@ public aspect Neo4jNodeBacking extends AbstractTypeAnnotatingMixinFields<GraphEn
// Look for a relationship
if (isNeo4jRelationshipField(f)) {
Relationship r = f.getAnnotation(Relationship.class);
if (r == null) {
graphEntityFieldSet(entity, (NodeBacked) newVal, getNeo4jPropertyName(thisJoinPoint.getSignature()),Direction.OUTGOING);
} else {
graphEntityFieldSet(entity, (NodeBacked) newVal, r.type(), r.direction().toNeo4jDir());
}
org.neo4j.graphdb.Relationship relationship=getRelationship(entity.getUnderlyingNode(), f);
if (relationship!=null) relationship.delete();
addRelationship(entity, newVal, f);
log.info("SET " + f + " -> Neo4J relationship with value=[" + newVal + "]");
return null;
}
@@ -176,9 +174,19 @@ public aspect Neo4jNodeBacking extends AbstractTypeAnnotatingMixinFields<GraphEn
return proceed(entity, newVal);
}
}
private void addRelationship(NodeBacked entity, Object newVal, Field f) {
Relationship r = f.getAnnotation(Relationship.class);
if (r == null) {
addRelationship(entity, (NodeBacked) newVal, getNeo4jPropertyName(f),Direction.OUTGOING);
} else {
addRelationship(entity, (NodeBacked) newVal, r.type(), r.direction().toNeo4jDir());
}
}
// todo what happens to the previous value, remove relationships?
private void graphEntityFieldSet(NodeBacked entity, NodeBacked newVal, String relationshipName, Direction direction) {
private void addRelationship(NodeBacked entity, NodeBacked newVal, String relationshipName, Direction direction) {
RelationshipType type = DynamicRelationshipType.withName(relationshipName);
Node me = entity.getUnderlyingNode();
@@ -199,8 +207,8 @@ public aspect Neo4jNodeBacking extends AbstractTypeAnnotatingMixinFields<GraphEn
}
private String getNeo4jPropertyName(Signature sig) {
return sig.toShortString();
private String getNeo4jPropertyName(Field field) {
return String.format("%s.%s",field.getDeclaringClass().getSimpleName(),field.getName());
}
}

View File

@@ -1,5 +1,8 @@
package org.springframework.persistence.test;
import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import org.springframework.persistence.graph.Direction;
import org.springframework.persistence.graph.GraphEntity;
import org.springframework.persistence.graph.Relationship;
@@ -18,6 +21,20 @@ public class Person {
@Relationship(type="mother",direction=Direction.BOTH)
Person mother;
// @Property(serialize=SerializationPolicy.STRING, index=true, queryable=true, removeOnReset=true)
// Date birthday;
/*
{
Field f;
if (f.getGenericType() instanceof ParameterizedType) {
((ParameterizedType)(f.getGenericType())).getActualTypeArguments();
}
}
@Relationship( target=Person.class, cardinality="", type="children",)
Collection<Person> children;
*/
public Person(String name, int age) {
this.name = name;
this.age = age;

View File

@@ -3,6 +3,7 @@ package org.springframework.persistence.test.graph;
import junit.framework.Assert;
import org.junit.After;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.neo4j.graphdb.DynamicRelationshipType;
@@ -51,15 +52,34 @@ public class Neo4jGraphPersistenceTest {
@Test
@Transactional
public void testCreateRelationshipOnSet() {
public void testCreateRelationshipWithoutAnnotationOnSet() {
Person p = new Person("Michael", 35);
Person spouse=new Person("Tina",36);
p.setSpouse(spouse);
Assert.assertEquals("Tina", p.getSpouse().getUnderlyingNode().getProperty("Person.name"));
Node spouseNode=p.getUnderlyingNode().getSingleRelationship(DynamicRelationshipType.withName("Person.spouse"), org.neo4j.graphdb.Direction.OUTGOING).getEndNode();
Assert.assertEquals(spouse.getUnderlyingNode(), spouseNode);
Assert.assertEquals(spouse, p.getSpouse());
}
@Test
@Ignore
@Transactional
public void testCreateRelationshipWithAnnotationOnSet() {
Person p = new Person("Michael", 35);
Person mother=new Person("Gabi",60);
p.setMother(mother);
Assert.assertEquals("Gabi", p.getMother().getUnderlyingNode().getProperty("Person.name"));
Node motherNode=p.getUnderlyingNode().getSingleRelationship(DynamicRelationshipType.withName("mother"), org.neo4j.graphdb.Direction.BOTH).getEndNode();
Assert.assertEquals(mother.getUnderlyingNode(), motherNode);
Assert.assertEquals(mother, p.getMother());
}
// TODO test delete relationship
// TODO test delete previous relationship
// TODO test incoming relationship
// TODO test bidirectional relationship
// TODO test remove property (set to null)
@Test
@Transactional