DATAGRAPH-407 deleting entities with a read-only index

This commit is contained in:
Michael Hunger
2013-11-11 08:43:45 +01:00
parent e5ffbb5400
commit 115ae5830a
2 changed files with 53 additions and 4 deletions

View File

@@ -36,13 +36,10 @@ public class Neo4jDatabaseCleaner {
public Map<String, Object> cleanDb() {
Map<String, Object> result = new HashMap<String, Object>();
Transaction tx = graph.beginTx();
try {
try (Transaction tx = graph.beginTx()) {
removeNodes(result);
clearIndex(result);
tx.success();
} finally {
tx.finish();
}
return result;
}

View File

@@ -0,0 +1,52 @@
package org.springframework.data.neo4j.support.mapping;
import org.junit.Test;
import org.neo4j.graphdb.*;
import org.neo4j.graphdb.index.AutoIndexer;
import org.neo4j.test.TestGraphDatabaseFactory;
import org.springframework.data.neo4j.support.Infrastructure;
import org.springframework.data.neo4j.support.MappingInfrastructureFactoryBean;
/**
* @author mh
* @since 11.11.13
*/
public class EntityRemoverTest {
@Test
public void testRemoveNodeEntityWithAutoIndex() throws Exception {
GraphDatabaseService db = new TestGraphDatabaseFactory().newImpermanentDatabase();
try (Transaction tx = db.beginTx()) {
AutoIndexer<Node> nodeAutoIndexer = db.index().getNodeAutoIndexer();
nodeAutoIndexer.setEnabled(true);
nodeAutoIndexer.startAutoIndexingProperty("foo");
Infrastructure infrastructure = MappingInfrastructureFactoryBean.createDirect(db, null);
Node node = db.createNode();
node.setProperty("foo", "bar");
infrastructure.getEntityRemover().remove(node);
node = db.createNode();
node.setProperty("foo", "bar");
infrastructure.getGraphDatabase().remove(node);
tx.success();
}
}
@Test
public void testRemoveRelationshipEntityWithAutoIndex() throws Exception {
GraphDatabaseService db = new TestGraphDatabaseFactory().newImpermanentDatabase();
try (Transaction tx = db.beginTx()) {
AutoIndexer<Relationship> autoIndexer = db.index().getRelationshipAutoIndexer();
autoIndexer.setEnabled(true);
autoIndexer.startAutoIndexingProperty("foo");
Infrastructure infrastructure = MappingInfrastructureFactoryBean.createDirect(db, null);
final Node node = db.createNode();
Relationship relationship = node.createRelationshipTo(node, DynamicRelationshipType.withName("KNOWS"));
relationship.setProperty("foo", "bar");
infrastructure.getEntityRemover().remove(relationship);
relationship = node.createRelationshipTo(node, DynamicRelationshipType.withName("KNOWS"));
relationship.setProperty("foo", "bar");
infrastructure.getGraphDatabase().remove(relationship);
tx.success();
}
}
}