/** * Ensures that the edge table with out and in foreign keys and property columns exists. * The edge table will reside in the out vertex's schema. * If a table, a foreign key or a column needs to be created a lock is first obtained. * * @param edgeLabelName The label for the edge. * @param foreignKeyOut The {@link SchemaTable} that represents the out vertex. * @param foreignKeyIn The {@link SchemaTable} that represents the in vertex. * @param properties The edge's properties with their type. * @return The {@link SchemaTable} that represents the edge. */ public void ensureEdgeLabelExist(final String edgeLabelName, final SchemaTable foreignKeyOut, final SchemaTable foreignKeyIn, Map<String, PropertyType> properties) { Objects.requireNonNull(edgeLabelName, "Given edgeLabelName must not be null"); Objects.requireNonNull(foreignKeyOut, "Given outTable must not be null"); Objects.requireNonNull(foreignKeyIn, "Given inTable must not be null"); Preconditions.checkState(getVertexLabel(foreignKeyOut.getSchema(), foreignKeyOut.getTable()).isPresent(), "The out vertex must already exist before invoking 'ensureEdgeLabelExist'. \"%s\" does not exist", foreignKeyIn.toString()); Preconditions.checkState(getVertexLabel(foreignKeyIn.getSchema(), foreignKeyIn.getTable()).isPresent(), "The in vertex must already exist before invoking 'ensureEdgeLabelExist'. \"%s\" does not exist", foreignKeyIn.toString()); //outVertexSchema will be there as the Precondition checked it. @SuppressWarnings("OptionalGetWithoutIsPresent") Schema outVertexSchema = this.getSchema(foreignKeyOut.getSchema()).get(); Schema inVertexSchema = this.getSchema(foreignKeyIn.getSchema()).get(); Optional<VertexLabel> outVertexLabel = outVertexSchema.getVertexLabel(foreignKeyOut.getTable()); Optional<VertexLabel> inVertexLabel = inVertexSchema.getVertexLabel(foreignKeyIn.getTable()); Preconditions.checkState(outVertexLabel.isPresent(), "out VertexLabel must be present"); Preconditions.checkState(inVertexLabel.isPresent(), "in VertexLabel must be present"); @SuppressWarnings("OptionalGetWithoutIsPresent") EdgeLabel edgeLabel = outVertexSchema.ensureEdgeLabelExist(edgeLabelName, outVertexLabel.get(), inVertexLabel.get(), properties); SchemaTable.of(foreignKeyOut.getSchema(), edgeLabel.getLabel()); }
/** * Ensures that the edge table with out and in foreign keys and property columns exists. * The edge table will reside in the out vertex's schema. * If a table, a foreign key or a column needs to be created a lock is first obtained. * * @param edgeLabelName The label for the edge. * @param foreignKeyOut The {@link SchemaTable} that represents the out vertex. * @param foreignKeyIn The {@link SchemaTable} that represents the in vertex. * @param properties The edge's properties with their type. * @return The {@link SchemaTable} that represents the edge. */ public void ensureEdgeLabelExist(final String edgeLabelName, final SchemaTable foreignKeyOut, final SchemaTable foreignKeyIn, Map<String, PropertyType> properties) { Objects.requireNonNull(edgeLabelName, "Given edgeLabelName must not be null"); Objects.requireNonNull(foreignKeyOut, "Given outTable must not be null"); Objects.requireNonNull(foreignKeyIn, "Given inTable must not be null"); Preconditions.checkState(getVertexLabel(foreignKeyOut.getSchema(), foreignKeyOut.getTable()).isPresent(), "The out vertex must already exist before invoking 'ensureEdgeLabelExist'. \"%s\" does not exist", foreignKeyIn.toString()); Preconditions.checkState(getVertexLabel(foreignKeyIn.getSchema(), foreignKeyIn.getTable()).isPresent(), "The in vertex must already exist before invoking 'ensureEdgeLabelExist'. \"%s\" does not exist", foreignKeyIn.toString()); //outVertexSchema will be there as the Precondition checked it. @SuppressWarnings("OptionalGetWithoutIsPresent") Schema outVertexSchema = this.getSchema(foreignKeyOut.getSchema()).get(); Schema inVertexSchema = this.getSchema(foreignKeyIn.getSchema()).get(); Optional<VertexLabel> outVertexLabel = outVertexSchema.getVertexLabel(foreignKeyOut.getTable()); Optional<VertexLabel> inVertexLabel = inVertexSchema.getVertexLabel(foreignKeyIn.getTable()); Preconditions.checkState(outVertexLabel.isPresent(), "out VertexLabel must be present"); Preconditions.checkState(inVertexLabel.isPresent(), "in VertexLabel must be present"); @SuppressWarnings("OptionalGetWithoutIsPresent") EdgeLabel edgeLabel = outVertexSchema.ensureEdgeLabelExist(edgeLabelName, outVertexLabel.get(), inVertexLabel.get(), properties); SchemaTable.of(foreignKeyOut.getSchema(), edgeLabel.getLabel()); }
vertexLabel = sqlgGraph.getTopology().getVertexLabel(schemaTable.getSchema(), schemaTable.getTable()).orElseThrow( () -> new IllegalStateException(String.format("VertexLabel %s not found.", schemaTable.toString())));
Optional<VertexLabel> outVertexLabelOptional = this.sqlgGraph.getTopology().getVertexLabel(this.schema, this.table); Optional<VertexLabel> inVertexLabelOptional = this.sqlgGraph.getTopology().getVertexLabel(((SqlgVertex) inVertex).schema, ((SqlgVertex) inVertex).table); Preconditions.checkState(outVertexLabelOptional.isPresent(), "Out VertexLabel must be present. Not found for %s", this.schema + "." + this.table); Preconditions.checkState(inVertexLabelOptional.isPresent(), "In VertexLabel must be present. Not found for %s", ((SqlgVertex) inVertex).schema + "." + ((SqlgVertex) inVertex).table);
Optional<VertexLabel> outVertexLabelOptional = this.sqlgGraph.getTopology().getVertexLabel(this.schema, this.table); Optional<VertexLabel> inVertexLabelOptional = this.sqlgGraph.getTopology().getVertexLabel(((SqlgVertex) inVertex).schema, ((SqlgVertex) inVertex).table); Preconditions.checkState(outVertexLabelOptional.isPresent(), "Out VertexLabel must be present. Not found for %s", this.schema + "." + this.table); Preconditions.checkState(inVertexLabelOptional.isPresent(), "In VertexLabel must be present. Not found for %s", ((SqlgVertex) inVertex).schema + "." + ((SqlgVertex) inVertex).table);
vertexLabel = sqlgGraph.getTopology().getVertexLabel(schemaTable.getSchema(), schemaTable.getTable()).orElseThrow( () -> new IllegalStateException(String.format("VertexLabel %s not found.", schemaTable.toString())));
SchemaTable schemaTable = schemaVertices.getKey(); VertexLabel vertexLabel = sqlgGraph.getTopology().getVertexLabel(schemaTable.getSchema(), schemaTable.getTable()) .orElseThrow(() -> new IllegalStateException(String.format("VertexLabel not found for %s.%s", schemaTable.getSchema(), schemaTable.getTable())));
SchemaTable schemaTable = schemaVertices.getKey(); VertexLabel vertexLabel = sqlgGraph.getTopology().getVertexLabel(schemaTable.getSchema(), schemaTable.getTable()) .orElseThrow(() -> new IllegalStateException(String.format("VertexLabel not found for %s.%s", schemaTable.getSchema(), schemaTable.getTable())));
SqlgGraph sqlgGraph = SqlgGraph.open(configuration); this.umlgGraph = new UmlgSqlgGraph(sqlgGraph); if (!sqlgGraph.getTopology().getVertexLabel(sqlgGraph.getSqlDialect().getPublicSchema(), UmlgGraph.ROOT_VERTEX).isPresent()) { try {
Optional<VertexLabel> outVertexLabelOptional = sqlgGraph.getTopology().getVertexLabel(out.getSchema(), out.getTable()); Optional<VertexLabel> inVertexLabelOptional = sqlgGraph.getTopology().getVertexLabel(in.getSchema(), in.getTable()); Preconditions.checkState(outVertexLabelOptional.isPresent(), "Out VertexLabel must be present. Not found for %s", out.toString()); Preconditions.checkState(inVertexLabelOptional.isPresent(), "In VertexLabel must be present. Not found for %s", in.toString());
SchemaTable outVertexLabelSchemaTable = SchemaTable.of(outVertex.getSchema(), outVertex.getTable()); SchemaTable inSchemaTable = SchemaTable.of(inVertex.getSchema(), inVertex.getTable()); VertexLabel outVertexLabel = sqlgGraph.getTopology().getVertexLabel(outVertexLabelSchemaTable.getSchema(), outVertexLabelSchemaTable.getTable()).orElseThrow(() -> new IllegalStateException(String.format("VertexLabel not found for %s.%s", outVertexLabelSchemaTable.getSchema(), outVertexLabelSchemaTable.getTable()))); VertexLabel inVertexLabel = sqlgGraph.getTopology().getVertexLabel(inSchemaTable.getSchema(), inSchemaTable.getTable()).orElseThrow(() -> new IllegalStateException(String.format("VertexLabel not found for %s.%s", inSchemaTable.getSchema(), inSchemaTable.getTable()))); EdgeLabel edgeLabel = sqlgGraph.getTopology().getEdgeLabel(outSchemaTable.getSchema(), sqlgEdge.getTable()).orElseThrow(() -> new IllegalStateException(String.format("EdgeLabel not found for %s.%s", outSchemaTable.getSchema(), sqlgEdge.getTable()))); MetaEdge metaEdge = MetaEdge.from(outSchemaTable, outVertex, inVertex);
SchemaTable outVertexLabelSchemaTable = SchemaTable.of(outVertex.getSchema(), outVertex.getTable()); SchemaTable inSchemaTable = SchemaTable.of(inVertex.getSchema(), inVertex.getTable()); VertexLabel outVertexLabel = sqlgGraph.getTopology().getVertexLabel(outVertexLabelSchemaTable.getSchema(), outVertexLabelSchemaTable.getTable()).orElseThrow(() -> new IllegalStateException(String.format("VertexLabel not found for %s.%s", outVertexLabelSchemaTable.getSchema(), outVertexLabelSchemaTable.getTable()))); VertexLabel inVertexLabel = sqlgGraph.getTopology().getVertexLabel(inSchemaTable.getSchema(), inSchemaTable.getTable()).orElseThrow(() -> new IllegalStateException(String.format("VertexLabel not found for %s.%s", inSchemaTable.getSchema(), inSchemaTable.getTable()))); EdgeLabel edgeLabel = sqlgGraph.getTopology().getEdgeLabel(outSchemaTable.getSchema(), sqlgEdge.getTable()).orElseThrow(() -> new IllegalStateException(String.format("EdgeLabel not found for %s.%s", outSchemaTable.getSchema(), sqlgEdge.getTable()))); MetaEdge metaEdge = MetaEdge.from(outSchemaTable, outVertex, inVertex);
private void process(SchemaTableTree rootSchemaTableTree) { SchemaTable table = rootSchemaTableTree.getSchemaTable(); Optional<? extends AbstractLabel> label; if (table.isVertexTable()) { label = sqlgGraph.getTopology().getVertexLabel(table.getSchema(), table.withOutPrefix().getTable()); } else if (table.isEdgeTable()) { label = sqlgGraph.getTopology().getEdgeLabel(table.getSchema(), table.withOutPrefix().getTable()); } else { label = Optional.empty(); } process(sqlgGraph, rootSchemaTableTree, label.orElseThrow(illegalState("unknown table: %s", table))); }
VertexLabel vertexLabel = null; if (!schemaTable.isTemporary()) { vertexLabel = sqlgGraph.getTopology().getVertexLabel(schemaTable.getSchema(), schemaTable.getTable()).orElseThrow( () -> new IllegalStateException(String.format("VertexLabel %s not found.", schemaTable.toString())));
Optional<VertexLabel> vertexLabelOptional = this.topology.getVertexLabel(inSchemaVertexLabelName, inVertexLabelName); Preconditions.checkState(vertexLabelOptional.isPresent(), "BUG: VertexLabel not found for schema %s and label %s", inSchemaVertexLabelName, inVertexLabelName);
this.outVertexLabel = sqlgGraph.getTopology().getVertexLabel(outSchemaTable.getSchema(), outSchemaTable.getTable()).orElseThrow(() -> new IllegalStateException(String.format("VertexLabel not found for %s.%s", outSchemaTable.getSchema(), outSchemaTable.getTable()))); this.inVertexLabel = sqlgGraph.getTopology().getVertexLabel(inSchemaTable.getSchema(), inSchemaTable.getTable()).orElseThrow(() -> new IllegalStateException(String.format("VertexLabel not found for %s.%s", inSchemaTable.getSchema(), inSchemaTable.getTable())));
Optional<VertexLabel> vertexLabelOptional = this.topology.getVertexLabel(inSchemaVertexLabelName, inVertexLabelName); Preconditions.checkState(vertexLabelOptional.isPresent(), "BUG: VertexLabel not found for schema %s and label %s", inSchemaVertexLabelName, inVertexLabelName);
private void setIdentifiersAndDistributionColumn() { if (this.schemaTable.isVertexTable()) { VertexLabel vertexLabel = this.sqlgGraph.getTopology().getVertexLabel( this.schemaTable.withOutPrefix().getSchema(), this.schemaTable.withOutPrefix().getTable() ).orElseThrow(() -> new IllegalStateException(String.format("Label %s must ne present.", this.schemaTable.toString()))); this.identifiers = vertexLabel.getIdentifiers(); if (vertexLabel.isDistributed()) { this.distributionColumn = vertexLabel.getDistributionPropertyColumn().getName(); } else { this.distributionColumn = null; } } else { EdgeLabel edgeLabel = this.sqlgGraph.getTopology().getEdgeLabel( this.schemaTable.withOutPrefix().getSchema(), this.schemaTable.withOutPrefix().getTable() ).orElseThrow(() -> new IllegalStateException(String.format("Label %s must ne present.", this.schemaTable.toString()))); this.identifiers = edgeLabel.getIdentifiers(); if (edgeLabel.isDistributed()) { this.distributionColumn = edgeLabel.getDistributionPropertyColumn().getName(); } else { this.distributionColumn = null; } } }
private void setIdentifiersAndDistributionColumn() { if (this.schemaTable.isVertexTable()) { VertexLabel vertexLabel = this.sqlgGraph.getTopology().getVertexLabel( this.schemaTable.withOutPrefix().getSchema(), this.schemaTable.withOutPrefix().getTable() ).orElseThrow(() -> new IllegalStateException(String.format("Label %s must ne present.", this.schemaTable.toString()))); this.identifiers = vertexLabel.getIdentifiers(); if (vertexLabel.isDistributed()) { this.distributionColumn = vertexLabel.getDistributionPropertyColumn().getName(); } else { this.distributionColumn = null; } } else { EdgeLabel edgeLabel = this.sqlgGraph.getTopology().getEdgeLabel( this.schemaTable.withOutPrefix().getSchema(), this.schemaTable.withOutPrefix().getTable() ).orElseThrow(() -> new IllegalStateException(String.format("Label %s must ne present.", this.schemaTable.toString()))); this.identifiers = edgeLabel.getIdentifiers(); if (edgeLabel.isDistributed()) { this.distributionColumn = edgeLabel.getDistributionPropertyColumn().getName(); } else { this.distributionColumn = null; } } }
RecordId.ID id = recordId.getID(); if (sqlgElement instanceof SqlgVertex) { Optional<VertexLabel> vertexLabelOptional = this.sqlgGraph.getTopology().getVertexLabel(schemaTable.getSchema(), schemaTable.getTable()); Preconditions.checkState(vertexLabelOptional.isPresent()); SqlgVertex sqlgVertex = (SqlgVertex)sqlgElement;