added mapping-context state-factories and persistent-entity to entity-states
This commit is contained in:
@@ -37,6 +37,7 @@ import org.springframework.data.neo4j.fieldaccess.DelegatingFieldAccessorFactory
|
||||
import org.springframework.data.neo4j.fieldaccess.Neo4jConversionServiceFactoryBean;
|
||||
import org.springframework.data.neo4j.fieldaccess.NodeDelegatingFieldAccessorFactory;
|
||||
import org.springframework.data.neo4j.fieldaccess.RelationshipDelegatingFieldAccessorFactory;
|
||||
import org.springframework.data.neo4j.mapping.Neo4JMappingContext;
|
||||
import org.springframework.data.neo4j.repository.DirectGraphRepositoryFactory;
|
||||
import org.springframework.data.neo4j.support.GraphDatabaseContext;
|
||||
import org.springframework.data.neo4j.support.node.Neo4jNodeBacking;
|
||||
@@ -149,6 +150,7 @@ public class Neo4jConfiguration {
|
||||
public RelationshipEntityStateFactory relationshipEntityStateFactory() throws Exception {
|
||||
RelationshipEntityStateFactory entityStateFactory = new RelationshipEntityStateFactory();
|
||||
entityStateFactory.setGraphDatabaseContext(graphDatabaseContext());
|
||||
entityStateFactory.setMappingContext(mappingContext());
|
||||
entityStateFactory.setRelationshipDelegatingFieldAccessorFactory(relationshipDelegatingFieldAccessorFactory());
|
||||
return entityStateFactory;
|
||||
}
|
||||
@@ -162,12 +164,18 @@ public class Neo4jConfiguration {
|
||||
return aspect;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Neo4JMappingContext mappingContext() {
|
||||
return new Neo4JMappingContext();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public NodeEntityStateFactory nodeEntityStateFactory() throws Exception {
|
||||
|
||||
NodeEntityStateFactory entityStateFactory = new NodeEntityStateFactory();
|
||||
entityStateFactory.setGraphDatabaseContext(graphDatabaseContext());
|
||||
entityStateFactory.setEntityManagerFactory(entityManagerFactory);
|
||||
entityStateFactory.setMappingContext(mappingContext());
|
||||
entityStateFactory.setNodeDelegatingFieldAccessorFactory(nodeDelegatingFieldAccessorFactory());
|
||||
return entityStateFactory;
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.data.neo4j.core.EntityState;
|
||||
import org.springframework.data.neo4j.core.GraphBacked;
|
||||
import org.springframework.data.neo4j.mapping.Neo4JPersistentEntity;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
@@ -38,12 +39,13 @@ public abstract class DefaultEntityState<ENTITY extends GraphBacked<STATE>, STAT
|
||||
private STATE state;
|
||||
protected final static Log log= LogFactory.getLog(DefaultEntityState.class);
|
||||
private final FieldAccessorFactoryProviders<ENTITY> fieldAccessorFactoryProviders;
|
||||
private final Neo4JPersistentEntity<?> persistentEntity;
|
||||
|
||||
|
||||
public DefaultEntityState(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, Neo4JPersistentEntity<?> persistentEntity) {
|
||||
this.state = underlyingState;
|
||||
this.entity = entity;
|
||||
this.type = type;
|
||||
this.persistentEntity = persistentEntity;
|
||||
if (delegatingFieldAccessorFactory!=null) {
|
||||
fieldAccessorFactoryProviders = delegatingFieldAccessorFactory.accessorFactoriesFor(type);
|
||||
this.fieldAccessors.putAll(fieldAccessorFactoryProviders.getFieldAccessors());
|
||||
|
||||
@@ -16,14 +16,14 @@
|
||||
|
||||
package org.springframework.data.neo4j.mapping;
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.springframework.data.mapping.context.AbstractMappingContext;
|
||||
import org.springframework.data.mapping.context.MappingContext;
|
||||
import org.springframework.data.mapping.model.SimpleTypeHolder;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* Neo4J specific {@link MappingContext} implementation. Simply creates {@link Neo4JPersistentEntityImpl} and
|
||||
* {@link Neo4JPersistentProperty} instances.
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.springframework.dao.InvalidDataAccessResourceUsageException;
|
||||
import org.springframework.data.neo4j.core.NodeBacked;
|
||||
import org.springframework.data.neo4j.fieldaccess.DefaultEntityState;
|
||||
import org.springframework.data.neo4j.fieldaccess.DelegatingFieldAccessorFactory;
|
||||
import org.springframework.data.neo4j.mapping.Neo4JPersistentEntity;
|
||||
import org.springframework.data.neo4j.support.GraphDatabaseContext;
|
||||
|
||||
/**
|
||||
@@ -32,8 +33,8 @@ public class NodeEntityState<ENTITY extends NodeBacked> extends DefaultEntitySta
|
||||
|
||||
private final GraphDatabaseContext graphDatabaseContext;
|
||||
|
||||
public NodeEntityState(final Node underlyingState, final ENTITY entity, final Class<? extends ENTITY> type, final GraphDatabaseContext graphDatabaseContext, final DelegatingFieldAccessorFactory<NodeBacked> nodeDelegatingFieldAccessorFactory) {
|
||||
super(underlyingState, entity, type, nodeDelegatingFieldAccessorFactory);
|
||||
public NodeEntityState(final Node underlyingState, final ENTITY entity, final Class<? extends ENTITY> type, final GraphDatabaseContext graphDatabaseContext, final DelegatingFieldAccessorFactory<NodeBacked> nodeDelegatingFieldAccessorFactory, Neo4JPersistentEntity<?> persistentEntity) {
|
||||
super(underlyingState, entity, type, nodeDelegatingFieldAccessorFactory,persistentEntity);
|
||||
this.graphDatabaseContext = graphDatabaseContext;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,18 +16,20 @@
|
||||
|
||||
package org.springframework.data.neo4j.support.node;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import javax.persistence.PersistenceUnitUtil;
|
||||
|
||||
import org.neo4j.graphdb.Node;
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
import org.springframework.data.neo4j.core.EntityState;
|
||||
import org.springframework.data.neo4j.core.NodeBacked;
|
||||
import org.springframework.data.neo4j.fieldaccess.DelegatingFieldAccessorFactory;
|
||||
import org.springframework.data.neo4j.fieldaccess.DetachedEntityState;
|
||||
import org.springframework.data.neo4j.mapping.Neo4JMappingContext;
|
||||
import org.springframework.data.neo4j.mapping.Neo4JPersistentEntity;
|
||||
import org.springframework.data.neo4j.support.GraphDatabaseContext;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import javax.persistence.PersistenceUnitUtil;
|
||||
|
||||
public class NodeEntityStateFactory {
|
||||
|
||||
private GraphDatabaseContext graphDatabaseContext;
|
||||
@@ -38,10 +40,14 @@ public class NodeEntityStateFactory {
|
||||
|
||||
private PartialNodeEntityState.PartialNodeDelegatingFieldAccessorFactory delegatingFieldAccessorFactory;
|
||||
|
||||
private Neo4JMappingContext mappingContext;
|
||||
|
||||
public EntityState<NodeBacked,Node> getEntityState(final NodeBacked entity) {
|
||||
final NodeEntity graphEntityAnnotation = entity.getClass().getAnnotation(NodeEntity.class); // todo cache ??
|
||||
final Class<? extends NodeBacked> entityType = entity.getClass();
|
||||
final NodeEntity graphEntityAnnotation = entityType.getAnnotation(NodeEntity.class); // todo cache ??
|
||||
final Neo4JPersistentEntity<?> persistentEntity = mappingContext.getPersistentEntity(entityType);
|
||||
if (graphEntityAnnotation.partial()) {
|
||||
final PartialNodeEntityState<NodeBacked> partialNodeEntityState = new PartialNodeEntityState<NodeBacked>(null, entity, entity.getClass(), graphDatabaseContext, getPersistenceUnitUtils(), delegatingFieldAccessorFactory);
|
||||
final PartialNodeEntityState<NodeBacked> partialNodeEntityState = new PartialNodeEntityState<NodeBacked>(null, entity, entityType, graphDatabaseContext, getPersistenceUnitUtils(), delegatingFieldAccessorFactory, persistentEntity);
|
||||
return new DetachedEntityState<NodeBacked, Node>(partialNodeEntityState, graphDatabaseContext) {
|
||||
@Override
|
||||
protected boolean isDetached() {
|
||||
@@ -49,7 +55,7 @@ public class NodeEntityStateFactory {
|
||||
}
|
||||
};
|
||||
} else {
|
||||
NodeEntityState<NodeBacked> nodeEntityState = new NodeEntityState<NodeBacked>(null, entity, entity.getClass(), graphDatabaseContext, nodeDelegatingFieldAccessorFactory);
|
||||
NodeEntityState<NodeBacked> nodeEntityState = new NodeEntityState<NodeBacked>(null, entity, entityType, graphDatabaseContext, nodeDelegatingFieldAccessorFactory, persistentEntity);
|
||||
// alternative was return new NestedTransactionEntityState<NodeBacked, Node>(nodeEntityState,graphDatabaseContext);
|
||||
return new DetachedEntityState<NodeBacked, Node>(nodeEntityState, graphDatabaseContext);
|
||||
}
|
||||
@@ -73,6 +79,14 @@ public class NodeEntityStateFactory {
|
||||
this.entityManagerFactory = entityManagerFactory;
|
||||
}
|
||||
|
||||
public Neo4JMappingContext getMappingContext() {
|
||||
return mappingContext;
|
||||
}
|
||||
|
||||
public void setMappingContext(Neo4JMappingContext mappingContext) {
|
||||
this.mappingContext = mappingContext;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
private void setUp() {
|
||||
this.delegatingFieldAccessorFactory = new PartialNodeEntityState.PartialNodeDelegatingFieldAccessorFactory(graphDatabaseContext);
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.springframework.data.neo4j.annotation.GraphProperty;
|
||||
import org.springframework.data.neo4j.annotation.RelatedTo;
|
||||
import org.springframework.data.neo4j.core.NodeBacked;
|
||||
import org.springframework.data.neo4j.fieldaccess.*;
|
||||
import org.springframework.data.neo4j.mapping.Neo4JPersistentEntity;
|
||||
import org.springframework.data.neo4j.support.GraphDatabaseContext;
|
||||
|
||||
import javax.persistence.PersistenceUnitUtil;
|
||||
@@ -44,8 +45,8 @@ public class PartialNodeEntityState<ENTITY extends NodeBacked> extends DefaultEn
|
||||
private final GraphDatabaseContext graphDatabaseContext;
|
||||
private PersistenceUnitUtil persistenceUnitUtil;
|
||||
|
||||
public PartialNodeEntityState(final Node underlyingState, final ENTITY entity, final Class<? extends ENTITY> type, final GraphDatabaseContext graphDatabaseContext, PersistenceUnitUtil persistenceUnitUtil, final PartialNodeDelegatingFieldAccessorFactory delegatingFieldAccessorFactory) {
|
||||
super(underlyingState, entity, type, delegatingFieldAccessorFactory);
|
||||
public PartialNodeEntityState(final Node underlyingState, final ENTITY entity, final Class<? extends ENTITY> type, final GraphDatabaseContext graphDatabaseContext, PersistenceUnitUtil persistenceUnitUtil, final PartialNodeDelegatingFieldAccessorFactory delegatingFieldAccessorFactory, final Neo4JPersistentEntity<?> persistentEntity) {
|
||||
super(underlyingState, entity, type, delegatingFieldAccessorFactory, persistentEntity);
|
||||
this.graphDatabaseContext = graphDatabaseContext;
|
||||
this.persistenceUnitUtil = persistenceUnitUtil;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,9 @@ import org.neo4j.graphdb.NotInTransactionException;
|
||||
import org.neo4j.graphdb.Relationship;
|
||||
import org.springframework.dao.InvalidDataAccessResourceUsageException;
|
||||
import org.springframework.data.neo4j.core.RelationshipBacked;
|
||||
import org.springframework.data.neo4j.fieldaccess.*;
|
||||
import org.springframework.data.neo4j.fieldaccess.DefaultEntityState;
|
||||
import org.springframework.data.neo4j.fieldaccess.DelegatingFieldAccessorFactory;
|
||||
import org.springframework.data.neo4j.mapping.Neo4JPersistentEntity;
|
||||
import org.springframework.data.neo4j.support.GraphDatabaseContext;
|
||||
|
||||
|
||||
@@ -32,8 +34,8 @@ public class RelationshipEntityState<ENTITY extends RelationshipBacked> extends
|
||||
|
||||
private final GraphDatabaseContext graphDatabaseContext;
|
||||
|
||||
public RelationshipEntityState(final Relationship underlyingState, final ENTITY entity, final Class<? extends ENTITY> type, final GraphDatabaseContext graphDatabaseContext, final DelegatingFieldAccessorFactory<RelationshipBacked> delegatingFieldAccessorFactory) {
|
||||
super(underlyingState, entity, type, delegatingFieldAccessorFactory);
|
||||
public RelationshipEntityState(final Relationship underlyingState, final ENTITY entity, final Class<? extends ENTITY> type, final GraphDatabaseContext graphDatabaseContext, final DelegatingFieldAccessorFactory<RelationshipBacked> delegatingFieldAccessorFactory, Neo4JPersistentEntity<?> persistentEntity) {
|
||||
super(underlyingState, entity, type, delegatingFieldAccessorFactory, persistentEntity);
|
||||
this.graphDatabaseContext = graphDatabaseContext;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.neo4j.graphdb.Relationship;
|
||||
import org.springframework.data.neo4j.core.EntityState;
|
||||
import org.springframework.data.neo4j.core.RelationshipBacked;
|
||||
import org.springframework.data.neo4j.fieldaccess.DelegatingFieldAccessorFactory;
|
||||
import org.springframework.data.neo4j.mapping.Neo4JMappingContext;
|
||||
import org.springframework.data.neo4j.support.GraphDatabaseContext;
|
||||
|
||||
public class RelationshipEntityStateFactory {
|
||||
@@ -27,9 +28,11 @@ public class RelationshipEntityStateFactory {
|
||||
private GraphDatabaseContext graphDatabaseContext;
|
||||
|
||||
private DelegatingFieldAccessorFactory<RelationshipBacked> relationshipDelegatingFieldAccessorFactory;
|
||||
private Neo4JMappingContext mappingContext;
|
||||
|
||||
public EntityState<RelationshipBacked, Relationship> getEntityState(final RelationshipBacked entity) {
|
||||
return new RelationshipEntityState<RelationshipBacked>(null,entity,entity.getClass(), graphDatabaseContext, relationshipDelegatingFieldAccessorFactory);
|
||||
final Class<? extends RelationshipBacked> entityType = entity.getClass();
|
||||
return new RelationshipEntityState<RelationshipBacked>(null,entity, entityType, graphDatabaseContext, relationshipDelegatingFieldAccessorFactory,mappingContext.getPersistentEntity(entityType));
|
||||
}
|
||||
|
||||
public void setGraphDatabaseContext(GraphDatabaseContext graphDatabaseContext) {
|
||||
@@ -40,4 +43,8 @@ public class RelationshipEntityStateFactory {
|
||||
DelegatingFieldAccessorFactory<RelationshipBacked> delegatingFieldAccessorFactory) {
|
||||
this.relationshipDelegatingFieldAccessorFactory = delegatingFieldAccessorFactory;
|
||||
}
|
||||
|
||||
public void setMappingContext(Neo4JMappingContext mappingContext) {
|
||||
this.mappingContext = mappingContext;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,8 +120,12 @@
|
||||
</property>
|
||||
<property name="graphDatabaseContext" ref="graphDatabaseContext"/>
|
||||
<property name="entityManagerFactory" ref="entityManagerFactory"/>
|
||||
<property name="mappingContext" ref="mappingContext"/>
|
||||
</bean>
|
||||
|
||||
<bean id="mappingContext" class="org.springframework.data.neo4j.mapping.Neo4JMappingContext"/>
|
||||
|
||||
|
||||
<bean id="relationshipEntityStateFactory" class="org.springframework.data.neo4j.support.relationship.RelationshipEntityStateFactory">
|
||||
<property name="relationshipDelegatingFieldAccessorFactory">
|
||||
<bean class="org.springframework.data.neo4j.fieldaccess.RelationshipDelegatingFieldAccessorFactory">
|
||||
@@ -129,6 +133,7 @@
|
||||
</bean>
|
||||
</property>
|
||||
<property name="graphDatabaseContext" ref="graphDatabaseContext"/>
|
||||
<property name="mappingContext" ref="mappingContext"/>
|
||||
</bean>
|
||||
|
||||
|
||||
@@ -136,10 +141,6 @@
|
||||
<constructor-arg ref="graphDatabaseContext" />
|
||||
</bean>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<bean id="transactionManager" class="org.springframework.data.neo4j.transaction.ChainedTransactionManager" >
|
||||
<constructor-arg>
|
||||
<list>
|
||||
|
||||
@@ -115,8 +115,11 @@
|
||||
</bean>
|
||||
</property>
|
||||
<property name="graphDatabaseContext" ref="graphDatabaseContext"/>
|
||||
<property name="mappingContext" ref="mappingContext"/>
|
||||
</bean>
|
||||
|
||||
<bean id="mappingContext" class="org.springframework.data.neo4j.mapping.Neo4JMappingContext"/>
|
||||
|
||||
<bean id="relationshipEntityStateFactory" class="org.springframework.data.neo4j.support.relationship.RelationshipEntityStateFactory">
|
||||
<property name="relationshipDelegatingFieldAccessorFactory">
|
||||
<bean class="org.springframework.data.neo4j.fieldaccess.RelationshipDelegatingFieldAccessorFactory">
|
||||
@@ -124,6 +127,7 @@
|
||||
</bean>
|
||||
</property>
|
||||
<property name="graphDatabaseContext" ref="graphDatabaseContext"/>
|
||||
<property name="mappingContext" ref="mappingContext"/>
|
||||
</bean>
|
||||
|
||||
<bean id="graphRepositoryFactory" class="org.springframework.data.neo4j.repository.DirectGraphRepositoryFactory">
|
||||
|
||||
Reference in New Issue
Block a user