resolved cyclic dependency of Neo4j-Template, can now be constructed just with a graph-database-service and is ready to use

This commit is contained in:
Michael Hunger
2012-05-01 03:09:41 +02:00
parent 884374f094
commit 9cd47c7c7d
29 changed files with 800 additions and 441 deletions

View File

@@ -127,7 +127,7 @@ public privileged aspect Neo4jNodeBacking { // extends AbstractTypeAnnotatingMix
/**
* State accessors that encapsulate the underlying state and the behaviour related to it (field access, creation)
*/
private transient EntityState<Node> NodeBacked.entityState;
private transient @Transient EntityState<Node> NodeBacked.entityState;
public <T extends NodeBacked> T NodeBacked.persist() {
return (T)this.entityState.persist();

View File

@@ -29,7 +29,7 @@ import org.springframework.data.neo4j.core.EntityState;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.data.neo4j.support.relationship.RelationshipEntityStateFactory;
import org.springframework.data.neo4j.template.Neo4jOperations;
import javax.persistence.Transient;
import java.lang.reflect.Field;
import static org.springframework.data.neo4j.support.DoReturn.unwrap;
@@ -98,7 +98,7 @@ public aspect Neo4jRelationshipBacking {
/**
* field for {@link org.springframework.data.neo4j.core.EntityState} that takes care of all entity operations
*/
private EntityState<Relationship> RelationshipBacked.entityState;
private transient @Transient EntityState<Relationship> RelationshipBacked.entityState;
public Neo4jTemplate RelationshipBacked.getTemplate() {

View File

@@ -32,7 +32,7 @@
<bean id="conversionService" class="org.springframework.data.neo4j.fieldaccess.Neo4jConversionServiceFactoryBean"/>
<bean id="mappingInfrastructure" class="org.springframework.data.neo4j.support.MappingInfrastructure">
<bean id="mappingInfrastructure" class="org.springframework.data.neo4j.support.MappingInfrastructureFactoryBean">
<property name="graphDatabaseService" ref="graphDatabaseService"/>
<property name="conversionService" ref="conversionService"/>
<property name="mappingContext" ref="mappingContext"/>
@@ -50,8 +50,8 @@
</property>
</bean>
<bean id="template" class="org.springframework.data.neo4j.support.Neo4jTemplate" init-method="postConstruct">
<property name="infrastructure" ref="mappingInfrastructure"/>
<bean id="template" class="org.springframework.data.neo4j.support.Neo4jTemplate">
<constructor-arg name="infrastructure" ref="mappingInfrastructure"/>
</bean>
@@ -78,25 +78,19 @@
<bean id="relationshipTypeRepresentationStrategy" factory-bean="typeRepresentationStrategyFactory" factory-method="getRelationshipTypeRepresentationStrategy"/>
<bean id="nodeEntityStateFactory" class="org.springframework.data.neo4j.support.node.NodeEntityStateFactory">
<property name="nodeDelegatingFieldAccessorFactory">
<bean class="org.springframework.data.neo4j.fieldaccess.NodeDelegatingFieldAccessorFactory">
<constructor-arg ref="template"/>
</bean>
</property>
<!--property name="template" ref="template"/-->
<property name="mappingContext" ref="mappingContext"/>
<constructor-arg ref="mappingContext"/>
<constructor-arg>
<bean class="org.springframework.data.neo4j.fieldaccess.NodeDelegatingFieldAccessorFactory$Factory"/>
</constructor-arg>
</bean>
<bean id="mappingContext" class="org.springframework.data.neo4j.support.mapping.Neo4jMappingContext"/>
<bean id="relationshipEntityStateFactory" class="org.springframework.data.neo4j.support.relationship.RelationshipEntityStateFactory">
<property name="relationshipDelegatingFieldAccessorFactory">
<bean class="org.springframework.data.neo4j.fieldaccess.RelationshipDelegatingFieldAccessorFactory">
<constructor-arg ref="template"/>
</bean>
</property>
<!--property name="template" ref="template"/-->
<property name="mappingContext" ref="mappingContext"/>
<constructor-arg ref="mappingContext"/>
<constructor-arg>
<bean class="org.springframework.data.neo4j.fieldaccess.RelationshipDelegatingFieldAccessorFactory$Factory"/>
</constructor-arg>
</bean>
<!--bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">

View File

@@ -21,10 +21,10 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.neo4j.aspects.config.Neo4jAspectConfiguration;
import org.springframework.data.neo4j.cross_store.support.node.CrossStoreNodeDelegatingFieldAccessorFactory;
import org.springframework.data.neo4j.cross_store.support.node.CrossStoreNodeEntityInstantiator;
import org.springframework.data.neo4j.cross_store.support.node.CrossStoreNodeEntityState;
import org.springframework.data.neo4j.cross_store.support.node.CrossStoreNodeEntityStateFactory;
import org.springframework.data.neo4j.fieldaccess.DelegatingFieldAccessorFactory;
import org.springframework.data.neo4j.fieldaccess.FieldAccessorFactoryFactory;
import org.springframework.data.neo4j.mapping.EntityInstantiator;
import org.springframework.data.neo4j.support.node.NodeEntityInstantiator;
import org.springframework.data.neo4j.support.node.NodeEntityStateFactory;
@@ -80,16 +80,13 @@ public class CrossStoreNeo4jConfiguration extends Neo4jAspectConfiguration {
}
@Override
public DelegatingFieldAccessorFactory nodeDelegatingFieldAccessorFactory() throws Exception {
final CrossStoreNodeEntityState.CrossStoreNodeDelegatingFieldAccessorFactory nodeDelegatingFieldAccessorFactory = new CrossStoreNodeEntityState.CrossStoreNodeDelegatingFieldAccessorFactory(neo4jTemplate());
nodeEntityStateFactory().setNodeDelegatingFieldAccessorFactory(nodeDelegatingFieldAccessorFactory);
return nodeDelegatingFieldAccessorFactory;
public FieldAccessorFactoryFactory nodeDelegatingFieldAccessorFactory() throws Exception {
return new CrossStoreNodeDelegatingFieldAccessorFactory.Factory();
}
@Bean
public NodeEntityStateFactory nodeEntityStateFactory() throws Exception {
final CrossStoreNodeEntityStateFactory nodeEntityStateFactory = new CrossStoreNodeEntityStateFactory();
nodeEntityStateFactory.setEntityManagerFactory(entityManagerFactory);
return nodeEntityStateFactory;
return new CrossStoreNodeEntityStateFactory(neo4jMappingContext(),nodeDelegatingFieldAccessorFactory(),entityManagerFactory);
}
}

View File

@@ -0,0 +1,111 @@
/**
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.neo4j.cross_store.support.node;
import org.springframework.data.neo4j.annotation.GraphProperty;
import org.springframework.data.neo4j.annotation.RelatedTo;
import org.springframework.data.neo4j.cross_store.fieldaccess.JpaIdFieldAccessListenerFactory;
import org.springframework.data.neo4j.fieldaccess.ConvertingNodePropertyFieldAccessorFactory;
import org.springframework.data.neo4j.fieldaccess.DelegatingFieldAccessorFactory;
import org.springframework.data.neo4j.fieldaccess.FieldAccessorFactory;
import org.springframework.data.neo4j.fieldaccess.FieldAccessorFactoryFactory;
import org.springframework.data.neo4j.fieldaccess.FieldAccessorListenerFactory;
import org.springframework.data.neo4j.fieldaccess.IndexingPropertyFieldAccessorListenerFactory;
import org.springframework.data.neo4j.fieldaccess.PropertyFieldAccessorFactory;
import org.springframework.data.neo4j.fieldaccess.QueryFieldAccessorFactory;
import org.springframework.data.neo4j.fieldaccess.ReadOnlyRelatedToCollectionFieldAccessorFactory;
import org.springframework.data.neo4j.fieldaccess.RelatedToCollectionFieldAccessorFactory;
import org.springframework.data.neo4j.fieldaccess.RelatedToSingleFieldAccessorFactory;
import org.springframework.data.neo4j.fieldaccess.RelatedToViaCollectionFieldAccessorFactory;
import org.springframework.data.neo4j.fieldaccess.RelatedToViaSingleFieldAccessorFactory;
import org.springframework.data.neo4j.fieldaccess.TraversalFieldAccessorFactory;
import org.springframework.data.neo4j.mapping.Neo4jPersistentProperty;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import java.util.Arrays;
import java.util.Collection;
/**
* @author mh
* @since 30.04.12
*/
public class CrossStoreNodeDelegatingFieldAccessorFactory extends DelegatingFieldAccessorFactory {
public CrossStoreNodeDelegatingFieldAccessorFactory(Neo4jTemplate template) {
super(template);
}
@Override
protected Collection<FieldAccessorListenerFactory> createListenerFactories() {
return Arrays.asList(
new IndexingPropertyFieldAccessorListenerFactory(
getTemplate(),
newPropertyFieldAccessorFactory(),
newConvertingNodePropertyFieldAccessorFactory()) {
@Override
public boolean accept(Neo4jPersistentProperty property) {
return property.isAnnotationPresent(GraphProperty.class) && super.accept(property);
}
},
new JpaIdFieldAccessListenerFactory(template));
}
@Override
protected Collection<? extends FieldAccessorFactory> createAccessorFactories() {
return Arrays.asList(
//new IdFieldAccessorFactory(),
//new TransientFieldAccessorFactory(),
new TraversalFieldAccessorFactory(template),
new QueryFieldAccessorFactory(template),
newPropertyFieldAccessorFactory(),
newConvertingNodePropertyFieldAccessorFactory(),
new RelatedToSingleFieldAccessorFactory(getTemplate()) {
@Override
public boolean accept(Neo4jPersistentProperty property) {
return property.isAnnotationPresent(RelatedTo.class) && super.accept(property);
}
},
new RelatedToCollectionFieldAccessorFactory(getTemplate()),
new ReadOnlyRelatedToCollectionFieldAccessorFactory(getTemplate()),
new RelatedToViaSingleFieldAccessorFactory(getTemplate()),
new RelatedToViaCollectionFieldAccessorFactory(getTemplate())
);
}
private ConvertingNodePropertyFieldAccessorFactory newConvertingNodePropertyFieldAccessorFactory() {
return new ConvertingNodePropertyFieldAccessorFactory(getTemplate()) {
@Override
public boolean accept(Neo4jPersistentProperty property) {
return property.isAnnotationPresent(GraphProperty.class) && super.accept(property);
}
};
}
private PropertyFieldAccessorFactory newPropertyFieldAccessorFactory() {
return new PropertyFieldAccessorFactory(getTemplate()) {
@Override
public boolean accept(Neo4jPersistentProperty property) {
return property.isAnnotationPresent(GraphProperty.class) && super.accept(property);
}
};
}
public static class Factory extends FieldAccessorFactoryFactory {
public DelegatingFieldAccessorFactory create(Neo4jTemplate template) {
return new CrossStoreNodeDelegatingFieldAccessorFactory(template);
}
}
}

View File

@@ -117,65 +117,4 @@ public class CrossStoreNodeEntityState<ENTITY extends NodeBacked> extends Defaul
return persistenceUnitUtil!=null ? persistenceUnitUtil.getIdentifier(entity) : null;
}
public static class CrossStoreNodeDelegatingFieldAccessorFactory extends DelegatingFieldAccessorFactory {
public CrossStoreNodeDelegatingFieldAccessorFactory(Neo4jTemplate template) {
super(template);
}
@Override
protected Collection<FieldAccessorListenerFactory> createListenerFactories() {
return Arrays.asList(
new IndexingPropertyFieldAccessorListenerFactory(
getTemplate(),
newPropertyFieldAccessorFactory(),
newConvertingNodePropertyFieldAccessorFactory()) {
@Override
public boolean accept(Neo4jPersistentProperty property) {
return property.isAnnotationPresent(GraphProperty.class) && super.accept(property);
}
},
new JpaIdFieldAccessListenerFactory(template));
}
@Override
protected Collection<? extends FieldAccessorFactory> createAccessorFactories() {
return Arrays.asList(
//new IdFieldAccessorFactory(),
//new TransientFieldAccessorFactory(),
new TraversalFieldAccessorFactory(template),
new QueryFieldAccessorFactory(template),
newPropertyFieldAccessorFactory(),
newConvertingNodePropertyFieldAccessorFactory(),
new RelatedToSingleFieldAccessorFactory(getTemplate()) {
@Override
public boolean accept(Neo4jPersistentProperty property) {
return property.isAnnotationPresent(RelatedTo.class) && super.accept(property);
}
},
new RelatedToCollectionFieldAccessorFactory(getTemplate()),
new ReadOnlyRelatedToCollectionFieldAccessorFactory(getTemplate()),
new RelatedToViaSingleFieldAccessorFactory(getTemplate()),
new RelatedToViaCollectionFieldAccessorFactory(getTemplate())
);
}
private ConvertingNodePropertyFieldAccessorFactory newConvertingNodePropertyFieldAccessorFactory() {
return new ConvertingNodePropertyFieldAccessorFactory(getTemplate()) {
@Override
public boolean accept(Neo4jPersistentProperty property) {
return property.isAnnotationPresent(GraphProperty.class) && super.accept(property);
}
};
}
private PropertyFieldAccessorFactory newPropertyFieldAccessorFactory() {
return new PropertyFieldAccessorFactory(getTemplate()) {
@Override
public boolean accept(Neo4jPersistentProperty property) {
return property.isAnnotationPresent(GraphProperty.class) && super.accept(property);
}
};
}
}
}

View File

@@ -19,9 +19,12 @@ import org.neo4j.graphdb.Node;
import org.springframework.data.neo4j.annotation.NodeEntity;
import org.springframework.data.neo4j.aspects.core.NodeBacked;
import org.springframework.data.neo4j.core.EntityState;
import org.springframework.data.neo4j.fieldaccess.DelegatingFieldAccessorFactory;
import org.springframework.data.neo4j.fieldaccess.DetachedEntityState;
import org.springframework.data.neo4j.fieldaccess.FieldAccessorFactoryFactory;
import org.springframework.data.neo4j.mapping.Neo4jPersistentEntity;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.data.neo4j.support.mapping.Neo4jMappingContext;
import org.springframework.data.neo4j.support.node.NodeEntityStateFactory;
import javax.persistence.EntityManagerFactory;
@@ -32,15 +35,21 @@ import javax.persistence.PersistenceUnitUtil;
* @since 30.09.11
*/
public class CrossStoreNodeEntityStateFactory extends NodeEntityStateFactory {
private EntityManagerFactory entityManagerFactory;
private final EntityManagerFactory entityManagerFactory;
public CrossStoreNodeEntityStateFactory(Neo4jMappingContext neo4jMappingContext, FieldAccessorFactoryFactory factory, EntityManagerFactory entityManagerFactory) {
super(neo4jMappingContext, factory);
this.entityManagerFactory = entityManagerFactory;
}
public EntityState<Node> getEntityState(final Object entity, boolean detachable, Neo4jTemplate template) {
final Class<?> entityType = entity.getClass();
if (isPartial(entityType)) {
final Neo4jPersistentEntity<?> persistentEntity = mappingContext.getPersistentEntity(entityType);
final DelegatingFieldAccessorFactory fieldAccessorFactory = nodeDelegatingFieldAccessorFactory.provideFactoryFor(template);
@SuppressWarnings("unchecked") final CrossStoreNodeEntityState<NodeBacked> partialNodeEntityState =
new CrossStoreNodeEntityState<NodeBacked>(null, (NodeBacked)entity, (Class<? extends NodeBacked>) entityType,
template, getPersistenceUnitUtils(), nodeDelegatingFieldAccessorFactory,
template, getPersistenceUnitUtils(), fieldAccessorFactory,
persistentEntity);
if (!detachable) return partialNodeEntityState;
return new DetachedEntityState<Node>(partialNodeEntityState, template) {
@@ -63,8 +72,4 @@ public class CrossStoreNodeEntityStateFactory extends NodeEntityStateFactory {
if (entityManagerFactory == null|| !entityManagerFactory.isOpen()) return null;
return entityManagerFactory.getPersistenceUnitUtil();
}
public void setEntityManagerFactory(EntityManagerFactory entityManagerFactory) {
this.entityManagerFactory = entityManagerFactory;
}
}

View File

@@ -0,0 +1,30 @@
/**
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.neo4j.partial;
import org.junit.runner.RunWith;
import org.springframework.test.context.CleanContextCacheTestExecutionListener;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:org/springframework/data/neo4j/partial/Neo4jGraphRecommendationTest-context-config.xml"})
@TestExecutionListeners({CleanContextCacheTestExecutionListener.class, DependencyInjectionTestExecutionListener.class, TransactionalTestExecutionListener.class})
public class RecommendationConfigTest extends RecommendationTest {
}

View File

@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j-2.0.xsd">
<neo4j:config graphDatabaseService="graphDatabaseService" entityManagerFactory="entityManagerFactory"/>
<bean id="graphDatabaseService" class="org.neo4j.test.ImpermanentGraphDatabase"
destroy-method="shutdown" scope="singleton">
</bean>
<context:property-placeholder location="classpath*:META-INF/spring/database.properties"/>
<context:spring-configured/>
<bean class="org.springframework.jdbc.datasource.DriverManagerDataSource" id="dataSource">
<property name="driverClassName" value="${database.driverClassName}"/>
<property name="url" value="${database.url}"/>
<property name="username" value="${database.username}"/>
<property name="password" value="${database.password}"/>
</bean>
<tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/>
<bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactory">
<property name="dataSource" ref="dataSource"/>
<property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml"/>
</bean>
<bean id="entityManager" class="org.springframework.orm.jpa.SharedEntityManagerCreator" factory-method="createSharedEntityManager">
<constructor-arg ref="entityManagerFactory"/>
</bean>
</beans>

View File

@@ -14,34 +14,10 @@
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!--
This will automatically locate any and all property files you have
within your classpath, provided they fall under the META-INF/spring
directory. The located property files are parsed and their values can
then be used within application context files in the form of
${propertyKey}.
-->
<context:property-placeholder location="classpath*:META-INF/spring/database.properties"/>
<!--
Turn on AspectJ @Configurable support. As a result, any time you
instantiate an object, Spring will attempt to perform dependency
injection on that object. This occurs for instantiation via the "new"
keyword, as well as via reflection. This is possible because AspectJ
is used to "weave" Roo-based applications at compile time. In effect
this feature allows dependency injection of any object at all in your
system, which is a very useful feature (without @Configurable you'd
only be able to dependency inject objects acquired from Spring or
subsequently presented to a specific Spring dependency injection
method). Roo applications use this useful feature in a number of
areas, such as @PersistenceContext injection into entities.
-->
<context:spring-configured/>
<!--
Start datastore config
-->
<bean id="neo4jNodeBacking" class="org.springframework.data.neo4j.aspects.support.node.Neo4jNodeBacking" factory-method="aspectOf">
<property name="template" ref="neo4jTemplate"/>
<property name="nodeEntityStateFactory" ref="nodeEntityStateFactory"/>
@@ -61,7 +37,7 @@
<constructor-arg ref="graphDatabaseService"/>
</bean>
<bean id="mappingInfrastructure" class="org.springframework.data.neo4j.support.MappingInfrastructure">
<bean id="mappingInfrastructure" class="org.springframework.data.neo4j.support.MappingInfrastructureFactoryBean">
<property name="graphDatabaseService" ref="graphDatabaseService"/>
<property name="conversionService">
<bean class="org.springframework.data.neo4j.fieldaccess.Neo4jConversionServiceFactoryBean"/>
@@ -76,7 +52,7 @@
</bean>
<bean id="neo4jTemplate" class="org.springframework.data.neo4j.support.Neo4jTemplate">
<property name="infrastructure" ref="mappingInfrastructure"/>
<constructor-arg name="infrastructure" ref="mappingInfrastructure"/>
</bean>
<bean id="graphEntityInstantiator" class="org.springframework.data.neo4j.cross_store.support.node.CrossStoreNodeEntityInstantiator">
<constructor-arg ref="nodeEntityInstantiator"/>
@@ -102,25 +78,21 @@
<bean id="relationshipTypeRepresentationStrategy" factory-bean="typeRepresentationStrategyFactory" factory-method="getRelationshipTypeRepresentationStrategy"/>
<bean id="nodeEntityStateFactory" class="org.springframework.data.neo4j.cross_store.support.node.CrossStoreNodeEntityStateFactory">
<property name="nodeDelegatingFieldAccessorFactory">
<bean class="org.springframework.data.neo4j.cross_store.support.node.CrossStoreNodeEntityState$CrossStoreNodeDelegatingFieldAccessorFactory">
<constructor-arg ref="neo4jTemplate"/>
</bean>
</property>
<property name="entityManagerFactory" ref="entityManagerFactory"/>
<property name="mappingContext" ref="mappingContext"/>
<constructor-arg ref="mappingContext"/>
<constructor-arg>
<bean class="org.springframework.data.neo4j.cross_store.support.node.CrossStoreNodeDelegatingFieldAccessorFactory$Factory"/>
</constructor-arg>
<constructor-arg name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<bean id="mappingContext" class="org.springframework.data.neo4j.support.mapping.Neo4jMappingContext"/>
<bean id="relationshipEntityStateFactory" class="org.springframework.data.neo4j.support.relationship.RelationshipEntityStateFactory">
<property name="relationshipDelegatingFieldAccessorFactory">
<bean class="org.springframework.data.neo4j.fieldaccess.RelationshipDelegatingFieldAccessorFactory">
<constructor-arg ref="neo4jTemplate"/>
</bean>
</property>
<property name="mappingContext" ref="mappingContext"/>
<constructor-arg ref="mappingContext"/>
<constructor-arg>
<bean class="org.springframework.data.neo4j.fieldaccess.RelationshipDelegatingFieldAccessorFactory$Factory"/>
</constructor-arg>
</bean>

View File

@@ -7,13 +7,13 @@
<version>2.1.0.BUILD-SNAPSHOT</version>
<name>myrestaurants-social</name>
<properties>
<spring.version>3.0.7.RELEASE</spring.version>
<spring.version>3.1.0.RELEASE</spring.version>
<spring-data-neo4j.version>${project.version}</spring-data-neo4j.version>
<aspectj.version>1.6.12</aspectj.version>
<slf4j.version>1.6.1</slf4j.version>
<neo4j.version>1.7</neo4j.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring-security.version>3.0.7.RELEASE</spring-security.version>
<spring-security.version>3.1.0.RELEASE</spring-security.version>
</properties>
<repositories>
<repository>

View File

@@ -7,7 +7,6 @@ import javax.validation.Valid;
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.support.GenericConversionService;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.WebDataBinder;

View File

@@ -20,7 +20,8 @@
<!--
neo4j datastore config
-->
<context:annotation-config/>
<!--context:annotation-config/-->
<context:spring-configured/>
<neo4j:config storeDirectory="target/db-test" entityManagerFactory="entityManagerFactory"/>
@@ -33,4 +34,5 @@
<property name="dataSource" ref="dataSource"/>
<property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml"/>
</bean>
<tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/>
</beans>

View File

@@ -1,30 +1,39 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j-2.0.xsd">
<import resource="DataStore-context.xml"/>
<context:spring-configured/>
<context:annotation-config/>
<context:spring-configured/>
<neo4j:config storeDirectory="target/db-test" entityManagerFactory="entityManagerFactory"/>
<jdbc:embedded-database id="dataSource" type="HSQL">
<jdbc:script location="classpath:schema.sql"/>
<jdbc:script location="classpath:restaurants-sample-data.sql"/>
</jdbc:embedded-database>
<bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactory"><!--depends-on="neo4jNodeBacking"-->
<property name="dataSource" ref="dataSource"/>
<property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml"/>
</bean>
<tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/>
<context:component-scan base-package="com.springone.myrestaurants">
<context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation"/>
</context:component-scan>
<tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/>
</beans>

View File

@@ -737,7 +737,7 @@
<groupId>com.springsource.bundlor</groupId>
<artifactId>com.springsource.bundlor.maven</artifactId>
<configuration>
<failOnWarnings>true</failOnWarnings>
<failOnWarnings>false</failOnWarnings>
</configuration>
<executions>
<execution>

View File

@@ -26,19 +26,20 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.core.convert.ConversionService;
import org.springframework.dao.support.PersistenceExceptionTranslator;
import org.springframework.data.convert.DefaultTypeMapper;
import org.springframework.data.convert.TypeMapper;
import org.springframework.data.neo4j.core.GraphDatabase;
import org.springframework.data.neo4j.core.TypeRepresentationStrategy;
import org.springframework.data.neo4j.fieldaccess.DelegatingFieldAccessorFactory;
import org.springframework.data.neo4j.fieldaccess.FieldAccessorFactoryFactory;
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.EntityInstantiator;
import org.springframework.data.neo4j.support.DelegatingGraphDatabase;
import org.springframework.data.neo4j.support.MappingInfrastructure;
import org.springframework.data.neo4j.support.MappingInfrastructureFactoryBean;
import org.springframework.data.neo4j.support.Neo4jExceptionTranslator;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.data.neo4j.support.index.IndexProvider;
@@ -91,42 +92,42 @@ public abstract class Neo4jConfiguration {
this.conversionService = conversionService;
}
@Autowired
@Autowired(required = true)
public void setGraphDatabaseService(GraphDatabaseService graphDatabaseService) {
this.graphDatabaseService = graphDatabaseService;
}
@Bean
public MappingInfrastructure mappingInfrastructure() throws Exception {
MappingInfrastructure infrastructure = new MappingInfrastructure();
infrastructure.setGraphDatabaseService(getGraphDatabaseService());
infrastructure.setTypeRepresentationStrategyFactory(typeRepresentationStrategyFactory());
infrastructure.setConversionService(neo4jConversionService());
infrastructure.setMappingContext(neo4jMappingContext());
infrastructure.setEntityStateHandler(entityStateHandler());
public MappingInfrastructureFactoryBean mappingInfrastructure() throws Exception {
MappingInfrastructureFactoryBean factoryBean = new MappingInfrastructureFactoryBean();
factoryBean.setGraphDatabaseService(getGraphDatabaseService());
factoryBean.setTypeRepresentationStrategyFactory(typeRepresentationStrategyFactory());
factoryBean.setConversionService(neo4jConversionService());
factoryBean.setMappingContext(neo4jMappingContext());
factoryBean.setEntityStateHandler(entityStateHandler());
infrastructure.setNodeEntityStateFactory(nodeEntityStateFactory());
infrastructure.setNodeTypeRepresentationStrategy(nodeTypeRepresentationStrategy());
infrastructure.setNodeEntityInstantiator(graphEntityInstantiator());
factoryBean.setNodeEntityStateFactory(nodeEntityStateFactory());
factoryBean.setNodeTypeRepresentationStrategy(nodeTypeRepresentationStrategy());
factoryBean.setNodeEntityInstantiator(graphEntityInstantiator());
infrastructure.setRelationshipEntityStateFactory(relationshipEntityStateFactory());
infrastructure.setRelationshipTypeRepresentationStrategy(relationshipTypeRepresentationStrategy());
infrastructure.setRelationshipEntityInstantiator(graphRelationshipInstantiator());
factoryBean.setRelationshipEntityStateFactory(relationshipEntityStateFactory());
factoryBean.setRelationshipTypeRepresentationStrategy(relationshipTypeRepresentationStrategy());
factoryBean.setRelationshipEntityInstantiator(graphRelationshipInstantiator());
infrastructure.setTransactionManager(neo4jTransactionManager());
infrastructure.setGraphDatabase(graphDatabase());
factoryBean.setTransactionManager(neo4jTransactionManager());
factoryBean.setGraphDatabase(graphDatabase());
infrastructure.setIndexProvider(indexProvider());
factoryBean.setIndexProvider(indexProvider());
if (validator!=null) {
infrastructure.setValidator(validator);
factoryBean.setValidator(validator);
}
return infrastructure;
return factoryBean;
}
@Bean(initMethod="postConstruct")
@Bean
public Neo4jTemplate neo4jTemplate() throws Exception {
return new Neo4jTemplate(mappingInfrastructure());
return new Neo4jTemplate(mappingInfrastructure().getObject());
}
@Bean
@@ -197,9 +198,6 @@ public abstract class Neo4jConfiguration {
public Neo4jMappingContext neo4jMappingContext() throws Exception {
final Neo4jMappingContext mappingContext = new Neo4jMappingContext();
mappingContext.setEntityAlias(entityAlias());
nodeEntityStateFactory().setMappingContext(mappingContext);
relationshipEntityStateFactory().setMappingContext(mappingContext);
return mappingContext;
}
@@ -210,26 +208,22 @@ public abstract class Neo4jConfiguration {
@Bean
public RelationshipEntityStateFactory relationshipEntityStateFactory() throws Exception {
return new RelationshipEntityStateFactory();
return new RelationshipEntityStateFactory(neo4jMappingContext(),relationshipDelegatingFieldAccessorFactory());
}
@Bean
public NodeEntityStateFactory nodeEntityStateFactory() throws Exception {
return new NodeEntityStateFactory();
return new NodeEntityStateFactory(neo4jMappingContext(), nodeDelegatingFieldAccessorFactory());
}
@Bean
public DelegatingFieldAccessorFactory nodeDelegatingFieldAccessorFactory() throws Exception {
final NodeDelegatingFieldAccessorFactory nodeDelegatingFieldAccessorFactory = new NodeDelegatingFieldAccessorFactory(neo4jTemplate());
nodeEntityStateFactory().setNodeDelegatingFieldAccessorFactory(nodeDelegatingFieldAccessorFactory);
return nodeDelegatingFieldAccessorFactory;
public FieldAccessorFactoryFactory nodeDelegatingFieldAccessorFactory() throws Exception {
return new NodeDelegatingFieldAccessorFactory.Factory();
}
@Bean
public DelegatingFieldAccessorFactory relationshipDelegatingFieldAccessorFactory() throws Exception {
final RelationshipDelegatingFieldAccessorFactory relationshipDelegatingFieldAccessorFactory = new RelationshipDelegatingFieldAccessorFactory(neo4jTemplate());
relationshipEntityStateFactory().setRelationshipDelegatingFieldAccessorFactory(relationshipDelegatingFieldAccessorFactory);
return relationshipDelegatingFieldAccessorFactory;
public FieldAccessorFactoryFactory relationshipDelegatingFieldAccessorFactory() throws Exception {
return new RelationshipDelegatingFieldAccessorFactory.Factory();
}
@Bean(name = {"neo4jTransactionManager","transactionManager"})
@@ -259,6 +253,8 @@ public abstract class Neo4jConfiguration {
}
@Bean
@Autowired
@DependsOn("graphDatabaseService")
public GraphDatabase graphDatabase() {
if (graphDatabaseService instanceof GraphDatabase) return (GraphDatabase) graphDatabaseService;
return new DelegatingGraphDatabase(graphDatabaseService);
@@ -278,4 +274,5 @@ public abstract class Neo4jConfiguration {
public IndexProvider indexProvider() throws Exception {
return new IndexProviderImpl(neo4jMappingContext(), graphDatabase());
}
}

View File

@@ -0,0 +1,38 @@
/**
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.neo4j.fieldaccess;
import org.springframework.data.neo4j.support.Neo4jTemplate;
/**
* @author mh
* @since 24.04.12
*/
public abstract class FieldAccessorFactoryFactory {
private DelegatingFieldAccessorFactory accessorFactory;
public abstract DelegatingFieldAccessorFactory create(Neo4jTemplate template);
public DelegatingFieldAccessorFactory provideFactoryFor(Neo4jTemplate template) {
if (accessorFactory != null) return accessorFactory;
synchronized (this) {
if (accessorFactory != null) return accessorFactory;
accessorFactory = create(template);
return accessorFactory;
}
}
}

View File

@@ -60,4 +60,11 @@ public class NodeDelegatingFieldAccessorFactory extends DelegatingFieldAccessorF
new DynamicPropertiesFieldAccessorFactory(template)
);
}
public static class Factory extends FieldAccessorFactoryFactory {
@Override
public DelegatingFieldAccessorFactory create(Neo4jTemplate template) {
return new NodeDelegatingFieldAccessorFactory(template);
}
}
}

View File

@@ -48,4 +48,11 @@ public class RelationshipDelegatingFieldAccessorFactory extends DelegatingFieldA
new DynamicPropertiesFieldAccessorFactory(template)
);
}
public static class Factory extends FieldAccessorFactoryFactory {
@Override
public DelegatingFieldAccessorFactory create(Neo4jTemplate template) {
return new RelationshipDelegatingFieldAccessorFactory(template);
}
}
}

