Search in sources :

Example 21 with SqlgGraph

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

the class TestLocalDateArray method testPeriodArray.

@Test
public void testPeriodArray() throws Exception {
    Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportsIntegerArrayValues());
    Period[] periods = new Period[] { Period.of(2016, 5, 5), Period.of(2015, 4, 4) };
    this.sqlgGraph.addVertex(T.label, "A", "periods", periods);
    this.sqlgGraph.tx().commit();
    // Create a new sqlgGraph
    try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
        List<? extends Property<Period[]>> properties = sqlgGraph1.traversal().V().hasLabel("A").<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 : SqlgGraph(org.umlg.sqlg.structure.SqlgGraph) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 22 with SqlgGraph

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

the class TestLocalDateArray method testZonedDateTimeArray2.

@Test
public void testZonedDateTimeArray2() throws Exception {
    Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportsLocalDateTimeArrayValues());
    ZoneId zoneIdShanghai = ZoneId.of("Asia/Shanghai");
    ZonedDateTime zonedDateTimeAGT = ZonedDateTime.of(LocalDateTime.now(), zoneIdShanghai);
    ZoneId zoneIdHarare = ZoneId.of("Africa/Harare");
    ZonedDateTime zonedDateTimeAGTHarare = ZonedDateTime.of(LocalDateTime.now(), zoneIdHarare);
    ZonedDateTime[] zonedDateTimes = new ZonedDateTime[] { zonedDateTimeAGT, zonedDateTimeAGTHarare };
    this.sqlgGraph.addVertex(T.label, "A", "zonedDateTimes", zonedDateTimes);
    this.sqlgGraph.tx().commit();
    // noinspection Duplicates
    try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
        List<? extends Property<ZonedDateTime[]>> properties = sqlgGraph1.traversal().V().hasLabel("A").<ZonedDateTime[]>properties("zonedDateTimes").toList();
        Assert.assertEquals(1, properties.size());
        Assert.assertTrue(properties.get(0).isPresent());
        ZonedDateTime[] value = properties.get(0).<ZonedDateTime[]>value();
        Assert.assertArrayEquals(zonedDateTimes, value);
    }
}
Also used : SqlgGraph(org.umlg.sqlg.structure.SqlgGraph) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 23 with SqlgGraph

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

the class TestGremlinCompileWithAs method testHasLabelOutWithAs_assert.

