use of org.umlg.sqlg.structure.topology.EdgeLabel in project sqlg by pietermartin.
the class SchemaTableTree method hasOnlyOneInOutEdgeLabel.
private boolean hasOnlyOneInOutEdgeLabel(SchemaTable schemaTable) {
Optional<Schema> schemaOptional = sqlgGraph.getTopology().getSchema(schemaTable.getSchema());
Preconditions.checkState(schemaOptional.isPresent(), "BUG: %s not found in the topology.", schemaTable.getSchema());
Schema schema = schemaOptional.get();
boolean result = true;
if (schemaTable.isVertexTable()) {
// Need to delete any in/out edges.
Optional<VertexLabel> vertexLabelOptional = schema.getVertexLabel(schemaTable.withOutPrefix().getTable());
Preconditions.checkState(vertexLabelOptional.isPresent(), "BUG: %s not found in the topology.", schemaTable.withOutPrefix().getTable());
VertexLabel vertexLabel = vertexLabelOptional.get();
Collection<EdgeLabel> outEdgeLabels = vertexLabel.getOutEdgeLabels().values();
for (EdgeLabel edgeLabel : outEdgeLabels) {
result = edgeLabel.getOutVertexLabels().size() == 1;
if (!result) {
break;
}
}
if (result) {
Collection<EdgeLabel> inEdgeLabels = vertexLabel.getInEdgeLabels().values();
for (EdgeLabel edgeLabel : inEdgeLabels) {
result = edgeLabel.getInVertexLabels().size() == 1;
if (!result) {
break;
}
}
}
}
return result;
}
use of org.umlg.sqlg.structure.topology.EdgeLabel in project sqlg by pietermartin.
the class TestTopologyDeleteSpecific method testRemoveAndAddInSameTransaction.
/**
* @see <a href="https://github.com/pietermartin/sqlg/issues/212">https://github.com/pietermartin/sqlg/issues/212</a>
*/
@Test
public void testRemoveAndAddInSameTransaction() {
// remove it, it does not exist but duplicating work logic.
Optional<EdgeLabel> aaEdgeLabelOpt = this.sqlgGraph.getTopology().getEdgeLabel(this.sqlgGraph.getSqlDialect().getPublicSchema(), "aa");
if (aaEdgeLabelOpt.isPresent()) {
aaEdgeLabelOpt.get().remove(false);
}
Optional<VertexLabel> aVertexLabelOpt = this.sqlgGraph.getTopology().getVertexLabel(this.sqlgGraph.getSqlDialect().getPublicSchema(), "A");
if (aVertexLabelOpt.isPresent()) {
aVertexLabelOpt.get().remove(false);
}
VertexLabel aVertexLabel = this.sqlgGraph.getTopology().ensureVertexLabelExist("A");
aVertexLabel.ensureEdgeLabelExist("aa", aVertexLabel);
this.sqlgGraph.tx().commit();
aaEdgeLabelOpt = this.sqlgGraph.getTopology().getEdgeLabel(this.sqlgGraph.getSqlDialect().getPublicSchema(), "aa");
if (aaEdgeLabelOpt.isPresent()) {
aaEdgeLabelOpt.get().remove(false);
}
aVertexLabelOpt = this.sqlgGraph.getTopology().getVertexLabel(this.sqlgGraph.getSqlDialect().getPublicSchema(), "A");
if (aVertexLabelOpt.isPresent()) {
aVertexLabelOpt.get().remove(false);
}
aVertexLabel = this.sqlgGraph.getTopology().ensureVertexLabelExist("A");
aVertexLabel.ensureEdgeLabelExist("aa", aVertexLabel);
this.sqlgGraph.tx().commit();
aaEdgeLabelOpt = this.sqlgGraph.getTopology().getEdgeLabel(this.sqlgGraph.getSqlDialect().getPublicSchema(), "aa");
assertTrue(aaEdgeLabelOpt.isPresent());
aVertexLabelOpt = this.sqlgGraph.getTopology().getVertexLabel(this.sqlgGraph.getSqlDialect().getPublicSchema(), "A");
assertTrue(aVertexLabelOpt.isPresent());
}
use of org.umlg.sqlg.structure.topology.EdgeLabel in project sqlg by pietermartin.
the class TestSchemaEagerCreation method testEdgeLabelsProperties.
@SuppressWarnings("OptionalGetWithoutIsPresent")
@Test
public void testEdgeLabelsProperties() {
Vertex a = this.sqlgGraph.addVertex(T.label, "A");
Vertex b = this.sqlgGraph.addVertex(T.label, "B");
a.addEdge("ab", b);
this.sqlgGraph.tx().commit();
Optional<VertexLabel> vertexLabelAOptional = this.sqlgGraph.getTopology().getPublicSchema().getVertexLabel("A");
assertTrue(vertexLabelAOptional.isPresent());
Optional<VertexLabel> vertexLabelBOptional = this.sqlgGraph.getTopology().getPublicSchema().getVertexLabel("B");
assertTrue(vertexLabelBOptional.isPresent());
Optional<EdgeLabel> edgeLabelOptional = vertexLabelAOptional.get().getOutEdgeLabel("ab");
assertTrue(edgeLabelOptional.isPresent());
Map<String, PropertyType> properties = new HashMap<>();
properties.put("name", PropertyType.STRING);
properties.put("age", PropertyType.INTEGER);
EdgeLabel edgeLabel = edgeLabelOptional.get();
edgeLabel.ensurePropertiesExist(properties);
this.sqlgGraph.tx().rollback();
edgeLabel = vertexLabelAOptional.get().getOutEdgeLabel("ab").get();
assertTrue(edgeLabel.getProperties().isEmpty());
edgeLabel = vertexLabelAOptional.get().getOutEdgeLabel("ab").get();
edgeLabel.ensurePropertiesExist(properties);
this.sqlgGraph.tx().commit();
edgeLabel = vertexLabelAOptional.get().getOutEdgeLabel("ab").get();
assertEquals(2, edgeLabel.getProperties().size());
}
use of org.umlg.sqlg.structure.topology.EdgeLabel in project sqlg by pietermartin.
the class TestSchemaEagerCreation method testEdgeLabelAddVertexLabels.
@SuppressWarnings("OptionalGetWithoutIsPresent")
@Test
public void testEdgeLabelAddVertexLabels() {
Vertex a = this.sqlgGraph.addVertex(T.label, "A");
Vertex b = this.sqlgGraph.addVertex(T.label, "B");
a.addEdge("ab", b);
this.sqlgGraph.tx().commit();
Optional<EdgeLabel> edgeLabelOptional = this.sqlgGraph.getTopology().getPublicSchema().getEdgeLabel("ab");
assertTrue(edgeLabelOptional.isPresent());
EdgeLabel edgeLabel = edgeLabelOptional.get();
VertexLabel inVertexLabel = this.sqlgGraph.getTopology().getPublicSchema().ensureVertexLabelExist("C");
edgeLabel.ensureEdgeVertexLabelExist(Direction.IN, inVertexLabel);
this.sqlgGraph.tx().rollback();
edgeLabelOptional = this.sqlgGraph.getTopology().getPublicSchema().getEdgeLabel("ab");
assertTrue(edgeLabelOptional.isPresent());
edgeLabel = edgeLabelOptional.get();
assertEquals(1, edgeLabel.getOutVertexLabels().size());
assertEquals(1, edgeLabel.getInVertexLabels().size());
inVertexLabel = this.sqlgGraph.getTopology().getPublicSchema().ensureVertexLabelExist("C");
edgeLabel.ensureEdgeVertexLabelExist(Direction.IN, inVertexLabel);
this.sqlgGraph.tx().commit();
assertEquals(1, edgeLabel.getOutVertexLabels().size());
assertEquals(2, edgeLabel.getInVertexLabels().size());
VertexLabel outVertexLabel = this.sqlgGraph.getTopology().ensureSchemaExist("D").ensureVertexLabelExist("D");
try {
edgeLabel.ensureEdgeVertexLabelExist(Direction.OUT, outVertexLabel);
fail("Should fail as the out vertex is in a different schema to the edgeLabel");
} catch (IllegalStateException e) {
// swallow
}
assertEquals(1, edgeLabel.getOutVertexLabels().size());
assertEquals(2, edgeLabel.getInVertexLabels().size());
this.sqlgGraph.tx().rollback();
assertEquals(1, edgeLabel.getOutVertexLabels().size());
assertEquals(2, edgeLabel.getInVertexLabels().size());
outVertexLabel = this.sqlgGraph.getTopology().getPublicSchema().ensureVertexLabelExist("D");
edgeLabel.ensureEdgeVertexLabelExist(Direction.OUT, outVertexLabel);
assertEquals(2, edgeLabel.getOutVertexLabels().size());
assertEquals(2, edgeLabel.getInVertexLabels().size());
this.sqlgGraph.tx().rollback();
assertEquals(1, edgeLabel.getOutVertexLabels().size());
assertEquals(2, edgeLabel.getInVertexLabels().size());
outVertexLabel = this.sqlgGraph.getTopology().getPublicSchema().ensureVertexLabelExist("D");
edgeLabel.ensureEdgeVertexLabelExist(Direction.OUT, outVertexLabel);
assertEquals(2, edgeLabel.getOutVertexLabels().size());
assertEquals(2, edgeLabel.getInVertexLabels().size());
this.sqlgGraph.tx().commit();
assertEquals(2, edgeLabel.getOutVertexLabels().size());
assertEquals(2, edgeLabel.getInVertexLabels().size());
}
use of org.umlg.sqlg.structure.topology.EdgeLabel in project sqlg by pietermartin.
the class TestSchemaEagerCreation method testAddEdgeLabelViaOutVertexLabel.
@SuppressWarnings("OptionalGetWithoutIsPresent")
@Test
public void testAddEdgeLabelViaOutVertexLabel() {
VertexLabel a = this.sqlgGraph.getTopology().ensureSchemaExist("A").ensureVertexLabelExist("A");
Optional<Schema> schemaOptional = this.sqlgGraph.getTopology().getSchema("A");
assertTrue(schemaOptional.isPresent());
VertexLabel b = schemaOptional.get().ensureVertexLabelExist("B");
a.ensureEdgeLabelExist("ab", b);
this.sqlgGraph.tx().commit();
Optional<EdgeLabel> edgeLabel = this.sqlgGraph.getTopology().getSchema("A").get().getEdgeLabel("ab");
assertTrue(edgeLabel.isPresent());
assertEquals("ab", edgeLabel.get().getLabel());
}
Aggregations