@Override public boolean equals(Object obj) { if (obj == this) return true; if (!super.equals(obj)) return false; final CollectionSchemaField that = (CollectionSchemaField)obj; return Objects.equals(this.elementField, that.elementField); }
protected ComplexFieldIndex(JsckInfo info, int schemaVersion, ComplexSchemaField field, SimpleSchemaField subField, String parentFieldName, String subFieldName) { super(info, schemaVersion, subField); this.parentStorageId = field.getStorageId(); this.parentFieldName = parentFieldName; this.subFieldName = subFieldName; assert this.parentStorageId > 0; }
@Override void writeXML(XMLStreamWriter writer) throws XMLStreamException { final QName tag = this.getXMLTag(); writer.writeStartElement(tag.getNamespaceURI(), tag.getLocalPart()); this.writeAttributes(writer); for (SimpleSchemaField subField : this.getSubFields().values()) subField.writeXML(writer, false); // omit (redundant) names for sub-fields writer.writeEndElement(); }
@Override boolean isCompatibleWith(SchemaField field) { if (field.getClass() != this.getClass()) return false; final ComplexSchemaField that = (ComplexSchemaField)field; return AbstractSchemaItem.isAll(this.getSubFields(), that.getSubFields(), SimpleSchemaField::isCompatibleWith); }
@Override public int hashCode() { return super.hashCode() ^ Objects.hashCode(this.elementField); }
@Override void lockDownRecurse() { super.lockDownRecurse(); if (this.elementField != null) this.elementField.lockDown(); }
protected Diffs differencesFrom(CollectionSchemaField that) { final Diffs diffs = new Diffs(super.differencesFrom(that)); final Diffs elementDiffs = this.elementField.differencesFrom(that.elementField); if (!elementDiffs.isEmpty()) diffs.add("changed element field", elementDiffs); return diffs; }
@Override public CollectionSchemaField clone() { final CollectionSchemaField clone = (CollectionSchemaField)super.clone(); if (clone.elementField != null) clone.elementField = clone.elementField.clone(); return clone; } }
@Override public String toString() { return "map " + super.toString() + " with key " + this.keyField + " and value " + this.valueField; }
SimpleSchemaField readSubField(XMLStreamReader reader, int formatVersion, String name) throws XMLStreamException { final SimpleSchemaField field = this.readMappedType(reader, false, SchemaModel.SIMPLE_FIELD_TAG_MAP); field.readXML(reader, formatVersion); if (field.getName() == null) field.setName(name); return field; }
@Override void writeCompatibilityHashData(DataOutputStream output) throws IOException { super.writeCompatibilityHashData(output); for (Map.Entry<String, SimpleSchemaField> entry : this.getSubFields().entrySet()) { output.writeUTF(entry.getKey()); entry.getValue().writeCompatibilityHashData(output); } }
@Override public int hashCode() { return super.hashCode() ^ Objects.hashCode(this.keyField) ^ Objects.hashCode(this.valueField); }
@Override void lockDownRecurse() { super.lockDownRecurse(); if (this.keyField != null) this.keyField.lockDown(); if (this.valueField != null) this.valueField.lockDown(); }
@Override public Diffs differencesFrom(MapSchemaField that) { final Diffs diffs = new Diffs(super.differencesFrom(that)); final Diffs keyDiffs = this.keyField.differencesFrom(that.keyField); if (!keyDiffs.isEmpty()) diffs.add("changed key field", keyDiffs); final Diffs valueDiffs = this.valueField.differencesFrom(that.valueField); if (!valueDiffs.isEmpty()) diffs.add("changed value field", valueDiffs); return diffs; }
@Override public MapSchemaField clone() { final MapSchemaField clone = (MapSchemaField)super.clone(); if (clone.keyField != null) clone.keyField = clone.keyField.clone(); if (clone.valueField != null) clone.valueField = clone.valueField.clone(); return clone; } }
@Override public String toString() { return super.toString() + (this.elementField != null ? " with element " + this.elementField : ""); }
@Override void validate() { super.validate(); for (Map.Entry<String, SimpleSchemaField> entry : this.getSubFields().entrySet()) { final String subFieldName = entry.getKey(); final SimpleSchemaField subField = entry.getValue(); if (subField == null) throw new InvalidSchemaException("invalid " + this + ": missing sub-field `" + subFieldName + "'"); subField.validate(); if (!subFieldName.equals(subField.getName())) { throw new InvalidSchemaException("sub-" + subField + " of " + this + " has the wrong name `" + subField.getName() + "' != `" + subFieldName + "'"); } } }
@Override public boolean equals(Object obj) { if (obj == this) return true; if (!super.equals(obj)) return false; final MapSchemaField that = (MapSchemaField)obj; return Objects.equals(this.keyField, that.keyField) && Objects.equals(this.valueField, that.valueField); }
private void doValidate() { // Validate object types and verify object type names are unique final TreeMap<String, SchemaObjectType> schemaObjectTypesByName = new TreeMap<>(); for (SchemaObjectType schemaObjectType : this.schemaObjectTypes.values()) { schemaObjectType.validate(); final String schemaObjectTypeName = schemaObjectType.getName(); final SchemaObjectType otherSchemaObjectType = schemaObjectTypesByName.put(schemaObjectTypeName, schemaObjectType); if (otherSchemaObjectType != null) throw new InvalidSchemaException("duplicate object name `" + schemaObjectTypeName + "'"); } // Collect all field storage ID's final TreeMap<Integer, AbstractSchemaItem> globalItemsByStorageId = new TreeMap<>(); for (SchemaObjectType schemaObjectType : this.schemaObjectTypes.values()) { for (SchemaField field : schemaObjectType.getSchemaFields().values()) { globalItemsByStorageId.put(field.getStorageId(), field); if (field instanceof ComplexSchemaField) { final ComplexSchemaField complexField = (ComplexSchemaField)field; for (SimpleSchemaField subField : complexField.getSubFields().values()) globalItemsByStorageId.put(subField.getStorageId(), subField); } } } // Verify object type, field, and index storage ID's are non-overlapping for (SchemaObjectType schemaObjectType : this.schemaObjectTypes.values()) { SchemaModel.verifyUniqueStorageId(globalItemsByStorageId, schemaObjectType); for (SchemaCompositeIndex index : schemaObjectType.getSchemaCompositeIndexes().values()) SchemaModel.verifyUniqueStorageId(globalItemsByStorageId, index); } }