diff --git a/spring-data-neo4j-aspects/src/test/java/org/springframework/data/neo4j/aspects/support/typerepresentation/LabelingNodeTypeRepresentationStrategyTests.java b/spring-data-neo4j-aspects/src/test/java/org/springframework/data/neo4j/aspects/support/typerepresentation/LabelingNodeTypeRepresentationStrategyTests.java index 187396a94..5e0197663 100644 --- a/spring-data-neo4j-aspects/src/test/java/org/springframework/data/neo4j/aspects/support/typerepresentation/LabelingNodeTypeRepresentationStrategyTests.java +++ b/spring-data-neo4j-aspects/src/test/java/org/springframework/data/neo4j/aspects/support/typerepresentation/LabelingNodeTypeRepresentationStrategyTests.java @@ -30,8 +30,7 @@ import org.springframework.data.neo4j.aspects.support.EntityTestBase; import org.springframework.data.neo4j.support.Neo4jTemplate; import org.springframework.data.neo4j.support.mapping.Neo4jMappingContext; import org.springframework.data.neo4j.support.mapping.StoredEntityType; -import org.springframework.data.neo4j.support.typerepresentation.CoreAPIBasedLabelingNodeTypeRepresentationStrategy; -import org.springframework.data.neo4j.support.typerepresentation.CypherBasedLabelingNodeTypeRepresentationStrategy; +import org.springframework.data.neo4j.support.typerepresentation.LabelingNodeTypeRepresentationStrategy; import org.springframework.test.context.CleanContextCacheTestExecutionListener; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestExecutionListeners; @@ -44,8 +43,7 @@ import org.springframework.transaction.annotation.Transactional; import java.util.Arrays; import java.util.HashSet; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.Assert.*; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {"classpath:org/springframework/data/neo4j/aspects/support/Neo4jGraphPersistenceTests-context.xml", @@ -54,7 +52,7 @@ import static org.junit.Assert.assertNull; public class LabelingNodeTypeRepresentationStrategyTests extends EntityTestBase { @Autowired - private CypherBasedLabelingNodeTypeRepresentationStrategy nodeTypeRepresentationStrategy; + private LabelingNodeTypeRepresentationStrategy nodeTypeRepresentationStrategy; @Autowired Neo4jTemplate neo4jTemplate; @@ -103,10 +101,22 @@ public class LabelingNodeTypeRepresentationStrategyTests extends EntityTestBase @Test @Transactional - public void testCount() throws Exception { - assertEquals(2, nodeTypeRepresentationStrategy.count(thingType)); + public void testCountOfSuperTypeIncludesSubTypes() throws Exception { + final int EXPECTED_NUM_THINGS = 1; + final int EXPECTED_NUM_SUBTHINGS = 1; + final int TOTAL_EXPECTED = EXPECTED_NUM_THINGS + EXPECTED_NUM_SUBTHINGS; + assertEquals(TOTAL_EXPECTED, nodeTypeRepresentationStrategy.count(thingType)); } + @Test + @Transactional + public void testCountOfSubTypeExcludesConcreteParents() throws Exception { + final int EXPECTED_NUM_THINGS = 1; + final int EXPECTED_NUM_SUBTHINGS = 1; + final int TOTAL_EXPECTED = EXPECTED_NUM_SUBTHINGS; + assertEquals(TOTAL_EXPECTED, nodeTypeRepresentationStrategy.count(subThingType)); + } + @Test @Transactional public void testGetJavaType() throws Exception { diff --git a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/support/typerepresentation/CoreAPIBasedLabelingNodeTypeRepresentationStrategy.java b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/support/typerepresentation/CoreAPIBasedLabelingNodeTypeRepresentationStrategy.java index a2e8a20a6..9042f8b5e 100644 --- a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/support/typerepresentation/CoreAPIBasedLabelingNodeTypeRepresentationStrategy.java +++ b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/support/typerepresentation/CoreAPIBasedLabelingNodeTypeRepresentationStrategy.java @@ -30,10 +30,12 @@ import org.springframework.data.neo4j.support.mapping.StoredEntityType; /** * Provides a Node Type Representation Strategy which makes use of Labels, and specifically * uses the Core API as the mechanism for dealing with this. (This is inline with how - * the original Node Type Representation Strategies used to work - moving forward a - * Cypher based one will be used, however this exists for comparison purposes at this + * the original Node Type Representation Strategies used to work - moving forward only + * the Cypher based one will be used, however this exists for comparison purposes at this * point in time in the development) * + * TODO - Delete me! + * * @author Nicki Watt * @since 24-09-2013 */ diff --git a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/support/typerepresentation/CypherBasedLabelingNodeTypeRepresentationStrategy.java b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/support/typerepresentation/LabelingNodeTypeRepresentationStrategy.java similarity index 50% rename from spring-data-neo4j/src/main/java/org/springframework/data/neo4j/support/typerepresentation/CypherBasedLabelingNodeTypeRepresentationStrategy.java rename to spring-data-neo4j/src/main/java/org/springframework/data/neo4j/support/typerepresentation/LabelingNodeTypeRepresentationStrategy.java index 6c1defb6a..797a90d85 100644 --- a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/support/typerepresentation/CypherBasedLabelingNodeTypeRepresentationStrategy.java +++ b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/support/typerepresentation/LabelingNodeTypeRepresentationStrategy.java @@ -16,9 +16,9 @@ package org.springframework.data.neo4j.support.typerepresentation; +import org.neo4j.graphdb.DynamicLabel; import org.neo4j.graphdb.Label; import org.neo4j.graphdb.Node; -import org.neo4j.graphdb.ResourceIterable; import org.neo4j.helpers.collection.ClosableIterable; import org.springframework.data.neo4j.annotation.QueryType; import org.springframework.data.neo4j.core.GraphDatabase; @@ -39,70 +39,75 @@ import java.util.Map; * @author Nicki Watt * @since 24-09-2013 */ -public class CypherBasedLabelingNodeTypeRepresentationStrategy implements NodeTypeRepresentationStrategy { +public class LabelingNodeTypeRepresentationStrategy implements NodeTypeRepresentationStrategy { + + public static final Label SDN_LABEL_STRATEGY = DynamicLabel.label("SDN_LABEL_STRATEGY"); + public static final String LABELSTRATEGY_PREFIX = "__TYPE__"; + public static final long REFERENCE_NODE_ID = 0L; - public static final String TYPE_PROPERTY_NAME = "__type__"; protected GraphDatabase graphDb; protected final Class clazz; protected QueryEngine queryEngine; + private boolean sdnLabelStrategyPresent; - public CypherBasedLabelingNodeTypeRepresentationStrategy(GraphDatabase graphDb) { + public LabelingNodeTypeRepresentationStrategy(GraphDatabase graphDb) { this.graphDb = graphDb; this.clazz = Node.class; this.queryEngine = graphDb.queryEngineFor(QueryType.Cypher); + this.sdnLabelStrategyPresent = false; } @Override public void writeTypeTo(Node state, StoredEntityType type) { if (type == null || !type.isNodeEntity()) return; - ResourceIterable