Esempio n. 1
0
 public void addOutEdge(final Edge edge) {
   boolean adding = false;
   String label = edge.getLabel();
   // Set<String> outs = getOutEdges();
   Set<String> outs = getOutEdgesSet(label);
   synchronized (outs) {
     if (!outs.contains((String) edge.getId())) {
       adding = true;
       outs.add((String) edge.getId());
     }
   }
   if (adding) {
     getParent().startTransaction(this);
     Map map = getOutDirtyMap();
     synchronized (map) {
       map.put(label, true);
     }
     Set<Edge> outLabelObjs = getOutEdgeCache(label);
     synchronized (outLabelObjs) {
       outLabelObjs.add(edge);
     }
     // outDirty_ = true;
     // Set<Edge> outObjs = getOutEdgeObjects();
     // synchronized (outObjs) {
     // outObjs.add(edge);
     // }
   }
   // setProperty(DominoVertex.OUT_NAME, outEdges_);
 }
Esempio n. 2
0
  public void addInEdge(final Edge edge) {
    boolean adding = false;
    String label = edge.getLabel();
    // Set<String> ins = getInEdges();
    Set<String> ins = getInEdgesSet(label);
    synchronized (ins) {
      if (!ins.contains((String) edge.getId())) {
        adding = true;
        ins.add((String) edge.getId());
      }
    }
    if (adding) {
      getParent().startTransaction(this);
      Map map = getInDirtyMap();
      synchronized (map) {
        map.put(label, true);
      }
      Set<Edge> inLabelObjs = getInEdgeCache(label);
      synchronized (inLabelObjs) {
        inLabelObjs.add(edge);
      }

      // inDirty_ = true;
      // Set<Edge> inObjs = getInEdgeObjects();
      // synchronized (inObjs) {
      // inObjs.add(edge);
      // }
    }
  }
Esempio n. 3
0
  public void removeEdge(final Edge edge) {
    getParent().startTransaction(this);
    String label = edge.getLabel();

    boolean inChanged = false;
    Set<String> ins = getInEdgesSet(label);
    if (ins != null) {
      //			System.out.println("Removing an in edge from " + label + " with id " + edge.getId() + "
      // from a vertex of type "
      //					+ getProperty("Form"));
      synchronized (ins) {
        inChanged = ins.remove(edge.getId());
      }
    } else {
      //			System.out.println("in edges were null from a vertex of type " + getProperty("Form") + ":
      // " + getId());
    }
    // Set<Edge> inObjs = getInEdgeObjects();
    // synchronized (inObjs) {
    // inObjs.remove(edge);
    // }
    if (inChanged) {
      //			System.out.println("Ins were changed so recording cache invalidation...");
      Set<Edge> inObjsLabel = getInEdgeCache(label);
      synchronized (inObjsLabel) {
        inObjsLabel.remove(edge);
      }
      Map<String, Boolean> inDirtyMap = getInDirtyMap();
      synchronized (inDirtyMap) {
        inDirtyMap.put(label, true);
      }
    }

    boolean outChanged = false;
    Set<String> outs = getOutEdgesSet(label);
    if (outs != null) {
      //			System.out.println("Removing an out edge from " + label + " with id " + edge.getId() + "
      // from a vertex of type "
      //					+ getProperty("Form"));
      synchronized (outs) {
        outChanged = outs.remove(edge.getId());
      }
    } else {
      //			System.out.println("out edges were null from a vertex of type " + getProperty("Form") +
      // ": " + getId());
    }
    if (outChanged) {
      //			System.out.println("Out were changed so recording cache invalidation...");
      Set<Edge> outObjsLabel = getOutEdgeCache(label);
      synchronized (outObjsLabel) {
        outObjsLabel.remove(edge);
      }
      Map<String, Boolean> outDirtyMap = getOutDirtyMap();
      synchronized (outDirtyMap) {
        outDirtyMap.put(label, true);
      }
    }
  }
