Package com.tinkerpop.blueprints.pgm

Examples of com.tinkerpop.blueprints.pgm.Vertex


    String edgeNameFor = GraphUtils.getEdgeNameFor(p);
    Iterable<Edge> edges = objectVertex.getOutEdges(edgeNameFor);
    Map values = (Map) p.get(toDelete);
    Map<Vertex, Edge> oldVertices = new HashMap<Vertex, Edge>();
    for(Edge e : edges) {
      Vertex inVertex = e.getInVertex();
      oldVertices.put(inVertex, e);
    }
    for(Object v : values.entrySet()) {
      Vertex valueVertex = getVertexFor(v, CascadeType.REFRESH, objectsBeingAccessed);
      if(oldVertices.containsKey(valueVertex)) {
        Edge oldEdge = oldVertices.remove(valueVertex);
        database.removeEdge(oldEdge);
        if(toCascade.contains(CascadeType.REMOVE)) {
          deleteOutEdgeVertex(objectVertex, valueVertex, v, objectsBeingAccessed);
View Full Code Here


    String edgeNameFor = GraphUtils.getEdgeNameFor(p);
    Iterable<Edge> edges = objectVertex.getOutEdges(edgeNameFor);
    Collection values = (Collection) p.get(toDelete);
    Map<Vertex, Edge> oldVertices = new HashMap<Vertex, Edge>();
    for(Edge e : edges) {
      Vertex inVertex = e.getInVertex();
      oldVertices.put(inVertex, e);
    }
    for(Object v : values) {
      Vertex valueVertex = getVertexFor(v, CascadeType.REFRESH, objectsBeingAccessed);
      if(oldVertices.containsKey(valueVertex)) {
        Edge oldEdge = oldVertices.remove(valueVertex);
        database.removeEdge(oldEdge);
        if(toCascade.contains(CascadeType.REMOVE)) {
          deleteOutEdgeVertex(objectVertex, valueVertex, v, objectsBeingAccessed);
View Full Code Here

   * @param valueVertex value vertex to remove
   * @param value object value
   */
  private <Type> void deleteOutEdgeVertex(Vertex objectVertex, Vertex valueVertex, Type value, Map<String, Object> objectsBeingUpdated) {
    // Locate vertex
    Vertex knownValueVertex = getVertexFor(value, CascadeType.REFRESH, objectsBeingUpdated);
    // Ensure vertex is our out one
    if(valueVertex.equals(knownValueVertex)) {
      // Delete vertex and other associated ones, only if they have no other input links (elsewhere delete is silently ignored)
      if(valueVertex.getInEdges().iterator().hasNext()) {
        // There are incoming edges to that vertex. Do nothing but log it
        if (logger.isLoggable(Level.FINE)) {
          logger.log(Level.FINE, "while deleting "+objectVertex.getProperty(Properties.vertexId.name())+"" +
              " we tried to delete "+knownValueVertex.getProperty(Properties.vertexId.name())+"" +
                  " which has other incoming edges, so we didn't deleted it");
        }
      } else {
        // OK, time to delete value vertex. Is it a managed node ?
        if(repository.containsKey(value.getClass())) {
          FinderCrudService<Type, ?> finderCrudService = (FinderCrudService<Type, ?>) repository.get(value.getClass());
          finderCrudService.delete(value);
        } else {
          // Literal nodes can be deleted without any trouble
          database.removeVertex(valueVertex);
        }
      }
    } else {
      if (logger.isLoggable(Level.WARNING)) {
        logger.log(Level.WARNING, "that's strange : value "+value+" is associated to "+knownValueVertex.getProperty(Properties.vertexId.name())+"" +
            " which blueprints says is different from "+valueVertex.getProperty(Properties.vertexId.name())+"." +
                " Under those circumstances, we can delete neither of them");
      }
    }
  }
View Full Code Here

   * @return
   */
  public Vertex getVertexFor(Object value, CascadeType cascade, Map<String, Object> objectsBeingUpdated) {
    // Here we suppose the service is the right one for the job (which may not be the case)
    if(containedClass.isInstance(value)) {
      Vertex returned = getIdVertexFor(containedClass.cast(value));
      if(returned==null) {
        doUpdate(containedClass.cast(value), cascade, objectsBeingUpdated);
        returned = getIdVertexFor(containedClass.cast(value));
      } else {
        // vertex already exist, but maybe object needs an update
View Full Code Here

   * @param objectsBeingAccessed map of objects currently being accessed, it avoid some loops during loading, but is absolutely NOT a persistent cache
   * @see #loadObject(String, Vertex, Map)
   */
  public DataType loadObject(String objectVertexId, Map<String, Object> objectsBeingAccessed) {
    // If cast fails, well, that's some fuckin mess, no ?
    Vertex objectVertex = GraphUtils.locateVertex(database, Properties.vertexId, objectVertexId);
    return persister.loadObject(this, objectVertexId, objectVertex, objectsBeingAccessed);
  }
View Full Code Here

                return STRING_CLASS;
            } else {
                Iterator<Edge> typeIterator = vertex.getOutEdges(IndexableGraphBackedFinderService.TYPE_EDGE_NAME).iterator();
                if(typeIterator.hasNext()) {
                    Edge toType = typeIterator.next();
                    Vertex type = toType.getInVertex();
                    // Do not use ClassLiteral here as this method must be blazing fast
                    return IndexableGraphBackedFinderService.classTransformer.extractClassIn(service.getDriver().getValue(type).toString());
                } else {
                    return STRING_CLASS;
                }
View Full Code Here

    Set<String> targetTypes = new TreeSet<String>();
    Map<Object, AtomicLong> edgesPerInVertices = new HashMap<Object, AtomicLong>();
    for(Edge e : correspondingEdges) {
      name = e.getLabel();
      if(GraphUtils.isInNamedGraphs(e, namedGraphs)) {
        Vertex inVertex = e.getOutVertex();
        if(!edgesPerInVertices.containsKey(inVertex)) {
          edgesPerInVertices.put(inVertex, new AtomicLong(0));
        }
        edgesPerInVertices.get(inVertex).incrementAndGet();
        Vertex outVertex = e.getInVertex();
        targetTypes.add(driver.getEffectiveType(outVertex));
      }
    }
    if(edgesPerInVertices.size()==0)
      throw new NoEdgeInNamedGraphsException("no edge named \""+name+"\" is declared in named graphs "+namedGraphs);
View Full Code Here

  @Override
  public Vertex loadVertexFor(String objectVertexId, String className) {
    CloseableSequence<Vertex> matching = database.getIndex(Index.VERTICES, Vertex.class).get(Properties.value.name(), objectVertexId);
    if (matching.hasNext()) {
      while (matching.hasNext()) {
        Vertex vertex = matching.next();
        String vertexTypeName = getEffectiveType(vertex);
        switch (GraphUtils.getKindOf(vertex)) {
        case literal:
        case bnode:
        case uri:
View Full Code Here

   */
  @Override
  protected Vertex createEmptyVertex(String vertexId, Class<? extends Object> valueClass) {
    // technical vertex id is no more used by gaedo which only rley upon the
    // getIdOfVertex method !
    Vertex returned = database.addVertex(valueClass.getName() + ":" + vertexId);
    returned.setProperty(Properties.value.name(), vertexId);
    if (Literals.containsKey(valueClass)) {
      // some literals aren't so ... literal, as they can accept incoming
      // connections (like classes)
      returned.setProperty(Properties.kind.name(), Literals.get(valueClass).getKind().name());
      returned.setProperty(Properties.type.name(), TypeUtils.getType(valueClass));
    } else {
      if (repository.containsKey(valueClass)) {
        returned.setProperty(Properties.kind.name(), Kind.uri.name());
      } else if (Tuples.containsKey(valueClass)) {
        // some literals aren't so ... literal, as they can accept
        // incoming connections (like classes)
        returned.setProperty(Properties.kind.name(), Tuples.get(valueClass).getKind().name());
      }
      // obtain vertex for type
      Vertex classVertex = classTransformer.getVertexFor(getDriver(), valueClass);
      Edge toType = getDriver().createEdgeFor(returned, classVertex, TypeProperty.INSTANCE);
      /*
       * Make sure literals are literals by changing that particular edge
       * context to a null value. Notice we COULD have stored literal type
       * as a property, instead of using
View Full Code Here

   * @param database database in which vertex will be stored
   * @param value
   * @return
   */
  public static Vertex getVertexForLiteral(GraphDatabaseDriver database, Object value) {
    Vertex returned = null;
    // Now distinct behaviour between known objects and unknown ones
    Class<? extends Object> valueClass = value.getClass();
    if(Literals.containsKey(valueClass)) {
      LiteralTransformer transformer = Literals.get(valueClass);
      returned = transformer.getVertexFor(database, valueClass.cast(value));
View Full Code Here

TOP

Related Classes of com.tinkerpop.blueprints.pgm.Vertex

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.