DATAGRAPH-407 Don't delete (from) read-only indexes
This commit is contained in:
@@ -19,6 +19,7 @@ package org.springframework.data.neo4j.support;
|
||||
import org.neo4j.graphdb.*;
|
||||
import org.neo4j.graphdb.index.Index;
|
||||
import org.neo4j.graphdb.index.IndexManager;
|
||||
import org.neo4j.graphdb.index.RelationshipIndex;
|
||||
import org.neo4j.graphdb.index.UniqueFactory;
|
||||
import org.neo4j.graphdb.traversal.TraversalDescription;
|
||||
import org.neo4j.index.lucene.ValueContext;
|
||||
@@ -104,14 +105,16 @@ public class DelegatingGraphDatabase implements GraphDatabase {
|
||||
private void removeFromIndexes(Node node) {
|
||||
final IndexManager indexManager = delegate.index();
|
||||
for (String indexName : indexManager.nodeIndexNames()) {
|
||||
indexManager.forNodes(indexName).remove(node);
|
||||
Index<Node> nodeIndex = indexManager.forNodes(indexName);
|
||||
if (nodeIndex.isWriteable()) nodeIndex.remove(node);
|
||||
}
|
||||
}
|
||||
|
||||
private void removeFromIndexes(Relationship relationship) {
|
||||
final IndexManager indexManager = delegate.index();
|
||||
for (String indexName : indexManager.relationshipIndexNames()) {
|
||||
indexManager.forRelationships(indexName).remove(relationship);
|
||||
RelationshipIndex relationshipIndex = indexManager.forRelationships(indexName);
|
||||
if (relationshipIndex.isWriteable()) relationshipIndex.remove(relationship);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,9 @@
|
||||
package org.springframework.data.neo4j.support.node;
|
||||
|
||||
import org.neo4j.graphdb.*;
|
||||
import org.neo4j.graphdb.index.Index;
|
||||
import org.neo4j.graphdb.index.IndexManager;
|
||||
import org.neo4j.graphdb.index.RelationshipIndex;
|
||||
import org.neo4j.tooling.GlobalGraphOperations;
|
||||
import org.springframework.data.neo4j.support.Neo4jTemplate;
|
||||
|
||||
@@ -62,8 +64,8 @@ public abstract class Neo4jHelper {
|
||||
public static void cleanDb( GraphDatabaseService graphDatabaseService, boolean includeReferenceNode ) {
|
||||
Transaction tx = graphDatabaseService.beginTx();
|
||||
try {
|
||||
removeNodes(graphDatabaseService, includeReferenceNode);
|
||||
clearIndex(graphDatabaseService);
|
||||
removeNodes(graphDatabaseService, includeReferenceNode);
|
||||
tx.success();
|
||||
} catch(Throwable t) {
|
||||
tx.failure();
|
||||
@@ -99,10 +101,12 @@ public abstract class Neo4jHelper {
|
||||
private static void clearIndex(GraphDatabaseService gds) {
|
||||
IndexManager indexManager = gds.index();
|
||||
for (String ix : indexManager.nodeIndexNames()) {
|
||||
indexManager.forNodes(ix).delete();
|
||||
Index<Node> nodeIndex = indexManager.forNodes(ix);
|
||||
if (nodeIndex.isWriteable()) nodeIndex.delete();
|
||||
}
|
||||
for (String ix : indexManager.relationshipIndexNames()) {
|
||||
indexManager.forRelationships(ix).delete();
|
||||
RelationshipIndex relationshipIndex = indexManager.forRelationships(ix);
|
||||
if (relationshipIndex.isWriteable()) relationshipIndex.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user