use of com.yahoo.document.annotation.AnnotationType in project vespa by vespa-engine.
the class VespaDocumentDeserializer42 method read.
public void read(Annotation annotation) {
int annotationTypeId = buf.getInt();
AnnotationType type = manager.getAnnotationTypeRegistry().getType(annotationTypeId);
if (type == null) {
throw new DeserializationException("Cannot deserialize annotation of type " + annotationTypeId + " (unknown type)");
}
annotation.setType(type);
byte features = buf.get();
int length = buf.getInt1_2_4Bytes();
if ((features & (byte) 1) == (byte) 1) {
// we have a span node
int spanNodeId = buf.getInt1_2_4Bytes();
try {
SpanNode node = spanNodes.get(spanNodeId);
annotation.setSpanNode(node);
} catch (IndexOutOfBoundsException ioobe) {
throw new DeserializationException("Could not deserialize annotation, associated span node not found ", ioobe);
}
}
if ((features & (byte) 2) == (byte) 2) {
// we have a value:
int dataTypeId = buf.getInt();
// if this data type ID the same as the one in our config?
if (dataTypeId != type.getDataType().getId()) {
// not the same, but we will handle it gracefully, and just skip past the data:
buf.position(buf.position() + length - 4);
} else {
FieldValue value = type.getDataType().createFieldValue();
value.deserialize(this);
annotation.setFieldValue(value);
}
}
}
use of com.yahoo.document.annotation.AnnotationType in project vespa by vespa-engine.
the class DocumentModelBuilder method anyParentsHavePayLoad.
private static boolean anyParentsHavePayLoad(SDAnnotationType sa, SDDocumentType sdoc) {
if (sa.getInherits() != null) {
AnnotationType tmp = sdoc.findAnnotation(sa.getInherits());
SDAnnotationType inherited = (SDAnnotationType) tmp;
return ((inherited.getSdDocType() != null) || anyParentsHavePayLoad(inherited, sdoc));
}
return false;
}
use of com.yahoo.document.annotation.AnnotationType in project vespa by vespa-engine.
the class DocumentModelBuilder method specialHandleAnnotationReferenceRecurse.
private static DataType specialHandleAnnotationReferenceRecurse(NewDocumentType docType, String fieldName, DataType dataType) {
if (dataType instanceof TemporaryAnnotationReferenceDataType) {
TemporaryAnnotationReferenceDataType refType = (TemporaryAnnotationReferenceDataType) dataType;
if (refType.getId() != 0) {
return null;
}
AnnotationType target = docType.getAnnotationType(refType.getTarget());
if (target == null) {
throw new RetryLaterException("Annotation '" + refType.getTarget() + "' in reference '" + fieldName + "' does not exist.");
}
dataType = new AnnotationReferenceDataType(target);
addType(docType, dataType);
return dataType;
} else if (dataType instanceof MapDataType) {
MapDataType mapType = (MapDataType) dataType;
DataType valueType = specialHandleAnnotationReferenceRecurse(docType, fieldName, mapType.getValueType());
if (valueType == null) {
return null;
}
mapType = mapType.clone();
mapType.setValueType(valueType);
addType(docType, mapType);
return mapType;
} else if (dataType instanceof CollectionDataType) {
CollectionDataType lstType = (CollectionDataType) dataType;
DataType nestedType = specialHandleAnnotationReferenceRecurse(docType, fieldName, lstType.getNestedType());
if (nestedType == null) {
return null;
}
lstType = lstType.clone();
lstType.setNestedType(nestedType);
addType(docType, lstType);
return lstType;
}
return null;
}
use of com.yahoo.document.annotation.AnnotationType in project vespa by vespa-engine.
the class DocumentManager method buildConfig.
private void buildConfig(Collection<AnnotationType> types, DocumentmanagerConfig.Builder builder) {
for (AnnotationType type : types) {
DocumentmanagerConfig.Annotationtype.Builder atb = new DocumentmanagerConfig.Annotationtype.Builder();
buildConfig(type, atb);
builder.annotationtype(atb);
}
}
use of com.yahoo.document.annotation.AnnotationType in project vespa by vespa-engine.
the class DocumentTypes method buildConfig.
private void buildConfig(AnnotationType annotation, DocumenttypesConfig.Documenttype.Annotationtype.Builder builder) {
builder.id(annotation.getId()).name(annotation.getName());
DataType dt = annotation.getDataType();
if (dt != null) {
builder.datatype(dt.getId());
}
for (AnnotationType inherited : annotation.getInheritedTypes()) {
builder.inherits(new DocumenttypesConfig.Documenttype.Annotationtype.Inherits.Builder().id(inherited.getId()));
}
}
Aggregations