repackaged, annotations for roo

This commit is contained in:
Michael Hunger
2010-08-27 23:03:47 +02:00
parent c1df1f6807
commit 0ad71da7dc
39 changed files with 227 additions and 142 deletions

View File

@@ -1,4 +1,4 @@
package org.springframework.persistence.graph;
package org.springframework.datastore.graph.api;
public enum Direction {

View File

@@ -0,0 +1,15 @@
package org.springframework.datastore.graph.api;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @author Michael Hunger
* @since 27.08.2010
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface GraphEntity {
}

View File

@@ -0,0 +1,20 @@
package org.springframework.datastore.graph.api;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @author Michael Hunger
* @since 27.08.2010
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface GraphEntityRelationship {
String type();
Direction direction() default Direction.OUTGOING;
Class<? extends NodeBacked> elementClass() default NodeBacked.class;
}

View File

@@ -0,0 +1,20 @@
package org.springframework.datastore.graph.api;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @author Michael Hunger
* @since 27.08.2010
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface GraphEntityRelationshipEntity {
String type();
Direction direction() default Direction.OUTGOING;
Class<? extends RelationshipBacked> elementClass() default RelationshipBacked.class;
}

View File

@@ -1,16 +1,13 @@
package org.springframework.persistence.graph;
package org.springframework.datastore.graph.api;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.persistence.graph.neo4j.NodeBacked;
import org.springframework.persistence.graph.neo4j.RelationshipBacked;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Graph {
public @interface GraphInactive {
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)

View File

@@ -0,0 +1,15 @@
package org.springframework.datastore.graph.api;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @author Michael Hunger
* @since 27.08.2010
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface GraphRelationship {
}

View File

@@ -0,0 +1,15 @@
package org.springframework.datastore.graph.api;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @author Michael Hunger
* @since 27.08.2010
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface GraphRelationshipEndNode {
}

View File

@@ -0,0 +1,15 @@
package org.springframework.datastore.graph.api;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @author Michael Hunger
* @since 27.08.2010
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface GraphRelationshipStartNode {
}

View File

@@ -1,4 +1,4 @@
package org.springframework.persistence.graph.neo4j;
package org.springframework.datastore.graph.api;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;

View File

@@ -1,4 +1,4 @@
package org.springframework.persistence.graph.neo4j;
package org.springframework.datastore.graph.api;
import org.neo4j.graphdb.Relationship;

View File

@@ -1,4 +1,6 @@
package org.springframework.persistence.graph.neo4j;
package org.springframework.datastore.graph.neo4j.fieldaccess;
import org.springframework.datastore.graph.api.NodeBacked;
public interface FieldAccessor {

View File

@@ -1,4 +1,4 @@
package org.springframework.persistence.graph.neo4j;
package org.springframework.datastore.graph.neo4j.fieldaccess;
import java.lang.reflect.Field;
import java.util.Collection;
@@ -7,7 +7,10 @@ import org.neo4j.graphdb.Direction;
import org.neo4j.graphdb.DynamicRelationshipType;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.springframework.persistence.graph.Graph;
import org.springframework.datastore.graph.api.GraphEntityRelationship;
import org.springframework.datastore.graph.api.GraphEntityRelationshipEntity;
import org.springframework.datastore.graph.api.NodeBacked;
import org.springframework.datastore.graph.api.RelationshipBacked;
import org.springframework.persistence.support.EntityInstantiator;
public class FieldAccessorFactory {
@@ -20,26 +23,26 @@ public class FieldAccessorFactory {
}
public FieldAccessor forField(Field field) {
Graph.Entity.Relationship relAnnotation = field.getAnnotation(Graph.Entity.Relationship.class);
GraphEntityRelationship relAnnotation = field.getAnnotation(GraphEntityRelationship.class);
if (isSingleRelationshipField(field)) {
Class<? extends NodeBacked> relatedType = (Class<? extends NodeBacked>) field.getType();
if (relAnnotation != null) {
return new SingleRelationshipFieldAccessor(DynamicRelationshipType.withName(relAnnotation.type()),
return new SingleRelationshipFieldAccessor(DynamicRelationshipType.withName(relAnnotation.type()),
relAnnotation.direction().toNeo4jDir(), relatedType, graphEntityInstantiator);
}
return new SingleRelationshipFieldAccessor(DynamicRelationshipType.withName(getNeo4jPropertyName(field)),
Direction.OUTGOING, relatedType, graphEntityInstantiator);
}
if (isOneToNRelationshipField(field)) {
return new OneToNRelationshipFieldAccessor(DynamicRelationshipType.withName(relAnnotation.type()),
return new OneToNRelationshipFieldAccessor(DynamicRelationshipType.withName(relAnnotation.type()),
relAnnotation.direction().toNeo4jDir(), relAnnotation.elementClass(), graphEntityInstantiator);
}
if (isReadOnlyOneToNRelationshipField(field)) {
return new ReadOnlyOneToNRelationshipFieldAccessor(DynamicRelationshipType.withName(relAnnotation.type()),
return new ReadOnlyOneToNRelationshipFieldAccessor(DynamicRelationshipType.withName(relAnnotation.type()),
relAnnotation.direction().toNeo4jDir(), relAnnotation.elementClass(), graphEntityInstantiator);
}
if (isOneToNRelationshipEntityField(field)) {
Graph.Entity.RelationshipEntity relEntityAnnotation = field.getAnnotation(Graph.Entity.RelationshipEntity.class);
GraphEntityRelationshipEntity relEntityAnnotation = field.getAnnotation(GraphEntityRelationshipEntity.class);
return new OneToNRelationshipEntityFieldAccessor(DynamicRelationshipType.withName(relEntityAnnotation.type()),
relEntityAnnotation.direction().toNeo4jDir(), relEntityAnnotation.elementClass(), relationshipEntityInstantiator);
}
@@ -52,19 +55,19 @@ public class FieldAccessorFactory {
private static boolean isOneToNRelationshipField(Field f) {
if (!Collection.class.isAssignableFrom(f.getType())) return false;
Graph.Entity.Relationship relAnnotation = f.getAnnotation(Graph.Entity.Relationship.class);
GraphEntityRelationship relAnnotation = f.getAnnotation(GraphEntityRelationship.class);
return relAnnotation != null && NodeBacked.class.isAssignableFrom(relAnnotation.elementClass()) && !relAnnotation.elementClass().equals(NodeBacked.class);
}
private static boolean isReadOnlyOneToNRelationshipField(Field f) {
Graph.Entity.Relationship relAnnotation = f.getAnnotation(Graph.Entity.Relationship.class);
GraphEntityRelationship relAnnotation = f.getAnnotation(GraphEntityRelationship.class);
return Iterable.class.equals(f.getType())
&& relAnnotation != null
&& !NodeBacked.class.equals(relAnnotation.elementClass());
}
private static boolean isOneToNRelationshipEntityField(Field f) {
Graph.Entity.RelationshipEntity relEntityAnnotation = f.getAnnotation(Graph.Entity.RelationshipEntity.class);
GraphEntityRelationshipEntity relEntityAnnotation = f.getAnnotation(GraphEntityRelationshipEntity.class);
return Iterable.class.isAssignableFrom(f.getType())
&& relEntityAnnotation != null
&& !RelationshipBacked.class.equals(relEntityAnnotation.elementClass());

View File

@@ -1,4 +1,6 @@
package org.springframework.persistence.graph.neo4j;
package org.springframework.datastore.graph.neo4j.fieldaccess;
import org.springframework.datastore.graph.api.NodeBacked;
import java.util.AbstractSet;
import java.util.Iterator;

View File

@@ -1,4 +1,4 @@
package org.springframework.persistence.graph.neo4j;
package org.springframework.datastore.graph.neo4j.fieldaccess;
import java.util.HashSet;
import java.util.Set;
@@ -7,6 +7,8 @@ import org.neo4j.graphdb.Direction;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.RelationshipType;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.datastore.graph.api.NodeBacked;
import org.springframework.datastore.graph.api.RelationshipBacked;
import org.springframework.persistence.support.EntityInstantiator;
public class OneToNRelationshipEntityFieldAccessor implements FieldAccessor {

View File

@@ -1,4 +1,4 @@
package org.springframework.persistence.graph.neo4j;
package org.springframework.datastore.graph.neo4j.fieldaccess;
import java.util.HashSet;
import java.util.Set;
@@ -8,7 +8,7 @@ import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.RelationshipType;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.persistence.graph.neo4j.ManagedFieldAccessorSet;
import org.springframework.datastore.graph.api.NodeBacked;
import org.springframework.persistence.support.EntityInstantiator;
public class OneToNRelationshipFieldAccessor implements FieldAccessor {

View File

@@ -1,4 +1,4 @@
package org.springframework.persistence.graph.neo4j;
package org.springframework.datastore.graph.neo4j.fieldaccess;
import java.util.HashSet;
import java.util.Set;
@@ -8,6 +8,7 @@ import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.RelationshipType;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.datastore.graph.api.NodeBacked;
import org.springframework.persistence.support.EntityInstantiator;
public class ReadOnlyOneToNRelationshipFieldAccessor implements FieldAccessor {
@@ -38,7 +39,7 @@ public class ReadOnlyOneToNRelationshipFieldAccessor implements FieldAccessor {
for (Relationship rel : entityNode.getRelationships(type, direction)) {
result.add(graphEntityInstantiator.createEntityFromState(rel.getOtherNode(entityNode), relatedType));
}
return new ManagedFieldAccessorSet<NodeBacked>(entity, result, this);
return new ManagedFieldAccessorSet<NodeBacked>(entity, result, this);
}
}

View File

@@ -1,10 +1,11 @@
package org.springframework.persistence.graph.neo4j;
package org.springframework.datastore.graph.neo4j.fieldaccess;
import org.neo4j.graphdb.Direction;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.RelationshipType;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.datastore.graph.api.NodeBacked;
import org.springframework.persistence.support.EntityInstantiator;
public class SingleRelationshipFieldAccessor implements FieldAccessor {

View File

@@ -1,4 +1,4 @@
package org.springframework.persistence.graph.neo4j;
package org.springframework.datastore.graph.neo4j.finder;
import java.util.ArrayList;
import java.util.List;
@@ -8,6 +8,8 @@ import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.NotFoundException;
import org.neo4j.graphdb.Relationship;
import org.springframework.datastore.graph.neo4j.spi.node.Neo4jHelper;
import org.springframework.datastore.graph.api.NodeBacked;
import org.springframework.persistence.support.EntityInstantiator;
public class Finder<T extends NodeBacked> {

View File

@@ -1,7 +1,8 @@
package org.springframework.persistence.graph.neo4j;
package org.springframework.datastore.graph.neo4j.finder;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.springframework.datastore.graph.api.NodeBacked;
import org.springframework.persistence.support.EntityInstantiator;
public class FinderFactory {

View File

@@ -1,11 +1,11 @@
package org.springframework.persistence.graph.neo4j;
package org.springframework.datastore.graph.neo4j.jpa;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.neo4j.kernel.EmbeddedGraphDatabase;
import org.springframework.datastore.graph.api.NodeBacked;
import org.springframework.persistence.support.EntityInstantiator;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.persistence.*;

View File

@@ -1,8 +1,8 @@
package org.springframework.persistence.graph.neo4j;
package org.springframework.datastore.graph.neo4j.jpa;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.datastore.graph.api.NodeBacked;
import org.springframework.persistence.support.EntityInstantiator;
import javax.annotation.Resource;

View File

@@ -1,4 +1,4 @@
package org.springframework.persistence.graph.neo4j;
package org.springframework.datastore.graph.neo4j.jpa;
import javax.persistence.EntityTransaction;
import javax.transaction.*;

View File

@@ -1,4 +1,4 @@
package org.springframework.persistence.graph.neo4j;
package org.springframework.datastore.graph.neo4j.jpa;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.datasource.ConnectionHandle;

View File

@@ -1,7 +1,8 @@
package org.springframework.persistence.graph.neo4j;
package org.springframework.datastore.graph.neo4j.jpa;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.springframework.datastore.graph.api.NodeBacked;
import org.springframework.persistence.support.EntityInstantiator;
import javax.annotation.Resource;

View File

@@ -1,6 +1,7 @@
package org.springframework.persistence.graph.neo4j;
package org.springframework.datastore.graph.neo4j.spi.node;
import org.neo4j.graphdb.Node;
import org.springframework.datastore.graph.api.NodeBacked;
import org.springframework.persistence.support.AbstractConstructorEntityInstantiator;
/**

View File

@@ -1,4 +1,4 @@
package org.springframework.persistence.graph.neo4j;
package org.springframework.datastore.graph.neo4j.spi.node;
import org.neo4j.graphdb.DynamicRelationshipType;
import org.neo4j.graphdb.GraphDatabaseService;
@@ -6,6 +6,7 @@ import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.RelationshipType;
import org.neo4j.util.GraphDatabaseUtil;
import org.springframework.datastore.graph.api.NodeBacked;
public abstract class Neo4jHelper {

View File

@@ -1,15 +1,8 @@
package org.springframework.persistence.graph.neo4j;
package org.springframework.datastore.graph.neo4j.spi.node;
import java.lang.reflect.Field;
import java.util.AbstractSet;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.aspectj.lang.reflect.FieldSignature;
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;
@@ -17,9 +10,13 @@ import org.neo4j.graphdb.Relationship;
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.Graph;
import org.springframework.datastore.graph.api.NodeBacked;
import org.springframework.datastore.graph.api.RelationshipBacked;
import org.springframework.datastore.graph.api.GraphEntity;
import org.springframework.datastore.graph.neo4j.fieldaccess.FieldAccessor;
import org.springframework.datastore.graph.neo4j.fieldaccess.FieldAccessorFactory;
import org.springframework.persistence.support.AbstractTypeAnnotatingMixinFields;
import org.springframework.persistence.support.EntityInstantiator;
@@ -30,7 +27,7 @@ import org.springframework.persistence.support.EntityInstantiator;
*
* @author Rod Johnson
*/
public aspect Neo4jNodeBacking extends AbstractTypeAnnotatingMixinFields<Graph.Entity,NodeBacked> {
public aspect Neo4jNodeBacking extends AbstractTypeAnnotatingMixinFields<GraphEntity, NodeBacked> {
//-------------------------------------------------------------------------
// Configure aspect for whole system.
@@ -60,8 +57,8 @@ public aspect Neo4jNodeBacking extends AbstractTypeAnnotatingMixinFields<Graph.E
// Neo4J backing node
//-------------------------------------------------------------------------
pointcut arbitraryUserConstructorOfNodeBackedObject(NodeBacked entity) :
execution((@Graph.Entity *).new(..)) &&
!execution((@Graph.Entity *).new(Node)) &&
execution((@GraphEntity *).new(..)) &&
!execution((@GraphEntity *).new(Node)) &&
this(entity); // && !cflow(execution(* fromStateInternal(..));

View File

@@ -1,8 +1,9 @@
package org.springframework.persistence.graph.neo4j;
package org.springframework.datastore.graph.neo4j.spi.relationship;
import java.lang.reflect.Constructor;
import org.neo4j.graphdb.Relationship;
import org.springframework.datastore.graph.api.RelationshipBacked;
import org.springframework.persistence.support.EntityInstantiator;
import sun.reflect.ReflectionFactory;

View File

@@ -1,28 +1,16 @@
package org.springframework.persistence.graph.neo4j;
package org.springframework.datastore.graph.neo4j.spi.relationship;
import java.lang.reflect.Field;
import java.util.AbstractSet;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.reflect.FieldSignature;
import org.neo4j.graphdb.Direction;
import org.neo4j.graphdb.DynamicRelationshipType;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
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.Graph;
import org.springframework.datastore.graph.api.*;
import org.springframework.persistence.support.AbstractTypeAnnotatingMixinFields;
import org.springframework.persistence.support.EntityInstantiator;
@@ -33,7 +21,7 @@ import org.springframework.persistence.support.EntityInstantiator;
*
* @author Rod Johnson
*/
public aspect Neo4jRelationshipBacking extends AbstractTypeAnnotatingMixinFields<Graph.Relationship,RelationshipBacked> {
public aspect Neo4jRelationshipBacking extends AbstractTypeAnnotatingMixinFields<GraphRelationship,RelationshipBacked> {
//-------------------------------------------------------------------------
// Configure aspect for whole system.
@@ -138,11 +126,11 @@ public aspect Neo4jRelationshipBacking extends AbstractTypeAnnotatingMixinFields
}
private boolean isEndNodeField(Field f) {
return f.isAnnotationPresent(Graph.Relationship.EndNode.class);
return f.isAnnotationPresent(GraphRelationshipEndNode.class);
}
private boolean isStartNodeField(Field f) {
return f.isAnnotationPresent(Graph.Relationship.StartNode.class);
return f.isAnnotationPresent(GraphRelationshipStartNode.class);
}
private boolean isPropertyType(Class<?> fieldType) {

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.datastore.graph.neo4j;
package org.springframework.datastore.graph.neo4j.support;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.datastore.graph.neo4j;
package org.springframework.datastore.graph.neo4j.support;
import java.util.List;

View File

@@ -1,8 +1,11 @@
package org.springframework.persistence.test;
package org.springframework.datastore.graph.neo4j;
import org.springframework.persistence.graph.Graph;
@Graph.Relationship
import org.springframework.datastore.graph.api.GraphRelationship;
import org.springframework.datastore.graph.api.GraphRelationshipEndNode;
import org.springframework.datastore.graph.api.GraphRelationshipStartNode;
@GraphRelationship
public class Friendship {
public Friendship() {
@@ -19,10 +22,10 @@ public class Friendship {
this.years = years;
}
@Graph.Relationship.StartNode
@GraphRelationshipStartNode
private Person p1;
@Graph.Relationship.EndNode
@GraphRelationshipEndNode
private Person p2;
private int years;

View File

@@ -1,18 +1,18 @@
package org.springframework.persistence.test;
package org.springframework.datastore.graph.neo4j;
import org.springframework.persistence.graph.Direction;
import org.springframework.persistence.graph.Graph;
import org.springframework.datastore.graph.api.Direction;
import org.springframework.datastore.graph.api.GraphEntity;
import org.springframework.datastore.graph.api.GraphEntityRelationship;
import java.util.Collection;
import java.util.HashSet;
@Graph.Entity
@GraphEntity
public class Group {
@Graph.Entity.Relationship(type = "persons", direction = Direction.OUTGOING, elementClass = Person.class)
@GraphEntityRelationship(type = "persons", direction = Direction.OUTGOING, elementClass = Person.class)
private Collection<Person> persons;
@Graph.Entity.Relationship(type = "persons", elementClass = Person.class)
@GraphEntityRelationship(type = "persons", elementClass = Person.class)
private Iterable<Person> readOnlyPersons;
public void setPersons(Collection<Person> persons) {

View File

@@ -1,11 +1,14 @@
package org.springframework.persistence.test;
package org.springframework.datastore.graph.neo4j;
import org.neo4j.graphdb.DynamicRelationshipType;
import org.neo4j.graphdb.Relationship;
import org.springframework.persistence.graph.Direction;
import org.springframework.persistence.graph.Graph;
import org.springframework.datastore.graph.api.Direction;
import org.springframework.datastore.graph.api.GraphEntity;
import org.springframework.datastore.graph.api.GraphEntityRelationship;
import org.springframework.datastore.graph.api.GraphEntityRelationshipEntity;
@Graph.Entity
@GraphEntity
public class Person {
private Long id;
@@ -18,13 +21,13 @@ public class Person {
private Person spouse;
@Graph.Entity.Relationship(type = "mother", direction = Direction.OUTGOING)
@GraphEntityRelationship(type = "mother", direction = Direction.OUTGOING)
private Person mother;
@Graph.Entity.Relationship(type = "boss", direction = Direction.INCOMING)
@GraphEntityRelationship(type = "boss", direction = Direction.INCOMING)
private Person boss;
@Graph.Entity.RelationshipEntity(type = "knows", elementClass = Friendship.class)
@GraphEntityRelationshipEntity(type = "knows", elementClass = Friendship.class)
private Iterable<Friendship> friendships;
// @Property(serialize=SerializationPolicy.STRING, index=true, queryable=true, removeOnReset=true)

View File

@@ -1,4 +1,4 @@
package org.springframework.persistence.test;
package org.springframework.datastore.graph.neo4j;
import java.util.ArrayList;
import java.util.List;
@@ -9,7 +9,7 @@ import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.persistence.graph.neo4j.Neo4jHelper;
import org.springframework.datastore.graph.neo4j.spi.node.Neo4jHelper;
/**
* EXAMPLE OF CODE THAT SHOULD BE GENERATED BY ROO BESIDES EACH GRAPHENTITY CLASS
@@ -23,7 +23,7 @@ privileged aspect Person_Graph_Entity {
// TODO should be a better way of getting this? Could at least pull out gdsholder class
private static GraphDatabaseService graphDatabaseService() {
return new GdsHolder().gds;
return new Person_Graph_Entity.GdsHolder().gds;
}
@Configurable
@@ -48,7 +48,7 @@ privileged aspect Person_Graph_Entity {
Node subrefNode = Neo4jHelper.findSubreferenceNode(Person.class, graphDatabaseService());
// TODO Neo4j should add lazy list on top of graph
List<Person> people = new ArrayList<Person>((int) countPeople());
for (Relationship rel : subrefNode.getRelationships(Neo4jHelper.INSTANCE_OF_RELATIONSHIP_TYPE, Direction.INCOMING)) {
for (Relationship rel : subrefNode.getRelationships(Neo4jHelper.INSTANCE_OF_RELATIONSHIP_TYPE, org.neo4j.graphdb.Direction.INCOMING)) {
Node personNode = rel.getStartNode();
people.add(new Person(personNode));
}

View File

@@ -1,4 +1,4 @@
package org.springframework.persistence.graph.neo4j;
package org.springframework.datastore.graph.neo4j.jpa;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -18,7 +18,8 @@ import org.junit.runner.RunWith;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.persistence.test.Person;
import org.springframework.datastore.graph.neo4j.Person;
import org.springframework.datastore.graph.neo4j.spi.node.Neo4jHelper;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
@@ -28,10 +29,9 @@ import org.springframework.transaction.annotation.Transactional;
* @since 20.08.2010
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:org/springframework/persistence/test/graph/Neo4jGraphPersistenceTest-context.xml"})
@ContextConfiguration(locations = {"classpath:org/springframework/datastore/graph/neo4j/spi/Neo4jGraphPersistenceTest-context.xml"})
@Transactional
public class Neo4jEntityManagerTest {
private static GraphDatabaseService gds;
@Resource
GraphDatabaseService graphDatabaseService;
@PersistenceContext(unitName="neo4j-persistence")
@@ -45,13 +45,8 @@ public class Neo4jEntityManagerTest {
Neo4jHelper.cleanDb(graphDatabaseService);
node = graphDatabaseService.createNode();
person = new Person(node);
gds=graphDatabaseService;
}
@AfterClass
public static void shutdownDb() {
gds.shutdown();
}
@Test
public void testPersist() throws Exception {
entityManager.persist(person);

View File

@@ -1,48 +1,37 @@
package org.springframework.persistence.test.graph;
package org.springframework.datastore.graph.neo4j.spi;
import junit.framework.Assert;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.neo4j.graphdb.Direction;
import org.neo4j.graphdb.DynamicRelationshipType;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.*;
import org.neo4j.helpers.collection.IteratorUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.dao.InvalidDataAccessResourceUsageException;
import org.springframework.persistence.graph.neo4j.Finder;
import org.springframework.persistence.graph.neo4j.FinderFactory;
import org.springframework.persistence.graph.neo4j.Neo4jHelper;
import org.springframework.persistence.graph.neo4j.NodeBacked;
import org.springframework.datastore.graph.api.NodeBacked;
import org.springframework.datastore.graph.neo4j.Friendship;
import org.springframework.datastore.graph.neo4j.Group;
import org.springframework.datastore.graph.neo4j.Person;
import org.springframework.datastore.graph.neo4j.finder.Finder;
import org.springframework.datastore.graph.neo4j.finder.FinderFactory;
import org.springframework.datastore.graph.neo4j.spi.node.Neo4jHelper;
import org.springframework.persistence.support.EntityInstantiator;
import org.springframework.persistence.test.Friendship;
import org.springframework.persistence.test.Group;
import org.springframework.persistence.test.Person;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.*;
//@Ignore
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@ContextConfiguration(locations = {"classpath:org/springframework/datastore/graph/neo4j/spi/Neo4jGraphPersistenceTest-context.xml"})
public class Neo4jGraphPersistenceTest {
private static GraphDatabaseService gds;
protected final Log log = LogFactory.getLog(getClass());
@Autowired
@@ -64,11 +53,6 @@ public class Neo4jGraphPersistenceTest {
@Transactional
public void cleanDb() {
Neo4jHelper.cleanDb(graphDatabaseService);
gds=graphDatabaseService;
}
@AfterClass
public static void shutdownDb() {
gds.shutdown();
}
@Test

View File

@@ -2,7 +2,7 @@
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="neo4j-persistence" transaction-type="RESOURCE_LOCAL">
<provider>org.springframework.persistence.graph.neo4j.Neo4jPersistenceProvider</provider>
<provider>org.springframework.datastore.graph.neo4j.jpa.Neo4jPersistenceProvider</provider>
<properties>
<property name="neo4j.path" value="test/data"/> <!-- TODO handle this -->
</properties>

View File

@@ -59,7 +59,7 @@
The most commonly used annotation is @Autowired, which instructs Spring to
dependency inject an object into your class.
-->
<context:component-scan base-package="org.springframework.persistence.test">
<context:component-scan base-package="org.springframework.datastore.graph.neo4j">
<context:exclude-filter expression=".*_Roo_.*" type="regex"/>
<context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation"/>
</context:component-scan>
@@ -69,27 +69,27 @@
Start datastore config
-->
<bean class="org.springframework.persistence.graph.neo4j.Neo4jNodeBacking" factory-method="aspectOf" />
<bean class="org.springframework.datastore.graph.neo4j.spi.node.Neo4jNodeBacking" factory-method="aspectOf" />
<bean class="org.springframework.persistence.graph.neo4j.Neo4jRelationshipBacking" factory-method="aspectOf" />
<bean class="org.springframework.datastore.graph.neo4j.spi.relationship.Neo4jRelationshipBacking" factory-method="aspectOf" />
<!--
<bean class="org.springframework.persistence.graph.Neo4jSimpleNodePropertyStorageForeignStoreKeyManager"/>
-->
<bean id="graphDbService" class="org.neo4j.kernel.EmbeddedGraphDatabase"
destroy-method="shutdown">
destroy-method="shutdown" scope="singleton">
<constructor-arg index="0" value="${neo4j.databaseDirectory}" />
</bean>
<bean id="finderFactory" class="org.springframework.persistence.graph.neo4j.FinderFactory">
<bean id="finderFactory" class="org.springframework.datastore.graph.neo4j.finder.FinderFactory">
<constructor-arg ref="graphDbService" />
<constructor-arg ref="graphEntityInstantiator" />
</bean>
<bean id="graphEntityInstantiator" name="gei" class="org.springframework.persistence.graph.neo4j.Neo4jConstructorGraphEntityInstantiator" />
<bean id="graphEntityInstantiator" name="gei" class="org.springframework.datastore.graph.neo4j.spi.node.Neo4jConstructorGraphEntityInstantiator" />
<bean id="relationshipEntityInstantiator" name="rei" class="org.springframework.persistence.graph.neo4j.ConstructorBypassingGraphRelationshipInstantiator" />
<bean id="relationshipEntityInstantiator" name="rei" class="org.springframework.datastore.graph.neo4j.spi.relationship.ConstructorBypassingGraphRelationshipInstantiator" />
<!--
-->
@@ -128,10 +128,10 @@
<bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactory">
<property name="jpaDialect">
<bean class="org.springframework.persistence.graph.neo4j.Neo4jJpaDialect"/>
<bean class="org.springframework.datastore.graph.neo4j.jpa.Neo4jJpaDialect"/>
</property>
<property name="persistenceProvider">
<bean class="org.springframework.persistence.graph.neo4j.Neo4jPersistenceProvider"/>
<bean class="org.springframework.datastore.graph.neo4j.jpa.Neo4jPersistenceProvider"/>
</property>
</bean>