Search in sources :

Example 11 with SqlgGraph

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

the class TestLocalDate method testLocalTime.

@Test
public void testLocalTime() throws Exception {
    LocalTime now = LocalTime.now();
    this.sqlgGraph.addVertex(T.label, "A", "time", now);
    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("time").toList();
        Assert.assertEquals(1, properties.size());
        Assert.assertTrue(properties.get(0).isPresent());
        LocalTime value = properties.get(0).<LocalTime>value();
        Assert.assertEquals(now.toSecondOfDay(), value.toSecondOfDay());
    }
}
Also used : SqlgGraph(org.umlg.sqlg.structure.SqlgGraph) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 12 with SqlgGraph

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

the class TestLocalDate method testLocalDateTimeUpdate.

@Test
public void testLocalDateTimeUpdate() throws Exception {
    LocalDateTime now = LocalDateTime.now();
    Vertex v = this.sqlgGraph.addVertex(T.label, "A", "dateTime", now);
    this.sqlgGraph.tx().commit();
    v.property("dateTime", now.plusHours(1));
    this.sqlgGraph.tx().commit();
    // Create a new sqlgGraph
    try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
        List<? extends Property> properties = sqlgGraph1.traversal().V().hasLabel("A").properties("dateTime").toList();
        Assert.assertEquals(1, properties.size());
        Assert.assertTrue(properties.get(0).isPresent());
        Assert.assertEquals(now.plusHours(1), properties.get(0).value());
    }
}
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 13 with SqlgGraph

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

the class TestLocalDate method testPeriod.

@Test
public void testPeriod() throws Exception {
    Period period = Period.of(2016, 5, 5);
    this.sqlgGraph.addVertex(T.label, "A", "period", period);
    this.sqlgGraph.tx().commit();
    // Create a new sqlgGraph
    try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
        List<? extends Property> properties = sqlgGraph1.traversal().V().hasLabel("A").properties("period").toList();
        Assert.assertEquals(1, properties.size());
        Assert.assertTrue(properties.get(0).isPresent());
        Assert.assertEquals(period, properties.get(0).value());
    }
}
Also used : SqlgGraph(org.umlg.sqlg.structure.SqlgGraph) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 14 with SqlgGraph

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

the class TestLocalDate method testLocalDateTime.

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

Example 15 with SqlgGraph

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

the class TestLocalDateArray method testLocalTimeArrayOnEdge.

@Test
public void testLocalTimeArrayOnEdge() throws Exception {
    Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportsLocalTimeArrayValues());
    LocalTime[] localTimes = new LocalTime[] { LocalTime.now(), LocalTime.now().minusHours(1) };
    Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "localTimes", localTimes);
    Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "localTimes", localTimes);
    a1.addEdge("aa", a2, "localTimes", localTimes);
    this.sqlgGraph.tx().commit();
    // Create a new sqlgGraph
    try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
        List<? extends Property<LocalTime[]>> properties = sqlgGraph1.traversal().E().hasLabel("aa").<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 : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) 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