Search in sources :

Example 1 with Topology

use of org.umlg.sqlg.structure.topology.Topology in project sqlg by pietermartin.

the class TestSchema method testEnsureSchema.

@Test
public void testEnsureSchema() {
    Topology mgr = this.sqlgGraph.getTopology();
    this.sqlgGraph.addVertex(T.label, "A.A");
    this.sqlgGraph.tx().commit();
    Assert.assertTrue(mgr.getSchema(this.sqlgGraph.getSqlDialect().getPublicSchema()).isPresent());
    Assert.assertTrue(mgr.getSchema("A").isPresent());
    Assert.assertNotNull(mgr.ensureSchemaExist("A"));
    Assert.assertFalse(mgr.getSchema("B").isPresent());
    Assert.assertNotNull(mgr.ensureSchemaExist("B"));
    Assert.assertTrue(mgr.getSchema("B").isPresent());
    this.sqlgGraph.tx().commit();
    Assert.assertTrue(mgr.getSchema("B").isPresent());
}
Also used : Topology(org.umlg.sqlg.structure.topology.Topology) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 2 with Topology

use of org.umlg.sqlg.structure.topology.Topology in project sqlg by pietermartin.

the class TestSchema method testExistingSchema.

@Test
public void testExistingSchema() throws SQLException {
    Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportsSchemaIfNotExists());
    String schema = "A";
    Connection c = this.sqlgGraph.tx().getConnection();
    try (Statement ps = c.createStatement()) {
        ps.executeUpdate("create schema " + this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(schema));
    }
    c.commit();
    Topology mgr = this.sqlgGraph.getTopology();
    Assert.assertFalse(mgr.getSchema("A").isPresent());
    this.sqlgGraph.addVertex(T.label, schema + ".A");
    this.sqlgGraph.tx().commit();
    Assert.assertTrue(mgr.getSchema("A").isPresent());
}
Also used : Statement(java.sql.Statement) Connection(java.sql.Connection) Topology(org.umlg.sqlg.structure.topology.Topology) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 3 with Topology

use of org.umlg.sqlg.structure.topology.Topology in project sqlg by pietermartin.

the class TestTopology method testAddColumns.

@Test
public void testAddColumns() {
    // Create Schema
    Topology topology = sqlgGraph.getTopology();
    topology.ensureSchemaExist("TEST");
    Map<String, Object> columns = new HashMap<>();
    columns.put("Test1", "");
    columns.put("Test2", "");
    // Add a vertex and remove to create columns
    Vertex v = sqlgGraph.addVertex("TEST" + "." + "TEST_Table", columns);
    v.remove();
    sqlgGraph.tx().commit();
    columns = new HashMap<>();
    columns.put("Test1", "T1");
    columns.put("Test2", "T2");
    // Add the data
    Vertex vv = sqlgGraph.addVertex("TEST" + "." + "TEST_Table", columns);
    sqlgGraph.tx().commit();
    // Simulating second load
    // Remove the whole table label
    Optional<VertexLabel> tableVertexLabel = sqlgGraph.getTopology().getVertexLabel("TEST", "TEST_Table");
    if (tableVertexLabel.isPresent()) {
        tableVertexLabel.get().remove(false);
    }
    columns = new HashMap<>();
    columns.put("Test1", "");
    columns.put("Test2", "");
    columns.put("Test3", "");
    // Add a vertex with more columns than previously had
    v = sqlgGraph.addVertex("TEST" + "." + "TEST_Table", columns);
    v.remove();
    sqlgGraph.tx().commit();
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) HashMap(java.util.HashMap) VertexLabel(org.umlg.sqlg.structure.topology.VertexLabel) Topology(org.umlg.sqlg.structure.topology.Topology) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 Topology (org.umlg.sqlg.structure.topology.Topology)3 BaseTest (org.umlg.sqlg.test.BaseTest)3 Connection (java.sql.Connection)1 Statement (java.sql.Statement)1 HashMap (java.util.HashMap)1 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)1 VertexLabel (org.umlg.sqlg.structure.topology.VertexLabel)1