Search in sources :

Example 36 with SqlgGraph

use of org.umlg.sqlg.structure.SqlgGraph in project sqlg by pietermartin.

the class TestTopologyUpgrade method testUpgradeTypesWithMoreThanOneColumnOnEdge.

@Test
public void testUpgradeTypesWithMoreThanOneColumnOnEdge() throws Exception {
    ZonedDateTime zonedDateTime = ZonedDateTime.now();
    Duration duration = Duration.ofDays(1);
    Period period = Period.of(1, 1, 1);
    Vertex a1 = this.sqlgGraph.addVertex(T.label, "A.A", "name", "a1");
    Vertex a2 = this.sqlgGraph.addVertex(T.label, "A.A", "name", "a2");
    a1.addEdge("ab", a2, "zonedDateTime", zonedDateTime, "duration", duration, "period", period);
    this.sqlgGraph.tx().commit();
    // Delete the topology
    dropSqlgSchema(this.sqlgGraph);
    this.sqlgGraph.tx().commit();
    this.sqlgGraph.close();
    try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
        List<Vertex> schemaVertices = sqlgGraph1.topology().V().hasLabel("sqlg_schema.schema").has("name", "A").toList();
        Assert.assertEquals(1, schemaVertices.size());
        // assert zonedDateTime
        List<Vertex> propertyVertices = sqlgGraph1.topology().V().hasLabel("sqlg_schema.schema").has("name", "A").out(Topology.SQLG_SCHEMA_SCHEMA_VERTEX_EDGE).has(Topology.SQLG_SCHEMA_VERTEX_LABEL_NAME, "A").out(Topology.SQLG_SCHEMA_OUT_EDGES_EDGE).out(Topology.SQLG_SCHEMA_EDGE_PROPERTIES_EDGE).has(Topology.SQLG_SCHEMA_PROPERTY_NAME, "zonedDateTime").toList();
        Assert.assertEquals(1, propertyVertices.size());
        Assert.assertEquals(PropertyType.ZONEDDATETIME, PropertyType.valueOf(propertyVertices.get(0).value("type")));
        List<Edge> edges = sqlgGraph1.traversal().E().hasLabel("ab").toList();
        Assert.assertEquals(1, edges.size());
        Assert.assertEquals(zonedDateTime, edges.get(0).value("zonedDateTime"));
        Assert.assertEquals(duration, edges.get(0).value("duration"));
        Assert.assertEquals(period, edges.get(0).value("period"));
    }
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) SqlgGraph(org.umlg.sqlg.structure.SqlgGraph) Edge(org.apache.tinkerpop.gremlin.structure.Edge) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 37 with SqlgGraph

use of org.umlg.sqlg.structure.SqlgGraph in project sqlg by pietermartin.

the class TestTopologyUpgrade method testUpgradeEdgeWithMultipleInOutLabelsAndAIndex.

