예제 #1
0
  private void visitInTx(SpatialIndexVisitor visitor, Long indexNodeId) {
    Node indexNode = database.getNodeById(indexNodeId);
    if (!visitor.needsToVisit(getIndexNodeEnvelope(indexNode))) {
      return;
    }

    if (indexNode.hasRelationship(RTreeRelationshipTypes.RTREE_CHILD, Direction.OUTGOING)) {
      // Node is not a leaf

      // collect children
      List<Long> children = new ArrayList<Long>();
      for (Relationship rel :
          indexNode.getRelationships(RTreeRelationshipTypes.RTREE_CHILD, Direction.OUTGOING)) {
        children.add(rel.getEndNode().getId());
      }

      // visit children
      for (Long child : children) {
        visitInTx(visitor, child);
      }
    } else if (indexNode.hasRelationship(
        RTreeRelationshipTypes.RTREE_REFERENCE, Direction.OUTGOING)) {
      // Node is a leaf
      try (Transaction tx = database.beginTx()) {
        for (Relationship rel :
            indexNode.getRelationships(
                RTreeRelationshipTypes.RTREE_REFERENCE, Direction.OUTGOING)) {
          visitor.onIndexReference(rel.getEndNode());
        }

        tx.success();
      }
    }
  }
예제 #2
0
  public void visit(SpatialIndexVisitor visitor, Node indexNode) {
    if (!visitor.needsToVisit(getIndexNodeEnvelope(indexNode))) {
      return;
    }

    try (Transaction tx = database.beginTx()) {
      if (indexNode.hasRelationship(RTreeRelationshipTypes.RTREE_CHILD, Direction.OUTGOING)) {
        // Node is not a leaf
        for (Relationship rel :
            indexNode.getRelationships(RTreeRelationshipTypes.RTREE_CHILD, Direction.OUTGOING)) {
          Node child = rel.getEndNode();
          // collect children results
          visit(visitor, child);
        }
      } else if (indexNode.hasRelationship(
          RTreeRelationshipTypes.RTREE_REFERENCE, Direction.OUTGOING)) {
        // Node is a leaf
        for (Relationship rel :
            indexNode.getRelationships(
                RTreeRelationshipTypes.RTREE_REFERENCE, Direction.OUTGOING)) {
          visitor.onIndexReference(rel.getEndNode());
        }
      }
      tx.success();
    }
  }
예제 #3
0
  protected Node findLeafContainingGeometryNode(Node geomNode, boolean throwExceptionIfNotFound) {
    if (!geomNode.hasRelationship(RTreeRelationshipTypes.RTREE_REFERENCE, Direction.INCOMING)) {
      if (throwExceptionIfNotFound) {
        throw new RuntimeException("GeometryNode not indexed with an RTree: " + geomNode.getId());
      } else {
        return null;
      }
    }

    Node indexNodeLeaf =
        geomNode
            .getSingleRelationship(RTreeRelationshipTypes.RTREE_REFERENCE, Direction.INCOMING)
            .getStartNode();

    Node root = null;
    Node child = indexNodeLeaf;
    while (root == null) {
      Node parent = getIndexNodeParent(child);
      if (parent == null) {
        root = child;
      } else {
        child = parent;
      }
    }

    if (root.getId() != getIndexRoot().getId()) {
      if (throwExceptionIfNotFound) {
        throw new RuntimeException("GeometryNode not indexed in this RTree: " + geomNode.getId());
      } else {
        return null;
      }
    } else {
      return indexNodeLeaf;
    }
  }