Esempio n. 4
0
 static Edge addEdge(Graph graph, Edge edge) {
   Edge newEdge = graph.getEdge(edge.getId());
   if (null == newEdge) {
     Vertex outVertex = addNode(graph, edge.getVertex(Direction.OUT));
     Vertex inVertex = addNode(graph, edge.getVertex(Direction.IN));
     String label = edge.getLabel();
     newEdge = graph.addEdge(edge.getId(), outVertex, inVertex, label);
     copyProperties(edge, edge);
   }
   return newEdge;
 }
  public void run2() {
    long testStartTime = System.nanoTime();
    marktime = System.nanoTime();

    try {
      timelog("Beginning graph2 test...");

      for (Vertex v : graph.getVertices()) {
        System.out.println("RESULT: " + v.getId().toString());
      }

      for (Edge e : graph.getEdges()) {
        System.out.println("RESULT: " + e.getId().toString() + ":" + e.getLabel());
      }
      //			lotus.domino.Session s = Factory.terminate();
      //			s.recycle();
      graph = null;
      System.gc();
    } catch (Throwable t) {
      t.printStackTrace();
    }
    long testEndTime = System.nanoTime();
    System.out.println(
        "Completed "
            + getClass().getSimpleName()
            + " run2 in "
            + ((testEndTime - testStartTime) / 1000000)
            + " ms");
  }
Esempio n. 6
0
  /*
   * (non-Javadoc)
   *
   * @see
   * com.tinkerpop.blueprints.Graph#removeEdge(com.tinkerpop.blueprints
   * .pgm.Edge)
   */
  @Override
  public void removeEdge(final Edge edge) {
    autoStartTransaction();

    assert edge instanceof DexEdge;
    getRawGraph().drop((Long) edge.getId());
  }
