Exemplo n.º 1
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;
  }
 private void createTenNodes() {
   Transaction tx = db.beginTx();
   for (int i = 0; i < 10; i++) {
     db.createNode();
   }
   tx.success();
   tx.finish();
 }
Exemplo n.º 3
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.º 4
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.º 5
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.º 6
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.º 7
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.º 8
0
 public void removeAllNodeProperties(long nodeId) throws NodeNotFoundException {
   Node node = node(nodeId);
   Transaction tx = graphDb.beginTx();
   try {
     clear(node);
     tx.success();
   } finally {
     tx.finish();
   }
 }
Exemplo n.º 9
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.º 10
0
 public void setAllNodeProperties(long nodeId, Map<String, Object> properties)
     throws PropertyValueException, NodeNotFoundException {
   Node node = node(nodeId);
   Transaction tx = graphDb.beginTx();
   try {
     set(clear(node), properties);
     tx.success();
   } finally {
     tx.finish();
   }
 }
Exemplo n.º 11
0
 public void removeAllRelationshipProperties(long relationshipId)
     throws RelationshipNotFoundException {
   Relationship relationship = relationship(relationshipId);
   Transaction tx = graphDb.beginTx();
   try {
     clear(relationship);
     tx.success();
   } finally {
     tx.finish();
   }
 }
Exemplo n.º 12
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.º 13
0
 public void removeNodeProperty(long nodeId, String key)
     throws NodeNotFoundException, NoSuchPropertyException {
   Node node = node(nodeId);
   Transaction tx = graphDb.beginTx();
   try {
     if (node.removeProperty(key) == null) {
       throw new NoSuchPropertyException(node, key);
     }
     tx.success();
   } finally {
     tx.finish();
   }
 }
Exemplo n.º 14
0
 public void removeRelationshipProperty(long relationshipId, String key)
     throws RelationshipNotFoundException, NoSuchPropertyException {
   Relationship relationship = relationship(relationshipId);
   Transaction tx = graphDb.beginTx();
   try {
     if (relationship.removeProperty(key) == null) {
       throw new NoSuchPropertyException(relationship, key);
     }
     tx.success();
   } finally {
     tx.finish();
   }
 }
Exemplo n.º 15
0
 public void setRelationshipProperty(long relationshipId, String key, Object value)
     throws PropertyValueException, RelationshipNotFoundException {
   Relationship relationship = relationship(relationshipId);
   value = property(value);
   Transaction tx = graphDb.beginTx();
   try {
     relationship.setProperty(key, value);
     tx.success();
   } catch (IllegalArgumentException e) {
     throw new PropertyValueException(key, value);
   } finally {
     tx.finish();
   }
 }
Exemplo n.º 16
0
 public void setNodeProperty(long nodeId, String key, Object value)
     throws PropertyValueException, NodeNotFoundException {
   Node node = node(nodeId);
   value = property(value);
   Transaction tx = graphDb.beginTx();
   try {
     node.setProperty(key, value);
     tx.success();
   } catch (IllegalArgumentException e) {
     throw new PropertyValueException(key, value);
   } finally {
     tx.finish();
   }
 }
Exemplo n.º 17
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.º 18
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.º 19
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.º 20
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.º 21
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.º 22
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.º 23
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.º 24
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.º 25
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.º 26
0
 public void deleteNode(long nodeId) throws NodeNotFoundException, OperationFailureException {
   Node node = node(nodeId);
   Transaction tx = graphDb.beginTx();
   try {
     node.delete();
     tx.success();
   } finally {
     try {
       tx.finish();
     } catch (TransactionFailureException e) {
       throw new OperationFailureException(
           String.format(
               "The node with id %d cannot be deleted. Check that the node is orphaned before deletion.",
               nodeId));
     }
   }
 }
Exemplo n.º 27
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.º 28
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();
    }
  }
  @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.º 30
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();
    }
  }