Search in sources :

Example 66 with SqlgGraph

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

the class TestLocalDateArray method testLocalDateTimeArrayOnEdge.

@Test
public void testLocalDateTimeArrayOnEdge() throws Exception {
    Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportsLocalDateTimeArrayValues());
    LocalDateTime[] localDateTimes = new LocalDateTime[] { LocalDateTime.now(), LocalDateTime.now() };
    Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "localDateTimes", localDateTimes);
    Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "localDateTimes", localDateTimes);
    a1.addEdge("aa", a2, "localDateTimes", localDateTimes);
    this.sqlgGraph.tx().commit();
    // Create a new sqlgGraph
    try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
        List<? extends Property<LocalDateTime[]>> properties = sqlgGraph1.traversal().E().hasLabel("aa").<LocalDateTime[]>properties("localDateTimes").toList();
        Assert.assertEquals(1, properties.size());
        Assert.assertTrue(properties.get(0).isPresent());
        LocalDateTime[] localDateTimesFromDb = properties.get(0).value();
        Assert.assertArrayEquals(localDateTimes, localDateTimesFromDb);
    }
}
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 67 with SqlgGraph

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

the class TestLocalDateArray method testDurationArrayOnEdge.

@Test
public void testDurationArrayOnEdge() throws Exception {
    Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportsIntegerArrayValues());
    Duration[] durations = new Duration[] { Duration.ofHours(1), Duration.ofHours(5) };
    Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "duration", durations);
    Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "duration", durations);
    a1.addEdge("aa", a2, "duration", durations);
    this.sqlgGraph.tx().commit();
    // Create a new sqlgGraph
    try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
        List<? extends Property<Duration[]>> properties = sqlgGraph1.traversal().E().hasLabel("aa").<Duration[]>properties("duration").toList();
        Assert.assertEquals(1, properties.size());
        Assert.assertTrue(properties.get(0).isPresent());
        Duration[] durationsFromDb = properties.get(0).value();
        Assert.assertArrayEquals(durations, durationsFromDb);
    }
}
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 68 with SqlgGraph

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

the class TestLocalDateArray method testPeriodArrayOnEdge.

@Test
public void testPeriodArrayOnEdge() throws Exception {
    Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportsIntegerArrayValues());
    Period[] periods = new Period[] { Period.of(2016, 5, 5), Period.of(2015, 4, 4) };
    Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "periods", periods);
    Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "periods", periods);
    a1.addEdge("aa", a2, "periods", periods);
    this.sqlgGraph.tx().commit();
    // Create a new sqlgGraph
    try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
        List<? extends Property<Period[]>> properties = sqlgGraph1.traversal().E().hasLabel("aa").<Period[]>properties("periods").toList();
        Assert.assertEquals(1, properties.size());
        Assert.assertTrue(properties.get(0).isPresent());
        Period[] periodsFromDb = properties.get(0).value();
        Assert.assertArrayEquals(periods, periodsFromDb);
    }
}
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 69 with SqlgGraph

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

the class TestJNDIInitialization method testLoadingDatasourceFromJndi.

@Test
public void testLoadingDatasourceFromJndi() throws Exception {
    SqlgGraph g = SqlgGraph.open(configuration);
    assertNotNull(g.getSqlDialect());
    assertEquals(configuration.getString("jdbc.url"), g.getJdbcUrl());
    assertNotNull(g.getConnection());
}
Also used : SqlgGraph(org.umlg.sqlg.structure.SqlgGraph) Test(org.junit.Test)

Example 70 with SqlgGraph

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

the class TestLoadArrayProperties method testLoadSchemaWithArrays.

@Test
public void testLoadSchemaWithArrays() throws Exception {
    Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportsBooleanArrayValues() && this.sqlgGraph.getSqlDialect().supportsFloatArrayValues() && this.sqlgGraph.getSqlDialect().supportsLongArrayValues() && this.sqlgGraph.getSqlDialect().supportsIntegerArrayValues() && this.sqlgGraph.getSqlDialect().supportsDoubleArrayValues() && this.sqlgGraph.getSqlDialect().supportsStringArrayValues());
    this.sqlgGraph.addVertex(T.label, "Person", "aBoolean", new boolean[] { true }, "aShort", new short[] { (short) 1 }, "aInteger", new int[] { 1 }, "aLong", new long[] { 1L }, "aFloat", new float[] { 1F }, "aDouble", new double[] { 1D }, "aString", new String[] { "aaaaaaaaaaaaa" });
    this.sqlgGraph.tx().commit();
    this.sqlgGraph.close();
    try (SqlgGraph sqlgGraph = SqlgGraph.open(configuration)) {
        Iterator<Vertex> iter = sqlgGraph.traversal().V().has(T.label, "Person");
        Assert.assertTrue(iter.hasNext());
        Vertex v = iter.next();
        Assert.assertTrue(Arrays.equals(new boolean[] { true }, (boolean[]) v.property("aBoolean").value()));
        Assert.assertTrue(Arrays.equals(new short[] { (short) 1 }, (short[]) v.property("aShort").value()));
        Assert.assertTrue(Arrays.equals(new int[] { 1 }, (int[]) v.property("aInteger").value()));
        Assert.assertTrue(Arrays.equals(new long[] { 1L }, (long[]) v.property("aLong").value()));
        Assert.assertTrue(Arrays.equals(new float[] { 1f }, (float[]) v.property("aFloat").value()));
        Assert.assertTrue(Arrays.equals(new double[] { 1d }, (double[]) v.property("aDouble").value()));
        Assert.assertTrue(Arrays.equals(new String[] { "aaaaaaaaaaaaa" }, (String[]) v.property("aString").value()));
    }
    try (SqlgGraph sqlgGraph = SqlgGraph.open(configuration)) {
        Iterator<Vertex> iter = sqlgGraph.traversal().V().has(T.label, "Person");
        Assert.assertTrue(iter.hasNext());
        Vertex v = iter.next();
        Assert.assertTrue(Arrays.equals(new boolean[] { true }, (boolean[]) v.property("aBoolean").value()));
        Assert.assertTrue(Arrays.equals(new short[] { (short) 1 }, (short[]) v.property("aShort").value()));
        Assert.assertTrue(Arrays.equals(new int[] { 1 }, (int[]) v.property("aInteger").value()));
        Assert.assertTrue(Arrays.equals(new long[] { 1L }, (long[]) v.property("aLong").value()));
        Assert.assertTrue(Arrays.equals(new float[] { 1f }, (float[]) v.property("aFloat").value()));
        Assert.assertTrue(Arrays.equals(new double[] { 1d }, (double[]) v.property("aDouble").value()));
        Assert.assertTrue(Arrays.equals(new String[] { "aaaaaaaaaaaaa" }, (String[]) v.property("aString").value()));
    }
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) SqlgGraph(org.umlg.sqlg.structure.SqlgGraph) 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