View File

@@ -0,0 +1,71 @@
/**
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.neo4j.support;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.springframework.core.convert.ConversionService;
import org.springframework.data.neo4j.conversion.ResultConverter;
import org.springframework.data.neo4j.core.GraphDatabase;
import org.springframework.data.neo4j.core.TypeRepresentationStrategy;
import org.springframework.data.neo4j.mapping.EntityInstantiator;
import org.springframework.data.neo4j.support.index.IndexProvider;
import org.springframework.data.neo4j.support.mapping.EntityRemover;
import org.springframework.data.neo4j.support.mapping.EntityStateHandler;
import org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister;
import org.springframework.data.neo4j.support.mapping.Neo4jMappingContext;
import org.springframework.data.neo4j.support.node.EntityStateFactory;
import org.springframework.data.neo4j.support.query.CypherQueryExecutor;
import org.springframework.data.neo4j.support.typerepresentation.TypeRepresentationStrategies;
import org.springframework.data.neo4j.support.typerepresentation.TypeRepresentationStrategyFactory;
import org.springframework.transaction.PlatformTransactionManager;
import javax.validation.Validator;
/**
* @author mh
* @since 24.04.12
*/
public interface Infrastructure {
EntityStateHandler getEntityStateHandler();
ConversionService getConversionService();
Validator getValidator();
GraphDatabaseService getGraphDatabaseService();
GraphDatabase getGraphDatabase();
ResultConverter getResultConverter();
EntityRemover getEntityRemover();
IndexProvider getIndexProvider();
Neo4jEntityPersister getEntityPersister();
PlatformTransactionManager getTransactionManager();
TypeRepresentationStrategies getTypeRepresentationStrategies();
Neo4jMappingContext getMappingContext();
TypeRepresentationStrategy<Node> getNodeTypeRepresentationStrategy();
TypeRepresentationStrategy<Relationship> getRelationshipTypeRepresentationStrategy();
}

