private void removeFromIndexes(Relationship relationship) {
     final IndexManager indexManager = delegate.index();
     for (String indexName : indexManager.relationshipIndexNames()) {
         RelationshipIndex relationshipIndex = indexManager.forRelationships(indexName);
         if (relationshipIndex.isWriteable()) relationshipIndex.remove(relationship);
     }
 }
Esempio n. 2
0
 public void removeFromRelationshipIndexNoKeyValue(String indexName, long id) {
   RelationshipIndex index = graphDb.index().forRelationships(indexName);
   Transaction tx = graphDb.beginTx();
   try {
     index.remove(graphDb.getRelationshipById(id));
     tx.success();
   } finally {
     tx.finish();
   }
 }
Esempio n. 3
0
 /**
  * {@inheritDoc}
  *
  * <p>Note that this method will force a successful closing of the current thread's transaction.
  * As such, once the index is dropped, the operation is committed.
  *
  * @param indexName the name of the index to drop
  */
 public synchronized void dropIndex(final String indexName) {
   this.autoStartTransaction();
   if (this.rawGraph.index().existsForNodes(indexName)) {
     org.neo4j.graphdb.index.Index<Node> nodeIndex = this.rawGraph.index().forNodes(indexName);
     if (nodeIndex.isWriteable()) {
       nodeIndex.delete();
     }
   } else if (this.rawGraph.index().existsForRelationships(indexName)) {
     RelationshipIndex relationshipIndex = this.rawGraph.index().forRelationships(indexName);
     if (relationshipIndex.isWriteable()) {
       relationshipIndex.delete();
     }
   }
   this.stopTransaction(Conclusion.SUCCESS);
 }
Esempio n. 4
0
  @Test
  public void testGettingAutoIndexByNameReturnsSomethingReadOnly() {
    // Create the node and relationship auto-indexes
    graphDb.index().getNodeAutoIndexer().setEnabled(true);
    graphDb.index().getNodeAutoIndexer().startAutoIndexingProperty("nodeProp");
    graphDb.index().getRelationshipAutoIndexer().setEnabled(true);
    graphDb.index().getRelationshipAutoIndexer().startAutoIndexingProperty("relProp");

    newTransaction();

    Node node1 = graphDb.createNode();
    Node node2 = graphDb.createNode();
    Relationship rel = node1.createRelationshipTo(node2, DynamicRelationshipType.withName("FOO"));
    node1.setProperty("nodeProp", "nodePropValue");
    rel.setProperty("relProp", "relPropValue");

    newTransaction();

    assertEquals(1, graphDb.index().nodeIndexNames().length);
    assertEquals(1, graphDb.index().relationshipIndexNames().length);

    assertEquals("node_auto_index", graphDb.index().nodeIndexNames()[0]);
    assertEquals("relationship_auto_index", graphDb.index().relationshipIndexNames()[0]);

    Index<Node> nodeIndex = graphDb.index().forNodes("node_auto_index");
    RelationshipIndex relIndex = graphDb.index().forRelationships("relationship_auto_index");
    assertEquals(node1, nodeIndex.get("nodeProp", "nodePropValue").getSingle());
    assertEquals(rel, relIndex.get("relProp", "relPropValue").getSingle());
    try {
      nodeIndex.add(null, null, null);
      fail("Auto indexes should not allow external manipulation");
    } catch (UnsupportedOperationException e) { // good
    }

    try {
      relIndex.add(null, null, null);
      fail("Auto indexes should not allow external manipulation");
    } catch (UnsupportedOperationException e) { // good
    }
  }