@Override public Schema getSchema() { if (!this.outVertexLabels.isEmpty()) { VertexLabel vertexLabel = this.outVertexLabels.iterator().next(); return vertexLabel.getSchema(); } else if (this.topology.isSqlWriteLockHeldByCurrentThread() && !this.uncommittedOutVertexLabels.isEmpty()) { VertexLabel vertexLabel = this.uncommittedOutVertexLabels.iterator().next(); return vertexLabel.getSchema(); } else { throw new IllegalStateException("BUG: no outVertexLabels present when getSchema() is called"); } }
@Override public Schema getSchema() { if (!this.outVertexLabels.isEmpty()) { VertexLabel vertexLabel = this.outVertexLabels.iterator().next(); return vertexLabel.getSchema(); } else if (this.topology.isSqlWriteLockHeldByCurrentThread() && !this.uncommittedOutVertexLabels.isEmpty()) { VertexLabel vertexLabel = this.uncommittedOutVertexLabels.iterator().next(); return vertexLabel.getSchema(); } else { throw new IllegalStateException("BUG: no outVertexLabels present when getSchema() is called"); } }
/** * Ensures that the {@link EdgeLabel} exists. It will be created if it does not exists. * "this" is the out {@link VertexLabel} and inVertexLabel is the inVertexLabel * This method is equivalent to {@link Schema#ensureEdgeLabelExist(String, VertexLabel, VertexLabel, Map)} * * @param edgeLabelName The EdgeLabel's label's name. * @param inVertexLabel The edge's in VertexLabel. * @return The {@link EdgeLabel}. */ public EdgeLabel ensureEdgeLabelExist(final String edgeLabelName, final VertexLabel inVertexLabel) { return this.getSchema().ensureEdgeLabelExist(edgeLabelName, this, inVertexLabel, Collections.emptyMap()); }
/** * Ensures that the {@link EdgeLabel} exists. It will be created if it does not exists. * "this" is the out {@link VertexLabel} and inVertexLabel is the inVertexLabel * This method is equivalent to {@link Schema#ensureEdgeLabelExist(String, VertexLabel, VertexLabel, Map)} * * @param edgeLabelName The EdgeLabel's label's name. * @param inVertexLabel The edge's in VertexLabel. * @return The {@link EdgeLabel}. */ public EdgeLabel ensureEdgeLabelExist(final String edgeLabelName, final VertexLabel inVertexLabel) { return this.getSchema().ensureEdgeLabelExist(edgeLabelName, this, inVertexLabel, Collections.emptyMap()); }
/** * Ensures that the {@link EdgeLabel} exists. It will be created if it does not exists. * "this" is the out {@link VertexLabel} and inVertexLabel is the inVertexLabel * This method is equivalent to {@link Schema#ensureEdgeLabelExist(String, VertexLabel, VertexLabel, Map)} * * @param edgeLabelName The EdgeLabel's label's name. * @param inVertexLabel The edge's in VertexLabel. * @param properties The EdgeLabel's properties * @return The EdgeLabel */ public EdgeLabel ensureEdgeLabelExist(final String edgeLabelName, final VertexLabel inVertexLabel, Map<String, PropertyType> properties) { return this.getSchema().ensureEdgeLabelExist(edgeLabelName, this, inVertexLabel, properties); }
@Override public void remove(boolean preserveData) { this.getSchema().removeVertexLabel(this, preserveData); }
/** * Ensures that the {@link EdgeLabel} exists. It will be created if it does not exists. * "this" is the out {@link VertexLabel} and inVertexLabel is the inVertexLabel * This method is equivalent to {@link Schema#ensureEdgeLabelExist(String, VertexLabel, VertexLabel, Map)} * * @param edgeLabelName The EdgeLabel's label's name. * @param inVertexLabel The edge's in VertexLabel. * @param properties The EdgeLabel's properties * @return The EdgeLabel */ public EdgeLabel ensureEdgeLabelExist(final String edgeLabelName, final VertexLabel inVertexLabel, Map<String, PropertyType> properties) { return this.getSchema().ensureEdgeLabelExist(edgeLabelName, this, inVertexLabel, properties); }
@Override public int hashCode() { //Edges are unique per out vertex schemas. //An edge must have at least one out vertex so take it to get the schema. VertexLabel vertexLabel; if (!this.outVertexLabels.isEmpty()) { vertexLabel = this.outVertexLabels.iterator().next(); } else { vertexLabel = this.uncommittedOutVertexLabels.iterator().next(); } return (vertexLabel.getSchema().getName() + this.getLabel()).hashCode(); }
@Override public int hashCode() { //Edges are unique per out vertex schemas. //An edge must have at least one out vertex so take it to get the schema. VertexLabel vertexLabel; if (!this.outVertexLabels.isEmpty()) { vertexLabel = this.outVertexLabels.iterator().next(); } else { vertexLabel = this.uncommittedOutVertexLabels.iterator().next(); } return (vertexLabel.getSchema().getName() + this.getLabel()).hashCode(); }
Pair<Set<SchemaTable>, Set<SchemaTable>> getUncommittedSchemaTableForeignKeys() { Pair<Set<SchemaTable>, Set<SchemaTable>> result = Pair.of(new HashSet<>(), new HashSet<>()); for (Map.Entry<String, EdgeLabel> uncommittedEdgeLabelEntry : this.uncommittedOutEdgeLabels.entrySet()) { result.getRight().add(SchemaTable.of(this.getSchema().getName(), EDGE_PREFIX + uncommittedEdgeLabelEntry.getValue().getLabel())); } for (Map.Entry<String, EdgeLabel> uncommittedEdgeLabelEntry : this.uncommittedInEdgeLabels.entrySet()) { result.getLeft().add(SchemaTable.of(uncommittedEdgeLabelEntry.getValue().getSchema().getName(), EDGE_PREFIX + uncommittedEdgeLabelEntry.getValue().getLabel())); } return result; }
Pair<Set<SchemaTable>, Set<SchemaTable>> getUncommittedSchemaTableForeignKeys() { Pair<Set<SchemaTable>, Set<SchemaTable>> result = Pair.of(new HashSet<>(), new HashSet<>()); for (Map.Entry<String, EdgeLabel> uncommittedEdgeLabelEntry : this.uncommittedOutEdgeLabels.entrySet()) { result.getRight().add(SchemaTable.of(this.getSchema().getName(), EDGE_PREFIX + uncommittedEdgeLabelEntry.getValue().getLabel())); } for (Map.Entry<String, EdgeLabel> uncommittedEdgeLabelEntry : this.uncommittedInEdgeLabels.entrySet()) { result.getLeft().add(SchemaTable.of(uncommittedEdgeLabelEntry.getValue().getSchema().getName(), EDGE_PREFIX + uncommittedEdgeLabelEntry.getValue().getLabel())); } return result; }
/** * add out foreign key between a vertex label and a edge label * * @param vertexLabel * @param edgeLabel */ void addOutForeignKeysToVertexLabel(VertexLabel vertexLabel, EdgeLabel edgeLabel) { Preconditions.checkState(isSqlWriteLockHeldByCurrentThread() || isTopologyMapWriteLockHeldByCurrentThread()); SchemaTable schemaTable = SchemaTable.of(vertexLabel.getSchema().getName(), VERTEX_PREFIX + vertexLabel.getLabel()); Pair<Set<SchemaTable>, Set<SchemaTable>> foreignKeys = this.schemaTableForeignKeyCache.computeIfAbsent( schemaTable, k -> Pair.of(new HashSet<>(), new HashSet<>()) ); foreignKeys.getRight().add(SchemaTable.of(vertexLabel.getSchema().getName(), EDGE_PREFIX + edgeLabel.getLabel())); }
/** * add in foreign key between a vertex label and a edge label * * @param vertexLabel * @param edgeLabel */ void addInForeignKeysToVertexLabel(VertexLabel vertexLabel, EdgeLabel edgeLabel) { Preconditions.checkState(isSqlWriteLockHeldByCurrentThread() || isTopologyMapWriteLockHeldByCurrentThread()); SchemaTable schemaTable = SchemaTable.of(vertexLabel.getSchema().getName(), VERTEX_PREFIX + vertexLabel.getLabel()); Pair<Set<SchemaTable>, Set<SchemaTable>> foreignKeys = this.schemaTableForeignKeyCache.computeIfAbsent( schemaTable, k -> Pair.of(new HashSet<>(), new HashSet<>()) ); foreignKeys.getLeft().add(SchemaTable.of(edgeLabel.getSchema().getName(), EDGE_PREFIX + edgeLabel.getLabel())); }
@Override public boolean equals(Object other) { if (!super.equals(other)) { return false; } if (!(other instanceof VertexLabel)) { return false; } VertexLabel otherVertexLabel = (VertexLabel) other; return this.schema.equals(otherVertexLabel.getSchema()) && super.equals(otherVertexLabel); }
@Override public boolean equals(Object other) { if (!super.equals(other)) { return false; } if (!(other instanceof VertexLabel)) { return false; } VertexLabel otherVertexLabel = (VertexLabel) other; return this.schema.equals(otherVertexLabel.getSchema()) && super.equals(otherVertexLabel); }
static EdgeLabel createEdgeLabel( String edgeLabelName, VertexLabel outVertexLabel, VertexLabel inVertexLabel, Map<String, PropertyType> properties, ListOrderedSet<String> identifiers) { Preconditions.checkState(!inVertexLabel.getSchema().isSqlgSchema(), "You may not create an edge to %s", Topology.SQLG_SCHEMA); //edges are created in the out vertex's schema. EdgeLabel edgeLabel = new EdgeLabel(false, edgeLabelName, outVertexLabel, inVertexLabel, properties, identifiers); edgeLabel.createEdgeTableOnDb(outVertexLabel, inVertexLabel, properties, identifiers); edgeLabel.committed = false; return edgeLabel; }
static EdgeLabel createEdgeLabel( String edgeLabelName, VertexLabel outVertexLabel, VertexLabel inVertexLabel, Map<String, PropertyType> properties, ListOrderedSet<String> identifiers) { Preconditions.checkState(!inVertexLabel.getSchema().isSqlgSchema(), "You may not create an edge to %s", Topology.SQLG_SCHEMA); //edges are created in the out vertex's schema. EdgeLabel edgeLabel = new EdgeLabel(false, edgeLabelName, outVertexLabel, inVertexLabel, properties, identifiers); edgeLabel.createEdgeTableOnDb(outVertexLabel, inVertexLabel, properties, identifiers); edgeLabel.committed = false; return edgeLabel; }
/** * remove in foreign key for a given vertex label and edge label * * @param vertexLabel * @param edgeLabel */ void removeInForeignKeysFromVertexLabel(VertexLabel vertexLabel, EdgeLabel edgeLabel) { Preconditions.checkState(isSqlWriteLockHeldByCurrentThread() || isTopologyMapWriteLockHeldByCurrentThread()); SchemaTable schemaTable = SchemaTable.of(vertexLabel.getSchema().getName(), VERTEX_PREFIX + vertexLabel.getLabel()); Pair<Set<SchemaTable>, Set<SchemaTable>> foreignKeys = this.schemaTableForeignKeyCache.get(schemaTable); if (foreignKeys != null && edgeLabel.isValid()) { foreignKeys.getLeft().remove(SchemaTable.of(edgeLabel.getSchema().getName(), EDGE_PREFIX + edgeLabel.getLabel())); } }
@Override void removeProperty(PropertyColumn propertyColumn, boolean preserveData) { this.getSchema().getTopology().lock(); if (!uncommittedRemovedProperties.contains(propertyColumn.getName())) { uncommittedRemovedProperties.add(propertyColumn.getName()); TopologyManager.removeVertexColumn(this.sqlgGraph, this.schema.getName(), VERTEX_PREFIX + getLabel(), propertyColumn.getName()); if (!preserveData) { removeColumn(this.schema.getName(), VERTEX_PREFIX + getLabel(), propertyColumn.getName()); } this.getSchema().getTopology().fire(propertyColumn, "", TopologyChangeAction.DELETE); } }
@Override void removeProperty(PropertyColumn propertyColumn, boolean preserveData) { this.getSchema().getTopology().lock(); if (!uncommittedRemovedProperties.contains(propertyColumn.getName())) { uncommittedRemovedProperties.add(propertyColumn.getName()); TopologyManager.removeVertexColumn(this.sqlgGraph, this.schema.getName(), VERTEX_PREFIX + getLabel(), propertyColumn.getName()); if (!preserveData) { removeColumn(this.schema.getName(), VERTEX_PREFIX + getLabel(), propertyColumn.getName()); } this.getSchema().getTopology().fire(propertyColumn, "", TopologyChangeAction.DELETE); } }