Pieces of code on the way to a better state.

This commit is contained in:
David Montag
2010-09-18 09:31:08 -07:00
parent ec8a0bbf46
commit 1114a25d29
6 changed files with 25 additions and 10 deletions

View File

@@ -37,7 +37,6 @@ public class DefaultEntityStateAccessors<ENTITY extends NodeBacked, STATE> imple
createAccessorsAndListeners(type, graphDatabaseContext);
}
@Override
public void createAndAssignNode() {
try {

View File

@@ -0,0 +1,16 @@
package org.springframework.datastore.graph.neo4j.fieldaccess;
import org.neo4j.graphdb.Node;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.datastore.graph.api.NodeBacked;
import org.springframework.datastore.graph.neo4j.support.GraphDatabaseContext;
public class DetachableEntityStateAccessorsFactory {
@Autowired
private GraphDatabaseContext graphDatabaseContext;
public EntityStateAccessors<NodeBacked> getEntityStateAccessors(NodeBacked entity) {
return new DetachableEntityStateAccessors<NodeBacked, Node>(
new DefaultEntityStateAccessors<NodeBacked, Node>(null,entity,entity.getClass(), graphDatabaseContext));
}
}

View File

@@ -6,7 +6,7 @@ import java.lang.reflect.Field;
* @author Michael Hunger
* @since 12.09.2010
*/
interface FieldAccessorFactory<E> {
public interface FieldAccessorFactory<E> {
boolean accept(Field f);
FieldAccessor<E,?> forField(Field f);
}

View File

@@ -19,6 +19,7 @@ import org.springframework.persistence.support.AbstractTypeAnnotatingMixinFields
import java.lang.reflect.Field;
import static org.springframework.datastore.graph.neo4j.fieldaccess.DoReturn.unwrap;
import org.springframework.datastore.graph.neo4j.fieldaccess.DetachableEntityStateAccessorsFactory;
/**
* Aspect to turn an object annotated with GraphEntity into a graph entity using Neo4J.
@@ -29,12 +30,12 @@ import static org.springframework.datastore.graph.neo4j.fieldaccess.DoReturn.unw
*/
public aspect Neo4jNodeBacking extends AbstractTypeAnnotatingMixinFields<GraphEntity, NodeBacked> {
private GraphDatabaseContext graphDatabaseContext;
private DelegatingFieldAccessorFactory fieldAccessorFactory;
private DetachableEntityStateAccessorsFactory entityStateAccessorsFactory;
@Autowired
public void init(GraphDatabaseContext ctx) {
public void init(GraphDatabaseContext ctx, DetachableEntityStateAccessorsFactory entityStateAccessorsFactory) {
this.graphDatabaseContext = ctx;
this.fieldAccessorFactory = new DelegatingFieldAccessorFactory(ctx);
this.entityStateAccessorsFactory = entityStateAccessorsFactory;
}
//-------------------------------------------------------------------------
@@ -48,7 +49,7 @@ public aspect Neo4jNodeBacking extends AbstractTypeAnnotatingMixinFields<GraphEn
// Create a new node in the Graph if no Node was passed in a constructor
before(NodeBacked entity) : arbitraryUserConstructorOfNodeBackedObject(entity) {
entity.underlyingState=new DetachableEntityStateAccessors(new DefaultEntityStateAccessors<NodeBacked,Node>(null,entity,entity.getClass(),graphDatabaseContext));
entity.underlyingState = entityStateAccessorsFactory.getEntityStateAccessors(entity);
if (graphDatabaseContext.transactionIsRunning()) {
entity.underlyingState.createAndAssignNode();
} else {
@@ -62,8 +63,8 @@ public aspect Neo4jNodeBacking extends AbstractTypeAnnotatingMixinFields<GraphEn
public void NodeBacked.setUnderlyingNode(Node n) {
this.underlyingNode = n;
if (this.underlyingState==null) {
this.underlyingState=new DetachableEntityStateAccessors(new DefaultEntityStateAccessors<NodeBacked,Node>(n,this,this.getClass(),Neo4jNodeBacking.aspectOf().graphDatabaseContext));
if (this.underlyingState == null) {
this.underlyingState = entityStateAccessorsFactory.getEntityStateAccessors(this);
} else {
this.underlyingState.setNode(n);
}

View File

@@ -13,8 +13,6 @@ import org.springframework.core.convert.ConversionService;
import org.springframework.datastore.graph.api.NodeBacked;
import org.springframework.datastore.graph.api.NodeTypeStrategy;
import org.springframework.datastore.graph.api.RelationshipBacked;
import org.springframework.datastore.graph.neo4j.fieldaccess.DelegatingFieldAccessorFactory;
import org.springframework.persistence.support.AbstractMixinFields;
import org.springframework.persistence.support.EntityInstantiator;
import javax.transaction.Status;

View File

@@ -91,6 +91,7 @@
<bean id="graphDatabaseContext" class="org.springframework.datastore.graph.neo4j.support.GraphDatabaseContext"/>
<bean id="EntityStateAccessorsFactory" class="org.springframework.datastore.graph.neo4j.fieldaccess.DetachableEntityStateAccessorsFactory" />
<bean id="finderFactory" class="org.springframework.datastore.graph.neo4j.finder.FinderFactory">
<constructor-arg ref="graphDatabaseContext" />