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);
}
}
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);
}
}
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());
}
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());
}
}
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);
}
}
}
Aggregations