diff options
Diffstat (limited to 'document/src')
14 files changed, 78 insertions, 40 deletions
diff --git a/document/src/main/java/com/yahoo/document/Document.java b/document/src/main/java/com/yahoo/document/Document.java index 23beab7523e..51a1602516e 100644 --- a/document/src/main/java/com/yahoo/document/Document.java +++ b/document/src/main/java/com/yahoo/document/Document.java @@ -99,7 +99,9 @@ public class Document extends StructuredFieldValue { docId = id; } + @Deprecated public Struct getHeader() { return header; } + @Deprecated public Struct getBody() { return body; } @Override @@ -116,8 +118,9 @@ public class Document extends StructuredFieldValue { return doc; } + @SuppressWarnings("deprecation") private void setNewType(DocumentType type) { - header = type.getHeaderType().createFieldValue(); + header = type.contentStruct().createFieldValue(); body = type.getBodyType().createFieldValue(); } @@ -188,14 +191,15 @@ public class Document extends StructuredFieldValue { @Override public FieldValue getFieldValue(Field field) { - if (field.isHeader()) { - return header.getFieldValue(field); - } else { - return body.getFieldValue(field); + FieldValue fv = header.getFieldValue(field); + if (fv == null) { + fv = body.getFieldValue(field); } + return fv; } @Override + @SuppressWarnings("deprecation") protected void doSetFieldValue(Field field, FieldValue value) { if (field.isHeader()) { header.setFieldValue(field, value); @@ -206,11 +210,11 @@ public class Document extends StructuredFieldValue { @Override public FieldValue removeFieldValue(Field field) { - if (field.isHeader()) { - return header.removeFieldValue(field); - } else { - return body.removeFieldValue(field); + FieldValue removed = header.removeFieldValue(field); + if (removed == null) { + removed = body.removeFieldValue(field); } + return removed; } @Override @@ -338,6 +342,7 @@ public class Document extends StructuredFieldValue { } @SuppressWarnings("deprecation") + @Deprecated public void serializeHeader(Serializer data) throws SerializationException { if (data instanceof DocumentWriter) { if (data instanceof com.yahoo.document.serialization.VespaDocumentSerializer42) { @@ -353,6 +358,7 @@ public class Document extends StructuredFieldValue { } } + @Deprecated public void serializeBody(Serializer data) throws SerializationException { if (getBody().getFieldCount() > 0) { if (data instanceof FieldWriter) { diff --git a/document/src/main/java/com/yahoo/document/DocumentType.java b/document/src/main/java/com/yahoo/document/DocumentType.java index 61e9a9ba83f..6244885798e 100755 --- a/document/src/main/java/com/yahoo/document/DocumentType.java +++ b/document/src/main/java/com/yahoo/document/DocumentType.java @@ -9,7 +9,17 @@ import com.yahoo.vespa.objects.Ids; import com.yahoo.vespa.objects.ObjectVisitor; import com.yahoo.vespa.objects.Serializer; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.ListIterator; +import java.util.Map; +import java.util.Set; + /** * <p>A document definition is a list of fields. Documents may inherit other documents, @@ -19,12 +29,13 @@ import java.util.*; * @author <a href="mailto:thomasg@yahoo-inc.com">Thomas Gundersen</a> * @author bratseth */ +// TODO Vespa 7 Remove header/body concept public class DocumentType extends StructuredDataType { public static final int classId = registerClass(Ids.document + 58, DocumentType.class); private StructDataType headerType; private StructDataType bodyType; - private List<DocumentType> inherits = new ArrayList<DocumentType>(1); + private List<DocumentType> inherits = new ArrayList<>(1); /** * Creates a new document type and registers it with the document type manager. @@ -89,15 +100,27 @@ public class DocumentType extends StructuredDataType { return false; } - public StructDataType getHeaderType() { + /** + * Provides the Struct describing the fields in the document. + * @return Struct describing the document fields. + */ + public StructDataType contentStruct() { return headerType; } + // Use contentStruct instead + @Deprecated + public StructDataType getHeaderType() { + return contentStruct(); + } + + @Deprecated public StructDataType getBodyType() { return bodyType; } @Override + @SuppressWarnings("deprecation") protected void register(DocumentTypeManager manager, List<DataType> seenTypes) { seenTypes.add(this); for (DocumentType type : getInheritedTypes()) { @@ -148,6 +171,7 @@ 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."); @@ -397,7 +421,7 @@ public class DocumentType extends StructuredDataType { * @return an unmodifiable snapshot of the fields in this type */ public Set<Field> fieldSet() { - Map<String, Field> map = new LinkedHashMap<String, Field>(); + Map<String, Field> map = new LinkedHashMap<>(); for (Field field : getFields()) { // Uniqify on field name map.put(field.getName(), field); } diff --git a/document/src/main/java/com/yahoo/document/DocumentTypeManagerConfigurer.java b/document/src/main/java/com/yahoo/document/DocumentTypeManagerConfigurer.java index 7678360ea30..be5c6856ee5 100644 --- a/document/src/main/java/com/yahoo/document/DocumentTypeManagerConfigurer.java +++ b/document/src/main/java/com/yahoo/document/DocumentTypeManagerConfigurer.java @@ -134,6 +134,7 @@ public class DocumentTypeManagerConfigurer implements ConfigSubscriber.SingleSub manager.register(type); } + @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(), ""); diff --git a/document/src/main/java/com/yahoo/document/Field.java b/document/src/main/java/com/yahoo/document/Field.java index 4098c85b3e3..16ce69453ab 100644 --- a/document/src/main/java/com/yahoo/document/Field.java +++ b/document/src/main/java/com/yahoo/document/Field.java @@ -16,6 +16,7 @@ import java.io.Serializable; * @author Thomas Gundersen * @author bratseth */ +//TODO Vespa 7 Remove deprecated methods. public class Field extends FieldBase implements FieldSet, Comparable, Serializable { protected DataType dataType; @@ -214,12 +215,20 @@ public class Field extends FieldBase implements FieldSet, Comparable, Serializab return forcedId; } - /** @return Returns true if this field should be a part of "header" serializations. */ + /** + * NB: Has no longer any semantic meaning as this is no longer an aspect with a field. + * @return Returns true if this field should be a part of "header" serializations. + */ + @Deprecated public boolean isHeader() { return isHeader; } - /** Sets whether this is a header field */ + /** + * NB: Has no longer any semantic meaning as this is no longer an aspect with a field. + * Sets whether this is a header field + */ + @Deprecated public void setHeader(boolean header) { this.isHeader = header; } diff --git a/document/src/main/java/com/yahoo/document/fieldset/BodyFields.java b/document/src/main/java/com/yahoo/document/fieldset/BodyFields.java index 912ec798fdb..72c48684b86 100644 --- a/document/src/main/java/com/yahoo/document/fieldset/BodyFields.java +++ b/document/src/main/java/com/yahoo/document/fieldset/BodyFields.java @@ -10,6 +10,8 @@ import com.yahoo.document.Field; * Time: 3:18 PM * To change this template use File | Settings | File Templates. */ +//TODO Vespa 7 Remove +@Deprecated public class BodyFields implements FieldSet { @Override public boolean contains(FieldSet o) { diff --git a/document/src/main/java/com/yahoo/document/fieldset/FieldSetRepo.java b/document/src/main/java/com/yahoo/document/fieldset/FieldSetRepo.java index 38ea190b0d4..a7035439903 100644 --- a/document/src/main/java/com/yahoo/document/fieldset/FieldSetRepo.java +++ b/document/src/main/java/com/yahoo/document/fieldset/FieldSetRepo.java @@ -15,6 +15,7 @@ import java.util.*; */ public class FieldSetRepo { + @SuppressWarnings("deprecation") FieldSet parseSpecialValues(String name) { if (name.equals("[id]")) { return new DocIdOnly(); } @@ -73,6 +74,7 @@ public class FieldSetRepo { return parseFieldCollection(docMan, type, fields); } + @SuppressWarnings("deprecation") public String serialize(FieldSet fieldSet) { if (fieldSet instanceof Field) { return ((Field)fieldSet).getName(); diff --git a/document/src/main/java/com/yahoo/document/fieldset/HeaderFields.java b/document/src/main/java/com/yahoo/document/fieldset/HeaderFields.java index e3b8befa226..ee55bd88faf 100644 --- a/document/src/main/java/com/yahoo/document/fieldset/HeaderFields.java +++ b/document/src/main/java/com/yahoo/document/fieldset/HeaderFields.java @@ -10,6 +10,8 @@ import com.yahoo.document.Field; * Time: 3:18 PM * To change this template use File | Settings | File Templates. */ +//TODO Vespa 7 Remove +@Deprecated public class HeaderFields implements FieldSet { @Override public boolean contains(FieldSet o) { diff --git a/document/src/main/java/com/yahoo/document/serialization/VespaDocumentSerializer42.java b/document/src/main/java/com/yahoo/document/serialization/VespaDocumentSerializer42.java index c3bf9303529..460d35ed266 100644 --- a/document/src/main/java/com/yahoo/document/serialization/VespaDocumentSerializer42.java +++ b/document/src/main/java/com/yahoo/document/serialization/VespaDocumentSerializer42.java @@ -71,8 +71,6 @@ import static com.yahoo.text.Utf8.calculateBytePositions; // When removing: Move content into VespaDocumentSerializerHead public class VespaDocumentSerializer42 extends BufferSerializer implements DocumentSerializer { - private final Compressor compressor = new Compressor(); - private final static Logger log = Logger.getLogger(VespaDocumentSerializer42.class.getName()); private boolean headerOnly; private int spanNodeCounter = -1; private int[] bytePositions; @@ -81,14 +79,6 @@ public class VespaDocumentSerializer42 extends BufferSerializer implements Docum super(buf); } - VespaDocumentSerializer42(ByteBuffer buf) { - super(buf); - } - - VespaDocumentSerializer42(byte[] buf) { - super(buf); - } - VespaDocumentSerializer42() { super(); } @@ -460,14 +450,6 @@ public class VespaDocumentSerializer42 extends BufferSerializer implements Docum putShort(null, (short) 0); // Used to hold the version. Is now always 0. } - - private static void serializeAttributeString(GrowableByteBuffer data, String input) { - byte[] inputBytes = createUTF8CharArray(input); - data.put((byte) (inputBytes.length)); - data.put(inputBytes); - data.put((byte) 0); - } - public void write(Annotation annotation) { buf.putInt(annotation.getType().getId()); //name hash 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 f2f7cc88d00..941dbc8d406 100644 --- a/document/src/main/java/com/yahoo/document/serialization/XmlSerializationHelper.java +++ b/document/src/main/java/com/yahoo/document/serialization/XmlSerializationHelper.java @@ -47,6 +47,7 @@ public class XmlSerializationHelper { xml.addContent(b.toString()); } + @SuppressWarnings("deprecation") public static void printDocumentXml(Document doc, XmlStream xml) { xml.addAttribute("documenttype", doc.getDataType().getName()); xml.addAttribute("documentid", doc.getId()); diff --git a/document/src/test/java/com/yahoo/document/DocumentSerializationTestCase.java b/document/src/test/java/com/yahoo/document/DocumentSerializationTestCase.java index 8090138ed2a..e45da62353d 100644 --- a/document/src/test/java/com/yahoo/document/DocumentSerializationTestCase.java +++ b/document/src/test/java/com/yahoo/document/DocumentSerializationTestCase.java @@ -57,6 +57,7 @@ import static org.junit.Assert.assertTrue; public class DocumentSerializationTestCase extends AbstractTypesTest { @Test + @SuppressWarnings("deprecation") public void testSerializationAllVersions() throws IOException { DocumentType docInDocType = new DocumentType("docindoc"); @@ -111,18 +112,18 @@ public class DocumentSerializationTestCase extends AbstractTypesTest { CompressionConfig noncomp = new CompressionConfig(); CompressionConfig lz4comp = new CompressionConfig(CompressionType.LZ4); { - doc.getDataType().getHeaderType().setCompressionConfig(noncomp); + doc.getDataType().contentStruct().setCompressionConfig(noncomp); doc.getDataType().getBodyType().setCompressionConfig(noncomp); FileOutputStream fout = new FileOutputStream(path + "document-java-currentversion-uncompressed.dat", false); doc.serialize(fout); fout.close(); } { - doc.getDataType().getHeaderType().setCompressionConfig(lz4comp); + doc.getDataType().contentStruct().setCompressionConfig(lz4comp); doc.getDataType().getBodyType().setCompressionConfig(lz4comp); FileOutputStream fout = new FileOutputStream(path + "document-java-currentversion-lz4-9.dat", false); doc.serialize(fout); - doc.getDataType().getHeaderType().setCompressionConfig(noncomp); + doc.getDataType().contentStruct().setCompressionConfig(noncomp); doc.getDataType().getBodyType().setCompressionConfig(noncomp); fout.close(); } diff --git a/document/src/test/java/com/yahoo/document/DocumentTestCase.java b/document/src/test/java/com/yahoo/document/DocumentTestCase.java index 84b33b3881c..6a2147d6f15 100644 --- a/document/src/test/java/com/yahoo/document/DocumentTestCase.java +++ b/document/src/test/java/com/yahoo/document/DocumentTestCase.java @@ -752,6 +752,7 @@ public class DocumentTestCase extends DocumentTestCaseBase { } @Test + @SuppressWarnings("deprecation") public void testGenerateSerializedFile() throws IOException { docMan = setUpCppDocType(); @@ -805,12 +806,12 @@ public class DocumentTestCase extends DocumentTestCaseBase { CompressionConfig noncomp = new CompressionConfig(); CompressionConfig lz4comp = new CompressionConfig(CompressionType.LZ4); - doc.getDataType().getHeaderType().setCompressionConfig(lz4comp); + doc.getDataType().contentStruct().setCompressionConfig(lz4comp); doc.getDataType().getBodyType().setCompressionConfig(lz4comp); buf = new GrowableByteBuffer(size, 2.0f); doc.serialize(buf); - doc.getDataType().getHeaderType().setCompressionConfig(noncomp); + doc.getDataType().contentStruct().setCompressionConfig(noncomp); doc.getDataType().getBodyType().setCompressionConfig(noncomp); fos = new FileOutputStream("src/tests/data/serializejava-compressed.dat"); fos.write(buf.array(), 0, buf.position()); @@ -818,6 +819,7 @@ public class DocumentTestCase extends DocumentTestCaseBase { } @Test + @SuppressWarnings("deprecation") public void testSerializeDeserialize() { setUpSertestDocType(); Document doc = getSertestDocument(); @@ -900,6 +902,7 @@ public class DocumentTestCase extends DocumentTestCaseBase { } @Test + @SuppressWarnings("deprecation") public void testSerializeDeserializeCompressed() { setUpSertestDocType(); Document doc = getSertestDocument(); @@ -907,13 +910,13 @@ public class DocumentTestCase extends DocumentTestCaseBase { CompressionConfig noncomp = new CompressionConfig(); CompressionConfig lz4comp = new CompressionConfig(CompressionType.LZ4); - doc.getDataType().getHeaderType().setCompressionConfig(lz4comp); + doc.getDataType().contentStruct().setCompressionConfig(lz4comp); doc.getDataType().getBodyType().setCompressionConfig(lz4comp); GrowableByteBuffer data = new GrowableByteBuffer(); doc.serialize(data); int size = doc.getSerializedSize(); - doc.getDataType().getHeaderType().setCompressionConfig(noncomp); + doc.getDataType().contentStruct().setCompressionConfig(noncomp); doc.getDataType().getBodyType().setCompressionConfig(noncomp); assertEquals(size, data.position()); diff --git a/document/src/test/java/com/yahoo/document/DocumentTypeManagerTestCase.java b/document/src/test/java/com/yahoo/document/DocumentTypeManagerTestCase.java index 6acae4f37c6..65c217e09e1 100644 --- a/document/src/test/java/com/yahoo/document/DocumentTypeManagerTestCase.java +++ b/document/src/test/java/com/yahoo/document/DocumentTypeManagerTestCase.java @@ -24,6 +24,7 @@ public class DocumentTypeManagerTestCase { // Verify that we can register and retrieve fields. @Test + @SuppressWarnings("deprecation") public void testRegisterAndGet() { DocumentTypeManager manager = new DocumentTypeManager(); diff --git a/document/src/test/java/com/yahoo/document/datatypes/StringTestCase.java b/document/src/test/java/com/yahoo/document/datatypes/StringTestCase.java index fd2b4a3982d..ffc372d4851 100644 --- a/document/src/test/java/com/yahoo/document/datatypes/StringTestCase.java +++ b/document/src/test/java/com/yahoo/document/datatypes/StringTestCase.java @@ -343,6 +343,7 @@ public class StringTestCase extends AbstractTypesTest { return document; } + @SuppressWarnings("deprecation") public Document consume(Document document, DocumentTypeManager docTypeMgr) { DocumentType type = docTypeMgr.getDocumentType("blog"); Collection<Field> fc = type.getFields(); diff --git a/document/src/test/java/com/yahoo/document/fieldset/FieldSetTestCase.java b/document/src/test/java/com/yahoo/document/fieldset/FieldSetTestCase.java index e9889d3149e..c11c58ff729 100644 --- a/document/src/test/java/com/yahoo/document/fieldset/FieldSetTestCase.java +++ b/document/src/test/java/com/yahoo/document/fieldset/FieldSetTestCase.java @@ -20,6 +20,7 @@ import static org.junit.Assert.assertTrue; public class FieldSetTestCase extends DocumentTestCaseBase { @Test + @SuppressWarnings("deprecation") public void testClone() throws Exception { assertTrue(new AllFields().clone() instanceof AllFields); assertTrue(new NoFields().clone() instanceof NoFields); @@ -29,6 +30,7 @@ public class FieldSetTestCase extends DocumentTestCaseBase { } @Test + @SuppressWarnings("deprecation") public void testParsing() { FieldSetRepo repo = new FieldSetRepo(); @@ -65,6 +67,7 @@ public class FieldSetTestCase extends DocumentTestCaseBase { } @Test + @SuppressWarnings("deprecation") public void testContains() throws Exception { Field headerField = testDocType.getField("intattr"); Field bodyField = testDocType.getField("rawattr"); |