private Node node(long id) throws NodeNotFoundException {
   try {
     return graphDb.getNodeById(id);
   } catch (NotFoundException e) {
     throw new NodeNotFoundException(e);
   }
 }
Example #2
0
 private Node node(long id) throws NodeNotFoundException {
   try {
     return graphDb.getNodeById(id);
   } catch (NotFoundException e) {
     throw new NodeNotFoundException(
         String.format("Cannot find node with id [%d] in database.", id));
   }
 }
Example #3
0
  public String createPagedTraverser(
      long nodeId, Map<String, Object> description, int pageSize, int leaseTime) {
    Node node = graphDb.getNodeById(nodeId);

    TraversalDescription traversalDescription = TraversalDescriptionBuilder.from(description);

    PagedTraverser traverser = new PagedTraverser(traversalDescription.traverse(node), pageSize);

    return leases.createLease(leaseTime, traverser).getId();
  }
Example #4
0
 public IndexedEntityRepresentation getIndexedNode(
     String indexName, String key, String value, long id) {
   if (!nodeIsIndexed(indexName, key, value, id)) throw new NotFoundException();
   Node node = graphDb.getNodeById(id);
   return new IndexedEntityRepresentation(
       node,
       key,
       value,
       new NodeIndexRepresentation(indexName, Collections.<String, String>emptyMap()));
 }
Example #5
0
 public void removeFromNodeIndexNoKeyValue(String indexName, long id) {
   Index<Node> index = graphDb.index().forNodes(indexName);
   Transaction tx = graphDb.beginTx();
   try {
     index.remove(graphDb.getNodeById(id));
     tx.success();
   } finally {
     tx.finish();
   }
 }
  @Test
  public void exampleQuery() throws Exception {
    // START SNIPPET: JavaQuery
    ExecutionEngine engine = new ExecutionEngine(db);
    ExecutionResult result = engine.execute("start n=node(0) where 1=1 return n");

    assertThat(result.columns(), hasItem("n"));
    Iterator<Node> n_column = result.columnAs("n");
    assertThat(asIterable(n_column), hasItem(db.getNodeById(0)));
    assertThat(result.toString(), containsString("Node[0]"));
    // END SNIPPET: JavaQuery
  }
Example #7
0
  public boolean nodeIsIndexed(String indexName, String key, Object value, long nodeId)
      throws DatabaseBlockedException {

    Index<Node> index = graphDb.index().forNodes(indexName);
    Transaction tx = graphDb.beginTx();
    try {
      Node expectedNode = graphDb.getNodeById(nodeId);
      IndexHits<Node> hits = index.get(key, value);
      boolean contains = iterableContains(hits, expectedNode);
      tx.success();
      return contains;
    } finally {
      tx.finish();
    }
  }
Example #8
0
  public ListRepresentation traverse(
      long startNode, Map<String, Object> description, TraverserReturnType returnType) {
    Node node = graphDb.getNodeById(startNode);

    List<Representation> result = new ArrayList<Representation>();

    TraversalDescription traversalDescription = TraversalDescriptionBuilder.from(description);
    for (Path position : traversalDescription.traverse(node)) {
      MappingRepresentation representation = returnType.toRepresentation(position);
      if (representation != null) {
        result.add(representation);
      }
    }

    return new ListRepresentation(returnType.repType, result);
  }
Example #9
0
 public IndexedEntityRepresentation addToNodeIndex(
     String indexName, String key, String value, long nodeId) {
   Transaction tx = graphDb.beginTx();
   try {
     Node node = graphDb.getNodeById(nodeId);
     Index<Node> index = graphDb.index().forNodes(indexName);
     index.add(node, key, value);
     tx.success();
     return new IndexedEntityRepresentation(
         node,
         key,
         value,
         new NodeIndexRepresentation(indexName, Collections.<String, String>emptyMap()));
   } finally {
     tx.finish();
   }
 }