Search in sources :

Example 26 with SqlgGraph

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

the class TestLoadArrayProperties method testLoadSchemaWithArraysWithoutFloat.

@Test
public void testLoadSchemaWithArraysWithoutFloat() throws Exception {
    Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportsBooleanArrayValues() && 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 }, "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 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 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)

Example 27 with SqlgGraph

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

the class TestTopologyMultipleGraphs method testDeepEqualsPublicSchema.

@Test
public void testDeepEqualsPublicSchema() throws InterruptedException {
    try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
        Vertex a1 = this.sqlgGraph.addVertex(T.label, "A");
        this.sqlgGraph.tx().commit();
        Thread.sleep(1_000);
        assertTrue(this.sqlgGraph.getTopology().equals(sqlgGraph1.getTopology()));
        a1.property("test", "asdasd");
        this.sqlgGraph.tx().commit();
        Thread.sleep(1_000);
        assertTrue(this.sqlgGraph.getTopology().equals(sqlgGraph1.getTopology()));
        Vertex b1 = this.sqlgGraph.addVertex(T.label, "B", "name", "b1");
        this.sqlgGraph.tx().commit();
        Thread.sleep(1_000);
        assertTrue(this.sqlgGraph.getTopology().equals(sqlgGraph1.getTopology()));
        a1.addEdge("ab", b1);
        this.sqlgGraph.tx().commit();
        Thread.sleep(1_000);
        assertTrue(this.sqlgGraph.getTopology().equals(sqlgGraph1.getTopology()));
        Vertex bb1 = this.sqlgGraph.addVertex(T.label, "BB", "name", "bb1");
        a1.addEdge("ab", bb1);
        this.sqlgGraph.tx().commit();
        Thread.sleep(1_000);
        assertTrue(this.sqlgGraph.getTopology().equals(sqlgGraph1.getTopology()));
        Vertex aa1 = this.sqlgGraph.addVertex(T.label, "AA", "name", "aa1");
        Edge ab = aa1.addEdge("ab", bb1);
        this.sqlgGraph.tx().commit();
        Thread.sleep(1_000);
        assertTrue(this.sqlgGraph.getTopology().equals(sqlgGraph1.getTopology()));
        ab.property("test", "asdasd");
        this.sqlgGraph.tx().commit();
        Thread.sleep(1_000);
        assertTrue(this.sqlgGraph.getTopology().equals(sqlgGraph1.getTopology()));
        assertTrue(this.sqlgGraph.getTopology().equals(sqlgGraph1.getTopology()));
    } catch (Exception e) {
        fail(e.getMessage());
    }
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) SqlgGraph(org.umlg.sqlg.structure.SqlgGraph) Edge(org.apache.tinkerpop.gremlin.structure.Edge) IOException(java.io.IOException) PropertyVetoException(java.beans.PropertyVetoException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 28 with SqlgGraph

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

the class TestTopologyMultipleGraphs method testModernAcrossGraphs.

@Test
public void testModernAcrossGraphs() {
    try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
        loadModern();
        Thread.sleep(1000);
        assertTrue(this.sqlgGraph.getTopology().equals(sqlgGraph1.getTopology()));
    } catch (Exception e) {
        fail(e.getMessage());
    }
}
Also used : SqlgGraph(org.umlg.sqlg.structure.SqlgGraph) IOException(java.io.IOException) PropertyVetoException(java.beans.PropertyVetoException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 29 with SqlgGraph

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

the class TestTopologyMultipleGraphs method testDeepEqualsAcrossSchema.

@Test
public void testDeepEqualsAcrossSchema() throws InterruptedException, IOException {
    try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
        Vertex a1 = this.sqlgGraph.addVertex(T.label, "A.A");
        this.sqlgGraph.tx().commit();
        Thread.sleep(1_000);
        assertTrue(this.sqlgGraph.getTopology().equals(sqlgGraph1.getTopology()));
        a1.property("test", "asdasd");
        this.sqlgGraph.tx().commit();
        Thread.sleep(1_000);
        assertTrue(this.sqlgGraph.getTopology().equals(sqlgGraph1.getTopology()));
        Vertex b1 = this.sqlgGraph.addVertex(T.label, "B.B", "name", "b1");
        this.sqlgGraph.tx().commit();
        Thread.sleep(1_000);
        assertTrue(this.sqlgGraph.getTopology().equals(sqlgGraph1.getTopology()));
        a1.addEdge("ab", b1);
        this.sqlgGraph.tx().commit();
        Thread.sleep(1_000);
        assertTrue(this.sqlgGraph.getTopology().equals(sqlgGraph1.getTopology()));
        Vertex bb1 = this.sqlgGraph.addVertex(T.label, "BB.BB", "name", "bb1");
        a1.addEdge("ab", bb1);
        this.sqlgGraph.tx().commit();
        Thread.sleep(1_000);
        assertTrue(this.sqlgGraph.getTopology().equals(sqlgGraph1.getTopology()));
        Vertex aa1 = this.sqlgGraph.addVertex(T.label, "AA.AA", "name", "aa1");
        Edge ab = aa1.addEdge("ab", bb1);
        this.sqlgGraph.tx().commit();
        Thread.sleep(1_000);
        assertTrue(this.sqlgGraph.getTopology().equals(sqlgGraph1.getTopology()));
        ab.property("test", "asdasd");
        this.sqlgGraph.tx().commit();
        Thread.sleep(1_000);
        assertTrue(this.sqlgGraph.getTopology().equals(sqlgGraph1.getTopology()));
        assertEquals(4, this.sqlgGraph.traversal().V().count().next(), 0);
        assertEquals(4, sqlgGraph1.traversal().V().count().next(), 0);
        assertEquals(3, this.sqlgGraph.traversal().E().count().next(), 0);
        assertEquals(3, sqlgGraph1.traversal().E().count().next(), 0);
        assertEquals(2, this.sqlgGraph.traversal().V(a1.id()).out("ab").count().next(), 0);
        assertEquals(2, sqlgGraph1.traversal().V(a1.id()).out("ab").count().next(), 0);
        assertEquals(1, this.sqlgGraph.traversal().V(aa1.id()).out("ab").count().next(), 0);
        assertEquals(1, sqlgGraph1.traversal().V(aa1.id()).out("ab").count().next(), 0);
    } catch (Exception e) {
        fail(e.getMessage());
    }
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) SqlgGraph(org.umlg.sqlg.structure.SqlgGraph) Edge(org.apache.tinkerpop.gremlin.structure.Edge) IOException(java.io.IOException) PropertyVetoException(java.beans.PropertyVetoException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 30 with SqlgGraph

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

the class TestTopologyUpgrade method testUpgrade.

@Test
public void testUpgrade() throws Exception {
    // with topology
    Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "john");
    Object idA1 = a1.id();
    Vertex b1 = this.sqlgGraph.addVertex(T.label, "B", "name", "joe");
    Object idB1 = b1.id();
    a1.addEdge("knows", b1, "name", "hithere");
    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().count().next().intValue());
        Assert.assertEquals(1, sqlgGraph1.traversal().E().count().next().intValue());
        Assert.assertTrue(sqlgGraph1.traversal().V().hasLabel("A").hasNext());
        Assert.assertTrue(sqlgGraph1.traversal().V().hasLabel("B").hasNext());
        Assert.assertEquals(1, sqlgGraph1.traversal().V().hasLabel("A").count().next().intValue());
        Assert.assertEquals(1, sqlgGraph1.traversal().V().hasLabel("B").count().next().intValue());
        Vertex a = sqlgGraph1.traversal().V().hasLabel("A").next();
        Assert.assertEquals(idA1, a.id());
        Vertex b = sqlgGraph1.traversal().V().hasLabel("B").next();
        Assert.assertEquals(idB1, b.id());
        Assert.assertEquals(1, sqlgGraph1.traversal().V(a).out("knows").count().next().intValue());
        Assert.assertEquals(b, sqlgGraph1.traversal().V(a).out("knows").next());
        Assert.assertEquals(1, sqlgGraph1.traversal().V(b).in("knows").count().next().intValue());
        Assert.assertEquals(a, sqlgGraph1.traversal().V(b).in("knows").next());
        Assert.assertEquals(1, sqlgGraph1.traversal().V(a).properties("name").count().next().intValue());
        Assert.assertTrue(sqlgGraph1.traversal().V(a).properties("name").next().isPresent());
        Assert.assertEquals("john", sqlgGraph1.traversal().V(a).properties("name").next().value());
        Assert.assertEquals(1, sqlgGraph1.traversal().V(a).outE("knows").properties("name").count().next().intValue());
        Assert.assertTrue(sqlgGraph1.traversal().V(a).outE("knows").properties("name").next().isPresent());
        Assert.assertEquals("hithere", sqlgGraph1.traversal().V(a).outE("knows").properties("name").next().value());
    }
    // from topology
    try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
        Assert.assertEquals(2, sqlgGraph1.traversal().V().count().next().intValue());
        Assert.assertEquals(1, sqlgGraph1.traversal().E().count().next().intValue());
        Assert.assertTrue(sqlgGraph1.traversal().V().hasLabel("A").hasNext());
        Assert.assertTrue(sqlgGraph1.traversal().V().hasLabel("B").hasNext());
        Assert.assertEquals(1, sqlgGraph1.traversal().V().hasLabel("A").count().next().intValue());
        Assert.assertEquals(1, sqlgGraph1.traversal().V().hasLabel("B").count().next().intValue());
        Vertex a = sqlgGraph1.traversal().V().hasLabel("A").next();
        Assert.assertEquals(idA1, a.id());
        Vertex b = sqlgGraph1.traversal().V().hasLabel("B").next();
        Assert.assertEquals(idB1, b.id());
        Assert.assertEquals(1, sqlgGraph1.traversal().V(a).out("knows").count().next().intValue());
        Assert.assertEquals(b, sqlgGraph1.traversal().V(a).out("knows").next());
        Assert.assertEquals(1, sqlgGraph1.traversal().V(b).in("knows").count().next().intValue());
        Assert.assertEquals(a, sqlgGraph1.traversal().V(b).in("knows").next());
        Assert.assertEquals(1, sqlgGraph1.traversal().V(a).properties("name").count().next().intValue());
        Assert.assertTrue(sqlgGraph1.traversal().V(a).properties("name").next().isPresent());
        Assert.assertEquals("john", sqlgGraph1.traversal().V(a).properties("name").next().value());
        Assert.assertEquals(1, sqlgGraph1.traversal().V(a).outE("knows").properties("name").count().next().intValue());
        Assert.assertTrue(sqlgGraph1.traversal().V(a).outE("knows").properties("name").next().isPresent());
        Assert.assertEquals("hithere", sqlgGraph1.traversal().V(a).outE("knows").properties("name").next().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)

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