/**
  * store properties into DB node
  *
  * @param node
  */
 public void setDGNode(Node node) {
   id.setProperty(node);
   name.setProperty(node);
   methodID.setProperty(node);
   startline.setProperty(node);
   node.addLabel(NEO4JAccess.ExceptionInterceptionNode);
 }
 private Node setLabels(Node node, Collection<String> labels) {
     if (labels==null || labels.isEmpty()) return node;
     for (String label : labels) {
         node.addLabel(DynamicLabel.label(label));
     }
     return node;
 }
Ejemplo n.º 3
0
  @Override
  public Object createVertex(
      final int id,
      final String type,
      final Map<String, ? extends Object> attributes,
      final Map<String, Object> outgoingEdges,
      final Map<String, Object> incomingEdges) {
    final Node node = graphDb.createNode(DynamicLabel.label(type));

    // this only works for inheritance hierarchies with
    if (ModelConstants.SUPERTYPES.containsKey(type)) {
      final String ancestor = ModelConstants.SUPERTYPES.get(type);
      node.addLabel(DynamicLabel.label(ancestor));
    }

    for (final Entry<String, ? extends Object> attribute : attributes.entrySet()) {
      final String key = attribute.getKey();
      Object value = attribute.getValue();

      // convert the value to string if it's an enum
      value = enumsToString(value);
      node.setProperty(key, value);
    }

    for (final Entry<String, Object> outgoingEdge : outgoingEdges.entrySet()) {
      final String label = outgoingEdge.getKey();
      if (outgoingEdge.getValue() instanceof Node) {
        final Node targetNode = (Node) outgoingEdge.getValue();
        node.createRelationshipTo(targetNode, relationship(label));
      }
    }

    for (final Entry<String, Object> incomingEdge : incomingEdges.entrySet()) {
      final String label = incomingEdge.getKey();
      if (incomingEdge.getValue() instanceof Node) {
        final Node sourceNode = (Node) incomingEdge.getValue();
        sourceNode.createRelationshipTo(node, relationship(label));
      }
    }

    return node;
  }
  @Test
  public void shouldEnforceUniquenessConstraintOnAddLabel() throws Exception {
    // given
    constrainedNode("Label1", "key1", "value1");

    newTransaction();

    // when
    Node node = db.createNode();
    node.setProperty("key1", "value1");
    try {
      node.addLabel(label("Label1"));

      fail("should have thrown exception");
    }
    // then
    catch (ConstraintViolationException e) {
      assertThat(e.getMessage(), containsString("\"key1\"=[value1]"));
    }
  }
Ejemplo n.º 5
0
 public void _addLabels(Node node, String[] labels) {
   for (String label : labels) node.addLabel(DynamicLabel.label(label));
 }
Ejemplo n.º 6
0
 public void _addLabel(Node node, String label) {
   node.addLabel(DynamicLabel.label(label));
 }
Ejemplo n.º 7
0
 public void _addLabels(Node node, Label[] labels) {
   for (Label label : labels) node.addLabel(label);
 }
Ejemplo n.º 8
0
 public void _addLabel(Node node, Label label) {
   node.addLabel(label);
 }
 public void add(Node node, String label) {
   node.addLabel(DynamicLabel.label(label));
   put(added, node, label);
 }