diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2020-06-16 07:40:42 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2020-06-16 09:46:17 +0000 |
commit | fcf38c0586e6166ed819a078355502bda4656d01 (patch) | |
tree | ba0fca554bccae26a0bdece24e715cc223c02c6a /document/src/main | |
parent | c0d8eff2873a2a352b368fe0e616caf812673a33 (diff) |
- Removing body struct from our own usage.
- Deprecate public methods using body struct.
- Update expected generated config.
Diffstat (limited to 'document/src/main')
7 files changed, 47 insertions, 126 deletions
diff --git a/document/src/main/java/com/yahoo/document/Document.java b/document/src/main/java/com/yahoo/document/Document.java index 375d8d962a5..116765b5530 100644 --- a/document/src/main/java/com/yahoo/document/Document.java +++ b/document/src/main/java/com/yahoo/document/Document.java @@ -44,7 +44,6 @@ public class Document extends StructuredFieldValue { public static final short SERIALIZED_VERSION = 8; private DocumentId docId; private Struct header; - private Struct body; private Long lastModified = null; /** @@ -75,7 +74,6 @@ public class Document extends StructuredFieldValue { public Document(Document doc) { this(doc.getDataType(), doc.getId()); header = doc.header; - body = doc.body; lastModified = doc.lastModified; } @@ -104,7 +102,7 @@ public class Document extends StructuredFieldValue { /** @deprecated do not use: Use getField(), getFieldValue() or iterator() instead */ @Deprecated // TODO: Remove on Vespa 8 - public Struct getBody() { return body; } + public Struct getBody() { return null; } @Override public void assign(Object o) { @@ -116,14 +114,11 @@ public class Document extends StructuredFieldValue { Document doc = (Document) super.clone(); doc.docId = docId.clone(); doc.header = header.clone(); - doc.body = body.clone(); return doc; } - @SuppressWarnings("deprecation") private void setNewType(DocumentType type) { header = type.contentStruct().createFieldValue(); - body = type.getBodyType().createFieldValue(); } public void setDataType(DataType type) { @@ -178,9 +173,6 @@ public class Document extends StructuredFieldValue { public Field getField(String fieldName) { Field field = header.getField(fieldName); if (field == null) { - field = body.getField(fieldName); - } - if (field == null) { for(DocumentType parent : getDataType().getInheritedTypes()) { field = parent.getField(fieldName); if (field != null) { @@ -193,36 +185,22 @@ public class Document extends StructuredFieldValue { @Override public FieldValue getFieldValue(Field field) { - FieldValue fv = header.getFieldValue(field); - if (fv == null) { - fv = body.getFieldValue(field); - } - return fv; + return header.getFieldValue(field); } @Override - @SuppressWarnings("deprecation") protected void doSetFieldValue(Field field, FieldValue value) { - if (field.isHeader()) { - header.setFieldValue(field, value); - } else { - body.setFieldValue(field, value); - } + header.setFieldValue(field, value); } @Override public FieldValue removeFieldValue(Field field) { - FieldValue removed = header.removeFieldValue(field); - if (removed == null) { - removed = body.removeFieldValue(field); - } - return removed; + return header.removeFieldValue(field); } @Override public void clear() { header.clear(); - body.clear(); } @Override @@ -230,29 +208,17 @@ public class Document extends StructuredFieldValue { return new Iterator<>() { private Iterator<Map.Entry<Field, FieldValue>> headerIt = header.iterator(); - private Iterator<Map.Entry<Field, FieldValue>> bodyIt = body.iterator(); public boolean hasNext() { - if (headerIt != null) { - if (headerIt.hasNext()) { - return true; - } else { - headerIt = null; - } - } - return bodyIt.hasNext(); + return headerIt.hasNext(); } public Map.Entry<Field, FieldValue> next() { - return (headerIt == null ? bodyIt.next() : headerIt.next()); + return headerIt.next(); } public void remove() { - if (headerIt == null) { - bodyIt.remove(); - } else { - headerIt.remove(); - } + headerIt.remove(); } }; } @@ -302,7 +268,7 @@ public class Document extends StructuredFieldValue { if (!(o instanceof Document)) return false; Document other = (Document) o; return (super.equals(o) && docId.equals(other.docId) && - header.equals(other.header) && body.equals(other.body)); + header.equals(other.header)); } @Override @@ -347,7 +313,7 @@ public class Document extends StructuredFieldValue { @Override public int getFieldCount() { - return header.getFieldCount() + body.getFieldCount(); + return header.getFieldCount(); } public void serialize(DocumentWriter writer) { @@ -393,7 +359,6 @@ public class Document extends StructuredFieldValue { return comp; } - comp = body.compareTo(otherValue.body); return comp; } diff --git a/document/src/main/java/com/yahoo/document/DocumentType.java b/document/src/main/java/com/yahoo/document/DocumentType.java index 23559878fbb..09b9fcf7563 100755 --- a/document/src/main/java/com/yahoo/document/DocumentType.java +++ b/document/src/main/java/com/yahoo/document/DocumentType.java @@ -38,7 +38,6 @@ public class DocumentType extends StructuredDataType { public static final String DOCUMENT = "[document]"; public static final int classId = registerClass(Ids.document + 58, DocumentType.class); private StructDataType headerType; - private StructDataType bodyType; private List<DocumentType> inherits = new ArrayList<>(1); private Map<String, Set<Field>> fieldSets = new HashMap<>(); private final Set<String> importedFieldNames; @@ -52,7 +51,7 @@ public class DocumentType extends StructuredDataType { * @param name The name of the new document type */ public DocumentType(String name) { - this(name, createHeaderStructType(name), createBodyStructType(name)); + this(name, createHeaderStructType(name)); } /** @@ -62,37 +61,46 @@ public class DocumentType extends StructuredDataType { * * @param name The name of the new document type * @param headerType The type of the header struct - * @param bodyType The type of the body struct */ + public DocumentType(String name, StructDataType headerType) { + this(name, headerType, Collections.emptySet()); + } + + /** + * @deprecated //TODO Will be removed on Vespa 8 + */ + @Deprecated public DocumentType(String name, StructDataType headerType, StructDataType bodyType) { - this(name, headerType, bodyType, Collections.emptySet()); + this(name, headerType, Collections.emptySet()); } - public DocumentType(String name, StructDataType headerType, - StructDataType bodyType, Set<String> importedFieldNames) { + public DocumentType(String name, StructDataType headerType, Set<String> importedFieldNames) { super(name); this.headerType = headerType; - this.bodyType = bodyType; this.importedFieldNames = Collections.unmodifiableSet(importedFieldNames); } + /** + * @deprecated //TODO Will be removed on Vespa 8 + */ + @Deprecated + public DocumentType(String name, StructDataType headerType, + StructDataType bodyType, Set<String> importedFieldNames) { + this(name, headerType, importedFieldNames); + } + public DocumentType(String name, Set<String> importedFieldNames) { - this(name, createHeaderStructType(name), createBodyStructType(name), importedFieldNames); + this(name, createHeaderStructType(name), importedFieldNames); } private static StructDataType createHeaderStructType(String name) { return new StructDataType(name + ".header"); } - private static StructDataType createBodyStructType(String name) { - return new StructDataType(name + ".body"); - } - @Override public DocumentType clone() { DocumentType type = (DocumentType) super.clone(); type.headerType = headerType.clone(); - type.bodyType = bodyType.clone(); type.inherits = new ArrayList<>(inherits.size()); type.inherits.addAll(inherits); return type; @@ -139,11 +147,10 @@ public class DocumentType extends StructuredDataType { @Deprecated // TODO: Remove on Vespa 8 /** @deprecated use contentStruct instead */ public StructDataType getBodyType() { - return bodyType; + return null; } @Override - @SuppressWarnings("deprecation") protected void register(DocumentTypeManager manager, List<DataType> seenTypes) { seenTypes.add(this); for (DocumentType type : getInheritedTypes()) { @@ -153,23 +160,17 @@ public class DocumentType extends StructuredDataType { } // Get parent fields into fields specified in this type StructDataType header = headerType.clone(); - StructDataType body = bodyType.clone(); header.clearFields(); - body.clearFields(); for (Field field : getAllUniqueFields()) { - (field.isHeader() ? header : body).addField(field); + header.addField(field); } headerType.assign(header); - bodyType.assign(body); if (!seenTypes.contains(headerType)) { headerType.register(manager, seenTypes); } - if (!seenTypes.contains(bodyType)) { - bodyType.register(manager, seenTypes); - } manager.registerSingleType(this); } @@ -194,7 +195,6 @@ public class DocumentType extends StructuredDataType { * * @param field the field to add */ - @SuppressWarnings("deprecation") public void addField(Field field) { if (isRegistered()) { throw new IllegalStateException("You cannot add fields to a document type that is already registered."); @@ -227,7 +227,7 @@ public class DocumentType extends StructuredDataType { } /** - * Adds a new body field to this document type and returns the new field object + * Adds a new field to this document type and returns the new field object * * @param name The name of the field to add * @param type The datatype of the field to add @@ -346,9 +346,6 @@ public class DocumentType extends StructuredDataType { */ public Field getField(String name) { Field field = headerType.getField(name); - if (field == null) { - field = bodyType.getField(name); - } if (field == null && !isRegistered()) { for (DocumentType inheritedType : inherits) { field = inheritedType.getField(name); @@ -361,9 +358,6 @@ public class DocumentType extends StructuredDataType { @Override public Field getField(int id) { Field field = headerType.getField(id); - if (field == null) { - field = bodyType.getField(id); - } if (field == null && !isRegistered()) { for (DocumentType inheritedType : inherits) { field = inheritedType.getField(id); @@ -384,7 +378,7 @@ public class DocumentType extends StructuredDataType { } public int getFieldCount() { - return headerType.getFieldCount() + bodyType.getFieldCount(); + return headerType.getFieldCount(); } public Set<String> getImportedFieldNames() { @@ -407,9 +401,6 @@ public class DocumentType extends StructuredDataType { } Field field = headerType.removeField(name); if (field == null) { - field = bodyType.removeField(name); - } - if (field == null) { for (DocumentType inheritedType : inherits) { field = inheritedType.removeField(name); if (field != null) break; @@ -433,7 +424,6 @@ public class DocumentType extends StructuredDataType { } collection.addAll(headerType.getFields()); - collection.addAll(bodyType.getFields()); return ImmutableList.copyOf(collection); } @@ -485,26 +475,19 @@ public class DocumentType extends StructuredDataType { public Iterator<Field> fieldIteratorThisTypeOnly() { return new Iterator<>() { Iterator<Field> headerIt = headerType.getFields().iterator(); - Iterator<Field> bodyIt = bodyType.getFields().iterator(); public boolean hasNext() { - if (headerIt != null) { - if (headerIt.hasNext()) return true; - headerIt = null; - } - return bodyIt.hasNext(); + return headerIt.hasNext(); } public Field next() { - return (headerIt != null ? headerIt.next() : bodyIt.next()); + return headerIt.next(); } public void remove() { if (headerIt != null) { headerIt.remove(); - } else { - bodyIt.remove(); } } }; @@ -514,8 +497,7 @@ public class DocumentType extends StructuredDataType { if (!(o instanceof DocumentType)) return false; DocumentType other = (DocumentType) o; // Ignore whether one of them have added inheritance to super Document.0 type - if (super.equals(o) && headerType.equals(other.headerType) && - bodyType.equals(other.bodyType)) { + if (super.equals(o) && headerType.equals(other.headerType)) { if ((inherits.size() > 1 || other.inherits.size() > 1) || (inherits.size() == 1 && other.inherits.size() == 1)) { return inherits.equals(other.inherits); @@ -527,7 +509,7 @@ public class DocumentType extends StructuredDataType { } public int hashCode() { - return super.hashCode() + headerType.hashCode() + bodyType.hashCode() + inherits.hashCode(); + return super.hashCode() + headerType.hashCode() + inherits.hashCode(); } @Override @@ -543,7 +525,6 @@ public class DocumentType extends StructuredDataType { public void visitMembers(ObjectVisitor visitor) { super.visitMembers(visitor); visitor.visit("headertype", headerType); - visitor.visit("bodytype", bodyType); visitor.visit("inherits", inherits); } } diff --git a/document/src/main/java/com/yahoo/document/DocumentTypeManagerConfigurer.java b/document/src/main/java/com/yahoo/document/DocumentTypeManagerConfigurer.java index 1d81d9e6e78..c802d2307c0 100644 --- a/document/src/main/java/com/yahoo/document/DocumentTypeManagerConfigurer.java +++ b/document/src/main/java/com/yahoo/document/DocumentTypeManagerConfigurer.java @@ -142,14 +142,10 @@ public class DocumentTypeManagerConfigurer implements ConfigSubscriber.SingleSub @SuppressWarnings("deprecation") private static void registerDocumentType(DocumentTypeManager manager, DocumentmanagerConfig.Datatype.Documenttype doc) { StructDataType header = (StructDataType) manager.getDataType(doc.headerstruct(), ""); - StructDataType body = (StructDataType) manager.getDataType(doc.bodystruct(), ""); - for (Field field : body.getFields()) { - field.setHeader(false); - } var importedFields = doc.importedfield().stream() .map(f -> f.name()) .collect(Collectors.toUnmodifiableSet()); - DocumentType type = new DocumentType(doc.name(), header, body, importedFields); + DocumentType type = new DocumentType(doc.name(), header, importedFields); for (Object j : doc.inherits()) { DocumentmanagerConfig.Datatype.Documenttype.Inherits parent = (DocumentmanagerConfig.Datatype.Documenttype.Inherits) j; diff --git a/document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializer6.java b/document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializer6.java index 27327daab47..cac05fb7879 100644 --- a/document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializer6.java +++ b/document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializer6.java @@ -118,14 +118,12 @@ public class VespaDocumentDeserializer6 extends BufferSerializer implements Docu doc.setId(documentId); Struct h = doc.getHeader(); - Struct b = doc.getBody(); h.clear(); - b.clear(); if ((content & 0x2) != 0) { - readHeaderBody(h, b); + readHeaderBody(h); } if ((content & 0x4) != 0) { - readHeaderBody(b, h); + readHeaderBody(h); } if (dataLength != (position() - dataPos)) { @@ -326,7 +324,7 @@ public class VespaDocumentDeserializer6 extends BufferSerializer implements Docu buf = bigBuf; } - private void readHeaderBody(Struct primary, Struct alternate) { + private void readHeaderBody(Struct primary) { primary.setVersion(version); if (version < 8) { @@ -371,24 +369,14 @@ public class VespaDocumentDeserializer6 extends BufferSerializer implements Docu buf = GrowableByteBuffer.wrap(destination); StructDataType priType = primary.getDataType(); - StructDataType altType = alternate.getDataType(); for (int i=0; i<numberOfFields; ++i) { int posBefore = position(); - Struct s = null; Integer f_id = fieldIdsAndLengths.get(i).first; Field structField = priType.getField(f_id); if (structField != null) { - s = primary; - } else { - structField = altType.getField(f_id); - if (structField != null) { - s = alternate; - } - } - if (s != null) { FieldValue value = structField.getDataType().createFieldValue(); value.deserialize(structField, this); - s.setFieldValue(structField, value); + primary.setFieldValue(structField, value); } //jump to beginning of next field: position(posBefore + fieldIdsAndLengths.get(i).second.intValue()); diff --git a/document/src/main/java/com/yahoo/document/serialization/VespaDocumentSerializer6.java b/document/src/main/java/com/yahoo/document/serialization/VespaDocumentSerializer6.java index 630f204c44d..3fca853b4d1 100644 --- a/document/src/main/java/com/yahoo/document/serialization/VespaDocumentSerializer6.java +++ b/document/src/main/java/com/yahoo/document/serialization/VespaDocumentSerializer6.java @@ -96,27 +96,20 @@ public class VespaDocumentSerializer6 extends BufferSerializer implements Docume doc.getId().serialize(this); - Struct head = doc.getHeader(); - Struct body = doc.getBody(); - boolean hasHead = (head.getFieldCount() != 0); - boolean hasBody = (body.getFieldCount() != 0); + boolean hasHead = (doc.getFieldCount() != 0); byte contents = 0x01; // Indicating we have document type which we always have if (hasHead) { contents |= 0x2; // Indicate we have header } - if (hasBody) { - contents |= 0x4; // Indicate we have a body - } + buf.put(contents); doc.getDataType().serialize(this); if (hasHead) { - head.serialize(null, this); - } - if (hasBody) { - body.serialize(null, this); + doc.getHeader().serialize(null, this); } + int finalPos = buf.position(); buf.position(lenPos); buf.putInt(finalPos - lenPos - 4); // Don't include the length itself or the version diff --git a/document/src/main/java/com/yahoo/document/serialization/XmlDocumentWriter.java b/document/src/main/java/com/yahoo/document/serialization/XmlDocumentWriter.java index 5db98f26141..9dc5b7c2480 100644 --- a/document/src/main/java/com/yahoo/document/serialization/XmlDocumentWriter.java +++ b/document/src/main/java/com/yahoo/document/serialization/XmlDocumentWriter.java @@ -106,7 +106,6 @@ public final class XmlDocumentWriter implements DocumentWriter { buffer.addAttribute("lastmodifiedtime", lastModified); } write(null, value.getHeader()); - write(null, value.getBody()); buffer.endTag(); } diff --git a/document/src/main/java/com/yahoo/document/serialization/XmlSerializationHelper.java b/document/src/main/java/com/yahoo/document/serialization/XmlSerializationHelper.java index 85bc4d032ff..8c6444fb853 100644 --- a/document/src/main/java/com/yahoo/document/serialization/XmlSerializationHelper.java +++ b/document/src/main/java/com/yahoo/document/serialization/XmlSerializationHelper.java @@ -55,7 +55,6 @@ public class XmlSerializationHelper { xml.addAttribute("lastmodifiedtime", lastModified); } doc.getHeader().printXml(xml); - doc.getBody().printXml(xml); } public static void printDoubleXml(DoubleFieldValue d, XmlStream xml) { |