DATAGRAPH-388 : Continued work - Refactoring and cleanup
This commit is contained in:
committed by
Michael Hunger
parent
0e7148add4
commit
9673fdf082
@@ -203,8 +203,6 @@ public abstract class Neo4jConfiguration {
|
||||
mappingContext.setInitialEntitySet(initialEntitySet);
|
||||
}
|
||||
mappingContext.setEntityAlias(entityAlias());
|
||||
mappingContext.setIsLabelBased(nodeTypeRepresentationStrategy().isLabelBased());
|
||||
mappingContext.setFailWhenIncompatibleLabelIndexUsage(false);
|
||||
return mappingContext;
|
||||
}
|
||||
|
||||
|
||||
@@ -104,7 +104,6 @@ public class MappingInfrastructureFactoryBean implements FactoryBean<Infrastruct
|
||||
try {
|
||||
if (this.mappingContext == null) {
|
||||
this.mappingContext = new Neo4jMappingContext();
|
||||
this.mappingContext.setIsLabelBased(false);
|
||||
}
|
||||
if (this.isNewStrategyFactory == null) {
|
||||
this.isNewStrategyFactory = new MappingContextIsNewStrategyFactory(mappingContext);
|
||||
|
||||
@@ -49,29 +49,6 @@ public class Neo4jMappingContext extends AbstractMappingContext<Neo4jPersistentE
|
||||
|
||||
private final static Logger log = LoggerFactory.getLogger(Neo4jMappingContext.class);
|
||||
|
||||
// By default we don't fail but rather just output a warning
|
||||
// (perhaps people have changed, or are busy changing TRS strategies
|
||||
// and are happy for properties annotated as label indexes to
|
||||
// resort to simple fields in this case ???)
|
||||
private boolean failWhenIncompatibleLabelIndexUsage = false;
|
||||
private Boolean isLabelBasedTRSInUse;
|
||||
|
||||
public Boolean getIsLabelBased() {
|
||||
return isLabelBasedTRSInUse;
|
||||
}
|
||||
|
||||
public void setIsLabelBased(Boolean labelBased) {
|
||||
isLabelBasedTRSInUse = labelBased;
|
||||
}
|
||||
|
||||
public boolean isFailWhenIncompatibleLabelIndexUsage() {
|
||||
return failWhenIncompatibleLabelIndexUsage;
|
||||
}
|
||||
|
||||
public void setFailWhenIncompatibleLabelIndexUsage(boolean failWhenIncompatibleLabelIndexUsage) {
|
||||
this.failWhenIncompatibleLabelIndexUsage = failWhenIncompatibleLabelIndexUsage;
|
||||
}
|
||||
|
||||
private final Map<Annotation, Boolean> referenceAnnotations = new IdentityHashMap<Annotation, java.lang.Boolean>();
|
||||
|
||||
protected <T> Neo4jPersistentEntityImpl<?> createPersistentEntity(TypeInformation<T> typeInformation) {
|
||||
@@ -90,29 +67,9 @@ public class Neo4jMappingContext extends AbstractMappingContext<Neo4jPersistentE
|
||||
final Neo4jPersistentEntityImpl<?> entity = super.addPersistentEntity(typeInformation);
|
||||
Collection<Neo4jPersistentEntity<?>> superTypeEntities = addSuperTypes(entity);
|
||||
entity.updateStoredType(new StoredEntityType(entity,superTypeEntities,entityAlias));
|
||||
doAdditionalEntityVerification(entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
private void doAdditionalEntityVerification(Neo4jPersistentEntityImpl<?> entity) {
|
||||
// NW-HACK checking if null for isLabelBasedTRSInUse, but should
|
||||
// prob just blow up??
|
||||
if (isLabelBasedTRSInUse!= null && !isLabelBasedTRSInUse) {
|
||||
entity.doWithProperties(new PropertyHandler<Neo4jPersistentProperty>() {
|
||||
@Override
|
||||
public void doWithPersistentProperty(Neo4jPersistentProperty persistentProperty) {
|
||||
if (persistentProperty.isIndexed() && persistentProperty.getIndexInfo().isLabelBased()) {
|
||||
if (failWhenIncompatibleLabelIndexUsage) {
|
||||
throw new RuntimeException(format("Incompatible entity definition: property %s has label based index annotation however label type representation strategy not in use",persistentProperty.getName()));
|
||||
} else {
|
||||
log.warn("Incompatible entity definition: property {} has label based index annotation however label type representation strategy not in use - will be treated as normal property", persistentProperty.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private List<Neo4jPersistentEntity<?>> addSuperTypes(Neo4jPersistentEntity<?> entity) {
|
||||
List<Neo4jPersistentEntity<?>> entities=new ArrayList<Neo4jPersistentEntity<?>>();
|
||||
final Class<?> type = entity.getType();
|
||||
|
||||
@@ -156,7 +156,7 @@ public abstract class AbstractDerivedFinderMethodTestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLabelBasedIndexQueryWithOneParam() throws Exception {
|
||||
public void testSchemaIndexQueryWithOneParam() throws Exception {
|
||||
assertRepositoryQueryMethod(ThingRepository.class,
|
||||
"findByAlias",
|
||||
new Object[]{"foo"},
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.data.neo4j.repository.query;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.neo4j.index.lucene.ValueContext;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.neo4j.core.NodeTypeRepresentationStrategy;
|
||||
import org.springframework.data.neo4j.support.typerepresentation.IndexBasedNodeTypeRepresentationStrategy;
|
||||
@@ -30,10 +29,6 @@ import org.springframework.test.context.support.DependencyInjectionTestExecution
|
||||
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -96,25 +91,17 @@ public class DerivedFinderMethodForIndexedBasedTRSTests extends AbstractDerivedF
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testLabelBasedIndexQueryWithOneParam() throws Exception {
|
||||
|
||||
// Ensure mappingContext set NOT to fail (but rather warn)
|
||||
// when incompatibility detected
|
||||
assertFalse(ctx.isFailWhenIncompatibleLabelIndexUsage());
|
||||
public void testSchemaIndexQueryWithOneParam() throws Exception {
|
||||
|
||||
/*
|
||||
Is this the correct logic??? - what should we do when a derived
|
||||
field has been marked as a label based indexed field and
|
||||
we have a legacy based indexing strategy in play. Have currently
|
||||
added in properties failWhenIncompatibleLabelIndexUsage and
|
||||
isLabelBasedTRSInUse to Neo4jMappingContext to help
|
||||
|
||||
TODO - Determine exactly what correct query should be when
|
||||
using a schema based index and a Legacy based TRS
|
||||
*/
|
||||
// "findByAlias",
|
||||
this.trsSpecificExpectedQuery = DEFAULT_START_CLAUSE +
|
||||
" WHERE `thing`.`alias` = {0} RETURN `thing`";
|
||||
this.trsSpecificExpectedParams = new Object[] { "foo" };
|
||||
super.testLabelBasedIndexQueryWithOneParam();
|
||||
super.testSchemaIndexQueryWithOneParam();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -28,8 +28,6 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
|
||||
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.junit.Assert.fail;
|
||||
@@ -370,12 +368,12 @@ public class DerivedFinderMethodForLabelBasedTRSTests extends AbstractDerivedFin
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testLabelBasedIndexQueryWithOneParam() throws Exception {
|
||||
public void testSchemaIndexQueryWithOneParam() throws Exception {
|
||||
// findByAlias
|
||||
this.trsSpecificExpectedQuery = DEFAULT_MATCH_CLAUSE +
|
||||
" WHERE `thing`.`alias` = {0}" +
|
||||
" RETURN `thing`";
|
||||
this.trsSpecificExpectedParams = new Object[] { "foo" };
|
||||
super.testLabelBasedIndexQueryWithOneParam();
|
||||
super.testSchemaIndexQueryWithOneParam();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user