Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
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.config;
 
 import  org.springframework.beans.factory.annotation.Autowired;
 import  org.springframework.beans.factory.annotation.Qualifier;
 import  org.springframework.context.ApplicationContextException;
 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.transaction.PlatformTransactionManager;
 
 import java.util.Set;
 
 import static java.util.Arrays.asList;

Abstract base class for code based configuration of Spring managed Neo4j infrastructure.

Subclasses are required to provide an implementation of graphDbService ....

Author(s):
Thomas Risberg
 
 @Configuration
 public abstract class Neo4jConfiguration {
 
     private ConversionService conversionService;
 
     private Set<? extends Class<?>> initialEntitySet;
 
     @Autowired(required = false)
     private Validator validator;
 
         return ;
     }
 
     @Qualifier("conversionService")
     @Autowired(required = false)
     public void setConversionService(ConversionService conversionService) {
         this. = conversionService;
     }
 
     @Autowired(required = true)
     public void setGraphDatabaseService(GraphDatabaseService graphDatabaseService) {
         this. = graphDatabaseService;
     }
 
     @Bean
     @DependsOn("neo4jMappingContext")
         MappingInfrastructureFactoryBean factoryBean = new MappingInfrastructureFactoryBean();
        factoryBean.setGraphDatabaseService(getGraphDatabaseService());
        factoryBean.setConversionService(neo4jConversionService());
        factoryBean.setMappingContext(neo4jMappingContext());
        factoryBean.setEntityStateHandler(entityStateHandler());
        factoryBean.setTransactionManager(neo4jTransactionManager());
        factoryBean.setGraphDatabase(graphDatabase());
        factoryBean.setIsNewStrategyFactory(isNewStrategyFactory());
        factoryBean.setTypeSafetyPolicy(typeSafetyPolicy());
        
        factoryBean.setIndexProvider(indexProvider());
        if (!=null) {
            factoryBean.setValidator();
        }
        return factoryBean;
    }
    
    @Bean
    }
    @Bean
    public Neo4jTemplate neo4jTemplate() throws Exception {
        return new Neo4jTemplate(mappingInfrastructure().getObject());
	}
    @Bean
    }
    @Bean
    }
    @Bean
    }
    @Bean
    public EntityStateHandler entityStateHandler() throws Exception {
        return new EntityStateHandler(neo4jMappingContext(),graphDatabase());
    }
    @Bean
    public TypeMapper<NodenodeTypeMapper() throws Exception {
    }
    @Bean
    }
    @Bean
        final SourceStateTransmitter<NodenodeSourceStateTransmitter = nodeStateTransmitter();
        final SourceStateTransmitter<RelationshiprelationshipSourceStateTransmitter = new SourceStateTransmitter<Relationship>(relationshipEntityStateFactory());
        return new Neo4jEntityFetchHandler(entityStateHandler(), neo4jConversionService(), nodeSourceStateTransmitterrelationshipSourceStateTransmitter);
    }
    @Bean
        return new SourceStateTransmitter<Node>(nodeEntityStateFactory());
    }
    //@Scope(BeanDefinition.SCOPE_PROTOTYPE)
    @Bean
    protected ConversionService neo4jConversionService() throws Exception {
        final Neo4jConversionServiceFactoryBean neo4jConversionServiceFactoryBean = new Neo4jConversionServiceFactoryBean();
        if (!=null) {
            neo4jConversionServiceFactoryBean.addConverters();
            return ;
        }
        return neo4jConversionServiceFactoryBean.getObject();
    }
    @Bean
        return new RelationshipEntityInstantiator(entityStateHandler());
    }
    @Bean
	}
    @Bean
        final Neo4jMappingContext mappingContext = new Neo4jMappingContext();
        if (!=null) {
            mappingContext.setInitialEntitySet();
        }
        mappingContext.setEntityAlias(entityAlias());
        mappingContext.setEntityIndexCreator(entityIndexCreator());
        return mappingContext;
    }
    @Bean
    protected EntityAlias entityAlias() {
        return new EntityAlias();
    }
    @Bean
    }
    @Bean
    }
    @Bean
        return new NodeDelegatingFieldAccessorFactory.Factory();
    }
    @Bean
    }
    @Bean(name = {"neo4jTransactionManager","transactionManager"})
    @Qualifier("neo4jTransactionManager")
	public PlatformTransactionManager neo4jTransactionManager() throws Exception {
	}
    @Bean
    public EntityIndexCreator entityIndexCreator() throws Exception {
        return new EntityIndexCreator(
                indexProvider(),
                schemaIndexProvider(),
                nodeTypeRepresentationStrategy().isLabelBased()
        );
    }
    @Bean
    @Autowired
    @DependsOn("graphDatabaseService")
    public GraphDatabase graphDatabase() {
        if ( instanceof GraphDatabasereturn (GraphDatabase;
        return new DelegatingGraphDatabase();
    }
//    @Bean
//    public ConfigurationCheck configurationCheck() throws Exception {
//        return new ConfigurationCheck(neo4jTemplate(),neo4jTransactionManager());
//    }
    @Bean
    public PersistenceExceptionTranslator persistenceExceptionTranslator() {
        return new Neo4jExceptionTranslator();
    }
    @Bean
    public IndexProvider indexProvider() throws Exception {
        return new IndexProviderImpl(graphDatabase());
    }
    @Bean
        return new SchemaIndexProvider(graphDatabase());
    }
    @Bean
    public TypeSafetyPolicy typeSafetyPolicy() throws Exception {
        return new TypeSafetyPolicy();
    }
    public Set<? extends Class<?>> getInitialEntitySet() {
        return ;
    }
    public void setInitialEntitySet(Set<? extends Class<?>> initialEntitySet) {
   		this. = initialEntitySet;
   	}
    private String[] basePackage;
    public String[] getBasePackage() {
        return ;
    }
    public void setBasePackage(String...basePackage) {
        try {
            this. = basePackage;
            setInitialEntitySet(BasePackageScanner.scanBasePackageForClasses(basePackage));
        } catch(ClassNotFoundException cnfe) {
            throw new ApplicationContextException("Error scanning packages for domain entities: "+ Arrays.toString(basePackage));
        }
    }
New to GrepCode? Check out our FAQ X