summaryrefslogtreecommitdiffstats
path: root/document/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'document/src/main/java')
-rw-r--r--document/src/main/java/com/yahoo/document/Document.java24
-rw-r--r--document/src/main/java/com/yahoo/document/DocumentGet.java42
-rw-r--r--document/src/main/java/com/yahoo/document/DocumentOperation.java3
-rwxr-xr-xdocument/src/main/java/com/yahoo/document/DocumentType.java32
-rw-r--r--document/src/main/java/com/yahoo/document/DocumentTypeManagerConfigurer.java1
-rw-r--r--document/src/main/java/com/yahoo/document/Field.java13
-rw-r--r--document/src/main/java/com/yahoo/document/fieldset/BodyFields.java2
-rw-r--r--document/src/main/java/com/yahoo/document/fieldset/FieldSetRepo.java2
-rw-r--r--document/src/main/java/com/yahoo/document/fieldset/HeaderFields.java2
-rw-r--r--document/src/main/java/com/yahoo/document/select/rule/AttributeNode.java2
-rw-r--r--document/src/main/java/com/yahoo/document/select/rule/DocumentNode.java3
-rw-r--r--document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializer42.java98
-rw-r--r--document/src/main/java/com/yahoo/document/serialization/VespaDocumentSerializer42.java18
-rw-r--r--document/src/main/java/com/yahoo/document/serialization/XmlSerializationHelper.java1
14 files changed, 206 insertions, 37 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/DocumentGet.java b/document/src/main/java/com/yahoo/document/DocumentGet.java
new file mode 100644
index 00000000000..0cf67f54b65
--- /dev/null
+++ b/document/src/main/java/com/yahoo/document/DocumentGet.java
@@ -0,0 +1,42 @@
+// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.document;
+
+/**
+ * Transient class. Only for internal use in document and documentapi.
+ *
+ * @author baldersheim
+ * @author toregge
+ */
+public class DocumentGet extends DocumentOperation {
+
+ private final DocumentId docId;
+
+ public DocumentGet(DocumentId docId) { this.docId = docId; }
+
+ @Override
+ public DocumentId getId() { return docId; }
+
+ @Override
+ public void setCondition(TestAndSetCondition condition) {
+ throw new UnsupportedOperationException("conditional DocumentGet is not supported");
+ }
+
+ @Override
+ public String toString() {
+ return "DocumentGet '" + docId + "'";
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof DocumentGet)) return false;
+ DocumentGet that = (DocumentGet) o;
+ if (!docId.equals(that.docId)) return false;
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ return docId.hashCode();
+ }
+}
diff --git a/document/src/main/java/com/yahoo/document/DocumentOperation.java b/document/src/main/java/com/yahoo/document/DocumentOperation.java
index 22ee0fd93eb..8209322c472 100644
--- a/document/src/main/java/com/yahoo/document/DocumentOperation.java
+++ b/document/src/main/java/com/yahoo/document/DocumentOperation.java
@@ -3,7 +3,8 @@ package com.yahoo.document;
/**
* Base class for "document operations".
- * These include "put" (DocumentPut), "update" (DocumentUpdate), and "remove" (DocumentRemove).
+ * These include "put" (DocumentPut), "update" (DocumentUpdate), "remove" (DocumentRemove)
+ * and "get" (DocumentGet). The latter only for internal use.
* Historically, put operations were represented by the Document class alone,
* but since it doesn't make much sense to put a *test and set* condition in Document,
* a more uniform interface for document operations was needed.
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/select/rule/AttributeNode.java b/document/src/main/java/com/yahoo/document/select/rule/AttributeNode.java
index 17f95087be1..b6d75acd0ea 100644
--- a/document/src/main/java/com/yahoo/document/select/rule/AttributeNode.java
+++ b/document/src/main/java/com/yahoo/document/select/rule/AttributeNode.java
@@ -135,6 +135,8 @@ public class AttributeNode implements ExpressionNode {
return Result.INVALID;
} else if (value instanceof DocumentRemove) {
return Result.INVALID;
+ } else if (value instanceof DocumentGet) {
+ return Result.INVALID;
}
return Result.FALSE;
}
diff --git a/document/src/main/java/com/yahoo/document/select/rule/DocumentNode.java b/document/src/main/java/com/yahoo/document/select/rule/DocumentNode.java
index 3fe3d5d7169..c0907693dab 100644
--- a/document/src/main/java/com/yahoo/document/select/rule/DocumentNode.java
+++ b/document/src/main/java/com/yahoo/document/select/rule/DocumentNode.java
@@ -46,6 +46,9 @@ public class DocumentNode implements ExpressionNode {
} else if (op instanceof DocumentRemove) {
DocumentRemove removeOp = (DocumentRemove)op;
return (removeOp.getId().getDocType().equals(type) ? op : Boolean.FALSE);
+ } else if (op instanceof DocumentGet) {
+ DocumentGet getOp = (DocumentGet)op;
+ return (getOp.getId().getDocType().equals(type) ? op : Boolean.FALSE);
} else {
throw new IllegalStateException("Document class '" + op.getClass().getName() + "' is not supported.");
}
diff --git a/document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializer42.java b/document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializer42.java
index f4c40980608..6ec7a1e2b21 100644
--- a/document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializer42.java
+++ b/document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializer42.java
@@ -136,16 +136,20 @@ public class VespaDocumentDeserializer42 extends VespaDocumentSerializer42 imple
doc.setDataType(readDocumentType());
+ Struct h = doc.getHeader();
+ Struct b = doc.getBody();
+ h.clear();
+ b.clear();
if ((content & 0x2) != 0) {
- doc.getHeader().deserialize(new Field("header"),this);
+ readHeaderBody(h, b);
}
if ((content & 0x4) != 0) {
- doc.getBody().deserialize(new Field("body"),this);
+ readHeaderBody(b, h);
} else if (body != null) {
GrowableByteBuffer header = getBuf();
setBuf(body);
body = null;
- doc.getBody().deserialize(new Field("body"), this);
+ readHeaderBody(b, h);
body = getBuf();
setBuf(header);
}
@@ -377,6 +381,94 @@ public class VespaDocumentDeserializer42 extends VespaDocumentSerializer42 imple
buf = bigBuf;
}
+ private void readHeaderBody(Struct primary, Struct alternate) {
+ primary.setVersion(version);
+ int startPos = position();
+
+ if (version < 6) {
+ throw new DeserializationException("Illegal document serialization version " + version);
+ }
+
+ int dataSize;
+ if (version < 7) {
+ long rSize = getInt2_4_8Bytes(null);
+ //TODO: Look into how to support data segments larger than INT_MAX bytes
+ if (rSize > Integer.MAX_VALUE) {
+ throw new DeserializationException("Raw size of data block is too large.");
+ }
+ dataSize = (int)rSize;
+ } else {
+ dataSize = getInt(null);
+ }
+
+ byte comprCode = getByte(null);
+ CompressionType compression = CompressionType.valueOf(comprCode);
+
+ int uncompressedSize = 0;
+ if (compression != CompressionType.NONE &&
+ compression != CompressionType.INCOMPRESSIBLE)
+ {
+ // uncompressedsize (full size of FIELDS only, after decompression)
+ long pSize = getInt2_4_8Bytes(null);
+ //TODO: Look into how to support data segments larger than INT_MAX bytes
+ if (pSize > Integer.MAX_VALUE) {
+ throw new DeserializationException("Uncompressed size of data block is too large.");
+ }
+ uncompressedSize = (int) pSize;
+ }
+
+ int numberOfFields = getInt1_4Bytes(null);
+
+ List<Tuple2<Integer, Long>> fieldIdsAndLengths = new ArrayList<>(numberOfFields);
+ for (int i=0; i<numberOfFields; ++i) {
+ // id, length (length only used for unknown fields
+ fieldIdsAndLengths.add(new Tuple2<>(getInt1_4Bytes(null), getInt2_4_8Bytes(null)));
+ }
+
+ // save a reference to the big buffer we're reading from:
+ GrowableByteBuffer bigBuf = buf;
+
+ if (version < 7) {
+ // In V6 and earlier, the length included the header.
+ int headerSize = position() - startPos;
+ dataSize -= headerSize;
+ }
+ byte[] destination = compressor.decompress(compression, getBuf().array(), position(), uncompressedSize, Optional.of(dataSize));
+
+ // set position in original buffer to after data
+ position(position() + dataSize);
+
+ // for a while: deserialize from this buffer instead:
+ 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, version);
+ if (structField != null) {
+ s = primary;
+ } else {
+ structField = altType.getField(f_id, version);
+ if (structField != null) {
+ s = alternate;
+ }
+ }
+ if (s != null) {
+ FieldValue value = structField.getDataType().createFieldValue();
+ value.deserialize(structField, this);
+ s.setFieldValue(structField, value);
+ }
+ //jump to beginning of next field:
+ position(posBefore + fieldIdsAndLengths.get(i).second.intValue());
+ }
+
+ // restore the original buffer
+ buf = bigBuf;
+ }
+
public void read(FieldBase field, StructuredFieldValue value) {
throw new IllegalArgumentException("read not implemented yet.");
}
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());