Java Code Examples for org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.EventStrategy#Builder

The following examples show how to use org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.EventStrategy#Builder . 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: TestDropStepBarrier.java    From sqlg with MIT License 6 votes vote down vote up
@Test
public void dropProperty() {
    final AtomicBoolean triggered = new AtomicBoolean(false);
    final MutationListener listener = new AbstractMutationListener() {
        @Override
        public void vertexPropertyRemoved(final VertexProperty element) {
            triggered.set(true);
        }
    };
    final EventStrategy.Builder builder = EventStrategy.build().addListener(listener);
    final EventStrategy eventStrategy = builder.create();
    Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1");
    Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1");
    Vertex a3 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1");
    this.sqlgGraph.tx().commit();

    this.sqlgGraph.traversal().withStrategies(eventStrategy).V().properties().drop().iterate();
    this.sqlgGraph.tx().commit();
    Assert.assertTrue(triggered.get());
    Assert.assertFalse(this.sqlgGraph.traversal().V().hasLabel("A").has("name").hasNext());
}
 
Example 2
Source File: TestTraversalAddV.java    From sqlg with MIT License 6 votes vote down vote up
@Test
public void shouldDetachVertexWhenAdded() {
    final AtomicBoolean triggered = new AtomicBoolean(false);

    final MutationListener listener = new AbstractMutationListener() {
        @Override
        public void vertexAdded(final Vertex element) {
            Assert.assertThat(element, IsInstanceOf.instanceOf(DetachedVertex.class));
            Assert.assertEquals("thing", element.label());
            Assert.assertEquals("there", element.value("here"));
            triggered.set(true);
        }
    };
    final EventStrategy.Builder builder = EventStrategy.build().addListener(listener);

    builder.eventQueue(new EventStrategy.TransactionalEventQueue(this.sqlgGraph));

    final EventStrategy eventStrategy = builder.create();
    final GraphTraversalSource gts = create(eventStrategy);

    gts.addV("thing").property("here", "there").iterate();
    sqlgGraph.tx().commit();
    Assert.assertThat(triggered.get(), Is.is(true));
}
 
Example 3
Source File: TestDropStep.java    From sqlg with MIT License 5 votes vote down vote up
@Before
    public void before() throws Exception {
        super.before();
        configuration.setProperty("implement.foreign.keys", this.fkOn);
        this.removedVertices.clear();
        if (this.mutatingCallback) {
//            Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportReturningDeletedRows());
            final MutationListener listener = new AbstractMutationListener() {
                @Override
                public void vertexRemoved(final Vertex vertex) {
                    removedVertices.add(vertex);
                }

                @Override
                public void edgeRemoved(final Edge edge) {
                    removedEdges.add(edge);
                }
            };
            final EventStrategy.Builder builder = EventStrategy.build().addListener(listener);
            EventStrategy eventStrategy = builder.create();
            this.dropTraversal = this.sqlgGraph.traversal();
            if (this.mutatingCallback) {
                this.dropTraversal = this.dropTraversal.withStrategies(eventStrategy);
            }
        } else {
            this.dropTraversal = this.sqlgGraph.traversal();
        }
    }
 
Example 4
Source File: TestDropStep.java    From sqlg with MIT License 5 votes vote down vote up
@Test
public void shouldReferenceVertexWhenRemoved() {
    final AtomicBoolean triggered = new AtomicBoolean(false);
    final Vertex v = this.sqlgGraph.addVertex();
    final String label = v.label();
    final Object id = v.id();

    final MutationListener listener = new AbstractMutationListener() {
        @Override
        public void vertexRemoved(final Vertex element) {
            Assert.assertThat(element, IsInstanceOf.instanceOf(ReferenceVertex.class));
            Assert.assertEquals(id, element.id());
            Assert.assertEquals(label, element.label());
            triggered.set(true);
        }
    };
    final EventStrategy.Builder builder = EventStrategy.build().addListener(listener)
        .detach(EventStrategy.Detachment.REFERENCE);

    if (this.sqlgGraph.features().graph().supportsTransactions())
        builder.eventQueue(new EventStrategy.TransactionalEventQueue(this.sqlgGraph));

    final EventStrategy eventStrategy = builder.create();
    final GraphTraversalSource gts = this.sqlgGraph.traversal().withStrategies(eventStrategy);

    gts.V(v).drop().iterate();
    this.sqlgGraph.tx().commit();

    AbstractGremlinTest.assertVertexEdgeCounts(this.sqlgGraph, 0, 0);
    Assert.assertThat(triggered.get(), CoreMatchers.is(true));
}
 
