refactored names for stateaccessors

This commit is contained in:
Michael Hunger
2011-03-01 11:18:59 +01:00
parent 841b5b4725
commit ec4d18309c
47 changed files with 264 additions and 259 deletions

View File

@@ -65,7 +65,7 @@ public class Neo4jEntityManager implements EntityManager {
private Node nodeFor(final Object entity) {
checkClosed();
if (!(entity instanceof NodeBacked)) throw new IllegalArgumentException("Not a nodebacked entity " + entity);
final Node node = ((NodeBacked) entity).getUnderlyingState();
final Node node = ((NodeBacked) entity).getPersistentState();
if (node == null) throw new IllegalArgumentException("Node of entity " + entity + " is null");
return node;
}

View File

@@ -9,6 +9,6 @@ public abstract class Car {
}
public Car(Node n) {
setUnderlyingState(n);
setPersistentState(n);
}
}

View File

@@ -53,7 +53,7 @@ public class Neo4jEntityManagerTest {
@Before
public void setUp() {
person = new Person("Michael",35);
node = person.getUnderlyingState();
node = person.getPersistentState();
}
@Test
@@ -144,7 +144,7 @@ public class Neo4jEntityManagerTest {
@Test
public void testRefresh() throws Exception {
entityManager.refresh(person);
assertEquals(node, person.getUnderlyingState());
assertEquals(node, person.getPersistentState());
}
@Test
public void testClear() throws Exception {

View File

@@ -71,12 +71,12 @@
<bean id="neo4jNodeBacking" class="org.springframework.data.graph.neo4j.support.node.Neo4jNodeBacking" factory-method="aspectOf">
<property name="graphDatabaseContext" ref="graphDatabaseContext"/>
<property name="nodeEntityStateAccessorsFactory" ref="nodeEntityStateAccessorsFactory"/>
<property name="nodeEntityStateFactory" ref="nodeEntityStateFactory"/>
</bean>
<bean class="org.springframework.data.graph.neo4j.support.relationship.Neo4jRelationshipBacking" factory-method="aspectOf">
<property name="graphDatabaseContext" ref="graphDatabaseContext"/>
<property name="relationshipEntityStateAccessorsFactory" ref="relationshipEntityStateAccessorsFactory"/>
<property name="relationshipEntityStateFactory" ref="relationshipEntityStateFactory"/>
</bean>
<!--
@@ -106,7 +106,7 @@
</property>
</bean>
<bean id="nodeEntityStateAccessorsFactory" class="org.springframework.data.graph.neo4j.fieldaccess.NodeEntityStateAccessorsFactory">
<bean id="nodeEntityStateFactory" class="org.springframework.data.graph.neo4j.fieldaccess.NodeEntityStateFactory">
<property name="nodeDelegatingFieldAccessorFactory">
<bean class="org.springframework.data.graph.neo4j.fieldaccess.NodeDelegatingFieldAccessorFactory">
<constructor-arg ref="graphDatabaseContext"/>
@@ -117,7 +117,7 @@
<property name="finderFactory" ref="finderFactory"/>
</bean>
<bean id="relationshipEntityStateAccessorsFactory" class="org.springframework.data.graph.neo4j.fieldaccess.RelationshipEntityStateAccessorsFactory">
<bean id="relationshipEntityStateFactory" class="org.springframework.data.graph.neo4j.fieldaccess.RelationshipEntityStateFactory">
<property name="graphDatabaseContext" ref="graphDatabaseContext"/>
<property name="finderFactory" ref="finderFactory"/>
</bean>

View File

@@ -29,10 +29,10 @@ public interface GraphBacked<STATE> {
* internal setter used for initializing the graph-db state on existing or newly created entities
* @param state (Node or Relationship)
*/
void setUnderlyingState(STATE state);
void setPersistentState(STATE state);
/**
* @return the underlying graph-db state or null if the current entity is not related to the graph-store (possible with unsaved or partial entities)
*/
STATE getUnderlyingState();
STATE getPersistentState();
}

View File

@@ -25,8 +25,8 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.graph.neo4j.fieldaccess.Neo4jConversionServiceFactoryBean;
import org.springframework.data.graph.neo4j.fieldaccess.NodeDelegatingFieldAccessorFactory;
import org.springframework.data.graph.neo4j.fieldaccess.NodeEntityStateAccessorsFactory;
import org.springframework.data.graph.neo4j.fieldaccess.RelationshipEntityStateAccessorsFactory;
import org.springframework.data.graph.neo4j.fieldaccess.NodeEntityStateFactory;
import org.springframework.data.graph.neo4j.fieldaccess.RelationshipEntityStateFactory;
import org.springframework.data.graph.neo4j.finder.FinderFactory;
import org.springframework.data.graph.neo4j.support.GraphDatabaseContext;
import org.springframework.data.graph.neo4j.support.SubReferenceNodeTypeStrategy;
@@ -110,10 +110,10 @@ public class Neo4jConfiguration {
public Neo4jRelationshipBacking neo4jRelationshipBacking(GraphDatabaseContext graphDatabaseContext, FinderFactory finderFactory) {
Neo4jRelationshipBacking aspect = Neo4jRelationshipBacking.aspectOf();
aspect.setGraphDatabaseContext(graphDatabaseContext);
RelationshipEntityStateAccessorsFactory entityStateAccessorsFactory = new RelationshipEntityStateAccessorsFactory();
entityStateAccessorsFactory.setGraphDatabaseContext(graphDatabaseContext);
entityStateAccessorsFactory.setFinderFactory(finderFactory);
aspect.setRelationshipEntityStateAccessorsFactory(entityStateAccessorsFactory);
RelationshipEntityStateFactory entityStateFactory = new RelationshipEntityStateFactory();
entityStateFactory.setGraphDatabaseContext(graphDatabaseContext);
entityStateFactory.setFinderFactory(finderFactory);
aspect.setRelationshipEntityStateFactory(entityStateFactory);
return aspect;
}
@@ -121,12 +121,12 @@ public class Neo4jConfiguration {
public Neo4jNodeBacking neo4jNodeBacking(GraphDatabaseContext graphDatabaseContext, FinderFactory finderFactory) {
Neo4jNodeBacking aspect = Neo4jNodeBacking.aspectOf();
aspect.setGraphDatabaseContext(graphDatabaseContext);
NodeEntityStateAccessorsFactory entityStateAccessorsFactory = new NodeEntityStateAccessorsFactory();
entityStateAccessorsFactory.setGraphDatabaseContext(graphDatabaseContext);
entityStateAccessorsFactory.setFinderFactory(finderFactory);
entityStateAccessorsFactory.setNodeDelegatingFieldAccessorFactory(
NodeEntityStateFactory entityStateFactory = new NodeEntityStateFactory();
entityStateFactory.setGraphDatabaseContext(graphDatabaseContext);
entityStateFactory.setFinderFactory(finderFactory);
entityStateFactory.setNodeDelegatingFieldAccessorFactory(
new NodeDelegatingFieldAccessorFactory(graphDatabaseContext, finderFactory));
aspect.setNodeEntityStateAccessorsFactory(entityStateAccessorsFactory);
aspect.setNodeEntityStateFactory(entityStateFactory);
return aspect;
}

View File

@@ -28,17 +28,17 @@ import java.util.Map;
* @author Michael Hunger
* @since 12.09.2010
*/
public abstract class DefaultEntityStateAccessors<ENTITY extends GraphBacked<STATE>, STATE> implements EntityStateAccessors<ENTITY,STATE> {
public abstract class DefaultEntityState<ENTITY extends GraphBacked<STATE>, STATE> implements EntityState<ENTITY,STATE> {
protected final ENTITY entity;
protected final Class<? extends ENTITY> type;
private final Map<Field, FieldAccessor<ENTITY>> fieldAccessors;
private final Map<Field,List<FieldAccessListener<ENTITY,?>>> fieldAccessorListeners;
private STATE state;
protected final static Log log= LogFactory.getLog(DefaultEntityStateAccessors.class);
protected final static Log log= LogFactory.getLog(DefaultEntityState.class);
private final FieldAccessorFactoryProviders<ENTITY> fieldAccessorFactoryProviders;
public DefaultEntityStateAccessors(final STATE underlyingState, final ENTITY entity, final Class<? extends ENTITY> type, final DelegatingFieldAccessorFactory delegatingFieldAccessorFactory) {
public DefaultEntityState(final STATE underlyingState, final ENTITY entity, final Class<? extends ENTITY> type, final DelegatingFieldAccessorFactory delegatingFieldAccessorFactory) {
this.state = underlyingState;
this.entity = entity;
this.type = type;
@@ -56,17 +56,17 @@ public abstract class DefaultEntityStateAccessors<ENTITY extends GraphBacked<STA
}
@Override
public void setUnderlyingState(final STATE state) {
public void setPersistentState(final STATE state) {
this.state = state;
}
@Override
public boolean hasUnderlyingState() {
public boolean hasPersistentState() {
return this.state!=null;
}
@Override
public STATE getUnderlyingState() {
public STATE getPersistentState() {
return state;
}

View File

@@ -18,7 +18,6 @@ package org.springframework.data.graph.neo4j.fieldaccess;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.data.graph.annotation.NodeEntity;
import org.springframework.data.graph.core.GraphBacked;
import org.springframework.data.graph.neo4j.support.GraphDatabaseContext;
import org.springframework.util.ObjectUtils;
@@ -34,14 +33,14 @@ import static org.springframework.data.graph.neo4j.fieldaccess.DoReturn.unwrap;
* @author Michael Hunger
* @since 15.09.2010
*/
public class DetachableEntityStateAccessors<ENTITY extends GraphBacked<STATE>, STATE> implements EntityStateAccessors<ENTITY,STATE> {
public class DetachableEntityState<ENTITY extends GraphBacked<STATE>, STATE> implements EntityState<ENTITY,STATE> {
private final Map<Field, Object> dirty = new HashMap<Field, Object>();
protected final EntityStateAccessors<ENTITY,STATE> delegate;
private final static Log log = LogFactory.getLog(DetachableEntityStateAccessors.class);
protected final EntityState<ENTITY,STATE> delegate;
private final static Log log = LogFactory.getLog(DetachableEntityState.class);
private GraphDatabaseContext graphDatabaseContext;
private final boolean autoAttach;
public DetachableEntityStateAccessors(final EntityStateAccessors<ENTITY, STATE> delegate, GraphDatabaseContext graphDatabaseContext, boolean autoAttach) {
public DetachableEntityState(final EntityState<ENTITY, STATE> delegate, GraphDatabaseContext graphDatabaseContext, boolean autoAttach) {
this.delegate = delegate;
this.graphDatabaseContext = graphDatabaseContext;
this.autoAttach = autoAttach;
@@ -58,19 +57,19 @@ public class DetachableEntityStateAccessors<ENTITY extends GraphBacked<STATE>, S
}
@Override
public boolean hasUnderlyingState() {
return delegate.hasUnderlyingState();
public boolean hasPersistentState() {
return delegate.hasPersistentState();
}
@Override
public STATE getUnderlyingState() {
return delegate.getUnderlyingState();
public STATE getPersistentState() {
return delegate.getPersistentState();
}
@Override
public Object getValue(final Field field) {
if (!transactionIsRunning() || !hasUnderlyingState()) {
if (getEntity().getUnderlyingState()==null || isDirty(field)) {
if (!transactionIsRunning() || !hasPersistentState()) {
if (getEntity().getPersistentState()==null || isDirty(field)) {
if (log.isDebugEnabled()) log.debug("Outside of transaction, GET value from field " + field);
return null;
}
@@ -86,11 +85,11 @@ public class DetachableEntityStateAccessors<ENTITY extends GraphBacked<STATE>, S
@Override
public Object setValue(final Field field, final Object newVal) {
if (!transactionIsRunning() || !hasUnderlyingState()) {
if (!transactionIsRunning() || !hasPersistentState()) {
final ENTITY entity = getEntity();
if (!isDirty(field) && isWritable(field)) {
Object existingValue;
if (entity.getUnderlyingState()!=null) existingValue = unwrap(delegate.getValue(field));
if (entity.getPersistentState()!=null) existingValue = unwrap(delegate.getValue(field));
else {
existingValue = getValueFromEntity(field);
if (existingValue == null) existingValue = getDefaultValue(field.getType());
@@ -125,7 +124,7 @@ public class DetachableEntityStateAccessors<ENTITY extends GraphBacked<STATE>, S
*/
private void flushDirty() {
final ENTITY entity = getEntity();
final boolean newState = entity.getUnderlyingState()==null;
final boolean newState = entity.getPersistentState()==null;
if (newState) {
return;
// createAndAssignState();
@@ -144,8 +143,8 @@ public class DetachableEntityStateAccessors<ENTITY extends GraphBacked<STATE>, S
}
@Override
public void setUnderlyingState(final STATE state) {
delegate.setUnderlyingState(state);
public void setPersistentState(final STATE state) {
delegate.setPersistentState(state);
}
@@ -163,7 +162,7 @@ public class DetachableEntityStateAccessors<ENTITY extends GraphBacked<STATE>, S
final Object nodeValue = unwrap(delegate.getValue(field));
final Object previousValue = entry.getValue();
if (!ObjectUtils.nullSafeEquals(nodeValue, previousValue)) {
throw new ConcurrentModificationException("Node " + entity.getUnderlyingState() + " field " + field + " changed in between previous " + previousValue + " current " + nodeValue); // todo or just overwrite
throw new ConcurrentModificationException("Node " + entity.getPersistentState() + " field " + field + " changed in between previous " + previousValue + " current " + nodeValue); // todo or just overwrite
}
}
@@ -188,13 +187,13 @@ public class DetachableEntityStateAccessors<ENTITY extends GraphBacked<STATE>, S
}
@Override
public ENTITY attach(boolean isOnCreate) {
public ENTITY persist(boolean isOnCreate) {
if (!autoAttach && isOnCreate) {
log.warn("Not automatically attaching entity " + getEntity().getClass());
return getEntity();
}
if (graphDatabaseContext.transactionIsRunning()) {
ENTITY result = delegate.attach(isOnCreate);
ENTITY result = delegate.persist(isOnCreate);
flushDirty();
return result;
}

View File

@@ -26,10 +26,10 @@ import java.lang.reflect.Field;
* @author Michael Hunger
* @since 15.09.2010
*/
public interface EntityStateAccessors<ENTITY extends GraphBacked<STATE>,STATE> {
public interface EntityState<ENTITY extends GraphBacked<STATE>,STATE> {
ENTITY getEntity();
void setUnderlyingState(STATE state);
void setPersistentState(STATE state);
/**
* @param field
@@ -53,10 +53,11 @@ public interface EntityStateAccessors<ENTITY extends GraphBacked<STATE>,STATE> {
/**
* callback for creating and initializing an initial state
*/
@Deprecated
void createAndAssignState();
boolean hasUnderlyingState();
STATE getUnderlyingState();
boolean hasPersistentState();
STATE getPersistentState();
ENTITY attach(boolean isOnCreate);
ENTITY persist(boolean isOnCreate);
}

View File

@@ -18,7 +18,7 @@ package org.springframework.data.graph.neo4j.fieldaccess;
/**
* interface for field accessors, encapsulates reading and writing from fields and write support information about the field.
* It is used by the {@link org.springframework.data.graph.neo4j.fieldaccess.EntityStateAccessors} which is delegated to by the
* It is used by the {@link EntityState} which is delegated to by the
* {@link org.springframework.data.graph.neo4j.support.node.Neo4jNodeBacking} {@link org.springframework.data.graph.neo4j.support.relationship.Neo4jRelationshipBacking}
* aspects.
* @param <ENTITY>

View File

@@ -63,7 +63,7 @@ public class IdFieldAccessorFactory implements FieldAccessorFactory<NodeBacked>
@Override
public Object getValue(final NodeBacked nodeBacked) {
return doReturn(nodeBacked.getUnderlyingState().getId());
return doReturn(nodeBacked.getPersistentState().getId());
}
}

View File

@@ -106,8 +106,8 @@ class IndexingNodePropertyFieldAccessorListenerFactory<T extends GraphBacked<?>>
public void valueChanged(GraphBacked<T> graphBacked, Object oldVal, Object newVal) {
if (newVal instanceof Number) newVal = ValueContext.numeric((Number) newVal);
if (newVal==null) index.remove(graphBacked.getUnderlyingState(), indexKey, null);
else index.add(graphBacked.getUnderlyingState(), indexKey, newVal);
if (newVal==null) index.remove(graphBacked.getPersistentState(), indexKey, null);
else index.add(graphBacked.getPersistentState(), indexKey, newVal);
}
}
}

View File

@@ -46,8 +46,8 @@ public class JpaIdFieldAccessListenerFactory implements FieldAccessorListenerFac
@Override
public void valueChanged(NodeBacked nodeBacked, Object oldVal, Object newVal) {
if (newVal != null) {
EntityStateAccessors stateAccessors=nodeBacked.getStateAccessors();
stateAccessors.attach(false);
EntityState entityState =nodeBacked.getEntityState();
entityState.persist(false);
}
}
}

View File

@@ -9,14 +9,14 @@ import org.springframework.data.graph.neo4j.support.GraphDatabaseContext;
import java.lang.reflect.Field;
import java.util.concurrent.Callable;
public class NestedTransactionEntityStateAccessors<ENTITY extends GraphBacked<STATE>, STATE> implements
EntityStateAccessors<ENTITY, STATE> {
protected final EntityStateAccessors<ENTITY, STATE> delegate;
private final static Log log = LogFactory.getLog(NestedTransactionEntityStateAccessors.class);
public class NestedTransactionEntityState<ENTITY extends GraphBacked<STATE>, STATE> implements
EntityState<ENTITY, STATE> {
protected final EntityState<ENTITY, STATE> delegate;
private final static Log log = LogFactory.getLog(NestedTransactionEntityState.class);
private GraphDatabaseContext graphDatabaseContext;
public NestedTransactionEntityStateAccessors(final EntityStateAccessors<ENTITY, STATE> delegate,
GraphDatabaseContext graphDatabaseContext) {
public NestedTransactionEntityState(final EntityState<ENTITY, STATE> delegate,
GraphDatabaseContext graphDatabaseContext) {
this.delegate = delegate;
this.graphDatabaseContext = graphDatabaseContext;
}
@@ -26,8 +26,8 @@ public class NestedTransactionEntityStateAccessors<ENTITY extends GraphBacked<ST
return delegate.getEntity();
}
public void setUnderlyingState(STATE state) {
delegate.setUnderlyingState(state);
public void setPersistentState(STATE state) {
delegate.setPersistentState(state);
}
@Override
@@ -60,20 +60,20 @@ public class NestedTransactionEntityStateAccessors<ENTITY extends GraphBacked<ST
}
@Override
public boolean hasUnderlyingState() {
return delegate.hasUnderlyingState();
public boolean hasPersistentState() {
return delegate.hasPersistentState();
}
@Override
public STATE getUnderlyingState() {
return delegate.getUnderlyingState();
public STATE getPersistentState() {
return delegate.getPersistentState();
}
@Override
public ENTITY attach(final boolean isOnCreate) {
public ENTITY persist(final boolean isOnCreate) {
return doInTransaction(new Callable<ENTITY>() {
public ENTITY call() throws Exception {
return delegate.attach(isOnCreate);
return delegate.persist(isOnCreate);
}
});
}

View File

@@ -19,7 +19,6 @@ package org.springframework.data.graph.neo4j.fieldaccess;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.NotInTransactionException;
import org.springframework.dao.InvalidDataAccessResourceUsageException;
import org.springframework.data.graph.annotation.NodeEntity;
import org.springframework.data.graph.core.NodeBacked;
import org.springframework.data.graph.neo4j.support.GraphDatabaseContext;
import org.springframework.persistence.support.StateProvider;
@@ -28,31 +27,31 @@ import org.springframework.persistence.support.StateProvider;
* @author Michael Hunger
* @since 21.09.2010
*/
public class NodeEntityStateAccessors<ENTITY extends NodeBacked> extends DefaultEntityStateAccessors<ENTITY, Node> {
public class NodeEntityState<ENTITY extends NodeBacked> extends DefaultEntityState<ENTITY, Node> {
private final GraphDatabaseContext graphDatabaseContext;
public NodeEntityStateAccessors(final Node underlyingState, final ENTITY entity, final Class<? extends ENTITY> type, final GraphDatabaseContext graphDatabaseContext, final NodeDelegatingFieldAccessorFactory nodeDelegatingFieldAccessorFactory) {
public NodeEntityState(final Node underlyingState, final ENTITY entity, final Class<? extends ENTITY> type, final GraphDatabaseContext graphDatabaseContext, final NodeDelegatingFieldAccessorFactory nodeDelegatingFieldAccessorFactory) {
super(underlyingState, entity, type, nodeDelegatingFieldAccessorFactory);
this.graphDatabaseContext = graphDatabaseContext;
}
@Override
public void createAndAssignState() {
if (hasUnderlyingState()) return;
if (hasPersistentState()) return;
try {
final Object id = getIdFromEntity();
if (id instanceof Number) {
final Node node = graphDatabaseContext.getNodeById(((Number) id).longValue());
setUnderlyingState(node);
setPersistentState(node);
if (log.isInfoEnabled())
log.info("Entity reattached " + entity.getClass() + "; used Node [" + getUnderlyingState() + "];");
log.info("Entity reattached " + entity.getClass() + "; used Node [" + getPersistentState() + "];");
return;
}
final Node node = graphDatabaseContext.createNode();
setUnderlyingState(node);
if (log.isInfoEnabled()) log.info("User-defined constructor called on class " + entity.getClass() + "; created Node [" + getUnderlyingState() + "]; Updating metamodel");
setPersistentState(node);
if (log.isInfoEnabled()) log.info("User-defined constructor called on class " + entity.getClass() + "; created Node [" + getPersistentState() + "]; Updating metamodel");
graphDatabaseContext.postEntityCreation(entity);
} catch (NotInTransactionException e) {
throw new InvalidDataAccessResourceUsageException("Not in a Neo4j transaction.", e);
@@ -60,10 +59,10 @@ public class NodeEntityStateAccessors<ENTITY extends NodeBacked> extends Default
}
@Override
public ENTITY attach(boolean isOnCreate) {
public ENTITY persist(boolean isOnCreate) {
Node node = StateProvider.retrieveState();
if (node != null) {
setUnderlyingState(node);
setPersistentState(node);
} else {
createAndAssignState();
}

View File

@@ -22,9 +22,9 @@ import org.springframework.data.graph.core.NodeBacked;
import org.springframework.data.graph.neo4j.finder.FinderFactory;
import org.springframework.data.graph.neo4j.support.GraphDatabaseContext;
import static org.springframework.data.graph.neo4j.fieldaccess.PartialNodeEntityStateAccessors.getId;
import static org.springframework.data.graph.neo4j.fieldaccess.PartialNodeEntityState.getId;
public class NodeEntityStateAccessorsFactory {
public class NodeEntityStateFactory {
private GraphDatabaseContext graphDatabaseContext;
@@ -32,23 +32,23 @@ public class NodeEntityStateAccessorsFactory {
private NodeDelegatingFieldAccessorFactory nodeDelegatingFieldAccessorFactory;
public EntityStateAccessors<NodeBacked,Node> getEntityStateAccessors(final NodeBacked entity) {
public EntityState<NodeBacked,Node> getEntityState(final NodeBacked entity) {
final NodeEntity graphEntityAnnotation = entity.getClass().getAnnotation(NodeEntity.class); // todo cache ??
boolean autoAttach = graphEntityAnnotation.autoAttach();
if (graphEntityAnnotation.partial()) {
PartialNodeEntityStateAccessors<NodeBacked> partialNodeEntityStateAccessors = new PartialNodeEntityStateAccessors<NodeBacked>(null, entity, entity.getClass(), graphDatabaseContext, finderFactory);
return new DetachableEntityStateAccessors<NodeBacked, Node>(partialNodeEntityStateAccessors, graphDatabaseContext, false) {
PartialNodeEntityState<NodeBacked> partialNodeEntityState = new PartialNodeEntityState<NodeBacked>(null, entity, entity.getClass(), graphDatabaseContext, finderFactory);
return new DetachableEntityState<NodeBacked, Node>(partialNodeEntityState, graphDatabaseContext, false) {
@Override
protected boolean transactionIsRunning() {
return super.transactionIsRunning() && getId(entity, entity.getClass()) != null;
}
};
} else {
NodeEntityStateAccessors<NodeBacked> nodeEntityStateAccessors = new NodeEntityStateAccessors<NodeBacked>(null, entity, entity.getClass(), graphDatabaseContext, nodeDelegatingFieldAccessorFactory);
NodeEntityState<NodeBacked> nodeEntityState = new NodeEntityState<NodeBacked>(null, entity, entity.getClass(), graphDatabaseContext, nodeDelegatingFieldAccessorFactory);
if (autoAttach) {
return new NestedTransactionEntityStateAccessors<NodeBacked, Node>(nodeEntityStateAccessors,graphDatabaseContext);
return new NestedTransactionEntityState<NodeBacked, Node>(nodeEntityState,graphDatabaseContext);
} else {
return new DetachableEntityStateAccessors<NodeBacked, Node>(nodeEntityStateAccessors, graphDatabaseContext, autoAttach);
return new DetachableEntityState<NodeBacked, Node>(nodeEntityState, graphDatabaseContext, autoAttach);
}
}
}

View File

@@ -57,6 +57,6 @@ public abstract class NodeToNodesRelationshipFieldAccessor<TARGET extends GraphB
@Override
protected Node getState(final NodeBacked entity) {
return entity.getUnderlyingState();
return entity.getPersistentState();
}
}

View File

@@ -105,7 +105,7 @@ public class OneToNRelationshipEntityFieldAccessorFactory implements FieldAccess
@Override
protected Iterable<Relationship> getStatesFromEntity(final NodeBacked entity) {
return entity.getUnderlyingState().getRelationships(type, direction);
return entity.getPersistentState().getRelationships(type, direction);
}
@Override
@@ -115,7 +115,7 @@ public class OneToNRelationshipEntityFieldAccessorFactory implements FieldAccess
@Override
protected Node getState(final NodeBacked nodeBacked) {
return nodeBacked.getUnderlyingState();
return nodeBacked.getPersistentState();
}
}

View File

@@ -36,14 +36,14 @@ import java.util.Collection;
* @author Michael Hunger
* @since 21.09.2010
*/
public class PartialNodeEntityStateAccessors<ENTITY extends NodeBacked> extends DefaultEntityStateAccessors<ENTITY, Node> {
public class PartialNodeEntityState<ENTITY extends NodeBacked> extends DefaultEntityState<ENTITY, Node> {
public static final String FOREIGN_ID = "foreignId";
public static final String FOREIGN_ID_INDEX = "foreign_id";
private final GraphDatabaseContext graphDatabaseContext;
public PartialNodeEntityStateAccessors(final Node underlyingState, final ENTITY entity, final Class<? extends ENTITY> type, final GraphDatabaseContext graphDatabaseContext, final FinderFactory finderFactory) {
public PartialNodeEntityState(final Node underlyingState, final ENTITY entity, final Class<? extends ENTITY> type, final GraphDatabaseContext graphDatabaseContext, final FinderFactory finderFactory) {
super(underlyingState, entity, type, new DelegatingFieldAccessorFactory(graphDatabaseContext, finderFactory) {
@Override
@@ -105,7 +105,7 @@ public class PartialNodeEntityStateAccessors<ENTITY extends NodeBacked> extends
// TODO handle non persisted Entity like running outside of an transaction
@Override
public void createAndAssignState() {
if (entity.getUnderlyingState() != null) return;
if (entity.getPersistentState() != null) return;
try {
final Object id = getId(entity,type);
if (id == null) return;
@@ -115,13 +115,13 @@ public class PartialNodeEntityStateAccessors<ENTITY extends NodeBacked> extends
if (node == null) {
node = graphDatabaseContext.createNode();
persistForeignId(node, id);
setUnderlyingState(node);
entity.setUnderlyingState(node);
log.info("User-defined constructor called on class " + entity.getClass() + "; created Node [" + entity.getUnderlyingState() + "]; Updating metamodel");
setPersistentState(node);
entity.setPersistentState(node);
log.info("User-defined constructor called on class " + entity.getClass() + "; created Node [" + entity.getPersistentState() + "]; Updating metamodel");
graphDatabaseContext.postEntityCreation(entity);
} else {
setUnderlyingState(node);
entity.setUnderlyingState(node);
setPersistentState(node);
entity.setPersistentState(node);
}
} catch (NotInTransactionException e) {
throw new InvalidDataAccessResourceUsageException("Not in a Neo4j transaction.", e);
@@ -129,10 +129,10 @@ public class PartialNodeEntityStateAccessors<ENTITY extends NodeBacked> extends
}
@Override
public ENTITY attach(boolean isOnCreate) {
public ENTITY persist(boolean isOnCreate) {
Node node = StateProvider.retrieveState();
if (node != null) {
setUnderlyingState(node);
setPersistentState(node);
} else {
createAndAssignState();
}

View File

@@ -62,7 +62,7 @@ public class PropertyFieldAccessorFactory implements FieldAccessorFactory<GraphB
@Override
public Object setValue(final GraphBacked<PropertyContainer> graphBacked, final Object newVal) {
final PropertyContainer propertyContainer = graphBacked.getUnderlyingState();
final PropertyContainer propertyContainer = graphBacked.getPersistentState();
if (newVal==null) {
propertyContainer.removeProperty(getPropertyName());
} else {
@@ -77,7 +77,7 @@ public class PropertyFieldAccessorFactory implements FieldAccessorFactory<GraphB
}
protected Object doGetValue(final GraphBacked<PropertyContainer> graphBacked) {
return graphBacked.getUnderlyingState().getProperty(getPropertyName(), getDefaultValue(field.getType()));
return graphBacked.getPersistentState().getProperty(getPropertyName(), getDefaultValue(field.getType()));
}
private String getPropertyName() {

View File

@@ -30,13 +30,13 @@ import java.util.Collection;
* @author Michael Hunger
* @since 21.09.2010
*/
public class RelationshipEntityStateAccessors<ENTITY extends RelationshipBacked> extends DefaultEntityStateAccessors<ENTITY, Relationship> {
public class RelationshipEntityState<ENTITY extends RelationshipBacked> extends DefaultEntityState<ENTITY, Relationship> {
private final GraphDatabaseContext graphDatabaseContext;
private final FinderFactory finderFactory;
public RelationshipEntityStateAccessors(final Relationship underlyingState, final ENTITY entity, final Class<? extends ENTITY> type, final GraphDatabaseContext graphDatabaseContext, final FinderFactory finderFactory) {
public RelationshipEntityState(final Relationship underlyingState, final ENTITY entity, final Class<? extends ENTITY> type, final GraphDatabaseContext graphDatabaseContext, final FinderFactory finderFactory) {
super(underlyingState, entity, type, new DelegatingFieldAccessorFactory(graphDatabaseContext, finderFactory) {
@Override
protected Collection<FieldAccessorListenerFactory<?>> createListenerFactories() {
@@ -64,27 +64,27 @@ public class RelationshipEntityStateAccessors<ENTITY extends RelationshipBacked>
@Override
public void createAndAssignState() {
if (entity.getUnderlyingState()!=null) return;
if (entity.getPersistentState()!=null) return;
try {
final Object id = getIdFromEntity();
if (id instanceof Number) {
final Relationship relationship = graphDatabaseContext.getRelationshipById(((Number) id).longValue());
setUnderlyingState(relationship);
setPersistentState(relationship);
if (log.isInfoEnabled())
log.info("Entity reattached " + entity.getClass() + "; used Relationship [" + entity.getUnderlyingState() + "];");
log.info("Entity reattached " + entity.getClass() + "; used Relationship [" + entity.getPersistentState() + "];");
return;
}
final Relationship relationship = null; // TODO graphDatabaseContext.create();
setUnderlyingState(relationship);
if (log.isInfoEnabled()) log.info("User-defined constructor called on class " + entity.getClass() + "; created Relationship [" + getUnderlyingState() + "]; Updating metamodel");
setPersistentState(relationship);
if (log.isInfoEnabled()) log.info("User-defined constructor called on class " + entity.getClass() + "; created Relationship [" + getPersistentState() + "]; Updating metamodel");
} catch (NotInTransactionException e) {
throw new InvalidDataAccessResourceUsageException("Not in a Neo4j transaction.", e);
}
}
@Override
public ENTITY attach(boolean isOnCreate) {
public ENTITY persist(boolean isOnCreate) {
createAndAssignState();
return entity;
}

View File

@@ -21,14 +21,14 @@ import org.springframework.data.graph.core.RelationshipBacked;
import org.springframework.data.graph.neo4j.finder.FinderFactory;
import org.springframework.data.graph.neo4j.support.GraphDatabaseContext;
public class RelationshipEntityStateAccessorsFactory {
public class RelationshipEntityStateFactory {
private GraphDatabaseContext graphDatabaseContext;
private FinderFactory finderFactory;
public EntityStateAccessors<RelationshipBacked, Relationship> getEntityStateAccessors(final RelationshipBacked entity) {
return new RelationshipEntityStateAccessors<RelationshipBacked>(null,entity,entity.getClass(), graphDatabaseContext, finderFactory);
public EntityState<RelationshipBacked, Relationship> getEntityState(final RelationshipBacked entity) {
return new RelationshipEntityState<RelationshipBacked>(null,entity,entity.getClass(), graphDatabaseContext, finderFactory);
}
public void setGraphDatabaseContext(GraphDatabaseContext graphDatabaseContext) {

View File

@@ -94,7 +94,7 @@ public class RelationshipNodeFieldAccessorFactory implements FieldAccessorFactor
@Override
public Object getValue(final RelationshipBacked relationshipBacked) {
final Relationship relationship = relationshipBacked.getUnderlyingState();
final Relationship relationship = relationshipBacked.getPersistentState();
final Node node = getNode(relationship);
if (node == null) {
return null;

View File

@@ -138,7 +138,7 @@ public class GraphDatabaseContext {
* @param entity to remove
*/
public void removeNodeEntity(NodeBacked entity) {
Node node = entity.getUnderlyingState();
Node node = entity.getPersistentState();
if (node==null) return;
this.nodeTypeStrategy.preEntityRemoval(entity);
for (Relationship relationship : node.getRelationships()) {
@@ -148,7 +148,7 @@ public class GraphDatabaseContext {
node.delete();
}
public void removeRelationshipEntity(RelationshipBacked entity) {
Relationship relationship = entity.getUnderlyingState();
Relationship relationship = entity.getPersistentState();
if (relationship==null) return;
removeRelationship(relationship);
}
@@ -333,7 +333,7 @@ public class GraphDatabaseContext {
}
public <T extends GraphBacked> T projectTo(GraphBacked entity, Class<T> targetType) {
final Object state = entity.getUnderlyingState();
final Object state = entity.getPersistentState();
if (state instanceof Node)
return (T) graphEntityInstantiator.createEntityFromState((Node) state, (Class<? extends NodeBacked>) targetType);
else

View File

@@ -92,7 +92,7 @@ public class SubReferenceNodeTypeStrategy implements NodeTypeStrategy {
Class<? extends NodeBacked> clazz = entity.getClass();
final Node subReference = obtainSubreferenceNode(clazz);
entity.getUnderlyingState().createRelationshipTo(subReference, INSTANCE_OF_RELATIONSHIP_TYPE);
entity.getPersistentState().createRelationshipTo(subReference, INSTANCE_OF_RELATIONSHIP_TYPE);
subReference.setProperty(SUBREF_CLASS_KEY, clazz.getName());
if (log.isDebugEnabled()) log.debug("Created link to subref node: " + subReference + " with type: " + clazz.getName());
@@ -110,7 +110,7 @@ public class SubReferenceNodeTypeStrategy implements NodeTypeStrategy {
Class<? extends NodeBacked> clazz = entity.getClass();
final Node subReference = obtainSubreferenceNode(clazz);
Node subRefNode = entity.getUnderlyingState();
Node subRefNode = entity.getPersistentState();
Relationship instanceOf = subRefNode.getSingleRelationship(INSTANCE_OF_RELATIONSHIP_TYPE, Direction.OUTGOING);
instanceOf.delete();
if (log.isDebugEnabled()) log.debug("Removed link to subref node: " + subReference + " with type: " + clazz.getName());

View File

@@ -31,7 +31,7 @@ public class Neo4jConstructorGraphEntityInstantiator extends AbstractConstructor
@Override
protected void setState(NodeBacked entity, Node s) {
entity.setUnderlyingState(s);
entity.setPersistentState(s);
}
}

View File

@@ -27,23 +27,19 @@ import org.neo4j.graphdb.RelationshipType;
import org.neo4j.graphdb.traversal.TraversalDescription;
import org.neo4j.graphdb.traversal.Traverser;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.data.graph.annotation.NodeEntity;
import org.springframework.data.graph.core.NodeBacked;
import org.springframework.data.graph.core.RelationshipBacked;
import org.springframework.data.graph.neo4j.fieldaccess.*;
import org.springframework.data.graph.neo4j.support.GraphDatabaseContext;
import org.springframework.persistence.support.AbstractTypeAnnotatingMixinFields;
import org.springframework.data.graph.annotation.*;
import java.lang.reflect.Field;
import static org.springframework.data.graph.neo4j.fieldaccess.DoReturn.unwrap;
import org.springframework.persistence.support.StateProvider;
/**
* Aspect for handling node entity creation and field access (read & write)
* puts the underlying state (Node) into and delegates field access to an {@link EntityStateAccessors} instance,
* created by a configured {@link NodeEntityStateAccessorsFactory}.
* puts the underlying state (Node) into and delegates field access to an {@link org.springframework.data.graph.neo4j.fieldaccess.EntityState} instance,
* created by a configured {@link org.springframework.data.graph.neo4j.fieldaccess.NodeEntityStateFactory}.
*
* Handles constructor invocation and partial entities as well.
*/
@@ -69,16 +65,16 @@ public aspect Neo4jNodeBacking { // extends AbstractTypeAnnotatingMixinFields<No
private GraphDatabaseContext graphDatabaseContext;
private NodeEntityStateAccessorsFactory entityStateAccessorsFactory;
private NodeEntityStateFactory entityStateFactory;
public void setGraphDatabaseContext(GraphDatabaseContext graphDatabaseContext) {
this.graphDatabaseContext = graphDatabaseContext;
}
public void setNodeEntityStateAccessorsFactory(NodeEntityStateAccessorsFactory entityStateAccessorsFactory) {
this.entityStateAccessorsFactory = entityStateAccessorsFactory;
public void setNodeEntityStateFactory(NodeEntityStateFactory entityStateFactory) {
this.entityStateFactory = entityStateFactory;
}
/**
* pointcut for constructors not taking a node to be handled by the aspect and the {@link EntityStateAccessors}
* pointcut for constructors not taking a node to be handled by the aspect and the {@link org.springframework.data.graph.neo4j.fieldaccess.EntityState}
*/
pointcut arbitraryUserConstructorOfNodeBackedObject(NodeBacked entity) :
execution((@NodeEntity *).new(..)) &&
@@ -89,51 +85,51 @@ public aspect Neo4jNodeBacking { // extends AbstractTypeAnnotatingMixinFields<No
/**
* Handle outside entity instantiation by either creating an appropriate backing node in the graph or in the case
* of a reinstantiated partial entity by assigning the original node to the entity, the concrete behaviour is delegated
* to the {@link EntityStateAccessors}. Also handles the java type representation in the graph.
* to the {@link org.springframework.data.graph.neo4j.fieldaccess.EntityState}. Also handles the java type representation in the graph.
* When running outside of a transaction, no node is created, this is handled later when the entity is accessed within
* a transaction again.
*/
before(NodeBacked entity): arbitraryUserConstructorOfNodeBackedObject(entity) {
if (entityStateAccessorsFactory == null) {
log.error("entityStateAccessorsFactory not set, not creating accessors for " + entity.getClass());
if (entityStateFactory == null) {
log.error("entityStateFactory not set, not creating accessors for " + entity.getClass());
} else {
if (entity.stateAccessors != null) return;
EntityStateAccessors<NodeBacked, Node> stateAccessors = entityStateAccessorsFactory.getEntityStateAccessors(entity);
entity.stateAccessors = stateAccessors;
stateAccessors.attach(true);
if (entity.entityState != null) return;
EntityState<NodeBacked, Node> entityState = entityStateFactory.getEntityState(entity);
entity.entityState = entityState;
entityState.persist(true);
}
}
public NodeBacked NodeBacked.attach() {
return this.stateAccessors.attach(false);
return this.entityState.persist(false);
}
/**
* State accessors that encapsulate the underlying state and the behaviour related to it (field access, creation)
*/
private transient EntityStateAccessors<NodeBacked,Node> NodeBacked.stateAccessors;
private transient EntityState<NodeBacked,Node> NodeBacked.entityState;
/**
* sets the underlying state to the given node, creates an {@link EntityStateAccessors} instance on demand for delegating
* sets the underlying state to the given node, creates an {@link org.springframework.data.graph.neo4j.fieldaccess.EntityState} instance on demand for delegating
* the behaviour, otherwise just updates the backing state
* @param n the node to be the backing state of the entity
*/
public void NodeBacked.setUnderlyingState(Node n) {
if (this.stateAccessors == null) {
this.stateAccessors = Neo4jNodeBacking.aspectOf().entityStateAccessorsFactory.getEntityStateAccessors(this);
public void NodeBacked.setPersistentState(Node n) {
if (this.entityState == null) {
this.entityState = Neo4jNodeBacking.aspectOf().entityStateFactory.getEntityState(this);
}
this.stateAccessors.setUnderlyingState(n);
this.entityState.setPersistentState(n);
}
public Node NodeBacked.getUnderlyingState() {
return this.stateAccessors.getUnderlyingState();
public Node NodeBacked.getPersistentState() {
return this.entityState.getPersistentState();
}
public EntityStateAccessors NodeBacked.getStateAccessors() {
return stateAccessors;
public EntityState NodeBacked.getEntityState() {
return entityState;
}
public boolean NodeBacked.hasUnderlyingNode() {
return this.stateAccessors!=null && this.stateAccessors.hasUnderlyingState();
return this.entityState!=null && this.entityState.hasPersistentState();
}
public <T extends NodeBacked> T NodeBacked.projectTo(Class<T> targetType) {
@@ -147,7 +143,7 @@ public aspect Neo4jNodeBacking { // extends AbstractTypeAnnotatingMixinFields<No
* @return the newly created relationship to the target node
*/
public Relationship NodeBacked.relateTo(NodeBacked target, RelationshipType type) {
return this.getUnderlyingState().createRelationshipTo(target.getUnderlyingState(), type);
return this.getPersistentState().createRelationshipTo(target.getPersistentState(), type);
}
/**
@@ -155,7 +151,7 @@ public aspect Neo4jNodeBacking { // extends AbstractTypeAnnotatingMixinFields<No
*/
public Long NodeBacked.getNodeId() {
if (!hasUnderlyingNode()) return null;
return getUnderlyingState().getId();
return getPersistentState().getId();
}
/**
@@ -167,7 +163,7 @@ public aspect Neo4jNodeBacking { // extends AbstractTypeAnnotatingMixinFields<No
*/
public <T extends NodeBacked> Iterable<T> NodeBacked.findAllByTraversal(final Class<T> targetType, TraversalDescription traversalDescription) {
if (!hasUnderlyingNode()) throw new IllegalStateException("No node attached to " + this);
final Traverser traverser = traversalDescription.traverse(this.getUnderlyingState());
final Traverser traverser = traversalDescription.traverse(this.getPersistentState());
return new NodeBackedNodeIterableWrapper<T>(traverser, targetType, Neo4jNodeBacking.aspectOf().graphDatabaseContext);
}
@@ -186,7 +182,7 @@ public aspect Neo4jNodeBacking { // extends AbstractTypeAnnotatingMixinFields<No
* @return relationship entity, instance of the provided relationshipClass
*/
public <R extends RelationshipBacked, N extends NodeBacked> R NodeBacked.relateTo(N target, Class<R> relationshipClass, String relationshipType) {
Relationship rel = this.getUnderlyingState().createRelationshipTo( target.getUnderlyingState(), DynamicRelationshipType.withName(relationshipType));
Relationship rel = this.getPersistentState().createRelationshipTo( target.getPersistentState(), DynamicRelationshipType.withName(relationshipType));
return (R)Neo4jNodeBacking.aspectOf().graphDatabaseContext.createEntityFromState(rel, relationshipClass);
}
@@ -204,9 +200,9 @@ public aspect Neo4jNodeBacking { // extends AbstractTypeAnnotatingMixinFields<No
* @param relationshipType
*/
public void NodeBacked.removeRelationshipTo(NodeBacked target, String relationshipType) {
Node myNode=this.getUnderlyingState();
Node otherNode=target.getUnderlyingState();
for (Relationship rel : this.getUnderlyingState().getRelationships(DynamicRelationshipType.withName(relationshipType))) {
Node myNode=this.getPersistentState();
Node otherNode=target.getPersistentState();
for (Relationship rel : this.getPersistentState().getRelationships(DynamicRelationshipType.withName(relationshipType))) {
if (rel.getOtherNode(myNode).equals(otherNode)) {
rel.delete();
return;
@@ -222,9 +218,9 @@ public aspect Neo4jNodeBacking { // extends AbstractTypeAnnotatingMixinFields<No
* @return and instance of the requested relationshipClass if the relationship was found, null otherwise
*/
public <R extends RelationshipBacked> R NodeBacked.getRelationshipTo( NodeBacked node, Class<R> relationshipClass, String type) {
Node myNode=this.getUnderlyingState();
Node otherNode=node.getUnderlyingState();
for (Relationship rel : this.getUnderlyingState().getRelationships(DynamicRelationshipType.withName(type))) {
Node myNode=this.getPersistentState();
Node otherNode=node.getPersistentState();
for (Relationship rel : this.getPersistentState().getRelationships(DynamicRelationshipType.withName(type))) {
if (rel.getOtherNode(myNode).equals(otherNode)) return (R)Neo4jNodeBacking.aspectOf().graphDatabaseContext.createEntityFromState(rel, relationshipClass);
}
return null;
@@ -238,7 +234,7 @@ public aspect Neo4jNodeBacking { // extends AbstractTypeAnnotatingMixinFields<No
if (obj == this) return true;
if (!hasUnderlyingNode()) return false;
if (obj instanceof NodeBacked) {
return this.getUnderlyingState().equals(((NodeBacked) obj).getUnderlyingState());
return this.getPersistentState().equals(((NodeBacked) obj).getPersistentState());
}
return false;
}
@@ -248,15 +244,15 @@ public aspect Neo4jNodeBacking { // extends AbstractTypeAnnotatingMixinFields<No
*/
public final int NodeBacked.hashCode() {
if (!hasUnderlyingNode()) return System.identityHashCode(this);
return getUnderlyingState().hashCode();
return getPersistentState().hashCode();
}
/**
* delegates field reads to the state accessors instance
*/
Object around(NodeBacked entity): entityFieldGet(entity) {
if (entity.stateAccessors==null) return proceed(entity);
Object result=entity.stateAccessors.getValue(field(thisJoinPoint));
if (entity.entityState==null) return proceed(entity);
Object result=entity.entityState.getValue(field(thisJoinPoint));
if (result instanceof DoReturn) return unwrap(result);
return proceed(entity);
}
@@ -265,8 +261,8 @@ public aspect Neo4jNodeBacking { // extends AbstractTypeAnnotatingMixinFields<No
* delegates field writes to the state accessors instance
*/
Object around(NodeBacked entity, Object newVal) : entityFieldSet(entity, newVal) {
if (entity.stateAccessors==null) return proceed(entity,newVal);
Object result=entity.stateAccessors.setValue(field(thisJoinPoint),newVal);
if (entity.entityState==null) return proceed(entity,newVal);
Object result=entity.entityState.setValue(field(thisJoinPoint),newVal);
if (result instanceof DoReturn) return unwrap(result);
return proceed(entity,result);
}

View File

@@ -18,7 +18,7 @@ package org.springframework.data.graph.neo4j.support.node;
import org.neo4j.graphdb.Node;
import org.springframework.data.graph.core.NodeBacked;
import org.springframework.data.graph.neo4j.fieldaccess.PartialNodeEntityStateAccessors;
import org.springframework.data.graph.neo4j.fieldaccess.PartialNodeEntityState;
import org.springframework.persistence.support.EntityInstantiator;
import javax.persistence.EntityManager;
@@ -51,10 +51,10 @@ public class PartialNeo4jEntityInstantiator implements EntityInstantiator<NodeBa
* @return
*/
public <T extends NodeBacked> T createEntityFromState(Node n, Class<T> entityClass) {
if (n.hasProperty(PartialNodeEntityStateAccessors.FOREIGN_ID)) {
final Object foreignId = n.getProperty(PartialNodeEntityStateAccessors.FOREIGN_ID);
if (n.hasProperty(PartialNodeEntityState.FOREIGN_ID)) {
final Object foreignId = n.getProperty(PartialNodeEntityState.FOREIGN_ID);
final T result = entityManager.find(entityClass, foreignId);
result.setUnderlyingState(n);
result.setPersistentState(n);
return result;
}
return delegate.createEntityFromState(n, entityClass);

View File

@@ -54,7 +54,7 @@ public class ConstructorBypassingGraphRelationshipInstantiator implements Entity
@Override
public <T extends RelationshipBacked> T createEntityFromState(Relationship r, Class<T> c) {
T t = createWithoutConstructorInvocation(c);
t.setUnderlyingState(r);
t.setPersistentState(r);
return t;
}

View File

@@ -22,12 +22,10 @@ import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.reflect.FieldSignature;
import org.neo4j.graphdb.Relationship;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.data.graph.annotation.RelationshipEntity;
import org.springframework.data.graph.core.NodeBacked;
import org.springframework.data.graph.core.RelationshipBacked;
import org.springframework.data.graph.neo4j.fieldaccess.*;
import org.springframework.data.graph.neo4j.support.GraphDatabaseContext;
import org.springframework.persistence.support.AbstractTypeAnnotatingMixinFields;
import org.springframework.data.graph.annotation.*;
import java.lang.reflect.Field;
@@ -35,8 +33,8 @@ import static org.springframework.data.graph.neo4j.fieldaccess.DoReturn.unwrap;
/**
* Aspect for handling relationship entity creation and field access (read & write)
* puts the underlying state into and delegates field access to an {@link EntityStateAccessors} instance,
* created by a configured {@link RelationshipEntityStateAccessorsFactory}
* puts the underlying state into and delegates field access to an {@link org.springframework.data.graph.neo4j.fieldaccess.EntityState} instance,
* created by a configured {@link org.springframework.data.graph.neo4j.fieldaccess.RelationshipEntityStateFactory}
*/
public aspect Neo4jRelationshipBacking {
@@ -59,47 +57,47 @@ public aspect Neo4jRelationshipBacking {
!set(* RelationshipBacked.*);
private GraphDatabaseContext graphDatabaseContext;
private RelationshipEntityStateAccessorsFactory entityStateAccessorsFactory;
private RelationshipEntityStateFactory entityStateFactory;
public void setGraphDatabaseContext(GraphDatabaseContext graphDatabaseContext) {
this.graphDatabaseContext = graphDatabaseContext;
}
public void setRelationshipEntityStateAccessorsFactory(RelationshipEntityStateAccessorsFactory entityStateAccessorsFactory) {
this.entityStateAccessorsFactory = entityStateAccessorsFactory;
public void setRelationshipEntityStateFactory(RelationshipEntityStateFactory entityStateFactory) {
this.entityStateFactory = entityStateFactory;
}
/**
* field for {@link EntityStateAccessors} that takes care of all entity operations
* field for {@link org.springframework.data.graph.neo4j.fieldaccess.EntityState} that takes care of all entity operations
*/
private EntityStateAccessors<RelationshipBacked,Relationship> RelationshipBacked.stateAccessors;
private EntityState<RelationshipBacked,Relationship> RelationshipBacked.entityState;
/**
* creates a new {@link EntityStateAccessors} instance with the relationship parameter or updates an existing one
* creates a new {@link org.springframework.data.graph.neo4j.fieldaccess.EntityState} instance with the relationship parameter or updates an existing one
* @param r
*/
public void RelationshipBacked.setUnderlyingState(Relationship r) {
if (this.stateAccessors == null) {
this.stateAccessors = Neo4jRelationshipBacking.aspectOf().entityStateAccessorsFactory.getEntityStateAccessors(this);
public void RelationshipBacked.setPersistentState(Relationship r) {
if (this.entityState == null) {
this.entityState = Neo4jRelationshipBacking.aspectOf().entityStateFactory.getEntityState(this);
}
this.stateAccessors.setUnderlyingState(r);
this.entityState.setPersistentState(r);
}
public Relationship RelationshipBacked.getUnderlyingState() {
return this.stateAccessors.getUnderlyingState();
public Relationship RelationshipBacked.getPersistentState() {
return this.entityState.getPersistentState();
}
public boolean RelationshipBacked.hasUnderlyingRelationship() {
return this.stateAccessors.hasUnderlyingState();
return this.entityState.hasPersistentState();
}
/**
* @return relationship id if there is an underlying relationship
*/
public Long RelationshipBacked.getId() {
public Long RelationshipBacked.getRelationshipId() {
if (!hasUnderlyingRelationship()) return null;
return getUnderlyingState().getId();
return getPersistentState().getId();
}
@@ -109,7 +107,7 @@ public aspect Neo4jRelationshipBacking {
*/
public final boolean RelationshipBacked.equals(Object obj) {
if (obj instanceof RelationshipBacked) {
return this.getUnderlyingState().equals(((RelationshipBacked) obj).getUnderlyingState());
return this.getPersistentState().equals(((RelationshipBacked) obj).getPersistentState());
}
return false;
}
@@ -118,7 +116,7 @@ public aspect Neo4jRelationshipBacking {
* @return hashCode of the underlying relationship
*/
public final int RelationshipBacked.hashCode() {
return getUnderlyingState().hashCode();
return getPersistentState().hashCode();
}
public void RelationshipBacked.remove() {
@@ -130,13 +128,13 @@ public aspect Neo4jRelationshipBacking {
}
Object around(RelationshipBacked entity): entityFieldGet(entity) {
Object result=entity.stateAccessors.getValue(field(thisJoinPoint));
Object result=entity.entityState.getValue(field(thisJoinPoint));
if (result instanceof DoReturn) return unwrap(result);
return proceed(entity);
}
Object around(RelationshipBacked entity, Object newVal) : entityFieldSet(entity, newVal) {
Object result=entity.stateAccessors.setValue(field(thisJoinPoint),newVal);
Object result=entity.entityState.setValue(field(thisJoinPoint),newVal);
if (result instanceof DoReturn) return unwrap(result);
return proceed(entity,result);
}

View File

@@ -9,6 +9,6 @@ public abstract class Car {
}
public Car(Node n) {
setUnderlyingState(n);
setPersistentState(n);
}
}

View File

@@ -31,7 +31,7 @@ privileged aspect Person_Graph_Entity {
* @param node
*/
public Person.new(Node node) {
setUnderlyingState(node);
setPersistentState(node);
}
// public static long Person.countPeople() {

View File

@@ -52,16 +52,16 @@ public class RecommendationTest {
public void jpaUserHasNodeAndId() {
User user = user("John");
Assert.assertNotNull("jpa-id",user.getId());
Assert.assertNotNull("node",user.getUnderlyingState());
Assert.assertNotNull("node",user.getPersistentState());
}
@Test
@Transactional
public void jpaUserCanHaveGraphProperties() {
User user = user("John");
Assert.assertNotNull("jpa-id",user.getId());
Assert.assertNotNull("node",user.getUnderlyingState());
Assert.assertNotNull("node",user.getPersistentState());
Assert.assertNotNull("nickname in entity",user.getNickname());
Assert.assertEquals("nickname in graph","John",user.getUnderlyingState().getProperty("nickname"));
Assert.assertEquals("nickname in graph","John",user.getPersistentState().getProperty("nickname"));
}
private User user(final String name) {
@@ -79,7 +79,7 @@ public class RecommendationTest {
public void jpaUserCanHaveGraphRelationships() {
User user = user("John");
Assert.assertNotNull("jpa-id",user.getId());
Assert.assertNotNull("node",user.getUnderlyingState());
Assert.assertNotNull("node",user.getPersistentState());
User user2 = user("Jane");
user.knows(user2);
Assert.assertEquals(user2, user.getFriends().iterator().next());

View File

@@ -41,7 +41,7 @@ public class AttachEntityTest {
}
private Node nodeFor(NodeBacked nodeBacked) {
return nodeBacked.getUnderlyingState();
return nodeBacked.getPersistentState();
}

View File

@@ -76,14 +76,27 @@ public class IndexTest {
final Person foundMe = personFinder.findByPropertyValue(Person.NAME_INDEX, "Person.name", NAME_VALUE);
assertEquals(spouse,foundMe.getSpouse());
}
@Test
@Transactional
@Ignore("Missing method to remove a node/property from index")
@Ignore("remove property from index not workin")
public void testRemovePropertyFromIndex() {
Group group = new Group();
group.setName(NAME_VALUE);
final NodeFinder<Group> finder = finderFactory.createNodeEntityFinder(Group.class);
graphDatabaseContext.getNodeIndex("node").remove(group.getUnderlyingState(), NAME, null);
graphDatabaseContext.getNodeIndex("node").remove(group.getPersistentState(), NAME);
final Group found = finder.findByPropertyValue(null, NAME, NAME_VALUE);
assertNull("Group.name removed from index", found);
}
@Test
@Transactional
@Ignore("remove property from index not workin")
public void testRemoveNodeFromIndex() {
Group group = new Group();
group.setName(NAME_VALUE);
final NodeFinder<Group> finder = finderFactory.createNodeEntityFinder(Group.class);
graphDatabaseContext.getNodeIndex("node").remove(group.getPersistentState());
final Group found = finder.findByPropertyValue(null, NAME, NAME_VALUE);
assertNull("Group.name removed from index", found);
}

View File

@@ -108,7 +108,7 @@ public class ModificationOutsideOfTransactionTest
private Node nodeFor( Person person )
{
return person.getUnderlyingState();
return person.getPersistentState();
}
@Test

View File

@@ -49,8 +49,8 @@ public class NodeEntityRelationshipTest {
Person p = new Person("Michael", 35);
Person spouse = new Person("Tina",36);
p.setSpouse(spouse);
Node spouseNode=p.getUnderlyingState().getSingleRelationship(DynamicRelationshipType.withName("Person.spouse"), Direction.OUTGOING).getEndNode();
assertEquals(spouse.getUnderlyingState(), spouseNode);
Node spouseNode=p.getPersistentState().getSingleRelationship(DynamicRelationshipType.withName("Person.spouse"), Direction.OUTGOING).getEndNode();
assertEquals(spouse.getPersistentState(), spouseNode);
assertEquals(spouse, p.getSpouse());
}
@@ -60,8 +60,8 @@ public class NodeEntityRelationshipTest {
Person p = new Person("Michael", 35);
Person mother = new Person("Gabi",60);
p.setMother(mother);
Node motherNode = p.getUnderlyingState().getSingleRelationship(DynamicRelationshipType.withName("mother"), Direction.OUTGOING).getEndNode();
assertEquals(mother.getUnderlyingState(), motherNode);
Node motherNode = p.getPersistentState().getSingleRelationship(DynamicRelationshipType.withName("mother"), Direction.OUTGOING).getEndNode();
assertEquals(mother.getPersistentState(), motherNode);
assertEquals(mother, p.getMother());
}
@@ -72,7 +72,7 @@ public class NodeEntityRelationshipTest {
Person spouse = new Person("Tina", 36);
p.setSpouse(spouse);
p.setSpouse(null);
Assert.assertNull(p.getUnderlyingState().getSingleRelationship(DynamicRelationshipType.withName("Person.spouse"), Direction.OUTGOING));
Assert.assertNull(p.getPersistentState().getSingleRelationship(DynamicRelationshipType.withName("Person.spouse"), Direction.OUTGOING));
Assert.assertNull(p.getSpouse());
}
@@ -84,7 +84,7 @@ public class NodeEntityRelationshipTest {
Person friend = new Person("Helga", 34);
p.setSpouse(spouse);
p.setSpouse(friend);
assertEquals(friend.getUnderlyingState(), p.getUnderlyingState().getSingleRelationship(DynamicRelationshipType.withName("Person.spouse"), Direction.OUTGOING).getEndNode());
assertEquals(friend.getPersistentState(), p.getPersistentState().getSingleRelationship(DynamicRelationshipType.withName("Person.spouse"), Direction.OUTGOING).getEndNode());
assertEquals(friend, p.getSpouse());
}
@@ -94,7 +94,7 @@ public class NodeEntityRelationshipTest {
Person p = new Person("David", 25);
Person boss = new Person("Emil", 32);
p.setBoss(boss);
assertEquals(boss.getUnderlyingState(), p.getUnderlyingState().getSingleRelationship(DynamicRelationshipType.withName("boss"), Direction.INCOMING).getStartNode());
assertEquals(boss.getPersistentState(), p.getPersistentState().getSingleRelationship(DynamicRelationshipType.withName("boss"), Direction.INCOMING).getStartNode());
assertEquals(boss, p.getBoss());
}
@@ -112,10 +112,10 @@ public class NodeEntityRelationshipTest {
Group group = new Group();
Set<Person> persons = new HashSet<Person>(Arrays.asList(michael, david));
group.setPersons(persons);
Relationship michaelRel = michael.getUnderlyingState().getSingleRelationship(DynamicRelationshipType.withName("persons"), Direction.INCOMING);
Relationship davidRel = david.getUnderlyingState().getSingleRelationship(DynamicRelationshipType.withName("persons"), Direction.INCOMING);
assertEquals(group.getUnderlyingState(), michaelRel.getStartNode());
assertEquals(group.getUnderlyingState(), davidRel.getStartNode());
Relationship michaelRel = michael.getPersistentState().getSingleRelationship(DynamicRelationshipType.withName("persons"), Direction.INCOMING);
Relationship davidRel = david.getPersistentState().getSingleRelationship(DynamicRelationshipType.withName("persons"), Direction.INCOMING);
assertEquals(group.getPersistentState(), michaelRel.getStartNode());
assertEquals(group.getPersistentState(), davidRel.getStartNode());
}
@Test

View File

@@ -44,11 +44,11 @@ import static org.junit.Assert.assertNull;
@Transactional
public void testUserConstructor() {
Person p = new Person("Rod", 39);
assertEquals(p.getName(), p.getUnderlyingState().getProperty("Person.name"));
assertEquals(p.getAge(), p.getUnderlyingState().getProperty("Person.age"));
assertEquals(p.getName(), p.getPersistentState().getProperty("Person.name"));
assertEquals(p.getAge(), p.getPersistentState().getProperty("Person.age"));
Person found = graphDatabaseContext.createEntityFromState(graphDatabaseContext.getNodeById(p.getNodeId()), Person.class);
assertEquals("Rod", found.getUnderlyingState().getProperty("Person.name"));
assertEquals(39, found.getUnderlyingState().getProperty("Person.age"));
assertEquals("Rod", found.getPersistentState().getProperty("Person.name"));
assertEquals(39, found.getPersistentState().getProperty("Person.age"));
}
@Test
@@ -58,9 +58,9 @@ import static org.junit.Assert.assertNull;
p.setName("Michael");
p.setAge(35);
p.setHeight((short)182);
assertEquals("Michael", p.getUnderlyingState().getProperty("Person.name"));
assertEquals(35, p.getUnderlyingState().getProperty("Person.age"));
assertEquals((short)182, p.getUnderlyingState().getProperty("Person.height"));
assertEquals("Michael", p.getPersistentState().getProperty("Person.name"));
assertEquals(35, p.getPersistentState().getProperty("Person.age"));
assertEquals((short)182, p.getPersistentState().getProperty("Person.height"));
assertEquals((short)182, (short)p.getHeight());
}
@Test
@@ -68,7 +68,7 @@ import static org.junit.Assert.assertNull;
public void testSetShortProperty() {
Group group = new Group();
group.setName("developers");
assertEquals("developers", group.getUnderlyingState().getProperty("name"));
assertEquals("developers", group.getPersistentState().getProperty("name"));
}
// own transaction handling because of http://wiki.neo4j.org/content/Delete_Semantics
@Test(expected = NotFoundException.class)

View File

@@ -45,7 +45,7 @@ public class ProjectionTest {
Named named = (Named)group.projectTo(Named.class);
assertEquals("named.name","developers", named.getName());
assertEquals("nameds node name property","developers", named.getUnderlyingState().getProperty("name"));
assertEquals("nameds node name property","developers", named.getPersistentState().getProperty("name"));
}
}

View File

@@ -46,14 +46,14 @@ public class PropertyTest {
public void testSetPropertyEnum() {
Person p = new Person("Michael", 35);
p.setPersonality(Personality.EXTROVERT);
assertEquals("Wrong enum serialization.", "EXTROVERT", p.getUnderlyingState().getProperty("Person.personality"));
assertEquals("Wrong enum serialization.", "EXTROVERT", p.getPersistentState().getProperty("Person.personality"));
}
@Test
@Transactional
public void testGetPropertyEnum() {
Person p = new Person("Michael", 35);
p.getUnderlyingState().setProperty("Person.personality", "EXTROVERT");
p.getPersistentState().setProperty("Person.personality", "EXTROVERT");
assertEquals("Did not deserialize property value properly.", Personality.EXTROVERT, p.getPersonality());
}
@@ -62,7 +62,7 @@ public class PropertyTest {
public void testSetTransientPropertyFieldNotManaged() {
Person p = new Person("Michael", 35);
p.setThought("food");
p.getUnderlyingState().getProperty("Person.thought");
p.getPersistentState().getProperty("Person.thought");
}
@Test
@@ -70,7 +70,7 @@ public class PropertyTest {
public void testGetTransientPropertyFieldNotManaged() {
Person p = new Person("Michael", 35);
p.setThought("food");
p.getUnderlyingState().setProperty("Person.thought", "sleep");
p.getPersistentState().setProperty("Person.thought", "sleep");
assertEquals("Should not have read transient value from graph.", "food", p.getThought());
}
@Test
@@ -81,7 +81,7 @@ public class PropertyTest {
Person p2 = new Person("David", 25);
Friendship f = p.knows(p2);
f.setFirstMeetingDate(new Date(3));
assertEquals("Date not serialized properly.", "3", f.getUnderlyingState().getProperty("Friendship.firstMeetingDate"));
assertEquals("Date not serialized properly.", "3", f.getPersistentState().getProperty("Friendship.firstMeetingDate"));
}
@Test
@@ -90,7 +90,7 @@ public class PropertyTest {
Person p = new Person("Michael", 35);
Person p2 = new Person("David", 25);
Friendship f = p.knows(p2);
f.getUnderlyingState().setProperty("Friendship.firstMeetingDate", "3");
f.getPersistentState().setProperty("Friendship.firstMeetingDate", "3");
assertEquals("Date not deserialized properly.", new Date(3), f.getFirstMeetingDate());
}
@@ -101,7 +101,7 @@ public class PropertyTest {
Person p2 = new Person("David", 25);
Friendship f = p.knows(p2);
f.setLatestLocation("Menlo Park");
f.getUnderlyingState().getProperty("Friendship.latestLocation");
f.getPersistentState().getProperty("Friendship.latestLocation");
}
@Test
@@ -111,7 +111,7 @@ public class PropertyTest {
Person p2 = new Person("David", 25);
Friendship f = p.knows(p2);
f.setLatestLocation("Menlo Park");
f.getUnderlyingState().setProperty("Friendship.latestLocation", "Palo Alto");
f.getPersistentState().setProperty("Friendship.latestLocation", "Palo Alto");
assertEquals("Should not have read transient value from graph.", "Menlo Park", f.getLatestLocation());
}
@@ -119,17 +119,15 @@ public class PropertyTest {
@Transactional
public void testEntityIdField() {
Person p = new Person("Michael", 35);
assertEquals("Wrong ID.", p.getUnderlyingState().getId(), p.getId());
assertEquals("Wrong ID.", p.getPersistentState().getId(), p.getId());
}
// Would like to have this working.
@Ignore
@Test
@Transactional
public void testRelationshipIdField() {
Person p = new Person("Michael", 35);
Person p2 = new Person("David", 25);
Friendship f = p.knows(p2);
// assertEquals("Wrong ID.", f.getUnderlyingState().getId(), f.getId());
assertEquals("Wrong ID.", (Long)f.getPersistentState().getId(), f.getRelationshipId());
}
}

View File

@@ -43,9 +43,9 @@ public class RelationshipEntityTest {
Person p = new Person("Michael", 35);
Person p2 = new Person("David", 25);
Friendship f = p.knows(p2);
Relationship rel = p.getUnderlyingState().getSingleRelationship(DynamicRelationshipType.withName("knows"), Direction.OUTGOING);
assertEquals(f.getUnderlyingState(), rel);
assertEquals(p2.getUnderlyingState(), rel.getEndNode());
Relationship rel = p.getPersistentState().getSingleRelationship(DynamicRelationshipType.withName("knows"), Direction.OUTGOING);
assertEquals(f.getPersistentState(), rel);
assertEquals(p2.getPersistentState(), rel.getEndNode());
}
@Test
@@ -55,7 +55,7 @@ public class RelationshipEntityTest {
Person p2 = new Person("David", 25);
Friendship f = p.knows(p2);
f.setYears(1);
assertEquals(1, f.getUnderlyingState().getProperty("Friendship.years"));
assertEquals(1, f.getPersistentState().getProperty("Friendship.years"));
}
@Test
@@ -64,7 +64,7 @@ public class RelationshipEntityTest {
Person p = new Person("Michael", 35);
Person p2 = new Person("David", 25);
Friendship f = p.knows(p2);
f.getUnderlyingState().setProperty("Friendship.years", 1);
f.getPersistentState().setProperty("Friendship.years", 1);
assertEquals(1, f.getYears());
}

View File

@@ -178,7 +178,7 @@ public class SubReferenceNodeTypeStrategyTest {
}
public Thing(Node n) {
setUnderlyingState(n);
setPersistentState(n);
}
}
}

View File

@@ -6,9 +6,11 @@ import org.junit.*;
import org.neo4j.graphdb.*;
import org.neo4j.kernel.ImpermanentGraphDatabase;
import org.neo4j.kernel.Traversal;
import org.neo4j.kernel.impl.transaction.SpringTransactionManager;
import org.springframework.dao.DataAccessException;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.jta.JtaTransactionManager;
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
import org.springframework.transaction.support.TransactionTemplate;
@@ -38,7 +40,7 @@ public class Neo4jTemplateApiTest {
@BeforeClass
public static void startDb() throws Exception {
graphDatabase = new ImpermanentGraphDatabase();
// tm = new JtaTransactionManager(new SpringTransactionManager(graphDatabase));
tm = new JtaTransactionManager(new SpringTransactionManager(graphDatabase));
}
@Before
@@ -112,7 +114,6 @@ public class Neo4jTemplateApiTest {
}
@Test
@Ignore("until the ImpermanentGraphDatabase cast issue is resolved in neo4j")
public void shouldRollbackViaStatus() throws Exception {
new TransactionTemplate(tm).execute(new TransactionCallbackWithoutResult() {
@Override

View File

@@ -72,12 +72,12 @@
<bean id="neo4jNodeBacking" class="org.springframework.data.graph.neo4j.support.node.Neo4jNodeBacking" factory-method="aspectOf">
<property name="graphDatabaseContext" ref="graphDatabaseContext"/>
<property name="nodeEntityStateAccessorsFactory" ref="nodeEntityStateAccessorsFactory"/>
<property name="nodeEntityStateFactory" ref="nodeEntityStateFactory"/>
</bean>
<bean class="org.springframework.data.graph.neo4j.support.relationship.Neo4jRelationshipBacking" factory-method="aspectOf">
<property name="graphDatabaseContext" ref="graphDatabaseContext"/>
<property name="relationshipEntityStateAccessorsFactory" ref="relationshipEntityStateAccessorsFactory"/>
<property name="relationshipEntityStateFactory" ref="relationshipEntityStateFactory"/>
</bean>
<!--
@@ -112,7 +112,7 @@
</property>
</bean>
<bean id="nodeEntityStateAccessorsFactory" class="org.springframework.data.graph.neo4j.fieldaccess.NodeEntityStateAccessorsFactory">
<bean id="nodeEntityStateFactory" class="org.springframework.data.graph.neo4j.fieldaccess.NodeEntityStateFactory">
<property name="nodeDelegatingFieldAccessorFactory">
<bean class="org.springframework.data.graph.neo4j.fieldaccess.NodeDelegatingFieldAccessorFactory">
<constructor-arg ref="graphDatabaseContext"/>
@@ -123,7 +123,7 @@
<property name="finderFactory" ref="finderFactory"/>
</bean>
<bean id="relationshipEntityStateAccessorsFactory" class="org.springframework.data.graph.neo4j.fieldaccess.RelationshipEntityStateAccessorsFactory">
<bean id="relationshipEntityStateFactory" class="org.springframework.data.graph.neo4j.fieldaccess.RelationshipEntityStateFactory">
<property name="graphDatabaseContext" ref="graphDatabaseContext"/>
<property name="finderFactory" ref="finderFactory"/>
</bean>

View File

@@ -69,12 +69,12 @@
<bean id="neo4jNodeBacking" class="org.springframework.data.graph.neo4j.support.node.Neo4jNodeBacking" factory-method="aspectOf">
<property name="graphDatabaseContext" ref="graphDatabaseContext"/>
<property name="nodeEntityStateAccessorsFactory" ref="nodeEntityStateAccessorsFactory"/>
<property name="nodeEntityStateFactory" ref="nodeEntityStateFactory"/>
</bean>
<bean class="org.springframework.data.graph.neo4j.support.relationship.Neo4jRelationshipBacking" factory-method="aspectOf">
<property name="graphDatabaseContext" ref="graphDatabaseContext"/>
<property name="relationshipEntityStateAccessorsFactory" ref="relationshipEntityStateAccessorsFactory"/>
<property name="relationshipEntityStateFactory" ref="relationshipEntityStateFactory"/>
</bean>
<bean id="graphDatabaseService" class="org.neo4j.kernel.ImpermanentGraphDatabase"
@@ -103,7 +103,7 @@
</property>
</bean>
<bean id="nodeEntityStateAccessorsFactory" class="org.springframework.data.graph.neo4j.fieldaccess.NodeEntityStateAccessorsFactory">
<bean id="nodeEntityStateFactory" class="org.springframework.data.graph.neo4j.fieldaccess.NodeEntityStateFactory">
<property name="nodeDelegatingFieldAccessorFactory">
<bean class="org.springframework.data.graph.neo4j.fieldaccess.NodeDelegatingFieldAccessorFactory">
<constructor-arg ref="graphDatabaseContext"/>
@@ -114,7 +114,7 @@
<property name="finderFactory" ref="finderFactory"/>
</bean>
<bean id="relationshipEntityStateAccessorsFactory" class="org.springframework.data.graph.neo4j.fieldaccess.RelationshipEntityStateAccessorsFactory">
<bean id="relationshipEntityStateFactory" class="org.springframework.data.graph.neo4j.fieldaccess.RelationshipEntityStateFactory">
<property name="graphDatabaseContext" ref="graphDatabaseContext"/>
<property name="finderFactory" ref="finderFactory"/>
</bean>

View File

@@ -15,10 +15,10 @@
properties. There are two specially annotated fields for the start and the end node of the relationship.
</para>
<para>
The aspect introduces some internal fields and some public methods to the entities for accessing the backing state via <code>getUnderlyingState()</code> and creating relationships with <code>relateTo</code> and retrieving relationship entities via <code>getRelationshipTo</code>. It also introduces finder methods like <code>find(Class&lt;? extends NodeEntity&gt;, TraversalDescription)</code> and equals and hashCode delegation.
The aspect introduces some internal fields and some public methods to the entities for accessing the backing state via <code>getPersistentState()</code> and creating relationships with <code>relateTo</code> and retrieving relationship entities via <code>getRelationshipTo</code>. It also introduces finder methods like <code>find(Class&lt;? extends NodeEntity&gt;, TraversalDescription)</code> and equals and hashCode delegation.
</para>
<para>
Spring Data Graph internally uses an abstraction called EntityStateAccessors that the field access and instantiation advices of the aspect delegate to, keeping the aspect code very small and focused to the pointcuts and delegation code. The EntityStateAccessors then use a number of FieldAccessor factories to create a FieldAccessor instance per field that does the specific handling needed for the concrete field.
Spring Data Graph internally uses an abstraction called EntityState that the field access and instantiation advices of the aspect delegate to, keeping the aspect code very small and focused to the pointcuts and delegation code. The EntityState then uses a number of FieldAccessor factories to create a FieldAccessor instance per field that does the specific handling needed for the concrete field.
</para>
</section>
<section>
@@ -219,7 +219,7 @@ Iterable<Person> davesFriends = finder.findAllByTraversal(dave,
<varlistentry>
<term>accessing the node or relationship backing the entity</term>
<listitem>
<para><code>entity.getUnderlyingState()</code></para>
<para><code>entity.getPersistentState()</code></para>
</listitem>
</varlistentry>
<varlistentry>

View File

@@ -110,7 +110,7 @@
<para>aspects and instantiators for node and relationship entities</para>
</listitem>
<listitem>
<para>EntityStateAccessors and FieldAccessFactories needed for the different field handling
<para>EntityState and FieldAccessFactories needed for the different field handling
</para>
</listitem>
<listitem>