A method and system for runtime interface inheritance and polymorphic query processing
By constructing a runtime ontology metamodel and maintaining the mapping relationship between interfaces and implementer object types at runtime, the problems of static and rigid interfaces and lack of support for polymorphic queries in existing technologies are solved. Dynamic adjustment of interface definitions and automatic expansion of polymorphic queries are realized, improving query efficiency and data accuracy.
Patent Information
- Application Number
- CN202611261217.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-19
- Publication Date
- 2026-11-17
AI Technical Summary
In existing technologies, TypeScript interfaces support inheritance and implementation, but only perform compile-time type checking, without involving runtime queries. The host of the interface remains a static language concept, which cannot be adjusted at runtime. GraphQL interfaces support polymorphic queries, but field compatibility checks are weak. Traditional ORM frameworks do not support interface-level query abstraction, resulting in the lack of support for polymorphic queries and the inability to uniformly query object instances of all implementation classes through the interface dimension.
This paper provides a runtime interface inheritance and polymorphic query processing method and system. By acquiring interface metadata, a runtime ontology metamodel is constructed at runtime, the mapping relationship between interfaces and implementer object types is maintained, query requests are received and interface nodes are replaced with implementer object type nodes in the query expression, multiple specific query sub-expressions are generated, and the results are executed and merged to obtain the final query result.
It enables dynamic adjustment of interface definitions, supports automatic expansion of polymorphic queries, reduces the maintenance cost of business model changes, improves query development efficiency and system performance, and ensures the accuracy of data queries and the integrity of public contracts.
Smart Images