Example 5
Source File: TestDropStepBarrier.java    From sqlg with MIT License 5 votes vote down vote up
@Test
public void dropPropertyuserSuppliedIds() {
    final AtomicBoolean triggered = new AtomicBoolean(false);
    final MutationListener listener = new AbstractMutationListener() {
        @Override
        public void vertexPropertyRemoved(final VertexProperty element) {
            triggered.set(true);
        }
    };
    final EventStrategy.Builder builder = EventStrategy.build().addListener(listener);
    final EventStrategy eventStrategy = builder.create();
    VertexLabel aVertexLabel = this.sqlgGraph.getTopology().ensureVertexLabelExist(
            "A",
            new LinkedHashMap<String, PropertyType>() {{
                put("uid1", PropertyType.varChar(100));
                put("uid2", PropertyType.varChar(100));
                put("uid3", PropertyType.varChar(100));
            }},
            ListOrderedSet.listOrderedSet(Arrays.asList("uid1", "uid2"))
    );
    VertexLabel bVertexLabel = this.sqlgGraph.getTopology().ensureVertexLabelExist(
            "B",
            new LinkedHashMap<String, PropertyType>() {{
                put("uid1", PropertyType.varChar(100));
                put("uid2", PropertyType.varChar(100));
                put("uid3", PropertyType.varChar(100));
            }},
            ListOrderedSet.listOrderedSet(Arrays.asList("uid1", "uid2"))
    );
    this.sqlgGraph.tx().commit();
    Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1", "uid1", UUID.randomUUID().toString(), "uid2", UUID.randomUUID().toString());
    Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1", "uid1", UUID.randomUUID().toString(), "uid2", UUID.randomUUID().toString());
    Vertex a3 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1", "uid1", UUID.randomUUID().toString(), "uid2", UUID.randomUUID().toString());
    this.sqlgGraph.tx().commit();

    this.sqlgGraph.traversal().withStrategies(eventStrategy).V().properties("name").drop().iterate();
    this.sqlgGraph.tx().commit();
    Assert.assertTrue(triggered.get());
    Assert.assertFalse(this.sqlgGraph.traversal().V().hasLabel("A").has("name").hasNext());
}
 
Example 6
Source File: TestDropStepPartition.java    From sqlg with MIT License 5 votes vote down vote up
@Before
    public void before() throws Exception {
        super.before();
        Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportsPartitioning());
        configuration.setProperty("implement.foreign.keys", this.fkOn);
        this.removedVertices.clear();
        if (this.mutatingCallback) {
//            Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportReturningDeletedRows());
            final MutationListener listener = new AbstractMutationListener() {
                @Override
                public void vertexRemoved(final Vertex vertex) {
                    removedVertices.add(vertex);
                }

                @Override
                public void edgeRemoved(final Edge edge) {
                    removedEdges.add(edge);
                }
            };
            final EventStrategy.Builder builder = EventStrategy.build().addListener(listener);
            EventStrategy eventStrategy = builder.create();
            this.dropTraversal = this.sqlgGraph.traversal();
            if (this.mutatingCallback) {
                this.dropTraversal = this.dropTraversal.withStrategies(eventStrategy);
            }
        } else {
            this.dropTraversal = this.sqlgGraph.traversal();
        }
    }
 
Example 7
Source File: TestDropStepTruncate.java    From sqlg with MIT License 5 votes vote down vote up
@Before
public void before() throws Exception {
    super.before();
    configuration.setProperty("implement.foreign.keys", this.fkOn);
    this.removedVertices.clear();
    if (this.mutatingCallback) {
        final MutationListener listener = new AbstractMutationListener() {
            @Override
            public void vertexRemoved(final Vertex vertex) {
                removedVertices.add(vertex);
            }

            @Override
            public void edgeRemoved(final Edge edge) {
                removedEdges.add(edge);
            }
        };
        final EventStrategy.Builder builder = EventStrategy.build().addListener(listener);
        EventStrategy eventStrategy = builder.create();
        this.dropTraversal = this.sqlgGraph.traversal();
        if (this.mutatingCallback) {
            this.dropTraversal = this.dropTraversal.withStrategies(eventStrategy);
        }
    } else {
        this.dropTraversal = this.sqlgGraph.traversal();
    }
}
 
Example 8
Source File: TestTinkerPopEvent.java    From sqlg with MIT License 5 votes vote down vote up
@Test
public void shouldDetachVertexPropertyWhenRemoved() {
    final AtomicBoolean triggered = new AtomicBoolean(false);
    final Vertex v = this.sqlgGraph.addVertex();
    final VertexProperty vp = v.property("to-remove","blah");
    final String label = vp.label();
    final Object value = vp.value();
    final VertexProperty vpToKeep = v.property("to-keep","dah");

    final MutationListener listener = new AbstractMutationListener() {
        @Override
        public void vertexPropertyRemoved(final VertexProperty element) {
            Assert.assertEquals(label, element.label());
            Assert.assertEquals(value, element.value());
            triggered.set(true);
        }
    };
    final EventStrategy.Builder builder = EventStrategy.build().addListener(listener);

    if (this.sqlgGraph.features().graph().supportsTransactions())
        builder.eventQueue(new EventStrategy.TransactionalEventQueue(this.sqlgGraph));

    final EventStrategy eventStrategy = builder.create();
    final GraphTraversalSource gts = create(eventStrategy);

    gts.V(v).properties("to-remove").drop().iterate();
    this.sqlgGraph.tx().commit();

    Assert.assertEquals(1, IteratorUtils.count(v.properties()));
    Assert.assertEquals(vpToKeep.value(), v.value("to-keep"));
    Assert.assertThat(triggered.get(), CoreMatchers.is(true));
}