Search in sources :

Example 11 with VertexLabel

use of org.umlg.sqlg.structure.topology.VertexLabel in project sqlg by pietermartin.

the class TestTopologyDeleteSpecific method testRemoveAndAddInSameTransaction.

/**
 * @see <a href="https://github.com/pietermartin/sqlg/issues/212">https://github.com/pietermartin/sqlg/issues/212</a>
 */
@Test
public void testRemoveAndAddInSameTransaction() {
    // remove it, it does not exist but duplicating work logic.
    Optional<EdgeLabel> aaEdgeLabelOpt = this.sqlgGraph.getTopology().getEdgeLabel(this.sqlgGraph.getSqlDialect().getPublicSchema(), "aa");
    if (aaEdgeLabelOpt.isPresent()) {
        aaEdgeLabelOpt.get().remove(false);
    }
    Optional<VertexLabel> aVertexLabelOpt = this.sqlgGraph.getTopology().getVertexLabel(this.sqlgGraph.getSqlDialect().getPublicSchema(), "A");
    if (aVertexLabelOpt.isPresent()) {
        aVertexLabelOpt.get().remove(false);
    }
    VertexLabel aVertexLabel = this.sqlgGraph.getTopology().ensureVertexLabelExist("A");
    aVertexLabel.ensureEdgeLabelExist("aa", aVertexLabel);
    this.sqlgGraph.tx().commit();
    aaEdgeLabelOpt = this.sqlgGraph.getTopology().getEdgeLabel(this.sqlgGraph.getSqlDialect().getPublicSchema(), "aa");
    if (aaEdgeLabelOpt.isPresent()) {
        aaEdgeLabelOpt.get().remove(false);
    }
    aVertexLabelOpt = this.sqlgGraph.getTopology().getVertexLabel(this.sqlgGraph.getSqlDialect().getPublicSchema(), "A");
    if (aVertexLabelOpt.isPresent()) {
        aVertexLabelOpt.get().remove(false);
    }
    aVertexLabel = this.sqlgGraph.getTopology().ensureVertexLabelExist("A");
    aVertexLabel.ensureEdgeLabelExist("aa", aVertexLabel);
    this.sqlgGraph.tx().commit();
    aaEdgeLabelOpt = this.sqlgGraph.getTopology().getEdgeLabel(this.sqlgGraph.getSqlDialect().getPublicSchema(), "aa");
    assertTrue(aaEdgeLabelOpt.isPresent());
    aVertexLabelOpt = this.sqlgGraph.getTopology().getVertexLabel(this.sqlgGraph.getSqlDialect().getPublicSchema(), "A");
    assertTrue(aVertexLabelOpt.isPresent());
}
Also used : VertexLabel(org.umlg.sqlg.structure.topology.VertexLabel) EdgeLabel(org.umlg.sqlg.structure.topology.EdgeLabel) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 12 with VertexLabel

use of org.umlg.sqlg.structure.topology.VertexLabel in project sqlg by pietermartin.

the class TestSchemaEagerCreation method testEdgeLabelsProperties.

@SuppressWarnings("OptionalGetWithoutIsPresent")
@Test
public void testEdgeLabelsProperties() {
    Vertex a = this.sqlgGraph.addVertex(T.label, "A");
    Vertex b = this.sqlgGraph.addVertex(T.label, "B");
    a.addEdge("ab", b);
    this.sqlgGraph.tx().commit();
    Optional<VertexLabel> vertexLabelAOptional = this.sqlgGraph.getTopology().getPublicSchema().getVertexLabel("A");
    assertTrue(vertexLabelAOptional.isPresent());
    Optional<VertexLabel> vertexLabelBOptional = this.sqlgGraph.getTopology().getPublicSchema().getVertexLabel("B");
    assertTrue(vertexLabelBOptional.isPresent());
    Optional<EdgeLabel> edgeLabelOptional = vertexLabelAOptional.get().getOutEdgeLabel("ab");
    assertTrue(edgeLabelOptional.isPresent());
    Map<String, PropertyType> properties = new HashMap<>();
    properties.put("name", PropertyType.STRING);
    properties.put("age", PropertyType.INTEGER);
    EdgeLabel edgeLabel = edgeLabelOptional.get();
    edgeLabel.ensurePropertiesExist(properties);
    this.sqlgGraph.tx().rollback();
    edgeLabel = vertexLabelAOptional.get().getOutEdgeLabel("ab").get();
    assertTrue(edgeLabel.getProperties().isEmpty());
    edgeLabel = vertexLabelAOptional.get().getOutEdgeLabel("ab").get();
    edgeLabel.ensurePropertiesExist(properties);
    this.sqlgGraph.tx().commit();
    edgeLabel = vertexLabelAOptional.get().getOutEdgeLabel("ab").get();
    assertEquals(2, edgeLabel.getProperties().size());
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) HashMap(java.util.HashMap) VertexLabel(org.umlg.sqlg.structure.topology.VertexLabel) EdgeLabel(org.umlg.sqlg.structure.topology.EdgeLabel) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 13 with VertexLabel

