Package com.tinkerpop.blueprints.pgm

Examples of com.tinkerpop.blueprints.pgm.Vertex


   * @param database database in which vertex will be stored
   * @param value
   * @return
   */
  public static Vertex getVertexForBasicObject(IndexableGraph 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));
    } else {
      throw new ObjectIsNotARealLiteralException(value, valueClass);
      // TODO do not forget to set id property
    }
    returned.setProperty(Properties.type.name(), valueClass.getName());
    return returned;
  }
View Full Code Here


  }

  public void loadCollection(Collection collection, Map<String, Object> objectsBeingAccessed) {
    try {
      for(Edge e : rootVertex.getOutEdges(GraphUtils.getEdgeNameFor(property))) {
        Vertex value = e.getInVertex();
        Object temporaryValue = GraphUtils.createInstance(classLoader, value, repository);
        if(repository.containsKey(temporaryValue.getClass())) {
          FinderCrudService service = repository.get(temporaryValue.getClass());
          if (service instanceof BluePrintsBackedFinderService) {
            BluePrintsBackedFinderService blueprints= (BluePrintsBackedFinderService) service;
View Full Code Here

   * Local delete implementation
   * @param toDelete
   */
  private void doDelete(DataType toDelete, Map<String, Object> objectsBeingAccessed) {
    String vertexId = getIdVertexId(toDelete, idProperty);
    Vertex objectVertex = GraphUtils.locateVertex(database, Properties.vertexId.name(), vertexId);
    if(objectVertex!=null) {
      Map<Property, Collection<CascadeType>> containedProperties = getContainedProperties(toDelete);
      for(Property p : containedProperties.keySet()) {
        Class<?> rawPropertyType = p.getType();
        Collection<CascadeType> toCascade = containedProperties.get(p);
View Full Code Here

    Iterable<Edge> edges = objectVertex.getOutEdges(edgeNameFor);
    if (logger.isLoggable(Level.FINEST)) {
      logger.log(Level.FINEST, "deleting edge "+edgeNameFor+" of "+objectVertex.getProperty(Properties.vertexId.name()));
    }
    for(Edge e : edges) {
      Vertex valueVertex = e.getInVertex();
      database.removeEdge(e);
      // Now what to do with vertex ? Delete it ?
      if(toCascade.contains(CascadeType.REMOVE)) {
        // yes, delete it forever (but before, see if there aren't more datas to delete
        deleteOutEdgeVertex(objectVertex, valueVertex, p.get(toDelete), 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

   * @param objectsBeingUpdated map containing subgraph of obejcts currently being updated, this is used to avoid loops, and NOT as a cache
   * @return updated object
   */
  private DataType doUpdate(DataType toUpdate, CascadeType cascade, Map<String, Object> objectsBeingUpdated) {
    String objectVertexId = getIdVertexId(toUpdate, idProperty);
    Vertex objectVertex = GraphUtils.locateVertex(database, Properties.vertexId, objectVertexId);
    // it's in fact an object creation
    if(objectVertex==null) {
      if (logger.isLoggable(Level.FINER)) {
        logger.log(Level.FINER, "object "+objectVertexId.toString()+" has never before been seen in graph, so create central node for it");
      }
      objectVertex = database.addVertex(objectVertexId);
      // As an aside, we add some indications regarding object id
      objectVertex.setProperty(Properties.vertexId.name(), objectVertexId);
      objectVertex.setProperty(Properties.kind.name(), Kind.managed.name());
      objectVertex.setProperty(Properties.type.name(), toUpdate.getClass().getName());
    }
    DataType updated = (DataType) objectsBeingUpdated.get(objectVertexId);
    if(updated==null) {
      try {
        objectsBeingUpdated.put(objectVertexId, toUpdate);
View Full Code Here

      Iterable<Edge> existingIterator = rootVertex.getOutEdges(GraphUtils.getEdgeNameFor(p));
      // Do not change previously existing vertices if they correspond to new ones
      Collection<Vertex> newVertices = createVerticesFor(value, cascade, objectsBeingAccessed);
      Map<Vertex, Edge> oldVertices = new HashMap<Vertex, Edge>();
      for(Edge e : existingIterator) {
        Vertex inVertex = e.getInVertex();
        if(newVertices.contains(inVertex)) {
          newVertices.remove(inVertex);
        } else {
          oldVertices.put(inVertex, e);
        }
View Full Code Here

   */
  private void updateSingle(Property p, DataType toUpdate, Vertex rootVertex, CascadeType cascade, Map<String, Object> objectsBeingAccessed) {
    Object value = p.get(toUpdate);
    // As a convention, null values are never stored
    if(value!=null) {
      Vertex valueVertex = getVertexFor(value, cascade, objectsBeingAccessed);
      Edge link = null;
      // Get previously existing vertex
      Iterator<Edge> existingIterator = rootVertex.getOutEdges(GraphUtils.getEdgeNameFor(p)).iterator();
      // property is single-valued, so iteration can be done at most one
      if(existingIterator.hasNext()) {
        // There is an existing edge, change its target and maybe delete previous one
        Edge existing = existingIterator.next();
        if(existing.getInVertex().equals(valueVertex)) {
          // Nothing to do
          link = existing;
        } else {
          // delete edge (TODO maybe delete vertex)
          database.removeEdge(existing);
          link = database.addEdge(rootVertex.getId().toString()+"_to_"+valueVertex.getId().toString(),
                  rootVertex, valueVertex, GraphUtils.getEdgeNameFor(p));
        }
      }
      if(existingIterator.hasNext()) {
        if (logger.isLoggable(Level.SEVERE)) {
          // There is some incoherent data in graph .. log it !
          StringBuilder sOut = new StringBuilder("An object with the following monovalued property\n").append(p.toGenericString()).append(" is linked to more than one vertex :");
          while(existingIterator.hasNext()) {
            sOut.append("\n\t").append(existingIterator.next().getInVertex().toString());
          }
          logger.log(Level.SEVERE, "Graph contains some incoherence :"+sOut.toString());
        }
      } else {
        if(link==null)
          // Now create edge
          link = database.addEdge(rootVertex.getId().toString()+"_to_"+valueVertex.getId().toString(),
                  rootVertex, valueVertex, GraphUtils.getEdgeNameFor(p));
      }
    }
  }
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

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.