private void createTenNodes() {
   Transaction tx = db.beginTx();
   for (int i = 0; i < 10; i++) {
     db.createNode();
   }
   tx.success();
   tx.finish();
 }
Exemplo n.º 2
0
 public void removeRelationshipIndex(String indexName) {
   Index<Relationship> index = graphDb.index().forRelationships(indexName);
   Transaction tx = graphDb.beginTx();
   try {
     index.delete();
     tx.success();
   } finally {
     tx.finish();
   }
 }
Exemplo n.º 3
0
 public void removeNodeIndex(String indexName) {
   Index<Node> index = graphDb.index().forNodes(indexName);
   Transaction tx = graphDb.beginTx();
   try {
     index.delete();
     tx.success();
   } finally {
     tx.finish();
   }
 }
Exemplo n.º 4
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();
   }
 }
Exemplo n.º 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();
   }
 }
Exemplo n.º 6
0
 public NodeRepresentation createNode(Map<String, Object> properties)
     throws PropertyValueException {
   final NodeRepresentation result;
   Transaction tx = graphDb.beginTx();
   try {
     result = new NodeRepresentation(set(graphDb.createNode(), properties));
     tx.success();
   } finally {
     tx.finish();
   }
   return result;
 }
Exemplo n.º 7
0
  public IndexRepresentation createRelationshipIndex(Map<String, Object> indexSpecification) {
    final String indexName = (String) indexSpecification.get("name");
    if (indexSpecification.containsKey("config")) {

      @SuppressWarnings("unchecked")
      Map<String, String> config = (Map<String, String>) indexSpecification.get("config");
      graphDb.index().forRelationships(indexName, config);

      return new RelationshipIndexRepresentation(indexName, config);
    }

    graphDb.index().forRelationships(indexName);
    return new RelationshipIndexRepresentation(indexName, Collections.<String, String>emptyMap());
  }
Exemplo n.º 8
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();
    }
  }
Exemplo n.º 9
0
  public Representation getAutoIndexedNodes(String key, String value) {

    List<Representation> representations = new ArrayList<Representation>();
    ReadableIndex<Node> index = graphDb.index().getNodeAutoIndexer().getAutoIndex();

    Transaction tx = graphDb.beginTx();
    try {
      for (Node node : index.get(key, value)) {
        representations.add(new NodeRepresentation(node));
      }
      tx.success();
      return new ListRepresentation(RepresentationType.NODE, representations);
    } finally {
      tx.finish();
    }
  }
Exemplo n.º 10
0
 private Node node(long id) throws NodeNotFoundException {
   try {
     return graphDb.getNodeById(id);
   } catch (NotFoundException e) {
     throw new NodeNotFoundException(e);
   }
 }
Exemplo n.º 11
0
 private Relationship relationship(long id) throws RelationshipNotFoundException {
   try {
     return graphDb.getRelationshipById(id);
   } catch (NotFoundException e) {
     throw new RelationshipNotFoundException();
   }
 }
Exemplo n.º 12
0
  public Representation getAutoIndexedRelationships(String key, String value) {

    List<Representation> representations = new ArrayList<Representation>();
    ReadableRelationshipIndex index = graphDb.index().getRelationshipAutoIndexer().getAutoIndex();

    Transaction tx = graphDb.beginTx();
    try {
      for (Relationship rel : index.get(key, value)) {
        representations.add(new RelationshipRepresentation(rel));
      }
      tx.success();
      return new ListRepresentation(RepresentationType.RELATIONSHIP, representations);
    } finally {
      tx.finish();
    }
  }
Exemplo n.º 13
0
  public RelationshipRepresentation createRelationship(
      long startNodeId, long endNodeId, String type, Map<String, Object> properties)
      throws StartNodeNotFoundException, EndNodeNotFoundException, PropertyValueException {

    Node start, end;
    try {
      start = node(startNodeId);
    } catch (NodeNotFoundException e) {
      throw new StartNodeNotFoundException();
    }
    try {
      end = node(endNodeId);
    } catch (NodeNotFoundException e) {
      throw new EndNodeNotFoundException();
    }
    final RelationshipRepresentation result;
    Transaction tx = graphDb.beginTx();
    try {
      result =
          new RelationshipRepresentation(
              set(
                  start.createRelationshipTo(end, DynamicRelationshipType.withName(type)),
                  properties));
      tx.success();
    } finally {
      tx.finish();
    }
    return result;
  }
