diff options
author | Arne H Juul <arnej@yahooinc.com> | 2022-06-03 10:55:18 +0000 |
---|---|---|
committer | gjoranv <gv@verizonmedia.com> | 2022-06-08 11:45:31 +0200 |
commit | 0b3579b8af74a1bdbab5759a51bd592fdbc11cb8 (patch) | |
tree | a078096d65da6b15e5bedb00a6a911bbfc078ed9 /document | |
parent | e337a30ca89055a6aa3f7aa9267d2f1e523e7bdd (diff) |
more cleanup of DocumentTypeManager API
Diffstat (limited to 'document')
5 files changed, 42 insertions, 45 deletions
diff --git a/document/abi-spec.json b/document/abi-spec.json index dcf89da32e4..abb9f76b311 100644 --- a/document/abi-spec.json +++ b/document/abi-spec.json @@ -492,13 +492,12 @@ "methods": [ "public void <init>()", "public void <init>(com.yahoo.document.config.DocumentmanagerConfig)", - "public void assign(com.yahoo.document.DocumentTypeManager)", "public static com.yahoo.document.DocumentTypeManager fromFile(java.lang.String)", - "public boolean hasDataType(java.lang.String)", "public void register(com.yahoo.document.DataType)", "public com.yahoo.document.DocumentType registerDocumentType(com.yahoo.document.DocumentType)", "public com.yahoo.document.DocumentType getDocumentType(com.yahoo.document.DataTypeName)", "public com.yahoo.document.DocumentType getDocumentType(java.lang.String)", + "public boolean hasDocumentType(java.lang.String)", "public final com.yahoo.document.Document createDocument(com.yahoo.io.GrowableByteBuffer)", "public com.yahoo.document.Document createDocument(com.yahoo.document.serialization.DocumentDeserializer)", "public java.util.Collection getDataTypes()", diff --git a/document/src/main/java/com/yahoo/document/DocumentTypeManager.java b/document/src/main/java/com/yahoo/document/DocumentTypeManager.java index a32772adb31..ee9366285a9 100644 --- a/document/src/main/java/com/yahoo/document/DocumentTypeManager.java +++ b/document/src/main/java/com/yahoo/document/DocumentTypeManager.java @@ -65,7 +65,7 @@ public class DocumentTypeManager { DocumentTypeManagerConfigurer.configureNewManager(config, this); } - public void assign(DocumentTypeManager other) { + void internalAssign(DocumentTypeManager other) { dataTypes = other.dataTypes; documentTypes = other.documentTypes; annotationTypeRegistry = other.annotationTypeRegistry; @@ -103,7 +103,7 @@ public class DocumentTypeManager { } } - public boolean hasDataType(String name) { + boolean hasDataTypeInternal(String name) { if (name.startsWith("tensor(")) return true; // built-in dynamic: Always present for (DataType type : dataTypes.values()) { if (type.getName().equalsIgnoreCase(name)) { @@ -114,19 +114,6 @@ public class DocumentTypeManager { } /** - * Use constants and factories in DataType instead. - * For structs, use getStructType() in DocumentType. - * For annotation payloads, use getDataType() in AnnotationType. - */ - DataType getDataType(String name) { - var type = getDataTypeInternal(name); - if (type == null) { - throw new IllegalArgumentException("No datatype named " + name); - } - return type; - } - - /** * For internal use only, avoid whenever possible. * Use constants and factories in DataType instead. * For structs, use getStructType() in DocumentType. @@ -163,7 +150,12 @@ public class DocumentTypeManager { return foundTypes.get(0); } - DataType getDataType(int code) { return getDataType(code, ""); } + /** + * Return a data type instance + * + * @param code the code of the data type to return, which must be either built in or present in this manager + */ + DataType getDataTypeByCode(int code) { return getDataTypeByCode(code, ""); } /** * Return a data type instance @@ -172,7 +164,7 @@ public class DocumentTypeManager { * @param detailedType detailed type information, or the empty string if none * @return the appropriate DataType instance */ - DataType getDataType(int code, String detailedType) { + DataType getDataTypeByCode(int code, String detailedType) { if (code == DataType.tensorDataTypeCode) // built-in dynamic return new TensorDataType(TensorType.fromSpec(detailedType)); @@ -202,7 +194,6 @@ public class DocumentTypeManager { * * @param type The datatype to register */ - @SuppressWarnings("deprecation") void registerSingleType(DataType type) { if (type instanceof TensorDataType) return; // built-in dynamic: Created on the fly if (dataTypes.containsKey(type.getId())) { @@ -259,6 +250,15 @@ public class DocumentTypeManager { return documentTypes.get(new DataTypeName(name)); } + /** + * Convenience method + * @param name the name of a document type + * @return returns true if a document type having this name is registered in this manager + */ + public boolean hasDocumentType(String name) { + return (getDocumentType(name) != null); + } + final public Document createDocument(GrowableByteBuffer buf) { DocumentDeserializer data = DocumentDeserializerFactory.create6(this, buf); return new Document(data); @@ -293,7 +293,7 @@ public class DocumentTypeManager { * Clears the DocumentTypeManager. After this operation, * only the default document type and data types are available. */ - void clear() { + void internalClear() { documentTypes.clear(); dataTypes.clear(); registerDefaultDataTypes(); diff --git a/document/src/main/java/com/yahoo/document/DocumentTypeManagerConfigurer.java b/document/src/main/java/com/yahoo/document/DocumentTypeManagerConfigurer.java index 17ecd2b9659..f11b1ae9531 100644 --- a/document/src/main/java/com/yahoo/document/DocumentTypeManagerConfigurer.java +++ b/document/src/main/java/com/yahoo/document/DocumentTypeManagerConfigurer.java @@ -163,14 +163,13 @@ public class DocumentTypeManagerConfigurer implements ConfigSubscriber.SingleSub return type; } - @SuppressWarnings("deprecation") private DataType getOrCreateType(int id) { if (typesById.containsKey(id)) { return typesById.get(id); } var config = configMap.remove(id); if (config == null) { - return manager.getDataType(id); + return manager.getDataTypeByCode(id); } assert(id == config.id()); for (var o : config.arraytype()) { @@ -215,7 +214,7 @@ public class DocumentTypeManagerConfigurer implements ConfigSubscriber.SingleSub } DataType fieldType = typesById.get(field.datatype()); if (fieldType == null) { - fieldType = manager.getDataType(field.datatype(), field.detailedtype()); + fieldType = manager.getDataTypeByCode(field.datatype(), field.detailedtype()); } if (field.id().size() == 1) { type.addField(new Field(field.name(), field.id().get(0).id(), fieldType)); @@ -301,11 +300,10 @@ public class DocumentTypeManagerConfigurer implements ConfigSubscriber.SingleSub } } - @SuppressWarnings("deprecation") private void addAnnotationTypePayloads(DocumentmanagerConfig config) { for (DocumentmanagerConfig.Annotationtype annType : config.annotationtype()) { AnnotationType annotationType = manager.getAnnotationTypeRegistry().getType(annType.id()); - DataType payload = manager.getDataType(annType.datatype(), ""); + DataType payload = manager.getDataTypeByCode(annType.datatype(), ""); if (! payload.equals(DataType.NONE)) { annotationType.setDataType(payload); } @@ -621,7 +619,7 @@ public class DocumentTypeManagerConfigurer implements ConfigSubscriber.SingleSub if (this.managerToConfigure.getDataTypes().size() != defaultTypeCount) { log.log(Level.FINE, "Live document config overwritten with new config."); } - managerToConfigure.assign(manager); + managerToConfigure.internalAssign(manager); } } diff --git a/document/src/test/java/com/yahoo/document/DocumentTestCase.java b/document/src/test/java/com/yahoo/document/DocumentTestCase.java index 3c1c7ae86e5..8d6fe7a8fa1 100644 --- a/document/src/test/java/com/yahoo/document/DocumentTestCase.java +++ b/document/src/test/java/com/yahoo/document/DocumentTestCase.java @@ -105,19 +105,19 @@ public class DocumentTestCase extends DocumentTestCaseBase { docMan = new DocumentTypeManager(); DocumentType docInDocType = new DocumentType("docindoc"); - docInDocType.addField(new Field("tull", 2, docMan.getDataType(2))); + docInDocType.addField(new Field("tull", 2, DataType.STRING)); docMan.registerDocumentType(docInDocType); DocumentType sertestDocType = new DocumentType("sertest"); - sertestDocType.addField(new Field("mailid", 2, docMan.getDataType(2))); - sertestDocType.addField(new Field("date", 3, docMan.getDataType(0))); - sertestDocType.addField(new Field("from", 4, docMan.getDataType(2))); - sertestDocType.addField(new Field("to", 6, docMan.getDataType(2))); - sertestDocType.addField(new Field("subject", 9, docMan.getDataType(2))); - sertestDocType.addField(new Field("body", 10, docMan.getDataType(2))); - sertestDocType.addField(new Field("attachmentcount", 11, docMan.getDataType(0))); - sertestDocType.addField(new Field("attachments", 1081629685, DataType.getArray(docMan.getDataType(2)))); + sertestDocType.addField(new Field("mailid", 2, DataType.STRING)); + sertestDocType.addField(new Field("date", 3, DataType.INT)); + sertestDocType.addField(new Field("from", 4, DataType.STRING)); + sertestDocType.addField(new Field("to", 6, DataType.STRING)); + sertestDocType.addField(new Field("subject", 9, DataType.STRING)); + sertestDocType.addField(new Field("body", 10, DataType.STRING)); + sertestDocType.addField(new Field("attachmentcount", 11, DataType.INT)); + sertestDocType.addField(new Field("attachments", 1081629685, DataType.getArray(DataType.STRING))); sertestDocType.addField(new Field("rawfield", 879, DataType.RAW)); sertestDocType.addField(new Field("weightedfield", 880, DataType.getWeightedSet(DataType.STRING))); sertestDocType.addField(new Field("weightedfieldCreate", 881, DataType.getWeightedSet(DataType.STRING, true, false))); @@ -1114,7 +1114,7 @@ public class DocumentTestCase extends DocumentTestCaseBase { docWithDinner.serialize(buf); buf.flip(); - docTypeManasjer.clear(); + docTypeManasjer.internalClear(); } { diff --git a/document/src/test/java/com/yahoo/document/DocumentTypeManagerTestCase.java b/document/src/test/java/com/yahoo/document/DocumentTypeManagerTestCase.java index f6cf589cce5..5cc4263d037 100644 --- a/document/src/test/java/com/yahoo/document/DocumentTypeManagerTestCase.java +++ b/document/src/test/java/com/yahoo/document/DocumentTypeManagerTestCase.java @@ -77,11 +77,11 @@ public class DocumentTypeManagerTestCase { DocumentTypeManager manager = new DocumentTypeManager(); manager.register(docType2); - assertEquals(struct, manager.getDataType(struct.getId())); + assertEquals(struct, manager.getDataTypeByCode(struct.getId())); assertEquals(struct, manager.getDataTypeInternal("mystruct")); - assertEquals(wset1, manager.getDataType(wset1.getId())); - assertEquals(wset2, manager.getDataType(wset2.getId())); - assertEquals(array, manager.getDataType(array.getId())); + assertEquals(wset1, manager.getDataTypeByCode(wset1.getId())); + assertEquals(wset2, manager.getDataTypeByCode(wset2.getId())); + assertEquals(array, manager.getDataTypeByCode(array.getId())); assertEquals(docType, manager.getDataTypeInternal("mydoc")); assertEquals(docType2, manager.getDataTypeInternal("myotherdoc")); assertEquals(docType, manager.getDocumentType(new DataTypeName("mydoc"))); @@ -104,7 +104,7 @@ public class DocumentTypeManagerTestCase { docType4.addField("bar", DataType.RAW); DocumentTypeManager manager = new DocumentTypeManager(); - manager.clear(); + manager.internalClear(); manager.register(docType1); manager.register(docType2); manager.register(docType3); @@ -127,8 +127,8 @@ public class DocumentTypeManagerTestCase { public void testReverseMapOrder() { DocumentTypeManager manager = createConfiguredManager("file:src/test/document/documentmanager.map.cfg"); - assertNotNull(manager.getDataType(1000)); - assertNotNull(manager.getDataType(1001)); + assertNotNull(manager.getDataTypeByCode(1000)); + assertNotNull(manager.getDataTypeByCode(1001)); } @SuppressWarnings("deprecation") @@ -505,7 +505,7 @@ search annotationsimplicitstruct { @SuppressWarnings("deprecation") private static void assertReferenceTypePresentInManager(DocumentTypeManager manager, int refTypeId, String refTargetTypeName) { - DataType type = manager.getDataType(refTypeId); + DataType type = manager.getDataTypeByCode(refTypeId); assertTrue(type instanceof ReferenceDataType); ReferenceDataType refType = (ReferenceDataType) type; |