Esempio n. 7
0
 private void writeEdgeProperties(Writer writer, Edge e) throws IOException {
   Object blueprintsId = e.getId();
   if (!useId) {
     writeKey(writer, edgeIdKey);
     if (blueprintsId instanceof Number) {
       writeNumberProperty(writer, (Number) blueprintsId);
     } else {
       writeStringProperty(writer, blueprintsId);
     }
   }
   writeProperties(writer, e);
 }
  /**
   * Deletes the edge between outvertex and inVertex. The edge is for attribute attributeName of
   * outVertex
   *
   * @param outVertex
   * @param inVertex
   * @param attributeName
   * @throws AtlasException
   */
  protected void deleteEdgeBetweenVertices(Vertex outVertex, Vertex inVertex, String attributeName)
      throws AtlasException {
    LOG.debug(
        "Removing edge from {} to {} with attribute name {}",
        string(outVertex),
        string(inVertex),
        attributeName);
    String typeName = GraphHelper.getTypeName(outVertex);
    String outId = GraphHelper.getIdFromVertex(outVertex);
    Id.EntityState state = GraphHelper.getState(outVertex);
    if ((outId != null && RequestContext.get().isDeletedEntity(outId))
        || state == Id.EntityState.DELETED) {
      // If the reference vertex is marked for deletion, skip updating the reference
      return;
    }

    IDataType type = typeSystem.getDataType(IDataType.class, typeName);
    AttributeInfo attributeInfo = getFieldMapping(type).fields.get(attributeName);
    String propertyName = GraphHelper.getQualifiedFieldName(type, attributeName);
    String edgeLabel = EDGE_LABEL_PREFIX + propertyName;
    Edge edge = null;

    switch (attributeInfo.dataType().getTypeCategory()) {
      case CLASS:
        // If its class attribute, its the only edge between two vertices
        if (attributeInfo.multiplicity.nullAllowed()) {
          edge = GraphHelper.getEdgeForLabel(outVertex, edgeLabel);
          if (shouldUpdateReverseAttribute) {
            GraphHelper.setProperty(outVertex, propertyName, null);
          }
        } else {
          // Cannot unset a required attribute.
          throw new NullRequiredAttributeException(
              "Cannot unset required attribute "
                  + GraphHelper.getQualifiedFieldName(type, attributeName)
                  + " on "
                  + string(outVertex)
                  + " edge = "
                  + edgeLabel);
        }
        break;

      case ARRAY:
        // If its array attribute, find the right edge between the two vertices and update array
        // property
        List<String> elements = outVertex.getProperty(propertyName);
        if (elements != null) {
          elements =
              new ArrayList<>(
                  elements); // Make a copy, else list.remove reflects on titan.getProperty()
          for (String elementEdgeId : elements) {
            Edge elementEdge = graphHelper.getEdgeByEdgeId(outVertex, edgeLabel, elementEdgeId);
            if (elementEdge == null) {
              continue;
            }

            Vertex elementVertex = elementEdge.getVertex(Direction.IN);
            if (elementVertex.getId().toString().equals(inVertex.getId().toString())) {
              edge = elementEdge;

              // TODO element.size includes deleted items as well. should exclude
              if (!attributeInfo.multiplicity.nullAllowed()
                  && elements.size() <= attributeInfo.multiplicity.lower) {
                // Deleting this edge would violate the attribute's lower bound.
                throw new NullRequiredAttributeException(
                    "Cannot remove array element from required attribute "
                        + GraphHelper.getQualifiedFieldName(type, attributeName)
                        + " on "
                        + string(outVertex)
                        + " "
                        + string(elementEdge));
              }

              if (shouldUpdateReverseAttribute) {
                // if composite attribute, remove the reference as well. else, just remove the edge
                // for example, when table is deleted, process still references the table
                // but when column is deleted, table will not reference the deleted column
                LOG.debug(
                    "Removing edge {} from the array attribute {}",
                    string(elementEdge),
                    attributeName);
                elements.remove(elementEdge.getId().toString());
                GraphHelper.setProperty(outVertex, propertyName, elements);
                break;
              }
            }
          }
        }
        break;

      case MAP:
        // If its map attribute, find the right edge between two vertices and update map property
        List<String> keys = outVertex.getProperty(propertyName);
        if (keys != null) {
          keys =
              new ArrayList<>(
                  keys); // Make a copy, else list.remove reflects on titan.getProperty()
          for (String key : keys) {
            String keyPropertyName = GraphHelper.getQualifiedNameForMapKey(propertyName, key);
            String mapEdgeId = outVertex.getProperty(keyPropertyName);
            Edge mapEdge = graphHelper.getEdgeByEdgeId(outVertex, keyPropertyName, mapEdgeId);
            Vertex mapVertex = mapEdge.getVertex(Direction.IN);
            if (mapVertex.getId().toString().equals(inVertex.getId().toString())) {
              // TODO keys.size includes deleted items as well. should exclude
              if (attributeInfo.multiplicity.nullAllowed()
                  || keys.size() > attributeInfo.multiplicity.lower) {
                edge = mapEdge;
              } else {
                // Deleting this entry would violate the attribute's lower bound.
                throw new NullRequiredAttributeException(
                    "Cannot remove map entry "
                        + keyPropertyName
                        + " from required attribute "
                        + GraphHelper.getQualifiedFieldName(type, attributeName)
                        + " on "
                        + string(outVertex)
                        + " "
                        + string(mapEdge));
              }

              if (shouldUpdateReverseAttribute) {
                // remove this key
                LOG.debug(
                    "Removing edge {}, key {} from the map attribute {}",
                    string(mapEdge),
                    key,
                    attributeName);
                keys.remove(key);
                GraphHelper.setProperty(outVertex, propertyName, keys);
                GraphHelper.setProperty(outVertex, keyPropertyName, null);
              }
              break;
            }
          }
        }
        break;

      case STRUCT:
      case TRAIT:
        break;

      default:
        throw new IllegalStateException(
            "There can't be an edge from "
                + string(outVertex)
                + " to "
                + string(inVertex)
                + " with attribute name "
                + attributeName
                + " which is not class/array/map attribute");
    }

    if (edge != null) {
      deleteEdge(edge, false);
      RequestContext requestContext = RequestContext.get();
      GraphHelper.setProperty(
          outVertex,
          Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY,
          requestContext.getRequestTime());
      requestContext.recordEntityUpdate(outId);
    }
  }