Exemplo n.º 14
0
  public boolean relationshipIsIndexed(
      String indexName, String key, Object value, long relationshipId)
      throws DatabaseBlockedException {

    Index<Relationship> index = graphDb.index().forRelationships(indexName);
    Transaction tx = graphDb.beginTx();
    try {
      Relationship expectedNode = graphDb.getRelationshipById(relationshipId);
      IndexHits<Relationship> hits = index.get(key, value);
      boolean contains = iterableContains(hits, expectedNode);
      tx.success();
      return contains;
    } finally {
      tx.finish();
    }
  }
Exemplo n.º 15
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();
   }
 }
Exemplo n.º 16
0
 public IndexedEntityRepresentation addToRelationshipIndex(
     String indexName, String key, String value, long relationshipId) {
   Transaction tx = graphDb.beginTx();
   try {
     Relationship relationship = graphDb.getRelationshipById(relationshipId);
     Index<Relationship> index = graphDb.index().forRelationships(indexName);
     index.add(relationship, key, value);
     tx.success();
     return new IndexedEntityRepresentation(
         relationship,
         key,
         value,
         new RelationshipIndexRepresentation(indexName, Collections.<String, String>emptyMap()));
   } finally {
     tx.finish();
   }
 }
Exemplo n.º 17
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));
   }
 }
Exemplo n.º 18
0
  public ListRepresentation getIndexedRelationshipsByQuery(
      String indexName, String key, String query) {
    if (!graphDb.index().existsForRelationships(indexName)) throw new NotFoundException();
    List<Representation> representations = new ArrayList<Representation>();
    Index<Relationship> index = graphDb.index().forRelationships(indexName);

    Transaction tx = graphDb.beginTx();
    try {
      for (Relationship rel : index.query(key, query)) {
        representations.add(new RelationshipRepresentation(rel));
      }
      tx.success();
      return new ListRepresentation(RepresentationType.RELATIONSHIP, representations);
    } finally {
      tx.finish();
    }
  }
Exemplo n.º 19
0
  public ListRepresentation getAutoIndexedRelationshipsByQuery(String query) {
    ReadableRelationshipIndex index = graphDb.index().getRelationshipAutoIndexer().getAutoIndex();
    List<Representation> representations = new ArrayList<Representation>();

    if (query != null) {
      Transaction tx = graphDb.beginTx();
      try {
        for (Relationship rel : index.query(query)) {
          representations.add(new RelationshipRepresentation(rel));
        }
        tx.success();
      } finally {
        tx.finish();
      }
    }
    return new ListRepresentation(RepresentationType.RELATIONSHIP, representations);
  }
Exemplo n.º 20
0
  public ListRepresentation getAutoIndexedNodesByQuery(String query) {
    ReadableIndex<Node> index = graphDb.index().getNodeAutoIndexer().getAutoIndex();
    List<Representation> representations = new ArrayList<Representation>();

    if (query != null) {
      Transaction tx = graphDb.beginTx();
      try {
        for (Node node : index.query(query)) {
          representations.add(new NodeRepresentation(node));
        }
        tx.success();
      } finally {
        tx.finish();
      }
    }
    return new ListRepresentation(RepresentationType.NODE, representations);
  }
Exemplo n.º 21
0
  public ListRepresentation getIndexedRelationships(String indexName, String key, String value) {
    if (!graphDb.index().existsForRelationships(indexName)) throw new NotFoundException();
    List<IndexedEntityRepresentation> representations =
        new ArrayList<IndexedEntityRepresentation>();
    Index<Relationship> index = graphDb.index().forRelationships(indexName);

    Transaction tx = graphDb.beginTx();
    try {
      IndexRepresentation indexRepresentation = new RelationshipIndexRepresentation(indexName);
      for (Relationship node : index.get(key, value)) {
        representations.add(new IndexedEntityRepresentation(node, key, value, indexRepresentation));
      }
      tx.success();
      return new ListRepresentation(RepresentationType.RELATIONSHIP, representations);
    } finally {
      tx.finish();
    }
  }