@Test
public void testUpgradeEdgeWithMultipleInOutLabelsAndAIndex() throws Exception {
    VertexLabel aVertexLabel = this.sqlgGraph.getTopology().getPublicSchema().ensureVertexLabelExist("A");
    VertexLabel bVertexLabel = this.sqlgGraph.getTopology().getPublicSchema().ensureVertexLabelExist("B");
    VertexLabel cVertexLabel = this.sqlgGraph.getTopology().getPublicSchema().ensureVertexLabelExist("C");
    Map<String, PropertyType> properties = new HashMap<String, PropertyType>() {

        {
            put("name", PropertyType.STRING);
        }
    };
    @SuppressWarnings("UnusedAssignment") EdgeLabel edgeLabel = this.sqlgGraph.getTopology().getPublicSchema().ensureEdgeLabelExist("edge", bVertexLabel, aVertexLabel, properties);
    edgeLabel = this.sqlgGraph.getTopology().getPublicSchema().ensureEdgeLabelExist("edge", cVertexLabel, aVertexLabel, properties);
    edgeLabel.ensureIndexExists(IndexType.UNIQUE, new ArrayList<>(edgeLabel.getProperties().values()));
    this.sqlgGraph.tx().commit();
    Vertex a1 = this.sqlgGraph.addVertex(T.label, "A");
    Vertex b1 = this.sqlgGraph.addVertex(T.label, "B");
    Vertex c1 = this.sqlgGraph.addVertex(T.label, "C");
    b1.addEdge("edge", a1, "name", "b");
    c1.addEdge("edge", a1, "name", "c");
    this.sqlgGraph.tx().commit();
    // Delete the topology
    dropSqlgSchema(this.sqlgGraph);
    this.sqlgGraph.tx().commit();
    this.sqlgGraph.close();
    try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
        Assert.assertEquals(3, sqlgGraph1.traversal().V().count().next().intValue());
        Assert.assertEquals(2, sqlgGraph1.traversal().E().count().next().intValue());
    }
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) SqlgGraph(org.umlg.sqlg.structure.SqlgGraph) PropertyType(org.umlg.sqlg.structure.PropertyType) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 38 with SqlgGraph

use of org.umlg.sqlg.structure.SqlgGraph in project sqlg by pietermartin.

the class TestTopologyUpgrade method testUpgradeArrayTypesWithMoreThanOneColumn.

@Test
public void testUpgradeArrayTypesWithMoreThanOneColumn() throws Exception {
    Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportsZonedDateTimeArrayValues());
    Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportsDurationArrayValues());
    Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportsPeriodArrayValues());
    ZonedDateTime[] zonedDateTimes = new ZonedDateTime[] { ZonedDateTime.now(), ZonedDateTime.now().minusMonths(1), ZonedDateTime.now().minusMonths(2) };
    Duration[] durations = new Duration[] { Duration.ofDays(1), Duration.ofDays(2), Duration.ofDays(3) };
    Period[] periods = new Period[] { Period.of(1, 1, 1), Period.of(2, 2, 2), Period.of(3, 3, 3) };
    this.sqlgGraph.addVertex(T.label, "A.A", "name", "a1", "zonedDateTimes", zonedDateTimes);
    this.sqlgGraph.addVertex(T.label, "A.A", "name", "a2", "durations", durations);
    this.sqlgGraph.addVertex(T.label, "A.A", "name", "a3", "periods", periods);
    this.sqlgGraph.tx().commit();
    // Delete the topology
    dropSqlgSchema(this.sqlgGraph);
    this.sqlgGraph.tx().commit();
    this.sqlgGraph.close();
    try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
        List<Vertex> schemaVertices = sqlgGraph1.topology().V().hasLabel("sqlg_schema.schema").has("name", "A").toList();
        Assert.assertEquals(1, schemaVertices.size());
        // assert zonedDateTimes
        List<Vertex> propertyVertices = sqlgGraph1.topology().V().hasLabel("sqlg_schema.schema").has("name", "A").out("schema_vertex").has("name", "A").out("vertex_property").has("name", "zonedDateTimes").toList();
        Assert.assertEquals(1, propertyVertices.size());
        Assert.assertEquals(PropertyType.ZONEDDATETIME_ARRAY, PropertyType.valueOf(propertyVertices.get(0).value("type")));
        List<Vertex> vertices = sqlgGraph1.traversal().V().hasLabel("A.A").has("name", "a1").toList();
        Assert.assertEquals(1, vertices.size());
        Assert.assertArrayEquals(zonedDateTimes, vertices.get(0).value("zonedDateTimes"));
        // assert durations
        propertyVertices = sqlgGraph1.topology().V().hasLabel("sqlg_schema.schema").has("name", "A").out("schema_vertex").has("name", "A").out("vertex_property").has("name", "durations").toList();
        Assert.assertEquals(1, propertyVertices.size());
        Assert.assertEquals(PropertyType.DURATION_ARRAY, PropertyType.valueOf(propertyVertices.get(0).value("type")));
        vertices = sqlgGraph1.traversal().V().hasLabel("A.A").has("name", "a2").toList();
        Assert.assertEquals(1, vertices.size());
        Assert.assertArrayEquals(durations, vertices.get(0).value("durations"));
        // assert periods
        propertyVertices = sqlgGraph1.topology().V().hasLabel("sqlg_schema.schema").has("name", "A").out("schema_vertex").has("name", "A").out("vertex_property").has("name", "periods").toList();
        Assert.assertEquals(1, propertyVertices.size());
        Assert.assertEquals(PropertyType.PERIOD_ARRAY, PropertyType.valueOf(propertyVertices.get(0).value("type")));
        vertices = sqlgGraph1.traversal().V().hasLabel("A.A").has("name", "a3").toList();
        Assert.assertEquals(1, vertices.size());
        Assert.assertArrayEquals(periods, vertices.get(0).value("periods"));
    }
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) SqlgGraph(org.umlg.sqlg.structure.SqlgGraph) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 39 with SqlgGraph

