summaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/documentmodel
diff options
context:
space:
mode:
authorArne H Juul <arnej@yahooinc.com>2022-03-17 08:05:02 +0000
committerArne H Juul <arnej@yahooinc.com>2022-03-17 08:05:02 +0000
commit046b7ef5501f6ce242060d16bd129d21a31f7e90 (patch)
treec918e5a39d9020997e20caecc4d54a3b2a8b322d /config-model/src/main/java/com/yahoo/documentmodel
parent7c1698de2336cdc39b45d2e61001576b1fdcaaaa (diff)
add new datatype model
Diffstat (limited to 'config-model/src/main/java/com/yahoo/documentmodel')
-rw-r--r--config-model/src/main/java/com/yahoo/documentmodel/NewDocumentReferenceDataType.java78
1 files changed, 78 insertions, 0 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
new file mode 100644
index 00000000000..bfec185938d
--- /dev/null
+++ b/config-model/src/main/java/com/yahoo/documentmodel/NewDocumentReferenceDataType.java
@@ -0,0 +1,78 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.documentmodel;
+
+import com.yahoo.document.DataType;
+import com.yahoo.document.StructuredDataType;
+import com.yahoo.document.TemporaryStructuredDataType;
+import com.yahoo.document.datatypes.FieldValue;
+
+/**
+ * @author arnej
+ */
+@SuppressWarnings("deprecation")
+public final class NewDocumentReferenceDataType extends DataType {
+
+ private StructuredDataType target;
+ private final boolean temporary;
+
+ private NewDocumentReferenceDataType(NewDocumentType.Name nameAndId,
+ StructuredDataType target,
+ boolean temporary)
+ {
+ super(nameAndId.getName(), nameAndId.getId());
+ this.target = target;
+ this.temporary = temporary;
+ }
+
+ private static NewDocumentType.Name buildTypeName(String documentName) {
+ String typeName = "Reference<" + documentName + ">";
+ return new NewDocumentType.Name(typeName);
+ }
+
+ public NewDocumentReferenceDataType(String documentName) {
+ this(buildTypeName(documentName), TemporaryStructuredDataType.create(documentName), true);
+ }
+
+ public NewDocumentReferenceDataType(NewDocumentType document) {
+ this(buildTypeName(document.getName()), document, false);
+ }
+
+ public boolean isTemporary() { return temporary; }
+
+ public StructuredDataType getTargetType() { return target; }
+
+ public void setTargetType(StructuredDataType type) {
+ assert(target.getName().equals(type.getName()));
+ if (temporary) {
+ this.target = type;
+ } else {
+ throw new IllegalStateException
+ (String.format("Unexpected attempt to replace already concrete target " +
+ "type in ReferenceDataType instance (type is '%s')", target.getName()));
+ }
+ }
+
+ @Override
+ public FieldValue createFieldValue() {
+ throw new IllegalArgumentException("not implemented");
+ }
+
+ @Override
+ public Class<FieldValue> getValueClass() {
+ throw new IllegalArgumentException("not implemented");
+ }
+
+ @Override
+ public boolean isValueCompatible(FieldValue value) {
+ throw new IllegalArgumentException("not implemented");
+ }
+
+ @Override
+ public boolean equals(Object rhs) {
+ if (rhs instanceof NewDocumentReferenceDataType) {
+ var other = (NewDocumentReferenceDataType) rhs;
+ return super.equals(other) && (temporary == other.temporary) && target.equals(other.target);
+ }
+ return false;
+ }
+}