Search in sources :

Example 61 with SqlgGraph

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

the class TestTopologyUpgrade method testUpgradeJson.

@Test
public void testUpgradeJson() throws Exception {
    Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportsJsonType());
    ObjectNode json = new ObjectMapper().createObjectNode();
    json.put("halo", "asdasd");
    this.sqlgGraph.addVertex(T.label, "A.A", "name", "a1", "json", json);
    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", "json").toList();
        Assert.assertEquals(1, propertyVertices.size());
        Assert.assertEquals(PropertyType.JSON, 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.assertEquals(json, vertices.get(0).value("json"));
    }
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) SqlgGraph(org.umlg.sqlg.structure.SqlgGraph) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 62 with SqlgGraph

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

the class TestTopologyUpgrade method testUpgradeMultipleInOutEdges2.

@Test
public void testUpgradeMultipleInOutEdges2() throws Exception {
    Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1");
    Vertex b1 = this.sqlgGraph.addVertex(T.label, "R_EG.B", "name", "b1");
    Vertex c1 = this.sqlgGraph.addVertex(T.label, "P_EG.C", "name", "c1");
    Object a1Id = a1.id();
    Object b1Id = b1.id();
    a1.addEdge("ab", b1, "weight", 5);
    a1.addEdge("ab", c1, "weight", 6);
    b1.addEdge("ba", a1, "wtf", "wtf1");
    b1.addEdge("ba", c1, "wtf", "wtf1");
    this.sqlgGraph.tx().commit();
    // Delete the topology
    dropSqlgSchema(this.sqlgGraph);
    this.sqlgGraph.tx().commit();
    this.sqlgGraph.close();
    // topology will be recreated
    try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
        Assert.assertEquals(2, sqlgGraph1.traversal().V(a1Id).out().count().next().intValue());
        Assert.assertEquals(2, sqlgGraph1.traversal().V(b1Id).out().count().next().intValue());
    }
}
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 63 with SqlgGraph

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

the class TestTopologyUpgrade method testModernGraph.

@Test
public void testModernGraph() throws Exception {
    loadModern();
    Traversal<Vertex, Long> traversal = this.sqlgGraph.traversal().V().both().both().count();
    Assert.assertEquals(new Long(30), traversal.next());
    Assert.assertFalse(traversal.hasNext());
    this.sqlgGraph.traversal().V().forEachRemaining(Element::remove);
    this.sqlgGraph.tx().commit();
    // Delete the topology
    dropSqlgSchema(this.sqlgGraph);
    this.sqlgGraph.tx().commit();
    this.sqlgGraph.close();
    try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
        loadModern(sqlgGraph1);
        traversal = sqlgGraph1.traversal().V().both().both().count();
        Assert.assertEquals(new Long(30), traversal.next());
        Assert.assertFalse(traversal.hasNext());
    }
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) SqlgGraph(org.umlg.sqlg.structure.SqlgGraph) Element(org.apache.tinkerpop.gremlin.structure.Element) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 64 with SqlgGraph

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

the class TestLocalDateArray method testLocalDateArray.

@Test
public void testLocalDateArray() throws Exception {
    Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportsLocalDateArrayValues());
    LocalDate[] localDates = new LocalDate[] { LocalDate.now(), LocalDate.now().minusDays(1) };
    this.sqlgGraph.addVertex(T.label, "A", "localDates", localDates);
    this.sqlgGraph.tx().commit();
    // Create a new sqlgGraph
    try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
        List<? extends Property<LocalDate[]>> properties = sqlgGraph1.traversal().V().hasLabel("A").<LocalDate[]>properties("localDates").toList();
        Assert.assertEquals(1, properties.size());
        Assert.assertTrue(properties.get(0).isPresent());
        Assert.assertArrayEquals(localDates, properties.get(0).value());
    }
}
Also used : SqlgGraph(org.umlg.sqlg.structure.SqlgGraph) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 65 with SqlgGraph

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

the class TestLocalDateArray method testLocalTimeArray.

@Test
public void testLocalTimeArray() throws Exception {
    Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportsLocalTimeArrayValues());
    LocalTime[] localTimes = new LocalTime[] { LocalTime.now(), LocalTime.now().minusHours(1) };
    this.sqlgGraph.addVertex(T.label, "A", "localTimes", localTimes);
    this.sqlgGraph.tx().commit();
    // Create a new sqlgGraph
    try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
        List<? extends Property<LocalTime[]>> properties = sqlgGraph1.traversal().V().hasLabel("A").<LocalTime[]>properties("localTimes").toList();
        Assert.assertEquals(1, properties.size());
        Assert.assertTrue(properties.get(0).isPresent());
        LocalTime[] value = properties.get(0).<LocalTime[]>value();
        List<LocalTime> localTimes1 = new ArrayList<>();
        for (LocalTime localTime : value) {
            localTimes1.add(localTime.minusNanos(localTime.getNano()));
        }
        Assert.assertArrayEquals(localTimes1.toArray(), value);
    }
}
Also used : SqlgGraph(org.umlg.sqlg.structure.SqlgGraph) ArrayList(java.util.ArrayList) 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