use of org.umlg.sqlg.structure.SqlgGraph in project sqlg by pietermartin.

the class TestTopologyUpgrade method testUpdateLocalDateTimeAndZonedDateTime.

@Test
public void testUpdateLocalDateTimeAndZonedDateTime() throws Exception {
    LocalDateTime localDateTime = LocalDateTime.now();
    ZonedDateTime zonedDateTime = ZonedDateTime.now();
    this.sqlgGraph.addVertex(T.label, "A", "localDateTime", localDateTime, "zonedDateTime", zonedDateTime);
    this.sqlgGraph.tx().commit();
    // Delete the topology
    dropSqlgSchema(this.sqlgGraph);
    this.sqlgGraph.tx().commit();
    this.sqlgGraph.close();
    try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
        Assert.assertEquals(localDateTime, sqlgGraph1.traversal().V().hasLabel("A").next().value("localDateTime"));
        Assert.assertEquals(zonedDateTime, sqlgGraph1.traversal().V().hasLabel("A").next().value("zonedDateTime"));
    }
}
Also used : SqlgGraph(org.umlg.sqlg.structure.SqlgGraph) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 40 with SqlgGraph

use of org.umlg.sqlg.structure.SqlgGraph in project sqlg by pietermartin.

the class TestTopologyUpgrade method testTopologyUpgradeForeignKey.

@Test
public void testTopologyUpgradeForeignKey() throws Exception {
    Vertex a1 = this.sqlgGraph.addVertex(T.label, "A");
    Vertex b1 = this.sqlgGraph.addVertex(T.label, "B");
    a1.addEdge("ab", b1);
    this.sqlgGraph.tx().commit();
    this.sqlgGraph.close();
    try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
        System.out.println("asd");
    }
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) SqlgGraph(org.umlg.sqlg.structure.SqlgGraph) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Aggregations

SqlgGraph (org.umlg.sqlg.structure.SqlgGraph)75 Test (org.junit.Test)68 BaseTest (org.umlg.sqlg.test.BaseTest)64 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)44 ConfigurationException (org.apache.commons.configuration.ConfigurationException)10 PropertyVetoException (java.beans.PropertyVetoException)9 IOException (java.io.IOException)9 Connection (java.sql.Connection)7 Edge (org.apache.tinkerpop.gremlin.structure.Edge)6 ResultSet (java.sql.ResultSet)4 Configuration (org.apache.commons.configuration.Configuration)4 Traversal (org.apache.tinkerpop.gremlin.process.traversal.Traversal)4 ReducingBarrierStep (org.apache.tinkerpop.gremlin.process.traversal.step.util.ReducingBarrierStep)4 Statement (java.sql.Statement)3 PropertyType (org.umlg.sqlg.structure.PropertyType)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 URL (java.net.URL)2 DatabaseMetaData (java.sql.DatabaseMetaData)2 PreparedStatement (java.sql.PreparedStatement)2