public Optional<EdgeLabel> getEdgeLabel(String schemaName, String edgeLabelName) { Preconditions.checkArgument(!edgeLabelName.startsWith(EDGE_PREFIX), "edge label name may not start with %s", EDGE_PREFIX); Optional<Schema> schemaOptional = getSchema(schemaName); if (schemaOptional.isPresent()) { Schema schema = schemaOptional.get(); return schema.getEdgeLabel(edgeLabelName); } else { return Optional.empty(); } }
public Optional<EdgeLabel> getEdgeLabel(String schemaName, String edgeLabelName) { Preconditions.checkArgument(!edgeLabelName.startsWith(EDGE_PREFIX), "edge label name may not start with %s", EDGE_PREFIX); Optional<Schema> schemaOptional = getSchema(schemaName); if (schemaOptional.isPresent()) { Schema schema = schemaOptional.get(); return schema.getEdgeLabel(edgeLabelName); } else { return Optional.empty(); } }
public Optional<VertexLabel> getVertexLabel(String schemaName, String label) { Preconditions.checkArgument(!label.startsWith(VERTEX_PREFIX), "vertex label may not start with %s", VERTEX_PREFIX); Optional<Schema> schemaOptional = this.getSchema(schemaName); if (schemaOptional.isPresent()) { return schemaOptional.get().getVertexLabel(label); } else { return Optional.empty(); } }
public Optional<VertexLabel> getVertexLabel(String schemaName, String label) { Preconditions.checkArgument(!label.startsWith(VERTEX_PREFIX), "vertex label may not start with %s", VERTEX_PREFIX); Optional<Schema> schemaOptional = this.getSchema(schemaName); if (schemaOptional.isPresent()) { return schemaOptional.get().getVertexLabel(label); } else { return Optional.empty(); } }
public Map<String, PropertyColumn> getPropertiesFor(SchemaTable schemaTable) { Optional<Schema> schemaOptional = getSchema(schemaTable.getSchema()); return schemaOptional.map(schema -> Collections.unmodifiableMap(schema.getPropertiesFor(schemaTable))).orElse(Collections.emptyMap()); }
public Map<String, PropertyColumn> getPropertiesWithGlobalUniqueIndexFor(SchemaTable schemaTable) { Optional<Schema> schemaOptional = getSchema(schemaTable.getSchema()); return schemaOptional.map(schema -> Collections.unmodifiableMap(schema.getPropertiesWithGlobalUniqueIndexFor(schemaTable))).orElse(Collections.emptyMap()); }
public Schema getPublicSchema() { Optional<Schema> schema = getSchema(this.sqlgGraph.getSqlDialect().getPublicSchema()); Preconditions.checkState(schema.isPresent(), "BUG: The public schema must always be present"); //noinspection OptionalGetWithoutIsPresent return schema.get(); }
public Schema getPublicSchema() { Optional<Schema> schema = getSchema(this.sqlgGraph.getSqlDialect().getPublicSchema()); Preconditions.checkState(schema.isPresent(), "BUG: The public schema must always be present"); //noinspection OptionalGetWithoutIsPresent return schema.get(); }
/** * Ensures that the vertex's table has the required columns. * If a columns needs to be created a lock will be obtained. * The vertex's schema and table must already exists. * * @param schemaName The schema the vertex resides in. * @param label The vertex's label. * @param properties The properties to create if they do not exist. */ public void ensureVertexLabelPropertiesExist(String schemaName, String label, Map<String, PropertyType> properties) { Preconditions.checkArgument(!label.startsWith(VERTEX_PREFIX), "label may not start with \"%s\"", VERTEX_PREFIX); if (!schemaName.equals(SQLG_SCHEMA)) { Optional<Schema> schemaOptional = getSchema(schemaName); if (!schemaOptional.isPresent()) { throw new IllegalStateException(String.format("BUG: schema \"%s\" can not be null", schemaName)); } //createVertexLabel the table schemaOptional.get().ensureVertexColumnsExist(label, properties); } }
/** * Ensures that the edge's table has the required columns. * If a columns needs to be created a lock will be obtained. * The edge's schema and table must already exists. * * @param schemaName The schema the edge resides in. * @param label The edge's label. * @param properties The properties to create if they do not exist. */ public void ensureEdgePropertiesExist(String schemaName, String label, Map<String, PropertyType> properties) { Preconditions.checkArgument(!label.startsWith(EDGE_PREFIX), "label may not start with \"%s\"", EDGE_PREFIX); Preconditions.checkState(!schemaName.equals(SQLG_SCHEMA), "Topology.ensureEdgePropertiesExist may not be called for \"%s\"", SQLG_SCHEMA); if (!schemaName.equals(SQLG_SCHEMA)) { Optional<Schema> schemaOptional = getSchema(schemaName); if (!schemaOptional.isPresent()) { throw new IllegalStateException(String.format("BUG: schema %s can not be null", schemaName)); } schemaOptional.get().ensureEdgeColumnsExist(label, properties); } }
public Map<String, PropertyColumn> getPropertiesFor(SchemaTable schemaTable) { Optional<Schema> schemaOptional = getSchema(schemaTable.getSchema()); return schemaOptional.map(schema -> Collections.unmodifiableMap(schema.getPropertiesFor(schemaTable))).orElse(Collections.emptyMap()); }
public Map<String, PropertyColumn> getPropertiesWithGlobalUniqueIndexFor(SchemaTable schemaTable) { Optional<Schema> schemaOptional = getSchema(schemaTable.getSchema()); return schemaOptional.map(schema -> Collections.unmodifiableMap(schema.getPropertiesWithGlobalUniqueIndexFor(schemaTable))).orElse(Collections.emptyMap()); }
/** * Ensures that the vertex's table has the required columns. * If a columns needs to be created a lock will be obtained. * The vertex's schema and table must already exists. * * @param schemaName The schema the vertex resides in. * @param label The vertex's label. * @param properties The properties to create if they do not exist. */ public void ensureVertexLabelPropertiesExist(String schemaName, String label, Map<String, PropertyType> properties) { Preconditions.checkArgument(!label.startsWith(VERTEX_PREFIX), "label may not start with \"%s\"", VERTEX_PREFIX); if (!schemaName.equals(SQLG_SCHEMA)) { Optional<Schema> schemaOptional = getSchema(schemaName); if (!schemaOptional.isPresent()) { throw new IllegalStateException(String.format("BUG: schema \"%s\" can not be null", schemaName)); } //createVertexLabel the table schemaOptional.get().ensureVertexColumnsExist(label, properties); } }
/** * Ensures that the edge's table has the required columns. * If a columns needs to be created a lock will be obtained. * The edge's schema and table must already exists. * * @param schemaName The schema the edge resides in. * @param label The edge's label. * @param properties The properties to create if they do not exist. */ public void ensureEdgePropertiesExist(String schemaName, String label, Map<String, PropertyType> properties) { Preconditions.checkArgument(!label.startsWith(EDGE_PREFIX), "label may not start with \"%s\"", EDGE_PREFIX); Preconditions.checkState(!schemaName.equals(SQLG_SCHEMA), "Topology.ensureEdgePropertiesExist may not be called for \"%s\"", SQLG_SCHEMA); if (!schemaName.equals(SQLG_SCHEMA)) { Optional<Schema> schemaOptional = getSchema(schemaName); if (!schemaOptional.isPresent()) { throw new IllegalStateException(String.format("BUG: schema %s can not be null", schemaName)); } schemaOptional.get().ensureEdgeColumnsExist(label, properties); } }
/** * Ensures that the schema exists. * * @param schemaName The schema to create if it does not exist. */ public Schema ensureSchemaExist(final String schemaName) { Optional<Schema> schemaOptional = this.getSchema(schemaName); Schema schema; if (!schemaOptional.isPresent()) { this.lock(); //search again after the lock is obtained. schemaOptional = this.getSchema(schemaName); if (!schemaOptional.isPresent()) { //create the schema and the vertex label. schema = Schema.createSchema(this.sqlgGraph, this, schemaName); this.uncommittedRemovedSchemas.remove(schemaName); this.uncommittedSchemas.put(schemaName, schema); fire(schema, "", TopologyChangeAction.CREATE); return schema; } else { return schemaOptional.get(); } } else { return schemaOptional.get(); } }
@Override public boolean equals(Object o) { if (o == null) { return false; } if (!(o instanceof Topology)) { return false; } z_internalTopologyMapReadLock(); try { Topology other = (Topology) o; if (this.schemas.equals(other.schemas)) { //check each schema individually as schema equals does not check the VertexLabels for (Map.Entry<String, Schema> schemaEntry : schemas.entrySet()) { Schema schema = schemaEntry.getValue(); Optional<Schema> otherSchemaOptional = other.getSchema(schemaEntry.getKey()); if (otherSchemaOptional.isPresent() && !schema.deepEquals(otherSchemaOptional.get())) { return false; } } return true; } else { return false; } } finally { z_internalTopologyMapReadUnLock(); } }
@Override public boolean equals(Object o) { if (o == null) { return false; } if (!(o instanceof Topology)) { return false; } z_internalTopologyMapReadLock(); try { Topology other = (Topology) o; if (this.schemas.equals(other.schemas)) { //check each schema individually as schema equals does not check the VertexLabels for (Map.Entry<String, Schema> schemaEntry : schemas.entrySet()) { Schema schema = schemaEntry.getValue(); Optional<Schema> otherSchemaOptional = other.getSchema(schemaEntry.getKey()); if (otherSchemaOptional.isPresent() && !schema.deepEquals(otherSchemaOptional.get())) { return false; } } return true; } else { return false; } } finally { z_internalTopologyMapReadUnLock(); } }
private boolean hasNoEdgeLabels(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(); Collection<EdgeLabel> inEdgeLabels = vertexLabel.getInEdgeLabels().values(); result = outEdgeLabels.isEmpty() && inEdgeLabels.isEmpty(); } return result; }
private boolean hasNoEdgeLabels(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(); Collection<EdgeLabel> inEdgeLabels = vertexLabel.getInEdgeLabels().values(); result = outEdgeLabels.isEmpty() && inEdgeLabels.isEmpty(); } return result; }
/** * 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()); }