use of org.umlg.sqlg.structure.topology.VertexLabel in project sqlg by pietermartin.

the class TestSchemaEagerCreation method testEdgeLabelAddVertexLabels.

@SuppressWarnings("OptionalGetWithoutIsPresent")
@Test
public void testEdgeLabelAddVertexLabels() {
    Vertex a = this.sqlgGraph.addVertex(T.label, "A");
    Vertex b = this.sqlgGraph.addVertex(T.label, "B");
    a.addEdge("ab", b);
    this.sqlgGraph.tx().commit();
    Optional<EdgeLabel> edgeLabelOptional = this.sqlgGraph.getTopology().getPublicSchema().getEdgeLabel("ab");
    assertTrue(edgeLabelOptional.isPresent());
    EdgeLabel edgeLabel = edgeLabelOptional.get();
    VertexLabel inVertexLabel = this.sqlgGraph.getTopology().getPublicSchema().ensureVertexLabelExist("C");
    edgeLabel.ensureEdgeVertexLabelExist(Direction.IN, inVertexLabel);
    this.sqlgGraph.tx().rollback();
    edgeLabelOptional = this.sqlgGraph.getTopology().getPublicSchema().getEdgeLabel("ab");
    assertTrue(edgeLabelOptional.isPresent());
    edgeLabel = edgeLabelOptional.get();
    assertEquals(1, edgeLabel.getOutVertexLabels().size());
    assertEquals(1, edgeLabel.getInVertexLabels().size());
    inVertexLabel = this.sqlgGraph.getTopology().getPublicSchema().ensureVertexLabelExist("C");
    edgeLabel.ensureEdgeVertexLabelExist(Direction.IN, inVertexLabel);
    this.sqlgGraph.tx().commit();
    assertEquals(1, edgeLabel.getOutVertexLabels().size());
    assertEquals(2, edgeLabel.getInVertexLabels().size());
    VertexLabel outVertexLabel = this.sqlgGraph.getTopology().ensureSchemaExist("D").ensureVertexLabelExist("D");
    try {
        edgeLabel.ensureEdgeVertexLabelExist(Direction.OUT, outVertexLabel);
        fail("Should fail as the out vertex is in a different schema to the edgeLabel");
    } catch (IllegalStateException e) {
    // swallow
    }
    assertEquals(1, edgeLabel.getOutVertexLabels().size());
    assertEquals(2, edgeLabel.getInVertexLabels().size());
    this.sqlgGraph.tx().rollback();
    assertEquals(1, edgeLabel.getOutVertexLabels().size());
    assertEquals(2, edgeLabel.getInVertexLabels().size());
    outVertexLabel = this.sqlgGraph.getTopology().getPublicSchema().ensureVertexLabelExist("D");
    edgeLabel.ensureEdgeVertexLabelExist(Direction.OUT, outVertexLabel);
    assertEquals(2, edgeLabel.getOutVertexLabels().size());
    assertEquals(2, edgeLabel.getInVertexLabels().size());
    this.sqlgGraph.tx().rollback();
    assertEquals(1, edgeLabel.getOutVertexLabels().size());
    assertEquals(2, edgeLabel.getInVertexLabels().size());
    outVertexLabel = this.sqlgGraph.getTopology().getPublicSchema().ensureVertexLabelExist("D");
    edgeLabel.ensureEdgeVertexLabelExist(Direction.OUT, outVertexLabel);
    assertEquals(2, edgeLabel.getOutVertexLabels().size());
    assertEquals(2, edgeLabel.getInVertexLabels().size());
    this.sqlgGraph.tx().commit();
    assertEquals(2, edgeLabel.getOutVertexLabels().size());
    assertEquals(2, edgeLabel.getInVertexLabels().size());
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexLabel(org.umlg.sqlg.structure.topology.VertexLabel) EdgeLabel(org.umlg.sqlg.structure.topology.EdgeLabel) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 14 with VertexLabel

use of org.umlg.sqlg.structure.topology.VertexLabel in project sqlg by pietermartin.

the class TestSchemaEagerCreation method testAddEdgeLabelViaOutVertexLabel.

@SuppressWarnings("OptionalGetWithoutIsPresent")
@Test
public void testAddEdgeLabelViaOutVertexLabel() {
    VertexLabel a = this.sqlgGraph.getTopology().ensureSchemaExist("A").ensureVertexLabelExist("A");
    Optional<Schema> schemaOptional = this.sqlgGraph.getTopology().getSchema("A");
    assertTrue(schemaOptional.isPresent());
    VertexLabel b = schemaOptional.get().ensureVertexLabelExist("B");
    a.ensureEdgeLabelExist("ab", b);
    this.sqlgGraph.tx().commit();
    Optional<EdgeLabel> edgeLabel = this.sqlgGraph.getTopology().getSchema("A").get().getEdgeLabel("ab");
    assertTrue(edgeLabel.isPresent());
    assertEquals("ab", edgeLabel.get().getLabel());
}
Also used : VertexLabel(org.umlg.sqlg.structure.topology.VertexLabel) Schema(org.umlg.sqlg.structure.topology.Schema) EdgeLabel(org.umlg.sqlg.structure.topology.EdgeLabel) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 15 with VertexLabel

use of org.umlg.sqlg.structure.topology.VertexLabel in project sqlg by pietermartin.

the class TestTinkerPopJira method testLazy2.

@Test
public void testLazy2() {
    VertexLabel aVertexLabel = this.sqlgGraph.getTopology().ensureVertexLabelExist("A");
    VertexLabel bVertexLabel = this.sqlgGraph.getTopology().ensureVertexLabelExist("B");
    VertexLabel cVertexLabel = this.sqlgGraph.getTopology().ensureVertexLabelExist("C");
    aVertexLabel.ensureEdgeLabelExist("ab", bVertexLabel);
    aVertexLabel.ensureEdgeLabelExist("ac", cVertexLabel);
    cVertexLabel.ensureEdgeLabelExist("ac", aVertexLabel);
    final Vertex a1 = this.sqlgGraph.addVertex(T.label, "A");
    final Vertex b1 = this.sqlgGraph.addVertex(T.label, "B");
    final Vertex c1 = this.sqlgGraph.addVertex(T.label, "C");
    a1.addEdge("ab", b1);
    a1.addEdge("ac", c1);
    this.sqlgGraph.tx().commit();
    AtomicInteger count = new AtomicInteger(0);
    this.sqlgGraph.traversal().V(a1).union(__.outE(), __.inE()).forEachRemaining(edge -> {
        a1.addEdge("ab", b1);
        c1.addEdge("ac", a1);
        count.getAndIncrement();
    });
    Assert.assertEquals(4, count.get());
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) VertexLabel(org.umlg.sqlg.structure.topology.VertexLabel) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Aggregations

VertexLabel (org.umlg.sqlg.structure.topology.VertexLabel)31 BaseTest (org.umlg.sqlg.test.BaseTest)23 Test (org.junit.Test)22 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)17 EdgeLabel (org.umlg.sqlg.structure.topology.EdgeLabel)11 PropertyColumn (org.umlg.sqlg.structure.topology.PropertyColumn)9 Schema (org.umlg.sqlg.structure.topology.Schema)7 PropertyVetoException (java.beans.PropertyVetoException)6 IOException (java.io.IOException)6 HashMap (java.util.HashMap)6 PropertyType (org.umlg.sqlg.structure.PropertyType)3 Direction (org.apache.tinkerpop.gremlin.structure.Direction)2 Edge (org.apache.tinkerpop.gremlin.structure.Edge)2 SqlgSqlExecutor (org.umlg.sqlg.strategy.SqlgSqlExecutor)2 org.umlg.sqlg.structure (org.umlg.sqlg.structure)2 GlobalUniqueIndex (org.umlg.sqlg.structure.topology.GlobalUniqueIndex)2 Preconditions (com.google.common.base.Preconditions)1 java.util (java.util)1 Collections (java.util.Collections)1 Map (java.util.Map)1