diff options
author | Arne H Juul <arnej@yahooinc.com> | 2022-03-17 09:52:25 +0000 |
---|---|---|
committer | Arne H Juul <arnej@yahooinc.com> | 2022-03-17 10:09:03 +0000 |
commit | 66cd9e646c66b255d2259ec39a72f5b3fd8ce100 (patch) | |
tree | 1499ac45e15858a01e794524906714959ab4bf58 /config-model/src/main/java/com/yahoo/documentmodel/NewDocumentReferenceDataType.java | |
parent | 046b7ef5501f6ce242060d16bd129d21a31f7e90 (diff) |
more compatible
Diffstat (limited to 'config-model/src/main/java/com/yahoo/documentmodel/NewDocumentReferenceDataType.java')
-rw-r--r-- | config-model/src/main/java/com/yahoo/documentmodel/NewDocumentReferenceDataType.java | 50 |
1 files changed, 42 insertions, 8 deletions
diff --git a/config-model/src/main/java/com/yahoo/documentmodel/NewDocumentReferenceDataType.java b/config-model/src/main/java/com/yahoo/documentmodel/NewDocumentReferenceDataType.java index bfec185938d..7652000389b 100644 --- a/config-model/src/main/java/com/yahoo/documentmodel/NewDocumentReferenceDataType.java +++ b/config-model/src/main/java/com/yahoo/documentmodel/NewDocumentReferenceDataType.java @@ -2,17 +2,26 @@ package com.yahoo.documentmodel; import com.yahoo.document.DataType; +import com.yahoo.document.DocumentType; +import com.yahoo.document.ReferenceDataType; import com.yahoo.document.StructuredDataType; import com.yahoo.document.TemporaryStructuredDataType; import com.yahoo.document.datatypes.FieldValue; +import com.yahoo.document.datatypes.ReferenceFieldValue; /** + * Model for ReferenceDataType which is more suitable when + * we want to end up with NewDocumentType as target type. + * * @author arnej - */ + **/ @SuppressWarnings("deprecation") public final class NewDocumentReferenceDataType extends DataType { private StructuredDataType target; + private DocumentType docTypeTarget = null; + private ReferenceDataType delegate = null; + private final boolean temporary; private NewDocumentReferenceDataType(NewDocumentType.Name nameAndId, @@ -29,8 +38,15 @@ public final class NewDocumentReferenceDataType extends DataType { return new NewDocumentType.Name(typeName); } - public NewDocumentReferenceDataType(String documentName) { - this(buildTypeName(documentName), TemporaryStructuredDataType.create(documentName), true); + public static NewDocumentReferenceDataType forDocumentName(String documentName) { + return new NewDocumentReferenceDataType(buildTypeName(documentName), + TemporaryStructuredDataType.create(documentName), + true); + } + + public NewDocumentReferenceDataType(DocumentType document) { + this(buildTypeName(document.getName()), document, true); + this.docTypeTarget = document; } public NewDocumentReferenceDataType(NewDocumentType document) { @@ -45,26 +61,44 @@ public final class NewDocumentReferenceDataType extends DataType { assert(target.getName().equals(type.getName())); if (temporary) { this.target = type; + if ((docTypeTarget == null) && (type instanceof DocumentType)) { + this.docTypeTarget = (DocumentType) type; + } } else { throw new IllegalStateException (String.format("Unexpected attempt to replace already concrete target " + - "type in ReferenceDataType instance (type is '%s')", target.getName())); + "type in NewDocumentReferenceDataType instance (type is '%s')", target.getName())); } } @Override public FieldValue createFieldValue() { - throw new IllegalArgumentException("not implemented"); + // TODO why do we even need this + if (delegate == null) { + if (docTypeTarget == null) { + var tmptmp = TemporaryStructuredDataType.create(target.getName()); + var tmp = ReferenceDataType.createWithInferredId(tmptmp); + return tmp.createFieldValue(); + } + delegate = ReferenceDataType.createWithInferredId(docTypeTarget); + } + return delegate.createFieldValue(); } @Override - public Class<FieldValue> getValueClass() { - throw new IllegalArgumentException("not implemented"); + public Class<? extends ReferenceFieldValue> getValueClass() { + return ReferenceFieldValue.class; } @Override public boolean isValueCompatible(FieldValue value) { - throw new IllegalArgumentException("not implemented"); + var dt = value.getDataType(); + if (dt instanceof ReferenceDataType) { + var refType = (ReferenceDataType) dt; + var docTypeName = refType.getTargetType().getName(); + return docTypeName.equals(target.getName()); + } + return false; } @Override |