Figure CN123115184A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing technology, specifically to a runtime interface inheritance and polymorphic query processing method and system. Background Technology
[0002] In existing technologies, TypeScript interfaces support inheritance and implementation, but this only involves compile-time type checking and does not involve runtime queries. The host of the interface remains a static language concept and cannot be adjusted at runtime. Traditional ORM frameworks typically do not support interface-level query abstraction, lack interface inheritance, and cannot define public contracts across object types, resulting in a lack of support for polymorphic queries and an inability to uniformly query object instances of all implementation classes through the interface dimension.
[0003] While GraphQL interfaces support polymorphic queries, field compatibility checks are relatively weak. Rule engines like Drools can partially implement runtime inheritance and polymorphism; for example, parameters in a rule can be defined as Java interfaces, allowing all objects implementing these interfaces to be used as parameters. However, inheritance itself still relies on the capabilities of the Java language and cannot escape the limitations of static inheritance in the host language.
[0004] Furthermore, existing technologies have shortcomings in terms of maintenance: field compatibility is not validated; when an object type declares an interface implementation, it cannot automatically verify whether field types, array properties, and nullability are compatible; calculating valid fields is difficult, as valid fields for an object type need to consider both its own fields and fields from all implemented interfaces, making manual maintenance prone to errors. In conclusion, an improved technical solution is urgently needed. Summary of the Invention
[0005] This application provides a runtime interface inheritance and polymorphic query processing method and system, which supports dynamic adjustment of interface contracts and automatically expands polymorphic queries based on the mapping relationship between the interface and the implementer object type during querying. This solves the technical problems of static and rigid interface definitions and the inability to uniformly query implementer object type instances through the interface dimension.
[0006] In a first aspect, embodiments of this application provide a runtime interface inheritance and polymorphic query processing method, the method comprising: Obtain interface metadata and construct a runtime ontology metamodel at runtime. The interface metadata includes field definitions and interface inheritance relationships. Maintain the mapping relationship between the interface and its corresponding implementer object type; Receive a query request, which includes the query target type and query expression; If the target type of the query is an interface, the types of all implementer objects that implement the interface are determined based on the mapping relationship. The nodes pointing to the interface in the query expression are replaced with nodes pointing to all implementer object types, generating multiple specific query sub-expressions. The multiple specific query sub-expressions are executed, and the execution results are merged to obtain the final query result.
[0007] In conjunction with the first aspect, in one implementation, it further includes: performing field compatibility checks when the object type declaration implements the interface.
[0008] In conjunction with the first aspect, in one implementation, the field compatibility check includes: comparing the consistency of the fields of the object type with the valid fields of the interface in terms of type, arrayability, and nullability.
[0009] In conjunction with the first aspect, in one implementation, the method further includes: parsing the inheritance chain of the interface in the interface metadata and generating an order-preserving and deduplicated inheritance chain result.
[0010] In conjunction with the first aspect, in one implementation, the method further includes: merging fields according to the order of the inheritance chain results to generate a valid set of fields for the interface.
[0011] In conjunction with the first aspect, in one implementation, the query expression includes at least one of the following: a base node, a filter node, a set operation node, and an association traversal node.
[0012] In conjunction with the first aspect, in one implementation, replacing the node pointing to the interface in the query expression with a node pointing to all implementer object types includes: Recursively traverse the nodes of the query expression; If the current node is a base node and matches the interface, then create a new base node pointing to the implementer object type; If the current node is a filter node, a set operation node, or an associative traversal node, its subexpressions are processed recursively while preserving the original node attributes.
[0013] In conjunction with the first aspect, in one implementation, preserving the original node attributes includes: If it is a filter node, retain the original filter conditions; If it is a set operation node, retain the original set operation type; If it is an associative traversal of nodes, the original link information and direction information are preserved.
[0014] In conjunction with the first aspect, in one implementation, the interface metadata is stored in the form of a declarative configuration file or a database record, the declarative configuration file including JSON, XML, or YAML formats.
[0015] Secondly, embodiments of this application provide a runtime interface inheritance and polymorphic query processing system, the system comprising: The metadata parsing module is configured to obtain interface metadata and build a runtime ontology metamodel at runtime. The interface metadata includes field definitions and interface inheritance relationships. The index building module is configured to maintain the mapping relationship between interfaces and their corresponding implementer object types. The query processing module is configured to receive query requests, which include a query target type and a query expression. If the query target type is an interface, it determines all implementer object types that implement the interface based on the mapping relationship, replaces the nodes pointing to the interface in the query expression with nodes pointing to all implementer object types, and generates multiple specific query sub-expressions. It then executes the multiple specific query sub-expressions and merges the execution results to obtain the final query result.
[0016] The beneficial effects of the technical solutions provided in this application include: This application transforms interface definitions from compile-time static constraints of traditional programming languages into dynamically loadable metadata by constructing a runtime ontology metamodel at runtime. This allows contractual content such as interface field definitions and inheritance relationships to be dynamically adjusted through a runtime-loadable ontology metamodel, eliminating dependence on the host programming language code interface and enabling it to take effect without recompiling the code. Compared to existing technologies where the interface host depends on static language concepts and cannot be adjusted at runtime, this application significantly reduces the maintenance cost of business model changes.
[0017] This application achieves automatic expansion of polymorphic queries by maintaining a mapping relationship between interfaces and implementer object types, and replacing nodes pointing to interfaces in the query expression with nodes pointing to implementer object types during query runtime. This allows developers to directly initiate queries based on interface types, and the system automatically retrieves all object instances implementing that interface and merges the results. Compared to existing ORM frameworks that do not support interface-level concepts or polymorphic queries, this application avoids application-layer code redundancy and multiple network round-trip overheads. Through automatic rewriting and result merging (automatic deduplication) at the engine layer, it significantly improves query development efficiency and system performance.
[0018] This application generates a pre-ordered and deduplicated inheritance chain by parsing the interface inheritance chain, and calculates the effective field set based on this, automatically solving the field merging problem under multi-level inheritance. Combined with a field compatibility verification mechanism, inconsistencies in type, array properties, or nullability can be detected when the object type declares and implements the interface. Compared to existing technologies where effective field calculation is difficult and runtime errors are caused by a lack of automatic verification, this application intercepts contract violation risks during the metadata loading stage, ensuring the integrity of cross-object type public contracts and the accuracy of data queries. Attached Figure Description
[0019] Figure 1 This is a flowchart illustrating the runtime interface inheritance and polymorphic query processing method in an embodiment of this application. Figure 2 This is a schematic diagram illustrating the metadata preprocessing steps in an embodiment of this application; Figure 3 This is a schematic diagram of the runtime interface inheritance and polymorphic query processing system of the embodiments of this application. Detailed Implementation
[0020] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present application.
[0021] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.
[0022] In a first aspect, embodiments of this application provide a runtime interface inheritance and polymorphic query processing method, which can be applied to the fields of information systems and ontology modeling, and supports multiple inheritance between interfaces, object type implementation declaration of interfaces, field compatibility verification, and automatic expansion of polymorphic queries.
[0023] The method in this embodiment is divided into two main stages: the metadata loading stage and the query execution stage. The metadata loading stage is executed when the system starts up or when metadata is updated, and the query execution stage is executed when a query request is received.
[0024] In one embodiment, such as Figure 1 As shown, runtime interface inheritance and polymorphic query processing methods include: S1: Obtain interface metadata and build the runtime ontology metamodel at runtime.
[0025] S2: Maintain the mapping relationship between the interface and its corresponding implementer object type.
[0026] S3: Receives a query request, which includes the query target type and query expression.
[0027] S4: If the target type of the query is an interface, determine all implementer object types that implement the interface based on the above mapping relationship, replace the nodes pointing to the interface in the above query expression with nodes pointing to all implementer object types, and generate multiple specific query sub-expressions; execute multiple specific query sub-expressions and merge the execution results to obtain the final query result.
[0028] In this embodiment, by constructing a runtime ontology metamodel at runtime, interface definitions are transformed from compile-time static constraints of traditional programming languages into dynamically loadable metadata. This allows contractual content such as interface field definitions and inheritance relationships to be dynamically adjusted through a runtime-loadable ontology metamodel, eliminating dependence on the host programming language code interface and enabling it to take effect without code recompilation. Furthermore, by maintaining the mapping relationship between interfaces and implementer object types, and replacing nodes pointing to interfaces in query expressions with nodes pointing to implementer object types during query runtime, automatic expansion of polymorphic queries is achieved. This allows developers to directly initiate queries based on interface types, and the system automatically retrieves all object instances implementing that interface and merges the results.
[0029] Furthermore, in step S1 above, the system loads the declarative ontology manifest at runtime and constructs a runtime ontology metamodel, where the interface metadata includes field definitions and interface inheritance relationships. Specifically, an interface is first defined in the declarative ontology manifest. This interface is not a code interface in the host programming language, but rather a runtime-loadable ontology metamodel used to establish common field contracts across multiple object types. The aforementioned interface definition preferably includes at least the following: Name and metadata: name, displayName, description, group, tags, stability, version; Inheritance declaration: extends, used to declare the set of parent interfaces that this interface inherits from, and supports multiple inheritance; Field definition: fields, whose field format is consistent with the field format of object type ObjectType; Link constraints: linkConstraints, used to declare interface-level association constraints; UI hints: uiHints, used to declare interface-level UI display configurations; Security policies: securityPolicies, propertyPolicies.
[0030] The interface fields and object type fields are described using a unified structure, enabling the interface fields to participate in inheritance merging and compatibility checks in subsequent steps.
[0031] It should be noted that this embodiment uses JSON format as an example of a declarative configuration file, but this is not a limitation on the storage format of this invention. In other embodiments of this invention, interface metadata can also be stored in other forms of declarative configuration files, such as structured data files like XML or YAML files. Furthermore, interface metadata can also be stored directly in database records, such as the table structure of a relational database or a document in a NoSQL database, rather than in a file. Regardless of the storage format used, as long as it can be parsed by the runtime engine into an ontology metamodel, including field definitions and interface inheritance relationships, it falls within the protection scope of this invention.
[0032] like Figure 2 As shown, after step S1 and before step S2, the following metadata preprocessing steps are preferably performed to ensure the validity of the data contract and the correctness of the query.
[0033] Step a1: Parse the inheritance chain of the interface in the interface metadata and generate an ordered and deduplicated inheritance chain result. After completing the interface definition, the system enters the interface inheritance chain parsing step. This step constructs the interface inheritance relationship graph based on the extends declaration in the interface definition, and performs recursive parsing on the target interface during ontology loading to determine its complete inheritance chain.
[0034] Specifically, the system starts from the target interface and recursively traverses upwards along the parent interface. During the traversal, the current access path is recorded through the access stack. When the interface to be resolved already appears in the access stack, an inheritance cycle is determined, loading is immediately terminated, and an error message containing the cycle path is output. When no inheritance cycle exists, the resolution result is processed to preserve order and remove duplicates, ensuring that the same interface is retained only once in the inheritance chain, and that the child interface is located after the parent interface.
[0035] The specific algorithm is to obtain the interface inheritance chain (list M, interface name I, access stack S = empty): a101. If the interface name I already exists in the access stack S, it is determined that there is a cycle in interface inheritance, an error is reported and the cycle path S plus I is output; a102. Read the list of parent interfaces of interface I (extends); a103. Initialize the parent list to an empty list; a104. Following the order in the parent interface list, execute the following for each parent interface P: call "Get Interface Inheritance Chain (M, P, S + I)" and append the returned result to the parent chain result; a105. Append the current interface I to the end of the parent chain result; a106. Perform order-preserving deduplication on the parent chain results to ensure that the same interface appears only once and that the child interface is located after the parent interface; a107. Returns the processed inheritance chain result.
[0036] Step a2: Perform field compatibility checks. This step mainly implements interface inheritance (field inheritance) through merging; to resolve field conflicts during merging, the following two algorithms can be used.
[0037] The specific algorithm is to generate a field signature (field F): Read the type attribute of field F; Read the array-like property isArray of field F; Read the nullable property of field F; Generate field signatures in the order of "type + arrayability + nullability"; Return the signature of the above fields.
[0038] The specific algorithm asserts field compatibility (owner, existing field existing, new field next): Calculate the field signature of the existing field "existing" and the field signature of the new field "next" respectively; Compare whether the signatures of the two fields are consistent; If they match, the two fields with the same name are considered compatible, and merging or overwriting is allowed. If they are inconsistent, an error will be reported. The error message will include at least the following: owner, field name next.name, expected field type existing.type, and actual field type next.type.
[0039] When an object type is declared to implement an interface, the system performs the above field compatibility check, comparing the consistency of the object type's fields with the valid fields of the interface in terms of type, arrayability, and nullability.
[0040] Step a3: Calculate the set of valid fields for the interface.
[0041] After resolving the interface inheritance chain and establishing field compatibility rules, the system further calculates the valid fields of the interface. Valid fields refer to the set of fields that are truly visible, inheritable, and queryable at runtime for a given interface. Specifically, fields are merged according to the order of the inheritance chain results to generate the set of valid fields for the interface.
[0042] The specific algorithm is to obtain the valid fields of the interface (list M, interface name I): Call "Get Interface Inheritance Chain" to obtain the order-preserving and deduplicated inheritance chain result of interface I; Initialize the set of valid fields to an empty list; Process interface name N one by one according to the inheritance chain results: read the field list of interface N; merge the field list with the currently valid field set; During the field merging process, if a field with the same name is encountered, the "assert field compatibility" function is called to perform a compatibility check; if the check passes, the later field is allowed to overwrite the earlier field. Returns the final set of valid fields.
[0043] Step a4: Calculate the set of valid fields for the object type.
[0044] After the valid fields for the interface are calculated, the system continues to calculate the valid fields for the object type. This step is used to address the difficulty in uniformly determining which fields of an object type are ultimately visible, queryable, and constrainable.
[0045] The specific algorithm is as follows: Obtain the valid fields of the object type (list M, object type name O). Read the definition information of object type O; Get a list of all interfaces implemented by object type O; Initialize the inherited field collection as an empty list; Process each interface I in the order of the interface list: call "Get valid fields of interface" to obtain the set of valid fields for interface I; merge this set of valid fields into the inherited field set; Merge the list of fields declared by object type O itself with the above-mentioned set of inherited fields; During the merging process, if a field with the same name is encountered, a field compatibility check is performed first; if the check passes, the object type's own field is allowed to override the previously inherited field. Returns the set of valid fields for object type O.
[0046] The merging strategy is as follows: when fields have the same name, the later one will overwrite the earlier one, but compatibility checks must be passed.
[0047] For step S2 above: Maintain the mapping relationship between the interface and its corresponding implementer object type. After completing the calculation of the valid fields of the object type, further establish the reverse lookup capability from the interface to the implementer. This step is used to support the reverse location of all specific object types from the interface dimension and is a prerequisite for realizing polymorphic query expansion.
[0048] The specific algorithm is to obtain the interface implementer (list M, interface name I): The initializer result set is empty; Iterate through all object types in list M; For each object type O, determine whether object type O implements interface I; If object type O implements interface I, then object type O is added to the implementer result set; After the traversal is complete, return the implementer's result set.
[0049] Step S2 maintains the mapping relationship between the interface and its corresponding implementer object type, providing a foundation for subsequent polymorphic query expansion.
[0050] It should be noted that steps a1 to a4 above are preferred sub-steps in the metadata loading stage, and their internal execution order can be adjusted according to actual needs, as long as they are completed before the query execution. The mapping relationship maintenance in step S2 can be performed after sub-steps a1 to a4, or it can be performed in parallel with them.
[0051] For step S3 above: receiving a query request, which includes the query target type and the query expression. The system receives the query request sent by the upstream module and parses it to obtain the query target type T and the object set expression X. The query expression includes basic nodes, filter nodes, set operation nodes, and associative traversal nodes.
[0052] Furthermore, in step S4 above, polymorphic query expansion is performed during the query runtime.
[0053] The specific algorithm is polymorphic query expansion (object set expression X, target type T): It should be noted that the query expression in this embodiment specifically adopts the form of object set expression.
[0054] b1: Determine if the target type T is an interface. If not, proceed to b2; if yes, proceed to b3. b2: If the target type T is not an interface, then the parsing process will be performed according to the query process for ordinary object types and the result will be returned; b3: If the target type T is an interface, then obtain the set of all implementers of interface T; b4: The initialization result identifier set ids is an empty set; b5: For each implementer type C, execute b51 to b53 in sequence: b51: In the object set expression X, replace the base node with the base type interface T with the base node with the base type object type C to obtain the concrete object set expression X_c; b52: Evaluate the specific object set expression X_c to obtain a list of object identifiers; b53: Add each identifier in the object identifier list to the result set ids to achieve automatic deduplication; b6: Convert the result set ids into a result list; b7: Returns the list of results.
[0055] The node replacement operation in step b51 is specifically implemented by recursively traversing the query expression. The system executes the algorithm for replacing the basic set of interfaces (query expression X, interface name T, specific type C), which specifically includes: Recursively traverse the nodes of the above query expression; If the current node is a base node and matches the interface, a new base node is created pointing to the implemented object type. Specifically, the node type of the query expression X is determined. If the node type is a base node and its interfaceBase is equal to the interface name T, a new base node is returned with its objectBase set to the concrete type C. If the node type is a base node but its interfaceBase is not equal to the interface name T, the node is returned as is.
[0056] If the current node is a filter node, a set operation node, or an associative traversal node, its subexpressions are processed recursively while preserving the original node attributes. Specifically, this includes: If the node type is a filter node, then the replacement operation is recursively performed on its input subexpression, while the original filtering conditions remain unchanged; If the node type is a union, intersection, or difference node, then the replacement operation is recursively performed on the left and right subexpressions respectively, while preserving the original set operation type unchanged; If the node type is a searchAround associative traversal node, then the replacement operation is recursively performed on its input subexpression, while preserving the original link information and direction information unchanged; For other types of nodes, return them as is.
[0057] The `replaceInterfaceBase` function recursively traverses the algebraic expression of the object set, replacing the base node of type `interfaceBase` with the base node of the specific `objectType`.
[0058] Among them, the above-mentioned retained original node attributes include: If it is a filter node, retain the original filter conditions; If it is a set operation node, retain the original set operation type; If it is an associative traversal of nodes, the original link information and direction information are preserved.
[0059] Through the recursive traversal and node replacement described above, the system completes the conversion from interface nodes to implementer object type nodes, generating multiple specific query sub-expressions. Subsequently, the system continues to execute steps b52 to b7, evaluates the generated specific query sub-expressions, and merges the execution results to obtain the final query result.
[0060] Preferably, in one embodiment, after step S3 and before step S4, the system further includes a step of obtaining a list of specific object types corresponding to the target. To facilitate downstream modules calling the polymorphic query function, the system can further provide a unified target type parsing capability, so that downstream modules do not need to distinguish whether the input target is an interface or an object type.
[0061] The specific algorithm is as follows: Obtain the specific object type corresponding to the target (list M, target name T): Parse the ontology target based on the target name T; Determine the type of the target; If the target type is an object, then a list containing only the name of that object type will be returned directly. If the target type is an interface, then call "Get Interface Implementers" to obtain all implementer object types corresponding to that interface; Extract a list of names for each implementer object type; Return to the list of names above.
[0062] Through this step, the system can uniformly handle the parsing of interfaces and object types. Downstream modules can directly use the returned list of object types for subsequent operations without having to determine the target type themselves.
[0063] Secondly, embodiments of this application also provide a runtime interface inheritance and polymorphic query processing system. For example... Figure 3 As shown, the system includes a metadata parsing module, an index building module, and a query processing module.
[0064] The metadata parsing module is configured to obtain interface metadata and construct a runtime ontology metamodel at runtime. The interface metadata includes field definitions and interface inheritance relationships. Specifically, this module is used to perform the relevant functions of metadata preprocessing steps a1 to a4 in the above embodiments, including parsing declarative configuration files or database records in JSON, XML, or YAML format, parsing inheritance chains, performing field compatibility checks, and calculating the set of valid fields.
[0065] The index building module is configured to maintain the mapping relationship between interfaces and their corresponding implementer object types. This module is specifically used to perform the functions described in step S2 above, including traversing object types and determining implementation relationships, and establishing a reverse lookup capability from interface to implementer.
[0066] The query processing module is configured to receive query requests, which include a query target type and a query expression. If the query target type is an interface, it determines all implementer object types that implement the interface based on the mapping relationship, replaces the nodes in the query expression that point to the interface with nodes that point to all the aforementioned implementer object types, and generates multiple specific query sub-expressions. It then executes these multiple specific query sub-expressions and merges the execution results to obtain the final query result. Specifically, this module performs the functions related to steps S3 to S5 in the above embodiments, including polymorphic query expansion, node replacement, recursive processing of sub-expressions, and result merging.
[0067] It should be noted that the sequence numbers of the embodiments in this application are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0068] The terms "comprising" and "having," and any variations thereof, in the specification, claims, and accompanying drawings of this application are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or apparatus that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to such process, method, product, or apparatus. The terms "first," "second," and "third," etc., are used to distinguish different objects, etc., and do not indicate a sequence, nor do they limit "first," "second," and "third" to different types.
[0069] In the description of the embodiments of this application, terms such as "exemplary," "for example," or "for instance" are used to indicate examples, illustrations, or explanations. Any embodiment or design described as "exemplary," "for example," or "for instance" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or designs. Specifically, the use of terms such as "exemplary," "for example," or "for instance" is intended to present the relevant concepts in a concrete manner.
[0070] In the description of the embodiments of this application, unless otherwise stated, " / " means "or". For example, A / B can mean A or B. The "and / or" in the text is merely a description of the relationship between related objects, indicating that there can be three relationships. For example, A and / or B can mean: A exists alone, A and B exist simultaneously, and B exists alone. In addition, in the description of the embodiments of this application, "multiple" means two or more.
[0071] In some processes described in the embodiments of this application, multiple operations or steps are included in a specific order. However, it should be understood that these operations or steps may not be executed in the order they appear in the embodiments of this application, or they may be executed in parallel. The sequence number of the operation is only used to distinguish different operations, and the sequence number itself does not represent any execution order. In addition, these processes may include more or fewer operations, and these operations or steps may be executed sequentially or in parallel, and these operations or steps may be combined.
[0072] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) as described above, and includes several instructions to cause a terminal device to execute the methods described in the various embodiments of this application.
[0073] The above are merely preferred embodiments of this application and do not limit the patent scope of this application. Any equivalent structural or procedural transformations made using the content of this application's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of this application.
Claims
1. A runtime interface inheritance and polymorphic query processing method, characterized in that, The method includes: Obtain interface metadata and construct a runtime ontology metamodel at runtime. The interface metadata includes field definitions and interface inheritance relationships. Maintain the mapping relationship between the interface and its corresponding implementer object type; Receive a query request, which includes the query target type and query expression; If the target type of the query is an interface, the types of all implementer objects that implement the interface are determined based on the mapping relationship. The nodes pointing to the interface in the query expression are replaced with nodes pointing to all implementer object types, generating multiple specific query sub-expressions. The multiple specific query sub-expressions are executed, and the execution results are merged to obtain the final query result.
2. The runtime interface inheritance and polymorphic query processing method as described in claim 1, characterized in that, Also includes: When an object type declares that implements the interface, perform field compatibility checks.
3. The runtime interface inheritance and polymorphic query processing method as described in claim 2, characterized in that, The field compatibility check includes comparing the consistency of the fields of the object type with the valid fields of the interface in terms of type, arrayability, and nullability.
4. The runtime interface inheritance and polymorphic query processing method as described in claim 1, characterized in that, The method further includes: parsing the inheritance chain of the interface in the interface metadata and generating an inheritance chain result that is ordered and deduplicated.
5. The runtime interface inheritance and polymorphic query processing method as described in claim 4, characterized in that, The method further includes merging fields according to the order of the inheritance chain results to generate a valid set of fields for the interface.
6. The runtime interface inheritance and polymorphic query processing method as described in claim 1, characterized in that, The query expression includes at least one of the following: basic node, filter node, set operation node, and association traversal node.
7. The runtime interface inheritance and polymorphic query processing method as described in claim 6, characterized in that, The step of replacing the node pointing to the interface in the query expression with a node pointing to all implementer object types includes: Recursively traverse the nodes of the query expression; If the current node is a base node and matches the interface, then create a new base node pointing to the implementer object type; If the current node is a filter node, a set operation node, or an associative traversal node, its subexpressions are processed recursively while preserving the original node attributes.
8. The runtime interface inheritance and polymorphic query processing method as described in claim 7, characterized in that, The retention of original node attributes includes: If it is a filter node, retain the original filter conditions; If it is a set operation node, retain the original set operation type; If it is an associative traversal of nodes, the original link information and direction information are preserved.
9. The runtime interface inheritance and polymorphic query processing method as described in claim 1, characterized in that, The interface metadata is stored in the form of a declarative configuration file or a database record, and the declarative configuration file includes JSON, XML or YAML format.
10. A runtime interface inheritance and polymorphic query processing system, characterized in that, The system includes: The metadata parsing module is configured to obtain interface metadata and build a runtime ontology metamodel at runtime. The interface metadata includes field definitions and interface inheritance relationships. The index building module is configured to maintain the mapping relationship between interfaces and their corresponding implementer object types. The query processing module is configured to receive query requests, which include a query target type and a query expression. If the query target type is an interface, it determines all implementer object types that implement the interface based on the mapping relationship, replaces the nodes pointing to the interface in the query expression with nodes pointing to all implementer object types, and generates multiple specific query sub-expressions. It then executes the multiple specific query sub-expressions and merges the execution results to obtain the final query result.