private void testHasLabelOutWithAs_assert(SqlgGraph sqlgGraph, Vertex a1, Vertex b1, Vertex b2, Vertex b3, Vertex b4, Edge e1, Edge e2, Edge e3, Edge e4) {
    DefaultGraphTraversal<Vertex, Map<String, Element>> traversal = (DefaultGraphTraversal) sqlgGraph.traversal().V(a1).outE("outB").as("e").inV().as("B").select("e", "B");
    Assert.assertEquals(4, traversal.getSteps().size());
    List<Map<String, Element>> result = traversal.toList();
    Assert.assertEquals(2, traversal.getSteps().size());
    Collections.sort(result, Comparator.comparing(o -> o.get("e").<String>value("edgeName")));
    Assert.assertEquals(4, result.size());
    Edge queryE0 = (Edge) result.get(0).get("e");
    Vertex queryB0 = (Vertex) result.get(0).get("B");
    Assert.assertEquals(e1, queryE0);
    Assert.assertEquals("b1", queryE0.inVertex().value("name"));
    Assert.assertEquals("a1", queryE0.outVertex().value("name"));
    Assert.assertEquals("edge1", queryE0.value("edgeName"));
    Assert.assertEquals(b1, queryB0);
    Assert.assertEquals("b1", queryB0.value("name"));
    Element queryE2 = result.get(1).get("e");
    Element queryB2 = result.get(1).get("B");
    Assert.assertEquals(e2, queryE2);
    Assert.assertEquals("edge2", queryE2.value("edgeName"));
    Assert.assertEquals(b2, queryB2);
    Assert.assertEquals("b2", queryB2.value("name"));
    Element queryE3 = result.get(2).get("e");
    Element queryB3 = result.get(2).get("B");
    Assert.assertEquals(e3, queryE3);
    Assert.assertEquals("edge3", queryE3.value("edgeName"));
    Assert.assertEquals(b3, queryB3);
    Assert.assertEquals("b3", queryB3.value("name"));
    Element queryE4 = result.get(3).get("e");
    Element queryB4 = result.get(3).get("B");
    Assert.assertEquals(e4, queryE4);
    Assert.assertEquals("edge4", queryE4.value("edgeName"));
    Assert.assertEquals(b4, queryB4);
    Assert.assertEquals("b4", queryB4.value("name"));
    DefaultGraphTraversal<Vertex, Edge> traversal1 = (DefaultGraphTraversal<Vertex, Edge>) sqlgGraph.traversal().V(a1.id()).bothE();
    Assert.assertEquals(2, traversal1.getSteps().size());
    final List<Edge> a1Edges = traversal1.toList();
    Assert.assertEquals(1, traversal1.getSteps().size());
    Assert.assertEquals(4, a1Edges.size());
    List<String> names = new ArrayList<>(Arrays.asList("b1", "b2", "b3", "b4"));
    for (Edge a1Edge : a1Edges) {
        names.remove(a1Edge.inVertex().<String>value("name"));
        Assert.assertEquals("a1", a1Edge.outVertex().<String>value("name"));
    }
    Assert.assertTrue(names.isEmpty());
}
Also used : java.util(java.util) BeforeClass(org.junit.BeforeClass) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test) IOException(java.io.IOException) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) T(org.apache.tinkerpop.gremlin.structure.T) SqlgGraph(org.umlg.sqlg.structure.SqlgGraph) PropertyVetoException(java.beans.PropertyVetoException) Element(org.apache.tinkerpop.gremlin.structure.Element) Assert(org.junit.Assert) DefaultGraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal) Edge(org.apache.tinkerpop.gremlin.structure.Edge) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Element(org.apache.tinkerpop.gremlin.structure.Element) DefaultGraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal) Edge(org.apache.tinkerpop.gremlin.structure.Edge)

Example 24 with SqlgGraph

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

the class TestForeignKeysAreOptional method testForeignKeysOffPostgres.

@Test
public void testForeignKeysOffPostgres() throws Exception {
    Assume.assumeTrue(this.sqlgGraph.getSqlDialect().getClass().getSimpleName().contains("Postgres"));
    Configuration conf = getConfigurationClone();
    conf.setProperty("implement.foreign.keys", "false");
    try (SqlgGraph g = SqlgGraph.open(conf)) {
        Vertex v1 = g.addVertex(T.label, "Person");
        Vertex v2 = g.addVertex(T.label, "Person");
        v1.addEdge("Edge1", v2);
        g.tx().commit();
        Connection conn = g.tx().getConnection();
        DatabaseMetaData dm = conn.getMetaData();
        ResultSet rs = dm.getImportedKeys("sqlgraphdb", "public", "E_Edge1");
        Assert.assertFalse(rs.next());
    }
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) SqlgGraph(org.umlg.sqlg.structure.SqlgGraph) Configuration(org.apache.commons.configuration.Configuration) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) DatabaseMetaData(java.sql.DatabaseMetaData) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 25 with SqlgGraph

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

the class TestAllVertices method testVertexIteratorWithIncorrectId.

@Test
public void testVertexIteratorWithIncorrectId() throws Exception {
    Graph g = this.sqlgGraph;
    final Vertex v1 = g.addVertex("name", "marko");
    final Object oid = v1.id();
    g.tx().onClose(Transaction.CLOSE_BEHAVIOR.ROLLBACK);
    g.close();
    try (SqlgGraph graph = SqlgGraph.open(configuration)) {
        try {
            graph.vertices(oid).next();
            Assert.fail("Vertex should not be found as close behavior was set to rollback");
        } catch (Exception ex) {
            validateException(Graph.Exceptions.elementNotFound(Vertex.class, oid), ex);
        }
    }
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Graph(org.apache.tinkerpop.gremlin.structure.Graph) SqlgGraph(org.umlg.sqlg.structure.SqlgGraph) 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