Package com.tinkerpop.blueprints

Examples of com.tinkerpop.blueprints.Edge


      // ordering.
      int order = 0;
      for(Object element : value) {
        if(allVertices.containsKey(element)) {
          Vertex vertex = allVertices.get(element);
          Edge edgeForVertex;
          if (savedEdges.containsKey(vertex)) {
            List<Edge> edges = savedEdges.get(vertex);
            edgeForVertex = edges.remove(0);
            if (edges.size() == 0)
              savedEdges.remove(vertex);
          } else
            edgeForVertex = driver.createEdgeFor(rootVertex, vertex, p);

          // Add a fancy-schmancy property to maintain order in this town (this property is NOT indexed)
          edgeForVertex.setProperty(Properties.collection_index.name(), order++);
        } else {
          // Element is a literal value, so it won't require a vertex, but a literal saving
          AbstractPropertyAdapter elementByIndexProperty = new LiteralInCollectionUpdaterProperty(p, order, element);
          updateLiteralPropertyIn(service.getDatabase(), toUpdate, rootVertex, elementByIndexProperty, element);
          suspectProperties.remove(GraphUtils.getEdgeNameFor(elementByIndexProperty));
View Full Code Here


     * Totally crazy confident non-nullity lack of test : this method is
     * only called when cascade type is either PERSIST or MERGE. In both
     * cases the call to getVertexFor will create the vertex if missing. As
     * a consequence there is no need for nullity check.
     */
    Edge link = null;
    // Get previously existing vertex
    List<Edge> matching = CollectionUtils.asList(service.getStrategy().getOutEdgesFor(rootVertex, p));
    // property is single-valued, so iteration can be done at most one
    if (matching.size() == 1) {
      // There is an existing edge, change its target and maybe delete
      // previous one
      Edge existing = matching.get(0);
      if (valueVertex != null && existing.getVertex(Direction.IN).equals(valueVertex)) {
        // Nothing to do
        link = existing;
      } else {
        // delete old edge (if it exists)
        GraphUtils.removeSafely(database, existing);
View Full Code Here

    private <DataType> void loadSingle(GraphDatabaseDriver driver, GraphMappingStrategy strategy, ClassLoader classloader, ServiceRepository repository, Property p, DataType returned, Vertex objectVertex, ObjectCache objectsBeingAccessed) {
        Iterator<Edge> iterator = strategy.getOutEdgesFor(objectVertex, p).iterator();
        Object value = null;
        if (iterator.hasNext()) {
            // yeah, there is a value !
            Edge edge = iterator.next();
            Vertex firstVertex = edge.getVertex(Direction.IN);
            value = GraphUtils.createInstance(driver, strategy, classloader, firstVertex, p.getType(), repository, objectsBeingAccessed);
            if (repository.containsKey(value.getClass())) {
                // value requires fields loading
                AbstractBluePrintsBackedFinderService<IndexableGraph, DataType, ?> blueprints = (AbstractBluePrintsBackedFinderService<IndexableGraph, DataType, ?>) repository.get(value.getClass());
                value = loadObject(blueprints, firstVertex, objectsBeingAccessed);
View Full Code Here

    private <DataType> void loadSingle(GraphDatabaseDriver driver, GraphMappingStrategy strategy, ClassLoader classloader, ServiceRepository repository, Property p, DataType returned, Vertex objectVertex, ObjectCache objectsBeingAccessed) {
        Iterator<Edge> iterator = strategy.getOutEdgesFor(objectVertex, p).iterator();
        Object value = null;
        if (iterator.hasNext()) {
            // yeah, there is a value !
            Edge edge = iterator.next();
            Vertex firstVertex = edge.getVertex(Direction.IN);
            value = GraphUtils.createInstance(driver, strategy, classloader, firstVertex, p.getType(), repository, objectsBeingAccessed);
            if (repository.containsKey(value.getClass())) {
                // value requires fields loading
                AbstractBluePrintsBackedFinderService<IndexableGraph, DataType, ?> blueprints = (AbstractBluePrintsBackedFinderService<IndexableGraph, DataType, ?>) repository.get(value.getClass());
                value = loadObject(blueprints, firstVertex, objectsBeingAccessed);
View Full Code Here

    return vertex.getProperty(Properties.value.name());
  }

  public Edge createEdgeFor(Vertex fromVertex, Vertex toVertex, Property property) {
    String edgeNameFor = GraphUtils.getEdgeNameFor(property);
    Edge returned = database.addEdge(getEdgeId(fromVertex, toVertex, property), fromVertex, toVertex, edgeNameFor);
    // Did you know labels are not edges properties ? Absolutely stunning
    // discovery !
    // database.getIndex(IndexNames.EDGES.getIndexName(),
    // Edge.class).put("label", edgeNameFor, returned);
View Full Code Here

            if(Kind.literal.equals(GraphUtils.getKindOf(vertex))) {
                // a literal with no type information should always been considered a string literal
            } else {
                Iterator<Edge> typeIterator = vertex.getEdges(Direction.OUT, IndexableGraphBackedFinderService.TYPE_EDGE_NAME).iterator();
                if(typeIterator.hasNext()) {
                    Edge toType = typeIterator.next();
                    Vertex type = toType.getVertex(Direction.IN);
                    // Do not use ClassLiteral here as this method must be blazing fast
                    String value = type.getProperty(Properties.value.name());
                    /*
                     *  usage of edge implies we refer to a remote class vertex, in which class is stored as an URI
                     *  (for compliance with the URI kind we set for class vertices). As a consequence, we have to use
View Full Code Here

   */
  public static void removeSafely(Graph database, Edge existing) {
    if (logger.isLoggable(REMOVAL_LOG_LEVEL)) {
      logger.log(REMOVAL_LOG_LEVEL, "removing safely " + existing);
    }
    Edge toRemove = null;
    if ((toRemove = database.getEdge(existing.getId())) == null) {
      if (logger.isLoggable(Level.WARNING)) {
        logger.log(Level.WARNING, "We tried to remove non existing edge " + toString(existing));
      }
    } else {
View Full Code Here

            oldVertices.put(inVertex, e);
        }
        for (Object v : values.entrySet()) {
            Vertex valueVertex = service.getVertexFor(v, CascadeType.REFRESH, objectsBeingAccessed);
            if (valueVertex!=null && oldVertices.containsKey(valueVertex)) {
                Edge oldEdge = oldVertices.remove(valueVertex);
                GraphUtils.removeSafely(database, oldEdge);
                if (toCascade.contains(CascadeType.REMOVE)) {
                    service.deleteOutEdgeVertex(objectVertex, valueVertex, v, objectsBeingAccessed);
                }
            }
View Full Code Here

        for (Object v : values) {
          // already heard about null-containing collections ? I do know them, and they're pure EVIL
          if(v!=null) {
              Vertex valueVertex = service.getVertexFor(v, CascadeType.REFRESH, objectsBeingAccessed);
              if (valueVertex !=null && oldVertices.containsKey(valueVertex)) {
                  Edge oldEdge = oldVertices.remove(valueVertex);
                  GraphUtils.removeSafely(database, oldEdge);
                  if (toCascade.contains(CascadeType.REMOVE)) {
                      service.deleteOutEdgeVertex(objectVertex, valueVertex, v, objectsBeingAccessed);
                  }
              }
View Full Code Here

      // ordering.
      int order = 0;
      for(Object element : value) {
        if(allVertices.containsKey(element)) {
          Vertex vertex = allVertices.get(element);
          Edge edgeForVertex;
          if (savedEdges.containsKey(vertex)) {
            List<Edge> edges = savedEdges.get(vertex);
            edgeForVertex = edges.remove(0);
            if (edges.size() == 0)
              savedEdges.remove(vertex);
          } else
            edgeForVertex = driver.createEdgeFor(rootVertex, vertex, p);

          // Add a fancy-schmancy property to maintain order in this town (this property is NOT indexed)
          edgeForVertex.setProperty(Properties.collection_index.name(), order++);
        } else {
          // Element is a literal value, so it won't require a vertex, but a literal saving
          AbstractPropertyAdapter elementByIndexProperty = new LiteralInCollectionUpdaterProperty(p, order, element);
          updateLiteralPropertyIn(service.getDatabase(), toUpdate, rootVertex, elementByIndexProperty, element);
          suspectProperties.remove(GraphUtils.getEdgeNameFor(elementByIndexProperty));
View Full Code Here

TOP

Related Classes of com.tinkerpop.blueprints.Edge

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.