DATAGRAPH-354
BeanCreationException when trying to use initial-EntitySet
This commit is contained in:
@@ -60,7 +60,6 @@ import org.springframework.data.support.IsNewStrategyFactory;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import javax.validation.Validator;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
@@ -243,7 +242,7 @@ public abstract class Neo4jConfiguration {
|
||||
|
||||
@Bean
|
||||
public IndexCreationMappingEventListener indexCreationMappingEventListener() throws Exception {
|
||||
return new IndexCreationMappingEventListener(neo4jTemplate());
|
||||
return new IndexCreationMappingEventListener(indexProvider());
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -254,6 +253,7 @@ public abstract class Neo4jConfiguration {
|
||||
return new DelegatingGraphDatabase(graphDatabaseService);
|
||||
}
|
||||
|
||||
// didn't help @DependsOn({"neo4jTemplate","neo4jTransactionManager","neo4jMappingContext"})
|
||||
@Bean
|
||||
public ConfigurationCheck configurationCheck() throws Exception {
|
||||
return new ConfigurationCheck(neo4jTemplate(),neo4jTransactionManager());
|
||||
@@ -266,7 +266,7 @@ public abstract class Neo4jConfiguration {
|
||||
|
||||
@Bean
|
||||
public IndexProvider indexProvider() throws Exception {
|
||||
return new IndexProviderImpl(neo4jMappingContext(), graphDatabase());
|
||||
return new IndexProviderImpl(graphDatabase());
|
||||
}
|
||||
|
||||
public Set<? extends Class<?>> getInitialEntitySet() {
|
||||
|
||||
@@ -21,7 +21,6 @@ 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.auditing.IsNewAwareAuditingHandler;
|
||||
import org.springframework.data.mapping.context.MappingContextIsNewStrategyFactory;
|
||||
import org.springframework.data.neo4j.annotation.QueryType;
|
||||
import org.springframework.data.neo4j.conversion.ResultConverter;
|
||||
@@ -152,7 +151,7 @@ public class MappingInfrastructureFactoryBean implements FactoryBean<Infrastruct
|
||||
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.indexProvider = new IndexProviderImpl(graphDatabase);
|
||||
}
|
||||
this.mappingInfrastructure = new MappingInfrastructure(graphDatabase, graphDatabaseService, indexProvider, resultConverter, transactionManager, typeRepresentationStrategies, entityRemover, entityPersister, entityStateHandler, cypherQueryExecutor, mappingContext, relationshipTypeRepresentationStrategy, nodeTypeRepresentationStrategy, validator, conversionService);
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -121,7 +121,7 @@ public class Neo4jTemplate implements Neo4jOperations, ApplicationContextAware {
|
||||
|
||||
public <S extends PropertyContainer, T> Index<S> getIndex(Class<T> type) {
|
||||
notNull(type, "entity type");
|
||||
return getIndexProvider().getIndex(type, null);
|
||||
return getIndexProvider().getIndex(getPersistentEntity(type), null);
|
||||
}
|
||||
|
||||
public <S extends PropertyContainer> Index<S> getIndex(String name) {
|
||||
@@ -130,7 +130,7 @@ public class Neo4jTemplate implements Neo4jOperations, ApplicationContextAware {
|
||||
}
|
||||
|
||||
public <S extends PropertyContainer, T> Index<S> getIndex(Class<T> type, String indexName, IndexType indexType) {
|
||||
return getIndexProvider().getIndex(type, indexName, indexType);
|
||||
return getIndexProvider().getIndex(getPersistentEntity(type), indexName, indexType);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -575,13 +575,14 @@ public class Neo4jTemplate implements Neo4jOperations, ApplicationContextAware {
|
||||
|
||||
@Override
|
||||
public <T extends PropertyContainer> Index<T> getIndex(String indexName, Class<?> indexedType) {
|
||||
return getIndexProvider().getIndex(indexedType, indexName);
|
||||
final Neo4jPersistentEntityImpl<?> persistentEntity = indexedType==null ? null : getPersistentEntity(indexedType);
|
||||
return getIndexProvider().getIndex(persistentEntity, indexName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends PropertyContainer> Index<T> getIndex(Class<?> indexedType, String propertyName) {
|
||||
final Neo4jPersistentProperty property = getPersistentProperty(indexedType, propertyName);
|
||||
if (property == null) return getIndexProvider().getIndex(indexedType, null);
|
||||
if (property == null) return getIndexProvider().getIndex(getPersistentEntity(indexedType), null);
|
||||
return getIndexProvider().getIndex(property, indexedType);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,17 +17,17 @@ package org.springframework.data.neo4j.support.index;
|
||||
|
||||
import org.neo4j.graphdb.PropertyContainer;
|
||||
import org.neo4j.graphdb.index.Index;
|
||||
import org.springframework.data.neo4j.mapping.Neo4jPersistentEntity;
|
||||
import org.springframework.data.neo4j.mapping.Neo4jPersistentProperty;
|
||||
|
||||
public interface IndexProvider {
|
||||
|
||||
<S extends PropertyContainer, T> Index<S> getIndex(Class<T> type);
|
||||
<S extends PropertyContainer, T> Index<S> getIndex(Neo4jPersistentEntity<T> type);
|
||||
|
||||
<S extends PropertyContainer, T> Index<S> getIndex(Class<T> type, String indexName);
|
||||
<S extends PropertyContainer, T> Index<S> getIndex(Neo4jPersistentEntity<T> type, String indexName);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
<S extends PropertyContainer, T> Index<S> getIndex(Class<T> type, String indexName,
|
||||
IndexType indexType);
|
||||
<S extends PropertyContainer, T> Index<S> getIndex(Neo4jPersistentEntity<T> persistentEntity, String indexName, IndexType indexType);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
<T extends PropertyContainer> Index<T> getIndex(String indexName);
|
||||
@@ -36,11 +36,10 @@ public interface IndexProvider {
|
||||
|
||||
// TODO handle existing indexes
|
||||
@SuppressWarnings("unchecked")
|
||||
<T extends PropertyContainer> Index<T> createIndex(Class<T> type, String indexName,
|
||||
<T extends PropertyContainer> Index<T> createIndex(Class<T> propertyContainerType, String indexName,
|
||||
IndexType fullText);
|
||||
|
||||
<S extends PropertyContainer> Index<S> getIndex(Neo4jPersistentProperty property,
|
||||
final Class<?> instanceType);
|
||||
<S extends PropertyContainer> Index<S> getIndex(Neo4jPersistentProperty property, final Class<?> instanceType);
|
||||
/**
|
||||
* adjust your indexName for the "__types__" indices
|
||||
*
|
||||
|
||||
@@ -21,9 +21,8 @@ import org.neo4j.graphdb.Relationship;
|
||||
import org.neo4j.graphdb.index.Index;
|
||||
import org.springframework.data.neo4j.annotation.Indexed;
|
||||
import org.springframework.data.neo4j.core.GraphDatabase;
|
||||
import org.springframework.data.neo4j.mapping.Neo4jPersistentEntity;
|
||||
import org.springframework.data.neo4j.mapping.Neo4jPersistentProperty;
|
||||
import org.springframework.data.neo4j.support.mapping.Neo4jMappingContext;
|
||||
import org.springframework.data.neo4j.support.mapping.Neo4jPersistentEntityImpl;
|
||||
|
||||
import static org.springframework.data.neo4j.support.ParameterCheck.notNull;
|
||||
|
||||
@@ -32,43 +31,42 @@ import static org.springframework.data.neo4j.support.ParameterCheck.notNull;
|
||||
* @since 17.10.11
|
||||
*/
|
||||
public class IndexProviderImpl implements IndexProvider {
|
||||
private final Neo4jMappingContext mappingContext;
|
||||
private final GraphDatabase graphDatabase;
|
||||
|
||||
public IndexProviderImpl(Neo4jMappingContext mappingContext, GraphDatabase graphDatabase) {
|
||||
this.mappingContext = mappingContext;
|
||||
public IndexProviderImpl(GraphDatabase graphDatabase) {
|
||||
this.graphDatabase = graphDatabase;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <S extends PropertyContainer, T> Index<S> getIndex(Class<T> type) {
|
||||
public <S extends PropertyContainer, T> Index<S> getIndex(Neo4jPersistentEntity<T> type) {
|
||||
return getIndex(type, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <S extends PropertyContainer, T> Index<S> getIndex(Class<T> type, String indexName) {
|
||||
public <S extends PropertyContainer, T> Index<S> getIndex(Neo4jPersistentEntity<T> type, String indexName) {
|
||||
return getIndex(type, indexName, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <S extends PropertyContainer, T> Index<S> getIndex(Class<T> type, String indexName, IndexType indexType) {
|
||||
if (type == null) {
|
||||
public <S extends PropertyContainer, T> Index<S> getIndex(Neo4jPersistentEntity<T> persistentEntity, String indexName, IndexType indexType) {
|
||||
if (persistentEntity == null) {
|
||||
notNull(indexName, "indexName");
|
||||
return getIndex(indexName);
|
||||
}
|
||||
|
||||
final Neo4jPersistentEntityImpl<?> persistentEntity = mappingContext.getPersistentEntity(type);
|
||||
final Class<?> type = persistentEntity.getType();
|
||||
if (indexName == null) indexName = customizeIndexName(Indexed.Name.get(type), type);
|
||||
final boolean useExistingIndex = indexType == null;
|
||||
|
||||
final boolean isNodeEntity = persistentEntity.isNodeEntity();
|
||||
final boolean isRelationshipEntity = persistentEntity.isRelationshipEntity();
|
||||
if (useExistingIndex) {
|
||||
if (persistentEntity.isNodeEntity() || persistentEntity.isRelationshipEntity()) return (Index<S>) graphDatabase.getIndex(indexName);
|
||||
if (isNodeEntity || isRelationshipEntity) return (Index<S>) graphDatabase.getIndex(indexName);
|
||||
throw new IllegalArgumentException("Wrong index type supplied: " + type + " expected Node- or Relationship-Entity");
|
||||
}
|
||||
|
||||
if (persistentEntity.isNodeEntity())
|
||||
if (isNodeEntity)
|
||||
return (Index<S>) createIndex(Node.class, indexName, indexType);
|
||||
if (persistentEntity.isRelationshipEntity())
|
||||
if (isRelationshipEntity)
|
||||
return (Index<S>) createIndex(Relationship.class, indexName, indexType);
|
||||
throw new IllegalArgumentException("Wrong index type supplied: " + type + " expected Node- or Relationship-Entity");
|
||||
}
|
||||
@@ -89,21 +87,21 @@ public class IndexProviderImpl implements IndexProvider {
|
||||
// TODO handle existing indexes
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends PropertyContainer> Index<T> createIndex(Class<T> type, String indexName, IndexType fullText) {
|
||||
return graphDatabase.createIndex(type, indexName, fullText);
|
||||
public <T extends PropertyContainer> Index<T> createIndex(Class<T> propertyContainerType, String indexName, IndexType fullText) {
|
||||
return graphDatabase.createIndex(propertyContainerType, indexName, fullText);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <S extends PropertyContainer> Index<S> getIndex(Neo4jPersistentProperty property, final Class<?> instanceType) {
|
||||
final Indexed indexedAnnotation = property.getAnnotation(Indexed.class);
|
||||
final Class<?> declaringType = property.getOwner().getType();
|
||||
final Neo4jPersistentEntity<?> declaringType = property.getOwner();
|
||||
final String providedIndexName = providedIndexName(indexedAnnotation);
|
||||
final Indexed.Level level = indexingLevel(indexedAnnotation);
|
||||
String indexName = customizeIndexName(Indexed.Name.get(level, declaringType, providedIndexName, instanceType), instanceType);
|
||||
String indexName = customizeIndexName(Indexed.Name.get(level, declaringType.getType(), providedIndexName, instanceType), instanceType);
|
||||
if (!property.isIndexed() || property.getIndexInfo().getIndexType() == IndexType.SIMPLE) {
|
||||
return getIndex(declaringType, indexName, IndexType.SIMPLE);
|
||||
}
|
||||
String defaultIndexName = customizeIndexName(Indexed.Name.get(level, declaringType, null, instanceType.getClass()), instanceType);
|
||||
String defaultIndexName = customizeIndexName(Indexed.Name.get(level, declaringType.getType(), null, instanceType.getClass()), instanceType);
|
||||
if (providedIndexName==null || providedIndexName.equals(defaultIndexName)) {
|
||||
throw new IllegalStateException("Index name for "+property+" must differ from the default name: "+defaultIndexName);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import org.springframework.data.mapping.PropertyHandler;
|
||||
import org.springframework.data.mapping.context.MappingContextEvent;
|
||||
import org.springframework.data.neo4j.mapping.Neo4jPersistentEntity;
|
||||
import org.springframework.data.neo4j.mapping.Neo4jPersistentProperty;
|
||||
import org.springframework.data.neo4j.support.Neo4jTemplate;
|
||||
import org.springframework.data.neo4j.support.index.IndexProvider;
|
||||
import org.springframework.data.neo4j.support.index.IndexType;
|
||||
|
||||
/**
|
||||
@@ -29,9 +29,9 @@ import org.springframework.data.neo4j.support.index.IndexType;
|
||||
* @since 12.04.12
|
||||
*/
|
||||
public class IndexCreationMappingEventListener implements ApplicationListener<MappingContextEvent<Neo4jPersistentEntity<?>, Neo4jPersistentProperty>> {
|
||||
private Neo4jTemplate template;
|
||||
public IndexCreationMappingEventListener(Neo4jTemplate template) {
|
||||
this.template = template;
|
||||
private IndexProvider indexProvider;
|
||||
public IndexCreationMappingEventListener(IndexProvider indexProvider) {
|
||||
this.indexProvider = indexProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -43,12 +43,12 @@ public class IndexCreationMappingEventListener implements ApplicationListener<Ma
|
||||
|
||||
private void ensureEntityIndexes(Neo4jPersistentEntity<?> entity) {
|
||||
final Class entityType = entity.getType();
|
||||
@SuppressWarnings("unchecked") Index index = template.getIndex(entityType, null, IndexType.SIMPLE);
|
||||
indexProvider.getIndex(entity, null, IndexType.SIMPLE);
|
||||
entity.doWithProperties(new PropertyHandler<Neo4jPersistentProperty>() {
|
||||
@Override
|
||||
public void doWithPersistentProperty(Neo4jPersistentProperty property) {
|
||||
if (property.isIndexed()) {
|
||||
template.getIndex(property, entityType);
|
||||
indexProvider.getIndex(property, entityType);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -56,7 +56,7 @@ public class DataGraphNamespaceHandlerTests {
|
||||
Neo4jTemplate neo4jTemplate;
|
||||
@Autowired
|
||||
PlatformTransactionManager transactionManager;
|
||||
@Autowired
|
||||
@Autowired(required = false)
|
||||
Neo4jMappingContext mappingContext;
|
||||
@Autowired(required = false)
|
||||
PersonRepository personRepository;
|
||||
@@ -100,7 +100,7 @@ public class DataGraphNamespaceHandlerTests {
|
||||
public void injectionForCodeConfiguredExistingGraphDatabaseService() {
|
||||
assertInjected("-code");
|
||||
}
|
||||
@Test @Ignore("BeanCreationException DATAGRAPH-354")
|
||||
@Test
|
||||
public void injectionForBasePackageOfEntities() {
|
||||
Config config = assertInjected("-entities");
|
||||
Collection<Neo4jPersistentEntityImpl<?>> entities = config.mappingContext.getPersistentEntities();
|
||||
|
||||
Reference in New Issue
Block a user