Added proper removal of relationship entities.
This commit is contained in:
@@ -22,13 +22,13 @@ public class RestRelationshipIndex extends RestIndex<Relationship> implements Re
|
||||
return Relationship.class;
|
||||
}
|
||||
|
||||
public void remove(Relationship entity, String key) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public void remove(Relationship entity) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
// public void remove(Relationship entity, String key) {
|
||||
// throw new UnsupportedOperationException();
|
||||
// }
|
||||
//
|
||||
// public void remove(Relationship entity) {
|
||||
// throw new UnsupportedOperationException();
|
||||
// }
|
||||
|
||||
protected Relationship createEntity( Map<?, ?> item ) {
|
||||
return new RestRelationship( (Map<?, ?>) item, restGraphDatabase );
|
||||
|
||||
@@ -24,20 +24,20 @@ import org.springframework.test.context.transaction.TransactionalTestExecutionLi
|
||||
@TestExecutionListeners({CleanContextCacheTestExecutionListener.class, DependencyInjectionTestExecutionListener.class, TransactionalTestExecutionListener.class})
|
||||
public class RestEntityPropertyValidationTest extends EntityPropertyValidationTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void startDb() throws Exception {
|
||||
RestTestBase.startDb();
|
||||
}
|
||||
@BeforeClass
|
||||
public static void startDb() throws Exception {
|
||||
RestTestBase.startDb();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void cleanDb() {
|
||||
RestTestBase.cleanDb();
|
||||
}
|
||||
@Before
|
||||
public void cleanDb() {
|
||||
RestTestBase.cleanDb();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void shutdownDb() {
|
||||
RestTestBase.shutdownDb();
|
||||
|
||||
}
|
||||
@AfterClass
|
||||
public static void shutdownDb() {
|
||||
RestTestBase.shutdownDb();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,20 +23,20 @@ import org.springframework.test.context.transaction.TransactionalTestExecutionLi
|
||||
@TestExecutionListeners({CleanContextCacheTestExecutionListener.class, DependencyInjectionTestExecutionListener.class, TransactionalTestExecutionListener.class})
|
||||
public class RestFinderTest extends GraphRepositoryTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void startDb() throws Exception {
|
||||
RestTestBase.startDb();
|
||||
}
|
||||
@BeforeClass
|
||||
public static void startDb() throws Exception {
|
||||
RestTestBase.startDb();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void cleanDb() {
|
||||
RestTestBase.cleanDb();
|
||||
}
|
||||
@Before
|
||||
public void cleanDb() {
|
||||
RestTestBase.cleanDb();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void shutdownDb() {
|
||||
RestTestBase.shutdownDb();
|
||||
|
||||
}
|
||||
@AfterClass
|
||||
public static void shutdownDb() {
|
||||
RestTestBase.shutdownDb();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,20 +27,20 @@ import java.net.NoRouteToHostException;
|
||||
@TestExecutionListeners({CleanContextCacheTestExecutionListener.class, DependencyInjectionTestExecutionListener.class, TransactionalTestExecutionListener.class})
|
||||
public class RestNodeEntityRelationshipTest extends NodeEntityRelationshipTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void startDb() throws Exception {
|
||||
RestTestBase.startDb();
|
||||
}
|
||||
@BeforeClass
|
||||
public static void startDb() throws Exception {
|
||||
RestTestBase.startDb();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void cleanDb() {
|
||||
RestTestBase.cleanDb();
|
||||
}
|
||||
@Before
|
||||
public void cleanDb() {
|
||||
RestTestBase.cleanDb();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void shutdownDb() {
|
||||
RestTestBase.shutdownDb();
|
||||
|
||||
}
|
||||
@AfterClass
|
||||
public static void shutdownDb() {
|
||||
RestTestBase.shutdownDb();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import org.junit.BeforeClass;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.neo4j.rest.graphdb.RestTestBase;
|
||||
import org.springframework.data.graph.neo4j.support.ProjectionTest;
|
||||
import org.springframework.data.graph.neo4j.support.RelationshipEntityTest;
|
||||
import org.springframework.test.context.CleanContextCacheTestExecutionListener;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.TestExecutionListeners;
|
||||
@@ -24,20 +23,20 @@ import org.springframework.test.context.transaction.TransactionalTestExecutionLi
|
||||
@TestExecutionListeners({CleanContextCacheTestExecutionListener.class, DependencyInjectionTestExecutionListener.class, TransactionalTestExecutionListener.class})
|
||||
public class RestProjectionTest extends ProjectionTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void startDb() throws Exception {
|
||||
RestTestBase.startDb();
|
||||
}
|
||||
@BeforeClass
|
||||
public static void startDb() throws Exception {
|
||||
RestTestBase.startDb();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void cleanDb() {
|
||||
RestTestBase.cleanDb();
|
||||
}
|
||||
@Before
|
||||
public void cleanDb() {
|
||||
RestTestBase.cleanDb();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void shutdownDb() {
|
||||
RestTestBase.shutdownDb();
|
||||
|
||||
}
|
||||
@AfterClass
|
||||
public static void shutdownDb() {
|
||||
RestTestBase.shutdownDb();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,20 +24,20 @@ import org.springframework.test.context.transaction.TransactionalTestExecutionLi
|
||||
@TestExecutionListeners({CleanContextCacheTestExecutionListener.class, DependencyInjectionTestExecutionListener.class, TransactionalTestExecutionListener.class})
|
||||
public class RestPropertyTest extends PropertyTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void startDb() throws Exception {
|
||||
RestTestBase.startDb();
|
||||
}
|
||||
@BeforeClass
|
||||
public static void startDb() throws Exception {
|
||||
RestTestBase.startDb();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void cleanDb() {
|
||||
RestTestBase.cleanDb();
|
||||
}
|
||||
@Before
|
||||
public void cleanDb() {
|
||||
RestTestBase.cleanDb();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void shutdownDb() {
|
||||
RestTestBase.shutdownDb();
|
||||
|
||||
}
|
||||
@AfterClass
|
||||
public static void shutdownDb() {
|
||||
RestTestBase.shutdownDb();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,20 +24,20 @@ import org.springframework.test.context.transaction.TransactionalTestExecutionLi
|
||||
@TestExecutionListeners({CleanContextCacheTestExecutionListener.class, DependencyInjectionTestExecutionListener.class, TransactionalTestExecutionListener.class})
|
||||
public class RestRelationshipEntityTest extends RelationshipEntityTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void startDb() throws Exception {
|
||||
RestTestBase.startDb();
|
||||
}
|
||||
@BeforeClass
|
||||
public static void startDb() throws Exception {
|
||||
RestTestBase.startDb();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void cleanDb() {
|
||||
RestTestBase.cleanDb();
|
||||
}
|
||||
@Before
|
||||
public void cleanDb() {
|
||||
RestTestBase.cleanDb();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void shutdownDb() {
|
||||
RestTestBase.shutdownDb();
|
||||
|
||||
}
|
||||
@AfterClass
|
||||
public static void shutdownDb() {
|
||||
RestTestBase.shutdownDb();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,9 +31,10 @@ import org.neo4j.graphdb.PropertyContainer;
|
||||
*/
|
||||
public interface TypeRepresentationStrategy<S extends PropertyContainer, T extends GraphBacked<S>> {
|
||||
/**
|
||||
* callback on entity creation for setting up type representation
|
||||
* @param state
|
||||
* @param type
|
||||
* Callback for setting up and/or storing type information after creation.
|
||||
*
|
||||
* @param state Backing state of entity being created
|
||||
* @param type Type of entity being created
|
||||
*/
|
||||
void postEntityCreation(S state, Class<? extends T> type);
|
||||
|
||||
@@ -57,10 +58,12 @@ public interface TypeRepresentationStrategy<S extends PropertyContainer, T exten
|
||||
<U extends T> Class<U> getJavaType(S state);
|
||||
|
||||
/**
|
||||
* callback for lifecycle management before node entity removal
|
||||
* @param entity
|
||||
* Callback for cleaning up type information before removal. If state does not have any
|
||||
* state associated, doesn't do anything.
|
||||
*
|
||||
* @param state Backing state of entity being removed
|
||||
*/
|
||||
void preEntityRemoval(T entity);
|
||||
void preEntityRemoval(S state);
|
||||
|
||||
/**
|
||||
* Instantiate the entity given its state. The type of the entity is inferred by the strategy
|
||||
|
||||
@@ -116,18 +116,10 @@ public class GraphDatabaseContext {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* removes the entity by cleaning the relationships first and then removing the node
|
||||
* it removes all of them from all indexes in advance
|
||||
* the entity and relationship are still accessible after removal but before transaction commit
|
||||
* but all modifications will throw an exception
|
||||
* @param entity to remove
|
||||
*/
|
||||
// TODO: What about connected relationship entities?
|
||||
public void removeNodeEntity(NodeBacked entity) {
|
||||
Node node = entity.getPersistentState();
|
||||
if (node==null) return;
|
||||
nodeTypeRepresentationStrategy.preEntityRemoval(entity);
|
||||
if (node == null) return;
|
||||
nodeTypeRepresentationStrategy.preEntityRemoval(node);
|
||||
for (Relationship relationship : node.getRelationships()) {
|
||||
removeRelationship(relationship);
|
||||
}
|
||||
@@ -135,6 +127,18 @@ public class GraphDatabaseContext {
|
||||
node.delete();
|
||||
}
|
||||
|
||||
public void removeRelationshipEntity(RelationshipBacked entity) {
|
||||
Relationship relationship = entity.getPersistentState();
|
||||
if (relationship == null) return;
|
||||
removeRelationship(relationship);
|
||||
}
|
||||
|
||||
private void removeRelationship(Relationship relationship) {
|
||||
relationshipTypeRepresentationStrategy.preEntityRemoval(relationship);
|
||||
removeFromIndexes(relationship);
|
||||
relationship.delete();
|
||||
}
|
||||
|
||||
private void removeFromIndexes(Node node) {
|
||||
IndexManager indexManager = getIndexManager();
|
||||
for (String indexName : indexManager.nodeIndexNames()) {
|
||||
@@ -142,18 +146,6 @@ public class GraphDatabaseContext {
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
public void removeRelationshipEntity(RelationshipBacked entity) {
|
||||
Relationship relationship = entity.getPersistentState();
|
||||
if (relationship==null) return;
|
||||
removeRelationship(relationship);
|
||||
}
|
||||
|
||||
private void removeRelationship(Relationship relationship) {
|
||||
removeFromIndexes(relationship);
|
||||
relationship.delete();
|
||||
}
|
||||
|
||||
private void removeFromIndexes(Relationship relationship) {
|
||||
IndexManager indexManager = getIndexManager();
|
||||
for (String indexName : indexManager.relationshipIndexNames()) {
|
||||
|
||||
@@ -84,7 +84,6 @@ public class IndexingNodeTypeRepresentationStrategy implements NodeTypeRepresent
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Class<? extends NodeBacked> getJavaType(Node node) {
|
||||
if (node == null) throw new IllegalArgumentException("Node is null");
|
||||
@@ -112,8 +111,8 @@ public class IndexingNodeTypeRepresentationStrategy implements NodeTypeRepresent
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preEntityRemoval(NodeBacked entity) {
|
||||
getNodeTypesIndex().remove(entity.getPersistentState());
|
||||
public void preEntityRemoval(Node state) {
|
||||
getNodeTypesIndex().remove(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -116,10 +116,11 @@ public class IndexingRelationshipTypeRepresentationStrategy implements Relations
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void preEntityRemoval(RelationshipBacked entity) {
|
||||
getRelTypesIndex().remove(entity.getPersistentState());
|
||||
}
|
||||
public void preEntityRemoval(Relationship state) {
|
||||
getRelTypesIndex().remove(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -16,26 +16,26 @@ public class NoopTypeRepresentationStrategy {
|
||||
|
||||
@Override
|
||||
public <U extends NodeBacked> Iterable<U> findAll(Class<U> clazz) {
|
||||
throw new UnsupportedOperationException("findAll not supported by NoopTypeRepresentationStrategy.");
|
||||
throw new UnsupportedOperationException("findAll not supported.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public long count(Class<? extends NodeBacked> entityClass) {
|
||||
throw new UnsupportedOperationException("count not supported by NoopTypeRepresentationStrategy.");
|
||||
throw new UnsupportedOperationException("count not supported.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preEntityRemoval(Node state) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends NodeBacked> getJavaType(Node state) {
|
||||
throw new UnsupportedOperationException("getJavaType not supported by NoopTypeRepresentationStrategy.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preEntityRemoval(NodeBacked entity) {
|
||||
throw new UnsupportedOperationException("getJavaType not supported.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public <U extends NodeBacked> U createEntity(Node state) {
|
||||
throw new UnsupportedOperationException("Creation with stored type not supported by NoopTypeRepresentationStrategy.");
|
||||
throw new UnsupportedOperationException("Creation with stored type not supported.");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -57,26 +57,26 @@ public class NoopTypeRepresentationStrategy {
|
||||
|
||||
@Override
|
||||
public <U extends RelationshipBacked> Iterable<U> findAll(Class<U> clazz) {
|
||||
throw new UnsupportedOperationException("findAll not supported by NoopTypeRepresentationStrategy.");
|
||||
throw new UnsupportedOperationException("findAll not supported.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public long count(Class<? extends RelationshipBacked> entityClass) {
|
||||
throw new UnsupportedOperationException("count not supported by NoopTypeRepresentationStrategy.");
|
||||
throw new UnsupportedOperationException("count not supported.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preEntityRemoval(Relationship state) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends RelationshipBacked> getJavaType(Relationship state) {
|
||||
throw new UnsupportedOperationException("getJavaType not supported by NoopTypeRepresentationStrategy.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preEntityRemoval(RelationshipBacked entity) {
|
||||
throw new UnsupportedOperationException("getJavaType not supported.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public <U extends RelationshipBacked> U createEntity(Relationship state) {
|
||||
throw new UnsupportedOperationException("Creation with stored type not supported by NoopTypeRepresentationStrategy.");
|
||||
throw new UnsupportedOperationException("Creation with stored type not supported.");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -100,34 +100,6 @@ public class SubReferenceNodeTypeRepresentationStrategy implements NodeTypeRepre
|
||||
updateSuperClassSubrefs(type, subReference);
|
||||
}
|
||||
|
||||
/**
|
||||
* removes instanceof relationship and decrements instance counters for type nodes
|
||||
* @param entity
|
||||
*/
|
||||
@Override
|
||||
public void preEntityRemoval(NodeBacked entity) {
|
||||
Class<? extends NodeBacked> clazz = entity.getClass();
|
||||
|
||||
final Node subReference = obtainSubreferenceNode(clazz);
|
||||
Node subRefNode = entity.getPersistentState();
|
||||
Relationship instanceOf = subRefNode.getSingleRelationship(INSTANCE_OF_RELATIONSHIP_TYPE, Direction.OUTGOING);
|
||||
instanceOf.delete();
|
||||
if (log.isDebugEnabled()) log.debug("Removed link to subref node: " + subReference + " with type: " + clazz.getName());
|
||||
TraversalDescription traversal = Traversal.description().depthFirst().relationships(SUBCLASS_OF_RELATIONSHIP_TYPE, Direction.OUTGOING);
|
||||
for (Node node : traversal.traverse(subReference).nodes()) {
|
||||
Integer count = (Integer) node.getProperty(SUBREFERENCE_NODE_COUNTER_KEY);
|
||||
Integer newCount = decrementAndGetCounter(node, SUBREFERENCE_NODE_COUNTER_KEY, 0);
|
||||
if (log.isDebugEnabled()) log.debug("count on ref " + node + " was " + count + " new " + newCount);
|
||||
}
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public <T extends NodeBacked> Class<T> confirmType(Node node, Class<T> type) {
|
||||
// Class<T> nodeType = this.<T>getJavaType(node);
|
||||
// if (type.isAssignableFrom(nodeType)) return nodeType;
|
||||
// throw new IllegalArgumentException(String.format("%s does not correspond to the node type %s of node %s",type,nodeType,node));
|
||||
// }
|
||||
|
||||
private void updateSuperClassSubrefs(Class<?> clazz, Node subReference) {
|
||||
Class<?> superClass = clazz.getSuperclass();
|
||||
if (superClass != null) {
|
||||
@@ -165,7 +137,24 @@ public class SubReferenceNodeTypeRepresentationStrategy implements NodeTypeRepre
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public void preEntityRemoval(Node state) {
|
||||
Class<? extends NodeBacked> clazz = getJavaType(state);
|
||||
if (clazz == null) return;
|
||||
final Node subReference = obtainSubreferenceNode(clazz);
|
||||
Relationship instanceOf = state.getSingleRelationship(INSTANCE_OF_RELATIONSHIP_TYPE, Direction.OUTGOING);
|
||||
instanceOf.delete();
|
||||
if (log.isDebugEnabled())
|
||||
log.debug("Removed link to subref node: " + subReference + " with type: " + clazz.getName());
|
||||
TraversalDescription traversal = Traversal.description().depthFirst().relationships(SUBCLASS_OF_RELATIONSHIP_TYPE, Direction.OUTGOING);
|
||||
for (Node node : traversal.traverse(subReference).nodes()) {
|
||||
Integer count = (Integer) node.getProperty(SUBREFERENCE_NODE_COUNTER_KEY);
|
||||
Integer newCount = decrementAndGetCounter(node, SUBREFERENCE_NODE_COUNTER_KEY, 0);
|
||||
if (log.isDebugEnabled()) log.debug("count on ref " + node + " was " + count + " new " + newCount);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends NodeBacked> Iterable<T> findAll(final Class<T> clazz) {
|
||||
final Node subrefNode = findSubreferenceNode(clazz);
|
||||
if (log.isDebugEnabled()) log.debug("Subref: " + subrefNode);
|
||||
|
||||
@@ -78,7 +78,7 @@ public class IndexingNodeTypeRepresentationStrategyTest {
|
||||
Transaction tx = graphDatabaseService.beginTx();
|
||||
try
|
||||
{
|
||||
nodeTypeRepresentationStrategy.preEntityRemoval(thing);
|
||||
nodeTypeRepresentationStrategy.preEntityRemoval(node(thing));
|
||||
tx.success();
|
||||
}
|
||||
finally
|
||||
@@ -92,9 +92,8 @@ public class IndexingNodeTypeRepresentationStrategyTest {
|
||||
assertEquals(node(subThing), subThingHits.getSingle());
|
||||
|
||||
tx = graphDatabaseService.beginTx();
|
||||
try
|
||||
{
|
||||
nodeTypeRepresentationStrategy.preEntityRemoval(subThing);
|
||||
try {
|
||||
nodeTypeRepresentationStrategy.preEntityRemoval(node(subThing));
|
||||
tx.success();
|
||||
}
|
||||
finally
|
||||
|
||||
@@ -74,7 +74,7 @@ public class IndexingRelationshipTypeRepresentationStrategyTest {
|
||||
Transaction tx = graphDatabaseService.beginTx();
|
||||
try
|
||||
{
|
||||
relationshipTypeRepresentationStrategy.preEntityRemoval(link);
|
||||
relationshipTypeRepresentationStrategy.preEntityRemoval(rel(link));
|
||||
tx.success();
|
||||
}
|
||||
finally
|
||||
|
||||
@@ -8,7 +8,10 @@ import org.neo4j.graphdb.*;
|
||||
import org.neo4j.helpers.collection.IteratorUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.graph.neo4j.Friendship;
|
||||
import org.springframework.data.graph.neo4j.FriendshipRepository;
|
||||
import org.springframework.data.graph.neo4j.Person;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.springframework.data.graph.neo4j.Person.persistedPerson;
|
||||
|
||||
import org.springframework.data.graph.neo4j.repository.DirectGraphRepositoryFactory;
|
||||
@@ -30,6 +33,10 @@ public class RelationshipEntityTest {
|
||||
|
||||
@Autowired
|
||||
private GraphDatabaseContext graphDatabaseContext;
|
||||
@Autowired
|
||||
private GraphDatabaseService graphDatabaseService;
|
||||
@Autowired
|
||||
private FriendshipRepository friendshipRepository;
|
||||
|
||||
@Autowired
|
||||
private DirectGraphRepositoryFactory graphRepositoryFactory;
|
||||
@@ -97,6 +104,64 @@ public class RelationshipEntityTest {
|
||||
Person p = persistedPerson("Michael", 35);
|
||||
Person p2 = persistedPerson("David", 25);
|
||||
Friendship f = p.knows(p2);
|
||||
assertEquals(f,p.getRelationshipTo(p2,Friendship.class, "knows"));
|
||||
assertEquals(f,p.getRelationshipTo(p2, Friendship.class, "knows"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveRelationshipEntity() {
|
||||
cleanDb();
|
||||
Friendship f;
|
||||
Transaction tx = graphDatabaseService.beginTx();
|
||||
try
|
||||
{
|
||||
Person p = persistedPerson("Michael", 35);
|
||||
Person p2 = persistedPerson("David", 25);
|
||||
f = p.knows(p2);
|
||||
tx.success();
|
||||
}
|
||||
finally
|
||||
{
|
||||
tx.finish();
|
||||
}
|
||||
Transaction tx2 = graphDatabaseService.beginTx();
|
||||
try
|
||||
{
|
||||
f.remove();
|
||||
tx2.success();
|
||||
}
|
||||
finally
|
||||
{
|
||||
tx2.finish();
|
||||
}
|
||||
assertFalse("Unexpected relationship entity found.", friendshipRepository.findAll().iterator().hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveRelationshipEntityIfNodeEntityIsRemoved() {
|
||||
cleanDb();
|
||||
Person p;
|
||||
Transaction tx = graphDatabaseService.beginTx();
|
||||
try
|
||||
{
|
||||
p = persistedPerson("Michael", 35);
|
||||
Person p2 = persistedPerson("David", 25);
|
||||
p.knows(p2);
|
||||
tx.success();
|
||||
}
|
||||
finally
|
||||
{
|
||||
tx.finish();
|
||||
}
|
||||
Transaction tx2 = graphDatabaseService.beginTx();
|
||||
try
|
||||
{
|
||||
p.remove();
|
||||
tx2.success();
|
||||
}
|
||||
finally
|
||||
{
|
||||
tx2.finish();
|
||||
}
|
||||
assertFalse("Unexpected relationship entity found.", friendshipRepository.findAll().iterator().hasNext());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,11 +113,11 @@ public class SubReferenceNodeTypeRepresentationStrategyTest {
|
||||
@Transactional
|
||||
public void testPreEntityRemoval() throws Exception {
|
||||
Node typeNode = getInstanceofRelationship(thingNode).getOtherNode(thingNode);
|
||||
nodeTypeRepresentationStrategy.preEntityRemoval(thing);
|
||||
nodeTypeRepresentationStrategy.preEntityRemoval(node(thing));
|
||||
assertNull("instanceof relationship was removed", getInstanceofRelationship(thingNode));
|
||||
assertNotNull("instanceof relationship was removed", getInstanceofRelationship(subThingNode));
|
||||
assertEquals("no things left after removal", 1, typeNode.getProperty(SubReferenceNodeTypeRepresentationStrategy.SUBREFERENCE_NODE_COUNTER_KEY));
|
||||
nodeTypeRepresentationStrategy.preEntityRemoval(subThing);
|
||||
nodeTypeRepresentationStrategy.preEntityRemoval(node(subThing));
|
||||
assertNull("instanceof relationship was removed", getInstanceofRelationship(subThingNode));
|
||||
assertEquals("no things left after removal", 0, typeNode.getProperty(SubReferenceNodeTypeRepresentationStrategy.SUBREFERENCE_NODE_COUNTER_KEY));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user