diff options
-rw-r--r-- | document/abi-spec.json | 1 | ||||
-rw-r--r-- | document/src/main/java/com/yahoo/document/DocumentType.java | 17 | ||||
-rw-r--r-- | document/src/test/java/com/yahoo/document/DocumentTypeManagerTestCase.java | 25 |
3 files changed, 41 insertions, 2 deletions
diff --git a/document/abi-spec.json b/document/abi-spec.json index e9bf2cb6430..661bc35bb83 100644 --- a/document/abi-spec.json +++ b/document/abi-spec.json @@ -437,6 +437,7 @@ "public java.lang.Class getValueClass()", "public boolean isValueCompatible(com.yahoo.document.datatypes.FieldValue)", "public com.yahoo.document.StructDataType contentStruct()", + "public com.yahoo.document.StructDataType getStructType(java.lang.String)", "public com.yahoo.document.StructDataType getDeclaredStructType(java.lang.String)", "public com.yahoo.document.StructDataType getHeaderType()", "protected void register(com.yahoo.document.DocumentTypeManager, java.util.List)", diff --git a/document/src/main/java/com/yahoo/document/DocumentType.java b/document/src/main/java/com/yahoo/document/DocumentType.java index 1469776583d..055785cb80f 100644 --- a/document/src/main/java/com/yahoo/document/DocumentType.java +++ b/document/src/main/java/com/yahoo/document/DocumentType.java @@ -142,17 +142,19 @@ public class DocumentType extends StructuredDataType { /** * Get a struct declared in this document (or any inherited * document). Returns null if no such struct was found. + * If multiple possible structs are found in inherited + * documents, throws exception. * * @param name the name of the struct * @return reference to a struct data type, or null **/ - public StructDataType getDeclaredStructType(String name) { + public StructDataType getStructType(String name) { var mine = declaredStructTypes.get(name); if (mine != null) { return mine; } for (DocumentType inheritedType : inherits) { - var fromParent = inheritedType.getDeclaredStructType(name); + var fromParent = inheritedType.getStructType(name); if (fromParent == null) { continue; } else if (mine == null) { @@ -164,6 +166,17 @@ public class DocumentType extends StructuredDataType { return mine; } + /** + * Get a struct declared in this document only. + * Returns null if no such struct was found. + * + * @param name the name of the struct + * @return reference to a struct data type, or null + **/ + public StructDataType getDeclaredStructType(String name) { + return declaredStructTypes.get(name); + } + /** only used during configuration */ void addDeclaredStructType(String name, StructDataType struct) { var old = declaredStructTypes.put(name, struct); diff --git a/document/src/test/java/com/yahoo/document/DocumentTypeManagerTestCase.java b/document/src/test/java/com/yahoo/document/DocumentTypeManagerTestCase.java index 622c7b2237f..5770b998c69 100644 --- a/document/src/test/java/com/yahoo/document/DocumentTypeManagerTestCase.java +++ b/document/src/test/java/com/yahoo/document/DocumentTypeManagerTestCase.java @@ -605,38 +605,63 @@ search annotationsimplicitstruct { var docType = manager.getDocumentType("foo"); var struct = docType.getDeclaredStructType("mystructinfoo"); assertNotNull(struct); + struct = docType.getStructType("mystructinfoo"); assertNotNull(struct.getField("f1")); struct = docType.getDeclaredStructType("mystructinbar"); assertNull(struct); + struct = docType.getStructType("mystructinbar"); + assertNull(struct); struct = docType.getDeclaredStructType("mystructinfoobar"); assertNull(struct); + struct = docType.getStructType("mystructinfoobar"); + assertNull(struct); struct = docType.getDeclaredStructType("mystruct"); + assertNull(struct); + struct = docType.getStructType("mystruct"); assertNotNull(struct); assertNotNull(struct.getField("f0")); docType = manager.getDocumentType("bar"); struct = docType.getDeclaredStructType("mystructinfoo"); assertNull(struct); + struct = docType.getStructType("mystructinfoo"); + assertNull(struct); struct = docType.getDeclaredStructType("mystructinbar"); assertNotNull(struct); assertNotNull(struct.getField("f2")); + struct = docType.getStructType("mystructinbar"); + assertNotNull(struct); + assertNotNull(struct.getField("f2")); struct = docType.getDeclaredStructType("mystructinfoobar"); assertNull(struct); + struct = docType.getStructType("mystructinfoobar"); + assertNull(struct); struct = docType.getDeclaredStructType("mystruct"); + assertNull(struct); + struct = docType.getStructType("mystruct"); assertNotNull(struct); assertNotNull(struct.getField("f0")); docType = manager.getDocumentType("foobar"); struct = docType.getDeclaredStructType("mystructinfoo"); + assertNull(struct); + struct = docType.getStructType("mystructinfoo"); assertNotNull(struct); assertNotNull(struct.getField("f1")); struct = docType.getDeclaredStructType("mystructinbar"); + assertNull(struct); + struct = docType.getStructType("mystructinbar"); assertNotNull(struct); assertNotNull(struct.getField("f2")); struct = docType.getDeclaredStructType("mystructinfoobar"); assertNotNull(struct); assertNotNull(struct.getField("f3")); + struct = docType.getStructType("mystructinfoobar"); + assertNotNull(struct); + assertNotNull(struct.getField("f3")); struct = docType.getDeclaredStructType("mystruct"); + assertNull(struct); + struct = docType.getStructType("mystruct"); assertNotNull(struct); assertNotNull(struct.getField("f0")); } |