@SuppressWarnings("OptionalGetWithoutIsPresent") static String globalUniqueIndexName(Topology topology, Set<PropertyColumn> properties) { List<PropertyColumn> propertyColumns = new ArrayList<>(properties); propertyColumns.sort(Comparator.comparing(PropertyColumn::getName)); String name = propertyColumns.stream().map(p -> p.getParentLabel().getLabel() + "_" + p.getName()).reduce((a, b) -> a + "_" + b).get(); if (("gui_schema_V_A" + name).length() > 50) { name = "globalUniqueIndex_" + topology.getGlobalUniqueIndexes().size(); } return name; }
@SuppressWarnings("OptionalGetWithoutIsPresent") static String globalUniqueIndexName(Topology topology, Set<PropertyColumn> properties) { List<PropertyColumn> propertyColumns = new ArrayList<>(properties); propertyColumns.sort(Comparator.comparing(PropertyColumn::getName)); String name = propertyColumns.stream().map(p -> p.getParentLabel().getLabel() + "_" + p.getName()).reduce((a, b) -> a + "_" + b).get(); if (("gui_schema_V_A" + name).length() > 50) { name = "globalUniqueIndex_" + topology.getGlobalUniqueIndexes().size(); } return name; }
@Override public String toString() { return this.abstractLabel.getSchema().getName() + "." + this.abstractLabel.getLabel() + "." + this.name; }
@Override public String toString() { return this.abstractLabel.getSchema().getName() + "." + this.abstractLabel.getLabel() + "." + this.name; }
List<Topology.TopologyValidationError> validateTopology(DatabaseMetaData metadata) throws SQLException { List<Topology.TopologyValidationError> validationErrors = new ArrayList<>(); try (ResultSet propertyRs = metadata.getIndexInfo(null, this.abstractLabel.getSchema().getName(), this.abstractLabel.getPrefix() + this.abstractLabel.getLabel(), false, false)) { Map<String, List<String>> indexColumns = new HashMap<>(); while (propertyRs.next()) { String columnName = propertyRs.getString("COLUMN_NAME"); String indexName = propertyRs.getString("INDEX_NAME"); List<String> columnNames; if (!indexColumns.containsKey(indexName)) { columnNames = new ArrayList<>(); indexColumns.put(indexName, columnNames); } else { columnNames = indexColumns.get(indexName); } columnNames.add(columnName); } if (!indexColumns.containsKey(this.getName())) { validationErrors.add(new Topology.TopologyValidationError(this)); } } return validationErrors; }
List<Topology.TopologyValidationError> validateTopology(DatabaseMetaData metadata) throws SQLException { List<Topology.TopologyValidationError> validationErrors = new ArrayList<>(); try (ResultSet propertyRs = metadata.getIndexInfo(null, this.abstractLabel.getSchema().getName(), this.abstractLabel.getPrefix() + this.abstractLabel.getLabel(), false, false)) { Map<String, List<String>> indexColumns = new HashMap<>(); while (propertyRs.next()) { String columnName = propertyRs.getString("COLUMN_NAME"); String indexName = propertyRs.getString("INDEX_NAME"); List<String> columnNames; if (!indexColumns.containsKey(indexName)) { columnNames = new ArrayList<>(); indexColumns.put(indexName, columnNames); } else { columnNames = indexColumns.get(indexName); } columnNames.add(columnName); } if (!indexColumns.containsKey(this.getName())) { validationErrors.add(new Topology.TopologyValidationError(this)); } } return validationErrors; }
@Override public int hashCode() { return (this.abstractLabel.getSchema().getName() + this.abstractLabel.getLabel() + this.getName()).hashCode(); }
@Override public int hashCode() { return (this.abstractLabel.getSchema().getName() + this.abstractLabel.getLabel() + this.getName()).hashCode(); }
Optional<JsonNode> toNotifyJson() { Preconditions.checkState(this.topology.isSqlWriteLockHeldByCurrentThread(), "GlobalUniqueIndex toNotifyJson() may only be called is the lock is held."); ObjectNode result = new ObjectNode(Topology.OBJECT_MAPPER.getNodeFactory()); ArrayNode propertyArrayNode = new ArrayNode(Topology.OBJECT_MAPPER.getNodeFactory()); for (PropertyColumn property : this.uncommittedProperties) { ObjectNode objectNode = property.toNotifyJson(); objectNode.put("schemaName", property.getParentLabel().getSchema().getName()); objectNode.put("abstractLabelLabel", property.getParentLabel().getLabel()); propertyArrayNode.add(objectNode); } result.put("name", getName()); result.set("uncommittedProperties", propertyArrayNode); return Optional.of(result); }
Optional<JsonNode> toNotifyJson() { Preconditions.checkState(this.topology.isSqlWriteLockHeldByCurrentThread(), "GlobalUniqueIndex toNotifyJson() may only be called is the lock is held."); ObjectNode result = new ObjectNode(Topology.OBJECT_MAPPER.getNodeFactory()); ArrayNode propertyArrayNode = new ArrayNode(Topology.OBJECT_MAPPER.getNodeFactory()); for (PropertyColumn property : this.uncommittedProperties) { ObjectNode objectNode = property.toNotifyJson(); objectNode.put("schemaName", property.getParentLabel().getSchema().getName()); objectNode.put("abstractLabelLabel", property.getParentLabel().getLabel()); propertyArrayNode.add(objectNode); } result.put("name", getName()); result.set("uncommittedProperties", propertyArrayNode); return Optional.of(result); }
@Override public boolean equals(Object o) { if (o == null) { return false; } if (!(o instanceof PropertyColumn)) { return false; } PropertyColumn other = (PropertyColumn) o; if (this.abstractLabel.getSchema().getName().equals(other.abstractLabel.getSchema().getName())) { if (this.abstractLabel.getLabel().equals(other.abstractLabel.getLabel())) { return this.getName().equals(other.getName()) && this.getPropertyType() == other.getPropertyType(); } else { return false; } } else { return false; } }
@Override public boolean equals(Object o) { if (o == null) { return false; } if (!(o instanceof PropertyColumn)) { return false; } PropertyColumn other = (PropertyColumn) o; if (this.abstractLabel.getSchema().getName().equals(other.abstractLabel.getSchema().getName())) { if (this.abstractLabel.getLabel().equals(other.abstractLabel.getLabel())) { return this.getName().equals(other.getName()) && this.getPropertyType() == other.getPropertyType(); } else { return false; } } else { return false; } }
sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(getSchema().getName())); sql.append("."); sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(getPrefix() + getLabel())); sql.append("', '"); sql.append(distributionPropertyColumn.getName()); sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(colocate.getSchema().getName())); sql.append("."); sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(colocate.getPrefix() + colocate.getLabel()));
sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(getSchema().getName())); sql.append("."); sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(getPrefix() + getLabel())); sql.append("', '"); sql.append(distributionPropertyColumn.getName()); sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(colocate.getSchema().getName())); sql.append("."); sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(colocate.getPrefix() + colocate.getLabel()));
/** * JSON representation of committed state * @return */ private JsonNode toJson(){ ObjectNode result = new ObjectNode(Topology.OBJECT_MAPPER.getNodeFactory()); ArrayNode propertyArrayNode = new ArrayNode(Topology.OBJECT_MAPPER.getNodeFactory()); for (PropertyColumn property : this.properties) { ObjectNode objectNode = property.toNotifyJson(); objectNode.put("schemaName", property.getParentLabel().getSchema().getName()); objectNode.put("abstractLabelLabel", property.getParentLabel().getLabel()); propertyArrayNode.add(objectNode); } result.put("name", getName()); result.set("properties", propertyArrayNode); return result; }
/** * JSON representation of committed state * @return */ private JsonNode toJson(){ ObjectNode result = new ObjectNode(Topology.OBJECT_MAPPER.getNodeFactory()); ArrayNode propertyArrayNode = new ArrayNode(Topology.OBJECT_MAPPER.getNodeFactory()); for (PropertyColumn property : this.properties) { ObjectNode objectNode = property.toNotifyJson(); objectNode.put("schemaName", property.getParentLabel().getSchema().getName()); objectNode.put("abstractLabelLabel", property.getParentLabel().getLabel()); propertyArrayNode.add(objectNode); } result.put("name", getName()); result.set("properties", propertyArrayNode); return result; }
public Index ensureIndexExists(final IndexType indexType, final List<PropertyColumn> properties) { String prefix = this instanceof VertexLabel ? VERTEX_PREFIX : EDGE_PREFIX; SchemaTable schemaTable = SchemaTable.of(this.getSchema().getName(), this.getLabel());
public Index ensureIndexExists(final IndexType indexType, final List<PropertyColumn> properties) { String prefix = this instanceof VertexLabel ? VERTEX_PREFIX : EDGE_PREFIX; SchemaTable schemaTable = SchemaTable.of(this.getSchema().getName(), this.getLabel());
static Index createIndex(SqlgGraph sqlgGraph, AbstractLabel abstractLabel, String indexName, IndexType indexType, List<PropertyColumn> properties) { Index index = new Index(indexName, indexType, abstractLabel, properties); SchemaTable schemaTable = SchemaTable.of(abstractLabel.getSchema().getName(), abstractLabel.getLabel()); //For partitioned tables the index is on each partition. //It is created when the partition is created. if (!abstractLabel.isPartition()) { String prefix = abstractLabel instanceof VertexLabel ? VERTEX_PREFIX : EDGE_PREFIX; index.createIndex(sqlgGraph, schemaTable.withPrefix(prefix), index.getName()); } else { for (Partition partition : abstractLabel.getPartitions().values()) { partition.createIndexOnLeafPartitions(index); } } TopologyManager.addIndex(sqlgGraph, index); index.committed = false; return index; }
static Index createIndex(SqlgGraph sqlgGraph, AbstractLabel abstractLabel, String indexName, IndexType indexType, List<PropertyColumn> properties) { Index index = new Index(indexName, indexType, abstractLabel, properties); SchemaTable schemaTable = SchemaTable.of(abstractLabel.getSchema().getName(), abstractLabel.getLabel()); //For partitioned tables the index is on each partition. //It is created when the partition is created. if (!abstractLabel.isPartition()) { String prefix = abstractLabel instanceof VertexLabel ? VERTEX_PREFIX : EDGE_PREFIX; index.createIndex(sqlgGraph, schemaTable.withPrefix(prefix), index.getName()); } else { for (Partition partition : abstractLabel.getPartitions().values()) { partition.createIndexOnLeafPartitions(index); } } TopologyManager.addIndex(sqlgGraph, index); index.committed = false; return index; }