View File

@@ -19,23 +19,17 @@ import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.springframework.core.convert.ConversionService;
import org.springframework.data.neo4j.annotation.QueryType;
import org.springframework.data.neo4j.conversion.ResultConverter;
import org.springframework.data.neo4j.core.GraphDatabase;
import org.springframework.data.neo4j.core.TypeRepresentationStrategy;
import org.springframework.data.neo4j.mapping.EntityInstantiator;
import org.springframework.data.neo4j.support.conversion.EntityResultConverter;
import org.springframework.data.neo4j.support.index.IndexProvider;
import org.springframework.data.neo4j.support.index.IndexProviderImpl;
import org.springframework.data.neo4j.support.mapping.EntityRemover;
import org.springframework.data.neo4j.support.mapping.EntityStateHandler;
import org.springframework.data.neo4j.support.mapping.EntityTools;
import org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister;
import org.springframework.data.neo4j.support.mapping.Neo4jMappingContext;
import org.springframework.data.neo4j.support.node.EntityStateFactory;
import org.springframework.data.neo4j.support.node.NodeEntityInstantiator;
import org.springframework.data.neo4j.support.query.CypherQueryExecutor;
import org.springframework.data.neo4j.support.relationship.RelationshipEntityInstantiator;
import org.springframework.data.neo4j.support.typerepresentation.TypeRepresentationStrategies;
import org.springframework.data.neo4j.support.typerepresentation.TypeRepresentationStrategyFactory;
import org.springframework.transaction.PlatformTransactionManager;
@@ -46,198 +40,111 @@ import javax.validation.Validator;
* @author mh
* @since 17.10.11
*/
public class MappingInfrastructure {
private ConversionService conversionService;
private Validator validator;
private TypeRepresentationStrategy<Node> nodeTypeRepresentationStrategy;
public class MappingInfrastructure implements Infrastructure {
private TypeRepresentationStrategy<Relationship> relationshipTypeRepresentationStrategy;
private final ConversionService conversionService;
private final Validator validator;
private final TypeRepresentationStrategy<Node> nodeTypeRepresentationStrategy;
private TypeRepresentationStrategyFactory typeRepresentationStrategyFactory;
private final TypeRepresentationStrategy<Relationship> relationshipTypeRepresentationStrategy;
private Neo4jMappingContext mappingContext;
private CypherQueryExecutor cypherQueryExecutor;
private EntityStateHandler entityStateHandler;
private Neo4jEntityPersister entityPersister;
private EntityStateFactory<Node> nodeEntityStateFactory;
private EntityStateFactory<Relationship> relationshipEntityStateFactory;
private EntityRemover entityRemover;
private TypeRepresentationStrategies typeRepresentationStrategies;
private EntityInstantiator<Relationship> relationshipEntityInstantiator;
private EntityInstantiator<Node> nodeEntityInstantiator;
private PlatformTransactionManager transactionManager;
private ResultConverter resultConverter;
private IndexProvider indexProvider;
private GraphDatabaseService graphDatabaseService;
private GraphDatabase graphDatabase;
private final Neo4jMappingContext mappingContext;
private final CypherQueryExecutor cypherQueryExecutor;
private final EntityStateHandler entityStateHandler;
private final Neo4jEntityPersister entityPersister;
private final EntityRemover entityRemover;
private final TypeRepresentationStrategies typeRepresentationStrategies;
private final PlatformTransactionManager transactionManager;
private final ResultConverter resultConverter;
private final IndexProvider indexProvider;
private final GraphDatabaseService graphDatabaseService;
private final GraphDatabase graphDatabase;
public MappingInfrastructure(GraphDatabase graphDatabase, PlatformTransactionManager transactionManager) {
public MappingInfrastructure(GraphDatabase graphDatabase, GraphDatabaseService graphDatabaseService, IndexProvider indexProvider, ResultConverter resultConverter, PlatformTransactionManager transactionManager, TypeRepresentationStrategies typeRepresentationStrategies, EntityRemover entityRemover, Neo4jEntityPersister entityPersister, EntityStateHandler entityStateHandler, CypherQueryExecutor cypherQueryExecutor, Neo4jMappingContext mappingContext, TypeRepresentationStrategy<Relationship> relationshipTypeRepresentationStrategy, TypeRepresentationStrategy<Node> nodeTypeRepresentationStrategy, Validator validator, ConversionService conversionService) {
this.graphDatabase = graphDatabase;
this.graphDatabaseService = graphDatabaseService;
this.indexProvider = indexProvider;
this.resultConverter = resultConverter;
this.transactionManager = transactionManager;
}
public MappingInfrastructure() {
}
// @PostConstruct // TODO
public void postConstruct() {
if (this.mappingContext == null) this.mappingContext = new Neo4jMappingContext();
if (this.graphDatabase == null) {
this.graphDatabase = new DelegatingGraphDatabase(graphDatabaseService);
}
if (nodeEntityInstantiator == null) {
nodeEntityInstantiator = new NodeEntityInstantiator(entityStateHandler);
}
if (relationshipEntityInstantiator == null) {
relationshipEntityInstantiator = new RelationshipEntityInstantiator(entityStateHandler);
}
if (this.typeRepresentationStrategyFactory==null) {
this.typeRepresentationStrategyFactory = new TypeRepresentationStrategyFactory(graphDatabase);
}
if (this.nodeTypeRepresentationStrategy == null) {
this.nodeTypeRepresentationStrategy = typeRepresentationStrategyFactory.getNodeTypeRepresentationStrategy();
}
if (this.relationshipTypeRepresentationStrategy == null) {
this.relationshipTypeRepresentationStrategy = typeRepresentationStrategyFactory.getRelationshipTypeRepresentationStrategy();
}
this.typeRepresentationStrategies = new TypeRepresentationStrategies(mappingContext, nodeTypeRepresentationStrategy, relationshipTypeRepresentationStrategy);
final EntityStateHandler entityStateHandler = new EntityStateHandler(mappingContext, graphDatabase);
EntityTools<Node> nodeEntityTools = new EntityTools<Node>(nodeTypeRepresentationStrategy, nodeEntityStateFactory, nodeEntityInstantiator,mappingContext);
EntityTools<Relationship> relationshipEntityTools = new EntityTools<Relationship>(relationshipTypeRepresentationStrategy, relationshipEntityStateFactory, relationshipEntityInstantiator, mappingContext);
this.entityPersister = new Neo4jEntityPersister(conversionService, nodeEntityTools, relationshipEntityTools, mappingContext, entityStateHandler);
this.entityRemover = new EntityRemover(this.entityStateHandler, nodeTypeRepresentationStrategy, relationshipTypeRepresentationStrategy, graphDatabase);
if (this.resultConverter==null) {
this.resultConverter = new EntityResultConverter<Object, Object>(conversionService);
}
this.graphDatabase.setResultConverter(resultConverter);
this.cypherQueryExecutor = new CypherQueryExecutor(graphDatabase.queryEngineFor(QueryType.Cypher, resultConverter));
if (this.indexProvider == null) {
this.indexProvider = new IndexProviderImpl(this.mappingContext, graphDatabase);
}
}
public void setTransactionManager(PlatformTransactionManager transactionManager) {
this.transactionManager = transactionManager;
}
public void setRelationshipEntityInstantiator(EntityInstantiator<Relationship> relationshipEntityInstantiator) {
this.relationshipEntityInstantiator = relationshipEntityInstantiator;
}
public void setNodeEntityInstantiator(EntityInstantiator<Node> nodeEntityInstantiator) {
this.nodeEntityInstantiator = nodeEntityInstantiator;
}
public void setEntityStateHandler(EntityStateHandler entityStateHandler) {
this.typeRepresentationStrategies = typeRepresentationStrategies;
this.entityRemover = entityRemover;
this.entityPersister = entityPersister;
this.entityStateHandler = entityStateHandler;
this.cypherQueryExecutor = cypherQueryExecutor;
this.mappingContext = mappingContext;
this.relationshipTypeRepresentationStrategy = relationshipTypeRepresentationStrategy;
this.nodeTypeRepresentationStrategy = nodeTypeRepresentationStrategy;
this.validator = validator;
this.conversionService = conversionService;
}
public void setNodeEntityStateFactory(EntityStateFactory<Node> nodeEntityStateFactory) {
this.nodeEntityStateFactory = nodeEntityStateFactory;
}
public void setRelationshipEntityStateFactory(EntityStateFactory<Relationship> relationshipEntityStateFactory) {
this.relationshipEntityStateFactory = relationshipEntityStateFactory;
}
@Override
public EntityStateHandler getEntityStateHandler() {
return entityStateHandler;
}
public TypeRepresentationStrategy<Node> getNodeTypeRepresentationStrategy() {
return nodeTypeRepresentationStrategy;
}
public void setNodeTypeRepresentationStrategy(TypeRepresentationStrategy<Node> nodeTypeRepresentationStrategy) {
this.nodeTypeRepresentationStrategy = nodeTypeRepresentationStrategy;
}
public TypeRepresentationStrategy<Relationship> getRelationshipTypeRepresentationStrategy() {
return relationshipTypeRepresentationStrategy;
}
public void setRelationshipTypeRepresentationStrategy(TypeRepresentationStrategy<Relationship> relationshipTypeRepresentationStrategy) {
this.relationshipTypeRepresentationStrategy = relationshipTypeRepresentationStrategy;
}
@Override
public ConversionService getConversionService() {
return conversionService;
}
public void setConversionService(ConversionService conversionService) {
this.conversionService = conversionService;
}
@Override
public Validator getValidator() {
return validator;
}
public void setValidator(Validator validatorFactory) {
this.validator = validatorFactory;
}
public void setMappingContext(Neo4jMappingContext mappingContext) {
this.mappingContext = mappingContext;
}
@Override
public GraphDatabaseService getGraphDatabaseService() {
return graphDatabaseService;
}
public void setGraphDatabaseService(GraphDatabaseService graphDatabaseService) {
this.graphDatabaseService = graphDatabaseService;
}
public void setGraphDatabase(GraphDatabase graphDatabase) {
this.graphDatabase = graphDatabase;
}
@Override
public GraphDatabase getGraphDatabase() {
return graphDatabase;
}
@Override
public ResultConverter getResultConverter() {
return resultConverter;
}
@Override
public EntityRemover getEntityRemover() {
return entityRemover;
}
@Override
public IndexProvider getIndexProvider() {
return indexProvider;
}
@Override
public Neo4jEntityPersister getEntityPersister() {
return entityPersister;
}
@Override
public PlatformTransactionManager getTransactionManager() {
return transactionManager;
}
@Override
public TypeRepresentationStrategies getTypeRepresentationStrategies() {
return typeRepresentationStrategies;
}
public CypherQueryExecutor getCypherQueryExecutor() {
return cypherQueryExecutor;
}
@Override
public Neo4jMappingContext getMappingContext() {
return mappingContext;
}
public void setTypeRepresentationStrategyFactory(TypeRepresentationStrategyFactory typeRepresentationStrategyFactory) {
this.typeRepresentationStrategyFactory = typeRepresentationStrategyFactory;
@Override
public TypeRepresentationStrategy<Node> getNodeTypeRepresentationStrategy() {
return nodeTypeRepresentationStrategy;
}
public void setIndexProvider(IndexProvider indexProvider) {
this.indexProvider = indexProvider;
@Override
public TypeRepresentationStrategy<Relationship> getRelationshipTypeRepresentationStrategy() {
return relationshipTypeRepresentationStrategy;
}
}

View File

@@ -0,0 +1,271 @@
/**
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.neo4j.support;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.convert.ConversionService;
import org.springframework.data.neo4j.annotation.QueryType;
import org.springframework.data.neo4j.conversion.ResultConverter;
import org.springframework.data.neo4j.core.GraphDatabase;
import org.springframework.data.neo4j.core.TypeRepresentationStrategy;
import org.springframework.data.neo4j.mapping.EntityInstantiator;
import org.springframework.data.neo4j.support.conversion.EntityResultConverter;
import org.springframework.data.neo4j.support.index.IndexProvider;
import org.springframework.data.neo4j.support.index.IndexProviderImpl;
import org.springframework.data.neo4j.support.mapping.EntityRemover;
import org.springframework.data.neo4j.support.mapping.EntityStateHandler;
import org.springframework.data.neo4j.support.mapping.EntityTools;
import org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister;
import org.springframework.data.neo4j.support.mapping.Neo4jMappingContext;
import org.springframework.data.neo4j.support.node.EntityStateFactory;
import org.springframework.data.neo4j.support.node.NodeEntityInstantiator;
import org.springframework.data.neo4j.support.query.CypherQueryExecutor;
import org.springframework.data.neo4j.support.relationship.RelationshipEntityInstantiator;
import org.springframework.data.neo4j.support.typerepresentation.TypeRepresentationStrategies;
import org.springframework.data.neo4j.support.typerepresentation.TypeRepresentationStrategyFactory;
import org.springframework.transaction.PlatformTransactionManager;
import javax.validation.Validator;
/**
* @author mh
* @since 17.10.11
*/
public class MappingInfrastructureFactoryBean implements FactoryBean<Infrastructure>, InitializingBean {
private ConversionService conversionService;
private Validator validator;
private TypeRepresentationStrategy<Node> nodeTypeRepresentationStrategy;
private TypeRepresentationStrategy<Relationship> relationshipTypeRepresentationStrategy;
private TypeRepresentationStrategyFactory typeRepresentationStrategyFactory;
private Neo4jMappingContext mappingContext;
private CypherQueryExecutor cypherQueryExecutor;
private EntityStateHandler entityStateHandler;
private Neo4jEntityPersister entityPersister;
private EntityStateFactory<Node> nodeEntityStateFactory;
private EntityStateFactory<Relationship> relationshipEntityStateFactory;
private EntityRemover entityRemover;
private TypeRepresentationStrategies typeRepresentationStrategies;
private EntityInstantiator<Relationship> relationshipEntityInstantiator;
private EntityInstantiator<Node> nodeEntityInstantiator;
private PlatformTransactionManager transactionManager;
private ResultConverter resultConverter;
private IndexProvider indexProvider;
private GraphDatabaseService graphDatabaseService;
private GraphDatabase graphDatabase;
private MappingInfrastructure mappingInfrastructure;
public MappingInfrastructureFactoryBean(GraphDatabase graphDatabase, PlatformTransactionManager transactionManager) {
this.graphDatabase = graphDatabase;
this.transactionManager = transactionManager;
}
public MappingInfrastructureFactoryBean(GraphDatabaseService graphDatabaseService, PlatformTransactionManager transactionManager) {
this.graphDatabaseService = graphDatabaseService;
this.transactionManager = transactionManager;
}
public MappingInfrastructureFactoryBean() {
}
@Override
public void afterPropertiesSet() {
if (this.mappingContext == null) this.mappingContext = new Neo4jMappingContext();
if (this.graphDatabase == null) {
this.graphDatabase = new DelegatingGraphDatabase(graphDatabaseService);
}
if (nodeEntityInstantiator == null) {
nodeEntityInstantiator = new NodeEntityInstantiator(entityStateHandler);
}
if (relationshipEntityInstantiator == null) {
relationshipEntityInstantiator = new RelationshipEntityInstantiator(entityStateHandler);
}
if (this.typeRepresentationStrategyFactory == null) {
this.typeRepresentationStrategyFactory = new TypeRepresentationStrategyFactory(graphDatabase);
}
if (this.nodeTypeRepresentationStrategy == null) {
this.nodeTypeRepresentationStrategy = typeRepresentationStrategyFactory.getNodeTypeRepresentationStrategy();
}
if (this.relationshipTypeRepresentationStrategy == null) {
this.relationshipTypeRepresentationStrategy = typeRepresentationStrategyFactory.getRelationshipTypeRepresentationStrategy();
}
this.typeRepresentationStrategies = new TypeRepresentationStrategies(mappingContext, nodeTypeRepresentationStrategy, relationshipTypeRepresentationStrategy);
final EntityStateHandler entityStateHandler = new EntityStateHandler(mappingContext, graphDatabase);
EntityTools<Node> nodeEntityTools = new EntityTools<Node>(nodeTypeRepresentationStrategy, nodeEntityStateFactory, nodeEntityInstantiator, mappingContext);
EntityTools<Relationship> relationshipEntityTools = new EntityTools<Relationship>(relationshipTypeRepresentationStrategy, relationshipEntityStateFactory, relationshipEntityInstantiator, mappingContext);
this.entityPersister = new Neo4jEntityPersister(conversionService, nodeEntityTools, relationshipEntityTools, mappingContext, entityStateHandler);
this.entityRemover = new EntityRemover(this.entityStateHandler, nodeTypeRepresentationStrategy, relationshipTypeRepresentationStrategy, graphDatabase);
if (this.resultConverter == null) {
this.resultConverter = new EntityResultConverter<Object, Object>(conversionService);
}
this.graphDatabase.setResultConverter(resultConverter);
this.cypherQueryExecutor = new CypherQueryExecutor(graphDatabase.queryEngineFor(QueryType.Cypher, resultConverter));
if (this.indexProvider == null) {
this.indexProvider = new IndexProviderImpl(this.mappingContext, graphDatabase);
}
this.mappingInfrastructure = new MappingInfrastructure(graphDatabase, graphDatabaseService, indexProvider, resultConverter, transactionManager, typeRepresentationStrategies, entityRemover, entityPersister, entityStateHandler, cypherQueryExecutor, mappingContext, relationshipTypeRepresentationStrategy, nodeTypeRepresentationStrategy, validator, conversionService);
}
public void setTransactionManager(PlatformTransactionManager transactionManager) {
this.transactionManager = transactionManager;
}
public void setRelationshipEntityInstantiator(EntityInstantiator<Relationship> relationshipEntityInstantiator) {
this.relationshipEntityInstantiator = relationshipEntityInstantiator;
}
public void setNodeEntityInstantiator(EntityInstantiator<Node> nodeEntityInstantiator) {
this.nodeEntityInstantiator = nodeEntityInstantiator;
}
public void setEntityStateHandler(EntityStateHandler entityStateHandler) {
this.entityStateHandler = entityStateHandler;
}
public void setNodeEntityStateFactory(EntityStateFactory<Node> nodeEntityStateFactory) {
this.nodeEntityStateFactory = nodeEntityStateFactory;
}
public void setRelationshipEntityStateFactory(EntityStateFactory<Relationship> relationshipEntityStateFactory) {
this.relationshipEntityStateFactory = relationshipEntityStateFactory;
}
public EntityStateHandler getEntityStateHandler() {
return entityStateHandler;
}
public TypeRepresentationStrategy<Node> getNodeTypeRepresentationStrategy() {
return nodeTypeRepresentationStrategy;
}
public void setNodeTypeRepresentationStrategy(TypeRepresentationStrategy<Node> nodeTypeRepresentationStrategy) {
this.nodeTypeRepresentationStrategy = nodeTypeRepresentationStrategy;
}
public TypeRepresentationStrategy<Relationship> getRelationshipTypeRepresentationStrategy() {
return relationshipTypeRepresentationStrategy;
}
public void setRelationshipTypeRepresentationStrategy(TypeRepresentationStrategy<Relationship> relationshipTypeRepresentationStrategy) {
this.relationshipTypeRepresentationStrategy = relationshipTypeRepresentationStrategy;
}
public ConversionService getConversionService() {
return conversionService;
}
public void setConversionService(ConversionService conversionService) {
this.conversionService = conversionService;
}
public Validator getValidator() {
return validator;
}
public void setValidator(Validator validatorFactory) {
this.validator = validatorFactory;
}
public void setMappingContext(Neo4jMappingContext mappingContext) {
this.mappingContext = mappingContext;
}
public GraphDatabaseService getGraphDatabaseService() {
return graphDatabaseService;
}
public void setGraphDatabaseService(GraphDatabaseService graphDatabaseService) {
this.graphDatabaseService = graphDatabaseService;
}
public void setGraphDatabase(GraphDatabase graphDatabase) {
this.graphDatabase = graphDatabase;
}
public GraphDatabase getGraphDatabase() {
return graphDatabase;
}
public ResultConverter getResultConverter() {
return resultConverter;
}
public EntityRemover getEntityRemover() {
return entityRemover;
}
public IndexProvider getIndexProvider() {
return indexProvider;
}
public Neo4jEntityPersister getEntityPersister() {
return entityPersister;
}
public PlatformTransactionManager getTransactionManager() {
return transactionManager;
}
public TypeRepresentationStrategies getTypeRepresentationStrategies() {
return typeRepresentationStrategies;
}
public CypherQueryExecutor getCypherQueryExecutor() {
return cypherQueryExecutor;
}
public Neo4jMappingContext getMappingContext() {
return mappingContext;
}
public void setTypeRepresentationStrategyFactory(TypeRepresentationStrategyFactory typeRepresentationStrategyFactory) {
this.typeRepresentationStrategyFactory = typeRepresentationStrategyFactory;
}
public void setIndexProvider(IndexProvider indexProvider) {
this.indexProvider = indexProvider;
}
@Override
public Infrastructure getObject() {
return mappingInfrastructure;
}
@Override
public Class<?> getObjectType() {
return Infrastructure.class;
}
@Override
public boolean isSingleton() {
return true;
}
public static Infrastructure createDirect(GraphDatabase graphDatabase, PlatformTransactionManager transactionManager) {
final MappingInfrastructureFactoryBean factoryBean = new MappingInfrastructureFactoryBean(graphDatabase, transactionManager);
factoryBean.afterPropertiesSet();
return factoryBean.getObject();
}
}

View File

@@ -83,14 +83,7 @@ TODO This is a merge of GraphDatabaseContext and the previous Neo4jTemplate, so
public class Neo4jTemplate implements Neo4jOperations , EntityPersister2 {
private static final Logger log = LoggerFactory.getLogger(Neo4jTemplate.class);
private MappingInfrastructure infrastructure = new MappingInfrastructure();
/**
* default constructor for dependency injection, TODO provide dependencies at creation time
*/
public Neo4jTemplate() {
this.infrastructure = new MappingInfrastructure();
}
private final Infrastructure infrastructure;
/**
* @param graphDatabase the neo4j graph database
@@ -98,15 +91,15 @@ public class Neo4jTemplate implements Neo4jOperations , EntityPersister2 {
*/
public Neo4jTemplate(final GraphDatabase graphDatabase, PlatformTransactionManager transactionManager) {
notNull(graphDatabase, "graphDatabase");
this.infrastructure = new MappingInfrastructure(graphDatabase,transactionManager);
this.infrastructure = MappingInfrastructureFactoryBean.createDirect(graphDatabase,transactionManager);
}
public Neo4jTemplate(final GraphDatabase graphDatabase) {
notNull(graphDatabase, "graphDatabase");
this.infrastructure = new MappingInfrastructure(graphDatabase,null);
this.infrastructure = MappingInfrastructureFactoryBean.createDirect(graphDatabase,null);
}
public Neo4jTemplate(MappingInfrastructure infrastructure) {
public Neo4jTemplate(Infrastructure infrastructure) {
this.infrastructure = infrastructure;
}
@@ -289,12 +282,6 @@ public class Neo4jTemplate implements Neo4jOperations , EntityPersister2 {
return infrastructure.getGraphDatabaseService().beginTx();
}
@SuppressWarnings("unused")
@PostConstruct
public void postConstruct() {
infrastructure.postConstruct();
}
@Override
public boolean isNodeEntity(Class<?> targetType) {
return getMappingContext().isNodeEntity(targetType);
@@ -646,11 +633,7 @@ public class Neo4jTemplate implements Neo4jOperations , EntityPersister2 {
return infrastructure.getGraphDatabaseService();
}
public void setInfrastructure(MappingInfrastructure infrastructure) {
this.infrastructure = infrastructure;
}
public MappingInfrastructure getInfrastructure() {
public Infrastructure getInfrastructure() {
return infrastructure;
}

View File

@@ -19,17 +19,21 @@ package org.springframework.data.neo4j.support.node;
import org.neo4j.graphdb.Node;
import org.springframework.data.neo4j.core.EntityState;
import org.springframework.data.neo4j.fieldaccess.DelegatingFieldAccessorFactory;
import org.springframework.data.neo4j.fieldaccess.DetachedEntityState;
import org.springframework.data.neo4j.fieldaccess.FieldAccessorFactoryFactory;
import org.springframework.data.neo4j.support.mapping.Neo4jMappingContext;
import org.springframework.data.neo4j.mapping.Neo4jPersistentEntity;
import org.springframework.data.neo4j.support.Neo4jTemplate;
public class NodeEntityStateFactory implements EntityStateFactory<Node> {
protected DelegatingFieldAccessorFactory nodeDelegatingFieldAccessorFactory;
protected final FieldAccessorFactoryFactory nodeDelegatingFieldAccessorFactory;
protected final Neo4jMappingContext mappingContext;
protected Neo4jMappingContext mappingContext;
public NodeEntityStateFactory(Neo4jMappingContext mappingContext, FieldAccessorFactoryFactory nodeDelegatingFieldAccessorFactory) {
this.nodeDelegatingFieldAccessorFactory = nodeDelegatingFieldAccessorFactory;
this.mappingContext = mappingContext;
}
public EntityState<Node> getEntityState(final Object entity, boolean detachable, Neo4jTemplate template) {
final Class<?> entityType = entity.getClass();
@@ -37,28 +41,10 @@ public class NodeEntityStateFactory implements EntityStateFactory<Node> {
(Neo4jPersistentEntity<Object>) mappingContext.getPersistentEntity(entityType);
NodeEntityState nodeEntityState = new NodeEntityState(null, entity, entityType, template,
nodeDelegatingFieldAccessorFactory, persistentEntity);
nodeDelegatingFieldAccessorFactory.provideFactoryFor(template), persistentEntity);
if (!detachable) {
return nodeEntityState;
}
return new DetachedEntityState<Node>(nodeEntityState, template);
}
public void setNodeDelegatingFieldAccessorFactory(
DelegatingFieldAccessorFactory nodeDelegatingFieldAccessorFactory) {
this.nodeDelegatingFieldAccessorFactory = nodeDelegatingFieldAccessorFactory;
}
/*
public void setTemplate(Neo4jTemplate template) {
this.template = template;
}
*/
public Neo4jMappingContext getMappingContext() {
return mappingContext;
}
public void setMappingContext(Neo4jMappingContext mappingContext) {
this.mappingContext = mappingContext;
}
}

View File

@@ -20,6 +20,7 @@ import org.neo4j.graphdb.Relationship;
import org.springframework.data.neo4j.core.EntityState;
import org.springframework.data.neo4j.fieldaccess.DelegatingFieldAccessorFactory;
import org.springframework.data.neo4j.fieldaccess.DetachedEntityState;
import org.springframework.data.neo4j.fieldaccess.FieldAccessorFactoryFactory;
import org.springframework.data.neo4j.mapping.Neo4jPersistentEntity;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.data.neo4j.support.mapping.Neo4jMappingContext;
@@ -27,27 +28,24 @@ import org.springframework.data.neo4j.support.node.EntityStateFactory;
public class RelationshipEntityStateFactory implements EntityStateFactory<Relationship> {
private DelegatingFieldAccessorFactory relationshipDelegatingFieldAccessorFactory;
private Neo4jMappingContext mappingContext;
private final FieldAccessorFactoryFactory relationshipDelegatingFieldAccessorFactory;
private final Neo4jMappingContext mappingContext;
public RelationshipEntityStateFactory(Neo4jMappingContext mappingContext, FieldAccessorFactoryFactory relationshipDelegatingFieldAccessorFactory) {
this.mappingContext = mappingContext;
this.relationshipDelegatingFieldAccessorFactory = relationshipDelegatingFieldAccessorFactory;
}
@SuppressWarnings("unchecked")
public EntityState<Relationship> getEntityState(final Object entity, boolean detachable, Neo4jTemplate template) {
final Class<?> entityType = entity.getClass();
final Neo4jPersistentEntity persistentEntity = (Neo4jPersistentEntity) mappingContext.getPersistentEntity(entityType);
final RelationshipEntityState relationshipEntityState = new RelationshipEntityState(null, entity, entityType, template, relationshipDelegatingFieldAccessorFactory, persistentEntity);
final DelegatingFieldAccessorFactory fieldAccessorFactory = relationshipDelegatingFieldAccessorFactory.provideFactoryFor(template);
final RelationshipEntityState relationshipEntityState = new RelationshipEntityState(null, entity, entityType, template, fieldAccessorFactory, persistentEntity);
if (!detachable) {
return relationshipEntityState;
}
return new DetachedEntityState<Relationship>(relationshipEntityState, template);
}
public void setRelationshipDelegatingFieldAccessorFactory(
DelegatingFieldAccessorFactory delegatingFieldAccessorFactory) {
this.relationshipDelegatingFieldAccessorFactory = delegatingFieldAccessorFactory;
}
public void setMappingContext(Neo4jMappingContext mappingContext) {
this.mappingContext = mappingContext;
}
}

View File

@@ -25,15 +25,19 @@ import org.springframework.data.convert.DefaultTypeMapper;
import org.springframework.data.convert.TypeMapper;
import org.springframework.data.neo4j.annotation.GraphId;
import org.springframework.data.neo4j.annotation.NodeEntity;
import org.springframework.data.neo4j.fieldaccess.DelegatingFieldAccessorFactory;
import org.springframework.data.neo4j.fieldaccess.FieldAccessorFactoryFactory;
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.model.Group;
import org.springframework.data.neo4j.model.Person;
import org.springframework.data.neo4j.support.DelegatingGraphDatabase;
import org.springframework.data.neo4j.support.MappingInfrastructure;
import org.springframework.data.neo4j.support.Infrastructure;
import org.springframework.data.neo4j.support.MappingInfrastructureFactoryBean;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.data.neo4j.support.mapping.*;
import org.springframework.data.neo4j.support.node.EntityStateFactory;
import org.springframework.data.neo4j.support.node.NodeEntityInstantiator;
import org.springframework.data.neo4j.support.node.NodeEntityStateFactory;
import org.springframework.data.neo4j.support.relationship.RelationshipEntityInstantiator;
@@ -56,8 +60,6 @@ import static java.util.Arrays.asList;
public class Neo4jPersistentTestBase {
private Transaction tx;
protected Neo4jTemplate template;
protected NodeEntityStateFactory nodeEntityStateFactory;
protected RelationshipEntityStateFactory relationshipEntityStateFactory;
protected EntityStateHandler entityStateHandler;
protected NodeEntityInstantiator nodeEntityInstantiator;
protected RelationshipEntityInstantiator relationshipEntityInstantiator;
@@ -88,30 +90,10 @@ public class Neo4jPersistentTestBase {
public void setUp() throws Exception {
// todo cleanup !!
mappingContext = new Neo4jMappingContext();
MappingInfrastructure infrastructure = createInfrastructure(mappingContext);
Infrastructure infrastructure = createInfrastructure(mappingContext);
template = new Neo4jTemplate(infrastructure);
nodeEntityStateFactory = createNodeEntityStateFactory(mappingContext);
relationshipEntityStateFactory = createRelationshipEntityStateFactory(mappingContext);
infrastructure.setNodeEntityStateFactory(nodeEntityStateFactory);
infrastructure.setRelationshipEntityStateFactory(relationshipEntityStateFactory);
template.postConstruct();
entityStateHandler = infrastructure.getEntityStateHandler();
nodeEntityInstantiator = new NodeEntityInstantiator(entityStateHandler);
relationshipEntityInstantiator = new RelationshipEntityInstantiator(entityStateHandler);
nodeTypeMapper = new DefaultTypeMapper<Node>(new TRSTypeAliasAccessor<Node>(infrastructure.getNodeTypeRepresentationStrategy()), asList(new ClassValueTypeInformationMapper()));
nodeStateTransmitter = new SourceStateTransmitter<Node>(nodeEntityStateFactory);
relationshipStateTransmitter = new SourceStateTransmitter<Relationship>(relationshipEntityStateFactory);
conversionService = template.getConversionService();
fetchHandler = new Neo4jEntityFetchHandler(entityStateHandler, conversionService, nodeStateTransmitter, relationshipStateTransmitter);
final EntityTools<Node> nodeEntityTools = new EntityTools<Node>(infrastructure.getNodeTypeRepresentationStrategy(), nodeEntityStateFactory, nodeEntityInstantiator, mappingContext);
final EntityTools<Relationship> relationshipEntityTools = new EntityTools<Relationship>(infrastructure.getRelationshipTypeRepresentationStrategy(), relationshipEntityStateFactory, relationshipEntityInstantiator, mappingContext);
entityPersister = new Neo4jEntityPersister(conversionService, nodeEntityTools, relationshipEntityTools, mappingContext, entityStateHandler);
tx = template.beginTx();
group = new Group();
@@ -120,33 +102,50 @@ public class Neo4jPersistentTestBase {
andres = new Person("Andrés", 36);
}
private NodeEntityStateFactory createNodeEntityStateFactory(Neo4jMappingContext mappingContext) {
final NodeEntityStateFactory nodeEntityStateFactory = new NodeEntityStateFactory();
nodeEntityStateFactory.setMappingContext(mappingContext);
nodeEntityStateFactory.setNodeDelegatingFieldAccessorFactory(new NodeDelegatingFieldAccessorFactory(template));
return nodeEntityStateFactory;
}
private RelationshipEntityStateFactory createRelationshipEntityStateFactory(Neo4jMappingContext mappingContext) {
final RelationshipEntityStateFactory relationshipEntityStateFactory = new RelationshipEntityStateFactory();
relationshipEntityStateFactory.setMappingContext(mappingContext);
relationshipEntityStateFactory.setRelationshipDelegatingFieldAccessorFactory(new RelationshipDelegatingFieldAccessorFactory(template));
return relationshipEntityStateFactory;
}
private MappingInfrastructure createInfrastructure(Neo4jMappingContext mappingContext) throws Exception {
MappingInfrastructure infrastructure = new MappingInfrastructure();
private Infrastructure createInfrastructure(Neo4jMappingContext mappingContext) throws Exception {
MappingInfrastructureFactoryBean factoryBean = new MappingInfrastructureFactoryBean();
final GraphDatabaseService gdb = new ImpermanentGraphDatabase();
infrastructure.setGraphDatabaseService(gdb);
factoryBean.setGraphDatabaseService(gdb);
final DelegatingGraphDatabase graphDatabase = new DelegatingGraphDatabase(gdb);
infrastructure.setGraphDatabase(graphDatabase);
infrastructure.setMappingContext(mappingContext);
factoryBean.setGraphDatabase(graphDatabase);
factoryBean.setMappingContext(mappingContext);
final EntityStateHandler entityStateHandler = new EntityStateHandler(mappingContext, graphDatabase);
infrastructure.setNodeTypeRepresentationStrategy(new NoopNodeTypeRepresentationStrategy());
infrastructure.setRelationshipTypeRepresentationStrategy(new NoopRelationshipTypeRepresentationStrategy());
infrastructure.setConversionService(new Neo4jConversionServiceFactoryBean().getObject());
infrastructure.setEntityStateHandler(entityStateHandler);
return infrastructure;
final NoopNodeTypeRepresentationStrategy nodeTypeRepresentationStrategy = new NoopNodeTypeRepresentationStrategy();
factoryBean.setNodeTypeRepresentationStrategy(nodeTypeRepresentationStrategy);
final NoopRelationshipTypeRepresentationStrategy relationshipTypeRepresentationStrategy = new NoopRelationshipTypeRepresentationStrategy();
factoryBean.setRelationshipTypeRepresentationStrategy(relationshipTypeRepresentationStrategy);
factoryBean.setConversionService(new Neo4jConversionServiceFactoryBean().getObject());
factoryBean.setEntityStateHandler(entityStateHandler);
EntityStateFactory<Node> nodeEntityStateFactory = new NodeEntityStateFactory(mappingContext, new FieldAccessorFactoryFactory() {
public DelegatingFieldAccessorFactory create(Neo4jTemplate template) {
return new NodeDelegatingFieldAccessorFactory(template);
}
});
EntityStateFactory<Relationship> relationshipEntityStateFactory = new RelationshipEntityStateFactory(mappingContext, new FieldAccessorFactoryFactory() {
public DelegatingFieldAccessorFactory create(Neo4jTemplate template) {
return new RelationshipDelegatingFieldAccessorFactory(template);
}
});
factoryBean.setNodeEntityStateFactory(nodeEntityStateFactory);
factoryBean.setRelationshipEntityStateFactory(relationshipEntityStateFactory);
nodeEntityInstantiator = new NodeEntityInstantiator(entityStateHandler);
relationshipEntityInstantiator = new RelationshipEntityInstantiator(entityStateHandler);
nodeTypeMapper = new DefaultTypeMapper<Node>(new TRSTypeAliasAccessor<Node>(nodeTypeRepresentationStrategy), asList(new ClassValueTypeInformationMapper()));
nodeStateTransmitter = new SourceStateTransmitter<Node>(nodeEntityStateFactory);
relationshipStateTransmitter = new SourceStateTransmitter<Relationship>(relationshipEntityStateFactory);
fetchHandler = new Neo4jEntityFetchHandler(entityStateHandler, conversionService, nodeStateTransmitter, relationshipStateTransmitter);
final EntityTools<Node> nodeEntityTools = new EntityTools<Node>(nodeTypeRepresentationStrategy, nodeEntityStateFactory, nodeEntityInstantiator, mappingContext);
final EntityTools<Relationship> relationshipEntityTools = new EntityTools<Relationship>(relationshipTypeRepresentationStrategy, relationshipEntityStateFactory, relationshipEntityInstantiator, mappingContext);
entityPersister = new Neo4jEntityPersister(conversionService, nodeEntityTools, relationshipEntityTools, mappingContext, entityStateHandler);
factoryBean.afterPropertiesSet();
return factoryBean.getObject();
}
protected List<Node> groupMemberNodes() {

View File

@@ -70,7 +70,6 @@ public class Neo4jTemplateApiTest {
transactionManager = createTransactionManager();
referenceNode = graphDatabase.getReferenceNode();
template = new Neo4jTemplate(graphDatabase, transactionManager);
template.postConstruct(); // todo defaults
createData();
}

View File

@@ -44,7 +44,6 @@ public abstract class NeoApiTest {
graph = createGraphDatabase();
transactionManager = createTransactionManager();
template = new Neo4jTemplate(graph, transactionManager);
template.postConstruct();
}
private ConversionService createConversionService() throws Exception {

View File

@@ -56,7 +56,6 @@ public class SnippetNeo4jTemplateMethodsTest extends DocumentingTestBase {
// SNIPPET template
// TODO auto-post-construct !!
final Neo4jTemplate neo = new Neo4jTemplate(graphDatabase);
neo.postConstruct();
Node mark = neo.createNode(map("name", "Mark"));
Node thomas = neo.createNode(map("name", "Thomas"));