예제 #4
0
 private void initIndexRoot() {
   Node layerNode = getRootNode();
   if (!layerNode.hasRelationship(RTreeRelationshipTypes.RTREE_ROOT, Direction.OUTGOING)) {
     // index initialization
     Node root = database.createNode();
     layerNode.createRelationshipTo(root, RTreeRelationshipTypes.RTREE_ROOT);
   }
 }
  @Test
  public void testTxCacheLoadIsolation() throws Exception {
    Node node = getGraphDb().createNode();
    node.setProperty("someproptest", "testing");
    Node node1 = getGraphDb().createNode();
    node1.setProperty("someotherproptest", 2);
    commit();
    EmbeddedGraphDatabase graphDb = (EmbeddedGraphDatabase) getGraphDb();
    TransactionManager txManager = graphDb.getConfig().getTxModule().getTxManager();
    NodeManager nodeManager = graphDb.getConfig().getGraphDbModule().getNodeManager();

    txManager.begin();
    node.setProperty("someotherproptest", "testing2");
    Relationship rel = node.createRelationshipTo(node1, MyRelTypes.TEST);
    javax.transaction.Transaction txA = txManager.suspend();
    txManager.begin();
    assertEquals("testing", node.getProperty("someproptest"));
    assertTrue(!node.hasProperty("someotherproptest"));
    assertTrue(!node.hasRelationship());
    nodeManager.clearCache();
    assertEquals("testing", node.getProperty("someproptest"));
    assertTrue(!node.hasProperty("someotherproptest"));
    javax.transaction.Transaction txB = txManager.suspend();
    txManager.resume(txA);
    assertEquals("testing", node.getProperty("someproptest"));
    assertTrue(node.hasProperty("someotherproptest"));
    assertTrue(node.hasRelationship());
    nodeManager.clearCache();
    assertEquals("testing", node.getProperty("someproptest"));
    assertTrue(node.hasProperty("someotherproptest"));
    assertTrue(node.hasRelationship());
    txManager.suspend();
    txManager.resume(txB);
    assertEquals("testing", node.getProperty("someproptest"));
    assertTrue(!node.hasProperty("someotherproptest"));
    assertTrue(!node.hasRelationship());
    txManager.rollback();
    txManager.resume(txA);
    node.delete();
    node1.delete();
    rel.delete();
    txManager.commit();
    newTransaction();
  }
예제 #6
0
 private void init(PrintWriter out) {
   final Node node = getReferenceNode();
   if (node != null && (node.hasRelationship() || hasProperties(node))) {
     String id = identifier(node);
     out.println("start " + id + " = node(" + node.getId() + ") with " + id + " ");
     String labels = labelString(node);
     if (!labels.isEmpty()) {
       out.print("set " + identifier(node) + " " + labels + " ");
     }
     appendPropertySetters(out, node);
   }
 }
예제 #7
0
  private void findAndCreateSuggestions(final Node node) {
    if (!node.hasRelationship(ConnectionType.KNOWS)) {
      return;
    }

    final Traverser traverser = friendToSuggestionTraversalDescription().traverse(node);
    for (final Node suggestionNode : traverser.nodes()) {
      if (!this.isSuggestionRelationshipPresent(node, suggestionNode)) {
        node.createRelationshipTo(suggestionNode, ConnectionType.SUGGESTED);
        if (logger.isInfoEnabled()) {
          logger.info(
              "New Suggestion Between {} and {}",
              node.getPropertyValues(),
              suggestionNode.getPropertyValues());
        }
      }
    }
  }
예제 #8
0
  private void initIndexMetadata() {
    Node layerNode = getRootNode();
    if (layerNode.hasRelationship(RTreeRelationshipTypes.RTREE_METADATA, Direction.OUTGOING)) {
      // metadata already present
      metadataNode =
          layerNode
              .getSingleRelationship(RTreeRelationshipTypes.RTREE_METADATA, Direction.OUTGOING)
              .getEndNode();

      maxNodeReferences = (Integer) metadataNode.getProperty("maxNodeReferences");
    } else {
      // metadata initialization
      metadataNode = database.createNode();
      layerNode.createRelationshipTo(metadataNode, RTreeRelationshipTypes.RTREE_METADATA);

      metadataNode.setProperty("maxNodeReferences", maxNodeReferences);
    }

    saveCount();
  }
 /** {@inheritDoc} */
 @Override
 public void expire(Node node) {
   if (!node.hasRelationship()) {
     node.delete();
   }
 }
예제 #10
0
 private boolean nodeIsLeaf(Node node) {
   return !node.hasRelationship(RTreeRelationshipTypes.RTREE_CHILD, Direction.OUTGOING);
 }
예제 #11
0
 @Override
 public boolean isLeaf() {
   return (!node.hasRelationship(RelType.HAS_CHILD, Direction.OUTGOING));
 }