Java Code Examples for org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal#property()

The following examples show how to use org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal#property() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AddV.java    From gremlin-ogm with Apache License 2.0 6 votes vote down vote up
@Override
@SneakyThrows
public GraphTraversal<Element, Element> apply(GraphTraversalSource g) {
  GraphTraversal traversal = g.addV(element.label());
  if (element.id() != null && HasFeature.Verifier.of(g)
      .verify(supportsUserSuppliedIds(element))) {
    traversal.property(T.id, element.id());
  }
  for (Field field : keyFields(element)) {
    String key = propertyKey(field);
    Object value = propertyValue(field, element);
    if (isMissing(value)) {
      throw org.apache.tinkerpop.gremlin.object.structure.Element.Exceptions.requiredKeysMissing(
          element.getClass(), key);
    }
    traversal.property(key, value);
  }
  return traversal;
}
 
Example 2
Source File: TraversalConstructionBenchmark.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Benchmark
public GraphTraversal testAddVWithPropsChained() {
    // construct a traversal that adds 100 vertices with 32 properties each
    GraphTraversal t = null;
    for (int ix = 0; ix < 100; ix++) {
        if (null == t)
            t = g.addV("person");
        else
            t = t.addV("person");

        for (int iy = 0; iy < 32; iy++) {
            if (iy % 2 == 0)
                t = t.property("x" + String.valueOf(iy), iy * ix);
            else
                t = t.property("x" + String.valueOf(iy), String.valueOf(iy + ix));
        }
    }

    return t;
}
 
Example 3
Source File: GraphMutateBenchmark.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Benchmark
public Vertex testAddVWithPropsChained() {
    // construct a traversal that adds 100 vertices with 32 properties each
    GraphTraversal<Vertex, Vertex> t = null;
    for (int ix = 0; ix < 100; ix++) {
        if (null == t)
            t = g.addV("person");
        else
            t = t.addV("person");

        for (int iy = 0; iy < 32; iy++) {
            if (iy % 2 == 0)
                t = t.property("x" + String.valueOf(iy), iy * ix);
            else
                t = t.property("x" + String.valueOf(iy), String.valueOf(iy + ix));
        }
    }

    return t.next();
}
 
Example 4
Source File: VertexGraph.java    From gremlin-ogm with Apache License 2.0 5 votes vote down vote up
protected <V extends Vertex> GraphTraversal create(V vertex) {
  GraphTraversal traversal = g
      .addV(vertex.label());
  Object vertexId = maybeSupplyId(vertex);
  if (vertexId != null) {
    traversal.property(T.id, vertexId);
  }
  return update(traversal, vertex, Properties::all);
}
 
Example 5
Source File: EdgeGraph.java    From gremlin-ogm with Apache License 2.0 5 votes vote down vote up
<E extends Edge> GraphTraversal create(E edge, Object fromId, Object toId) {
  GraphTraversal traversal = g
      .V().hasId(fromId).as("from")
      .V().hasId(toId).as("to")
      .addE(edge.label()).as("edge").from("from");
  Object edgeId = maybeSupplyId(edge);
  if (edgeId != null) {
    traversal.property(T.id, edgeId);
  }
  return update(traversal, edge, Properties::all);
}
 
Example 6
Source File: UpdateBy.java    From gremlin-ogm with Apache License 2.0 5 votes vote down vote up
@Override
public GraphTraversal property(GraphTraversal traversal, Update update) {
  if (update.getCardinality() != null) {
    traversal.property(update.getCardinality(),
        update.getKey(),
        update.getValue(),
        update.getKeyValues());
  } else {
    traversal.property(update.getKey(),
        update.getValue());
  }
  return traversal;
}
 
Example 7
Source File: TraversalConstructionBenchmark.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Benchmark
public GraphTraversal testAddVAddEWithPropsChained() {
    // construct a traversal that adds 100 vertices with 32 properties each as well as 300 edges with 8
    // properties each
    final Random rand = new Random(584545454L);

    GraphTraversal t = null;
    for (int ix = 0; ix < 10; ix++) {
        if (null == t)
            t = g.addV("person");
        else
            t = t.addV("person");

        for (int iy = 0; iy < 32; iy++) {
            if (iy % 2 == 0)
                t = t.property("x" + String.valueOf(iy), iy * ix);
            else
                t = t.property("x" + String.valueOf(iy), String.valueOf(iy + ix));
        }

        t = t.as("person" + ix);

        if (ix > 0) {
            int edgeCount = ix == 9 ? 6 : 3;
            for (int ie = 0; ie < edgeCount; ie++) {
                t = t.addE("knows").from("person" + ix).to("person" + rand.nextInt(ix));

                for (int iy = 0; iy < 8; iy++) {
                    if (iy % 2 == 0)
                        t = t.property("x" + String.valueOf(iy), iy * ie);
                    else
                        t = t.property("x" + String.valueOf(iy), String.valueOf(iy + ie));
                }
            }
        }
    }

    return t;
}
 
Example 8
Source File: GraphMutateBenchmark.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Benchmark
public Vertex testAddVWithProps() {
    GraphTraversal<Vertex, Vertex> t = g.addV("test");
    for (int iy = 0; iy < 32; iy++) {
        if (iy % 2 == 0)
            t = t.property("x" + String.valueOf(iy), iy);
        else
            t = t.property("x" + String.valueOf(iy), String.valueOf(iy));
    }
    return t.next();
}
 
Example 9
Source File: GraphMutateBenchmark.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Benchmark
public Edge testAddVAddEWithPropsChained() {
    // construct a traversal that adds 100 vertices with 32 properties each as well as 300 edges with 8
    // properties each
    final Random rand = new Random(584545454L);

    GraphTraversal<Vertex, ?> t = null;
    for (int ix = 0; ix < 10; ix++) {
        if (null == t)
            t = g.addV("person");
        else
            t = t.addV("person");

        for (int iy = 0; iy < 32; iy++) {
            if (iy % 2 == 0)
                t = t.property("x" + String.valueOf(iy), iy * ix);
            else
                t = t.property("x" + String.valueOf(iy), String.valueOf(iy + ix));
        }

        t = t.as("person" + ix);

        if (ix > 0) {
            int edgeCount = ix == 9 ? 6 : 3;
            for (int ie = 0; ie < edgeCount; ie++) {
                t = t.addE("knows").from("person" + ix).to("person" + rand.nextInt(ix));

                for (int iy = 0; iy < 8; iy++) {
                    if (iy % 2 == 0)
                        t = t.property("x" + String.valueOf(iy), iy * ie);
                    else
                        t = t.property("x" + String.valueOf(iy), String.valueOf(iy + ie));
                }
            }
        }
    }

    final Edge e = (Edge) t.next();
    return e;
}