Java Code Examples for org.apache.tinkerpop.gremlin.structure.util.detached.DetachedFactory#detach()

The following examples show how to use org.apache.tinkerpop.gremlin.structure.util.detached.DetachedFactory#detach() . 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: BytecodeHelper.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
public static void detachElements(final Bytecode bytecode) {
    for (final Bytecode.Instruction instruction : bytecode.getInstructions()) {
        final Object[] arguments = instruction.getArguments();
        for (int i = 0; i < arguments.length; i++) {
            if (arguments[i] instanceof Bytecode)
                detachElements((Bytecode) arguments[i]);
            else if(arguments[i] instanceof List) {
                final List<Object> list = new ArrayList<>();
                for(final Object object : (List)arguments[i]) {
                    list.add( DetachedFactory.detach(object, false));
                }
                arguments[i] = list;
            }
            else
                arguments[i] = DetachedFactory.detach(arguments[i], false);
        }
    }
}
 
Example 2
Source File: TestLoadEdge.java    From sqlg with MIT License 6 votes vote down vote up
@Test
public void shouldConstructDetachedEdge() {
    Graph g = this.sqlgGraph;
    loadModern();
    assertModernGraph(g, true, false);
    Edge e = g.traversal().E(convertToEdgeId("marko", "knows", "vadas")).next();
    e.property("year", 2002);
    g.tx().commit();
    e = g.traversal().E(convertToEdgeId("marko", "knows", "vadas")).next();
    final DetachedEdge detachedEdge = DetachedFactory.detach(e, true);
    Assert.assertEquals(convertToEdgeId("marko", "knows", "vadas"), detachedEdge.id());

    Assert.assertEquals("knows", detachedEdge.label());
    Assert.assertEquals(DetachedVertex.class, detachedEdge.vertices(Direction.OUT).next().getClass());
    Assert.assertEquals(convertToVertexId("marko"), detachedEdge.vertices(Direction.OUT).next().id());
    Assert.assertEquals("person", detachedEdge.vertices(Direction.IN).next().label());
    Assert.assertEquals(DetachedVertex.class, detachedEdge.vertices(Direction.IN).next().getClass());
    Assert.assertEquals(convertToVertexId("vadas"), detachedEdge.vertices(Direction.IN).next().id());
    Assert.assertEquals("person", detachedEdge.vertices(Direction.IN).next().label());

    Assert.assertEquals(2, IteratorUtils.count(detachedEdge.properties()));
    Assert.assertEquals(1, IteratorUtils.count(detachedEdge.properties("year")));
    Assert.assertEquals(0.5d, detachedEdge.properties("weight").next().value());
}
 
Example 3
Source File: GraphSONSerializersV3d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(final Path path, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
        throws IOException, JsonGenerationException {
    jsonGenerator.writeStartObject();

    // paths shouldn't serialize with properties if the path contains graph elements
    final Path p = DetachedFactory.detach(path, false);
    jsonGenerator.writeObjectField(GraphSONTokens.LABELS, p.labels());
    jsonGenerator.writeObjectField(GraphSONTokens.OBJECTS, p.objects());

    jsonGenerator.writeEndObject();
}
 
Example 4
Source File: GraphSONSerializersV2d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(final Path path, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
        throws IOException, JsonGenerationException {
    jsonGenerator.writeStartObject();

    // paths shouldn't serialize with properties if the path contains graph elements
    final Path p = DetachedFactory.detach(path, false);
    jsonGenerator.writeObjectField(GraphSONTokens.LABELS, p.labels());
    jsonGenerator.writeObjectField(GraphSONTokens.OBJECTS, p.objects());

    jsonGenerator.writeEndObject();
}
 
Example 5
Source File: IoEdgeTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = Graph.Features.EdgePropertyFeatures.class, feature = Graph.Features.EdgePropertyFeatures.FEATURE_DOUBLE_VALUES)
public void shouldReadWriteDetachedEdge() throws Exception {
    final Vertex v1 = graph.addVertex(T.label, "person");
    final Vertex v2 = graph.addVertex(T.label, "person");
    final Edge e = DetachedFactory.detach(v1.addEdge("friend", v2, "weight", 0.5d, "acl", "rw"), true);

    assertEdge(v1, v2, e, true);
}
 
Example 6
Source File: IoEdgeTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = Graph.Features.EdgePropertyFeatures.class, feature = Graph.Features.EdgePropertyFeatures.FEATURE_DOUBLE_VALUES)
public void shouldReadWriteDetachedEdgeAsReference() throws Exception {
    final Vertex v1 = graph.addVertex(T.label, "person");
    final Vertex v2 = graph.addVertex(T.label, "person");
    final Edge e = DetachedFactory.detach(v1.addEdge("friend", v2, "weight", 0.5d, "acl", "rw"), false);

    assertEdge(v1, v2, e, false);
}
 
Example 7
Source File: TestIoEdge.java    From sqlg with MIT License 5 votes vote down vote up
@Test
public void shouldReadWriteDetachedEdge() throws Exception {
    final Vertex v1 = this.sqlgGraph.addVertex(T.label, "person");
    final Vertex v2 = this.sqlgGraph.addVertex(T.label, "person");
    final Edge e = DetachedFactory.detach(v1.addEdge("friend", v2, "weight", 0.5d, "acl", "rw"), true);

    assertEdge(v1, v2, e, true);
}
 
Example 8
Source File: TestIoEdge.java    From sqlg with MIT License 5 votes vote down vote up
@Test
public void shouldReadWriteDetachedEdgeAsReference() throws Exception {
    final Vertex v1 = this.sqlgGraph.addVertex(T.label, "person");
    final Vertex v2 = this.sqlgGraph.addVertex(T.label, "person");
    final Edge e = DetachedFactory.detach(v1.addEdge("friend", v2, "weight", 0.5d, "acl", "rw"), false);

    assertEdge(v1, v2, e, false);
}
 
Example 9
Source File: EventStrategy.java    From tinkerpop with Apache License 2.0 2 votes vote down vote up
@Override
public Object detach(final Object object) {
    return DetachedFactory.detach(object, true);
}
 
Example 10
Source File: EventStrategy.java    From tinkerpop with Apache License 2.0 2 votes vote down vote up
@Override
public Object detach(final Object object) {
    return DetachedFactory.detach(object, false);
}