Exemplo n.º 22
0
  public ListRepresentation getIndexedNodesByQuery(String indexName, String key, String query) {
    if (!graphDb.index().existsForNodes(indexName)) throw new NotFoundException();
    Index<Node> index = graphDb.index().forNodes(indexName);
    List<Representation> representations = new ArrayList<Representation>();

    Transaction tx = graphDb.beginTx();
    try {
      if (query != null) {
        for (Node node : index.query(key, query)) {
          representations.add(new NodeRepresentation(node));
        }
      }
      tx.success();
      return new ListRepresentation(RepresentationType.NODE, representations);
    } finally {
      tx.finish();
    }
  }
Exemplo n.º 23
0
  public ListRepresentation getIndexedNodes(String indexName, String key, String value) {
    if (!graphDb.index().existsForNodes(indexName)) throw new NotFoundException();
    Index<Node> index = graphDb.index().forNodes(indexName);
    List<IndexedEntityRepresentation> representations =
        new ArrayList<IndexedEntityRepresentation>();

    Transaction tx = graphDb.beginTx();
    try {
      IndexRepresentation indexRepresentation = new NodeIndexRepresentation(indexName);
      IndexHits<Node> indexHits = index.get(key, value);
      for (Node node : indexHits) {
        representations.add(new IndexedEntityRepresentation(node, key, value, indexRepresentation));
      }
      tx.success();
      return new ListRepresentation(RepresentationType.NODE, representations);
    } finally {
      tx.finish();
    }
  }
Exemplo n.º 24
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();
  }
Exemplo n.º 25
0
 public void deleteRelationship(long relationshipId) throws RelationshipNotFoundException {
   Relationship relationship = relationship(relationshipId);
   Transaction tx = graphDb.beginTx();
   try {
     relationship.delete();
     tx.success();
   } finally {
     tx.finish();
   }
 }
Exemplo n.º 26
0
 public void removeAllNodeProperties(long nodeId) throws NodeNotFoundException {
   Node node = node(nodeId);
   Transaction tx = graphDb.beginTx();
   try {
     clear(node);
     tx.success();
   } finally {
     tx.finish();
   }
 }
  @Before
  public void setUp() throws IOException {
    db = new ImpermanentGraphDatabase();
    engine = new ExecutionEngine(db);
    Transaction tx = db.beginTx();
    andreasNode = db.createNode();
    johanNode = db.createNode();
    michaelaNode = db.getReferenceNode();
    andreasNode.setProperty("name", "Andreas");
    johanNode.setProperty("name", "Johan");
    michaelaNode.setProperty("name", "Michaela");

    index(andreasNode);
    index(johanNode);
    index(michaelaNode);

    tx.success();
    tx.finish();
  }
Exemplo n.º 28
0
 public IndexedEntityRepresentation getIndexedRelationship(
     String indexName, String key, String value, long id) {
   if (!relationshipIsIndexed(indexName, key, value, id)) throw new NotFoundException();
   Relationship node = graphDb.getRelationshipById(id);
   return new IndexedEntityRepresentation(
       node,
       key,
       value,
       new RelationshipIndexRepresentation(indexName, Collections.<String, String>emptyMap()));
 }
Exemplo n.º 29
0
 public void setAllRelationshipProperties(long relationshipId, Map<String, Object> properties)
     throws PropertyValueException, RelationshipNotFoundException {
   Relationship relationship = relationship(relationshipId);
   Transaction tx = graphDb.beginTx();
   try {
     set(clear(relationship), properties);
     tx.success();
   } finally {
     tx.finish();
   }
 }
Exemplo n.º 30
0
 public void removeAllRelationshipProperties(long relationshipId)
     throws RelationshipNotFoundException {
   Relationship relationship = relationship(relationshipId);
   Transaction tx = graphDb.beginTx();
   try {
     clear(relationship);
     tx.success();
   } finally {
     tx.finish();
   }
 }