use of org.umlg.sqlg.structure.SqlgGraph in project sqlg by pietermartin.
the class TestForeignKeysAreOptional method testForeignKeysOnHsqldb.
@Test
public void testForeignKeysOnHsqldb() throws Exception {
Assume.assumeTrue(this.sqlgGraph.getSqlDialect().getClass().getSimpleName().contains("Hsqldb"));
Configuration conf = getConfigurationClone();
conf.setProperty("implement.foreign.keys", "true");
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();
try (PreparedStatement preparedStatement = conn.prepareStatement("select * from information_schema.constraint_table_usage where CONSTRAINT_NAME like '%FK%'")) {
ResultSet rs = preparedStatement.executeQuery();
Assert.assertTrue(rs.next());
}
}
}
use of org.umlg.sqlg.structure.SqlgGraph in project sqlg by pietermartin.
the class TestForeignKeysAreOptional method testForeignKeysOffHsqldb.
@Test
public void testForeignKeysOffHsqldb() throws Exception {
Assume.assumeTrue(this.sqlgGraph.getSqlDialect().getClass().getSimpleName().contains("Hsqldb"));
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();
try (PreparedStatement preparedStatement = conn.prepareStatement("select * from information_schema.constraint_table_usage " + "where TABLE_NAME = 'E_Edge1' and CONSTRAINT_NAME like '%FK%'")) {
ResultSet rs = preparedStatement.executeQuery();
Assert.assertFalse(rs.next());
}
}
}
use of org.umlg.sqlg.structure.SqlgGraph in project sqlg by pietermartin.
the class TestForeignKeysAreOptional method testForeignKeysOnPostgres.
@Test
public void testForeignKeysOnPostgres() throws Exception {
Assume.assumeTrue(this.sqlgGraph.getSqlDialect().getClass().getSimpleName().contains("Postgres"));
Configuration conf = getConfigurationClone();
conf.setProperty("implement.foreign.keys", "true");
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("sqlggraphdb", "public", "E_Edge1");
Assert.assertTrue(rs.next());
}
}
use of org.umlg.sqlg.structure.SqlgGraph in project sqlg by pietermartin.
the class TestCaptureSchemaTableEdges method testLoadTableLabels.
@Test
public void testLoadTableLabels() throws Exception {
Vertex person1 = this.sqlgGraph.addVertex(T.label, "Person", "name", "pieter");
Vertex car1 = this.sqlgGraph.addVertex(T.label, "Car", "name", "bmw");
person1.addEdge("drives", car1);
Vertex car2 = this.sqlgGraph.addVertex(T.label, "Car", "name", "toyota");
person1.addEdge("drives", car2);
Vertex bmw = this.sqlgGraph.addVertex(T.label, "Model", "name", "bmw");
car1.addEdge("model", bmw);
Vertex toyota = this.sqlgGraph.addVertex(T.label, "Model", "name", "toyota");
car2.addEdge("model", toyota);
this.sqlgGraph.tx().commit();
this.sqlgGraph.close();
try (SqlgGraph sqlgGraph = SqlgGraph.open(configuration)) {
Map<SchemaTable, Pair<Set<SchemaTable>, Set<SchemaTable>>> localTabels = sqlgGraph.getTopology().getTableLabels();
assertTrue(localTabels.containsKey(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "V_Person")));
assertTrue(localTabels.containsKey(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "V_Car")));
assertTrue(localTabels.containsKey(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "V_Model")));
Pair<Set<SchemaTable>, Set<SchemaTable>> person = localTabels.get(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "V_Person"));
assertEquals(0, person.getLeft().size());
assertEquals(1, person.getRight().size());
assertEquals(sqlgGraph.getSqlDialect().getPublicSchema() + ".E_drives", person.getRight().iterator().next().toString());
Pair<Set<SchemaTable>, Set<SchemaTable>> car = localTabels.get(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "V_Car"));
assertEquals(1, car.getLeft().size());
assertEquals(1, car.getRight().size());
assertEquals(sqlgGraph.getSqlDialect().getPublicSchema() + ".E_drives", car.getLeft().iterator().next().toString());
Pair<Set<SchemaTable>, Set<SchemaTable>> model = localTabels.get(SchemaTable.of(sqlgGraph.getSqlDialect().getPublicSchema(), "V_Model"));
assertEquals(1, model.getLeft().size());
assertEquals(0, model.getRight().size());
assertEquals(sqlgGraph.getSqlDialect().getPublicSchema() + ".E_model", model.getLeft().iterator().next().toString());
}
}
use of org.umlg.sqlg.structure.SqlgGraph in project sqlg by pietermartin.
the class TestMultiThread method testMultipleGraphsMultipleLabels.
/**
* test when each graph is created in its own thread, in distributed mode
* each thread created a different label
*
* @throws Exception
*/
@Test
public void testMultipleGraphsMultipleLabels() throws Exception {
URL sqlProperties = Thread.currentThread().getContextClassLoader().getResource("sqlg.properties");
try {
configuration = new PropertiesConfiguration(sqlProperties);
Assume.assumeTrue(isPostgres());
configuration.addProperty("distributed", true);
if (!configuration.containsKey("jdbc.url"))
throw new IllegalArgumentException(String.format("SqlGraph configuration requires that the %s be set", "jdbc.url"));
} catch (ConfigurationException e) {
e.printStackTrace();
fail(e.getMessage());
}
ExecutorService executorService = newFixedThreadPool(200);
int loop = 20;
for (int i = 0; i < loop; i++) {
String n = "person" + i;
executorService.submit(() -> {
try {
try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
sqlgGraph1.addVertex(T.label, "Person" + n, "name", n);
sqlgGraph1.tx().commit();
}
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
});
}
executorService.shutdown();
executorService.awaitTermination(10, TimeUnit.SECONDS);
try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
for (int i = 0; i < loop; i++) {
String n = "person" + i;
Assert.assertEquals(1, sqlgGraph1.traversal().V().hasLabel("Person" + n).count().next().longValue());
}
}
}
Aggregations