Skip to content

Commit

Permalink
DATAGRAPH-206 fix for initialization of non-injection Neo4j-Template …
Browse files Browse the repository at this point in the history
…creation
  • Loading branch information
jexp committed May 2, 2012
1 parent fc3b902 commit c54abf7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Expand Up @@ -20,11 +20,15 @@
import org.neo4j.graphdb.Relationship;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
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.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.conversion.EntityResultConverter;
import org.springframework.data.neo4j.support.index.IndexProvider;
Expand All @@ -36,12 +40,15 @@
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.node.NodeEntityStateFactory;
import org.springframework.data.neo4j.support.query.CypherQueryExecutor;
import org.springframework.data.neo4j.support.relationship.RelationshipEntityInstantiator;
import org.springframework.data.neo4j.support.relationship.RelationshipEntityStateFactory;
import org.springframework.data.neo4j.support.typerepresentation.TypeRepresentationStrategies;
import org.springframework.data.neo4j.support.typerepresentation.TypeRepresentationStrategyFactory;
import org.springframework.transaction.PlatformTransactionManager;

import javax.inject.Provider;
import javax.validation.Validator;

/**
Expand Down Expand Up @@ -88,10 +95,14 @@ public MappingInfrastructureFactoryBean() {

@Override
public void afterPropertiesSet() {
try {
if (this.mappingContext == null) this.mappingContext = new Neo4jMappingContext();
if (this.graphDatabase == null) {
this.graphDatabase = new DelegatingGraphDatabase(graphDatabaseService);
}
if (this.conversionService==null) {
this.conversionService=new Neo4jConversionServiceFactoryBean().getObject();
}
if (nodeEntityInstantiator == null) {
nodeEntityInstantiator = new NodeEntityInstantiator(entityStateHandler);
}
Expand All @@ -107,6 +118,12 @@ public void afterPropertiesSet() {
if (this.relationshipTypeRepresentationStrategy == null) {
this.relationshipTypeRepresentationStrategy = typeRepresentationStrategyFactory.getRelationshipTypeRepresentationStrategy();
}
if (this.nodeEntityStateFactory==null) {
this.nodeEntityStateFactory = new NodeEntityStateFactory(mappingContext, new NodeDelegatingFieldAccessorFactory.Factory());
}
if (this.relationshipEntityStateFactory==null) {
this.relationshipEntityStateFactory = new RelationshipEntityStateFactory(mappingContext, new RelationshipDelegatingFieldAccessorFactory.Factory());
}
this.typeRepresentationStrategies = new TypeRepresentationStrategies(mappingContext, nodeTypeRepresentationStrategy, relationshipTypeRepresentationStrategy);

final EntityStateHandler entityStateHandler = new EntityStateHandler(mappingContext, graphDatabase);
Expand All @@ -123,6 +140,9 @@ public void afterPropertiesSet() {
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);
} catch (Exception e) {
throw new RuntimeException("error initializing "+getClass().getName(),e);
}
}

public void setTransactionManager(PlatformTransactionManager transactionManager) {
Expand Down
Expand Up @@ -27,6 +27,7 @@
import org.springframework.data.neo4j.support.Neo4jTemplateAware;
import org.springframework.data.neo4j.support.path.ConvertingEntityPath;

import javax.inject.Provider;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;
import java.util.Map;
Expand Down

0 comments on commit c54abf7

Please sign in to comment.