Method and apparatus for simplifying result set merging

CN117349351BActive Publication Date: 2026-09-25CHINA FAW CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311268249.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-09-28
Publication Date
2026-09-25
Estimated Expiration
2043-09-28

AI Technical Summary

Technical Problem

[0002]在现代云原生微服务技术体系下构建的应用,要求微服务间实现数据解耦,微服务间通过API实现业务编排与连接,各自数据库独立,而前端应用对数据的展示与操作交互,很多情况下数据来源于多个微服务,在原单体应用中,基于SQL表关联,很容易实现数据结果的关联合并,但在微服务下,此问题变得较为棘手

Benefits of technology

[0047]与现有技术相比,本发明的有益效果是:发明主要是通过设计一套描述结果集关联及字段映射的注解类,在业务场景中,程序员通过注解对集合合并规则进行描述,在程序编译时,本方案通过自定义编译机制,拦截读取自定义注解,生成具体实现类,并伴随业务代码一同编译打包,在运行期通过注入实现,程序中直接调用,完成结果集合并;本发明通过类SQL关联的注解定义,避免新引入的概念增加学习成本;利用java编译器扩展机制,在扩展编译中,过滤有自定义注解的接口源文件,生成结果集合并方法;利用哈希算法,实现两个集合多字段关联下的快速匹配;直接生成getter与setter方法,使用stream API,无反射并行处理实现,与程序员单独编写的性能一致;不需要进行数据复制,所以不会产生数据不一致性及增加系统复杂度,轻量化实现。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117349351B_ABST
    Figure CN117349351B_ABST
Patent Text Reader

Abstract

The application discloses a method and device for simplifying result set merging, wherein the method comprises adding an interface class file, defining an interface method in the interface class file according to a requirement of set merging; parameters in a parameter list of the interface method correspond to source sets and result sets respectively, and a merging relationship is described in a self-defined annotation of the interface method; a list of interface source files that have been defined is acquired, the self-defined annotation is parsed, an implementation class is cyclically generated, and the implementation class is compiled and packaged into a target package; through a factory mode, the specified implementation class is automatically loaded, an interface is called by a program, and the merging of the result set is completed; the application avoids increasing learning cost of newly introduced concepts through annotation definition; fast matching under the condition of two sets and multiple fields is realized; no reflection is used for parallel processing, and the performance is consistent with that of a programmer who writes a program alone; data copying is not needed, so that data inconsistency and system complexity increase are avoided, and lightweight implementation is realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of modern cloud data processing technology, and in particular to a method and apparatus for simplifying the merging of result sets. Background Technology

[0002] Applications built on the modern cloud-native microservices technology system require data decoupling between microservices. Microservices use APIs to orchestrate and connect business processes, and each has its own independent database. However, the data displayed and interacted with by the front-end application often comes from multiple microservices. In the original monolithic application, it was easy to merge data results based on SQL table joins, but this problem becomes more challenging in the microservices environment.

[0003] The most commonly used solutions in existing technologies mainly fall into four categories. The first requires calling other microservice APIs to obtain the result set, and then developing code to merge the result set. Due to the involvement of various cases such as left-right and inline operations, and field copying, a different merge processing code needs to be written for each business scenario, requiring a large amount of development work. The second solution is to abstract the logic of association and field copying using reflection to achieve generalization and reduce the amount of business code development. The third solution is to extract data from other microservices into the current microservice to achieve SQL join queries, which may lead to decoupling failure or a giant microservice, while also causing data inconsistency and increasing system complexity. The fourth solution is to build an independent OLAP database to support complex statistics and queries, but this solution has its limitations, as it cannot meet the requirements of uncommitted reads within transactions and real-time queries. The above problems urgently need to be solved. Summary of the Invention

[0004] The purpose of this invention is to provide a method and apparatus for simplifying the merging of result sets, so as to solve the problems mentioned in the background art.

[0005] To achieve the above objectives, the present invention provides the following technical solution: a method for simplifying result set merging, applied to applications built under a modern cloud-native microservice technology architecture, comprising:

[0006] In projects that require merging result sets, add an interface class file. For each set merging requirement, define an interface method in the interface class file.

[0007] The parameters in the parameter list of the interface method correspond to the source set and the result set, respectively, and the merging relationship is described in the custom annotation of the interface method;

[0008] Obtain a list of all defined interface source files in the source code project. Based on the source files, parse the custom annotations and generate the implementation class corresponding to each interface class file in a loop. After all implementation classes are generated, compile and package the implementation classes into the target package to enable runtime invocation.

[0009] By using the factory pattern, the specified implementation class is automatically loaded, the program calls the interface, and the result set is merged.

[0010] Furthermore, the parameters in the parameter list of the interface method correspond to the source set and the result set, respectively. The merging relationship is described in the custom annotation of the interface method, which also includes:

[0011] An interface class file defines at least one interface method, and an interface method defines multiple merge relationships.

[0012] Merge sets in the set to be merged. In the custom annotation, the merging relationship of the set pair is described and defined. The set to be merged is the set that has the set merging requirement, and the set pair is a pair of sets in the set to be merged that have the corresponding merging relationship.

[0013] Furthermore, custom annotations also include:

[0014] Define Result, Join, and VO in an interface class file;

[0015] The VO annotation is used to define all collection types used in an interface class file, where the collection type is a Java class and the VO annotation is a custom annotation.

[0016] The Result annotation is used when an interface method has no return value. It specifies a result collection as a parameter. The Result annotation is a custom annotation.

[0017] The `@Join` annotation is used on interface methods to define the corresponding merging relationship between collection pairs.

[0018] Furthermore, it also includes:

[0019] The Target attribute is an attribute of the Join annotation. It points to a parameter name in the interface method, specifying this parameter as the target set. The target set is the set generated after merging the set pairs.

[0020] The Source property is an attribute of the Join annotation, pointing to one of the parameter names of the interface method, explicitly specifying this parameter as the source collection for merging the collection pairs;

[0021] The Type property is an attribute of the Join annotation. It has three values: left, right, and inner, which represent three connection methods: left join, right join, and inner join. The default value is left.

[0022] The On attribute, which is an attribute of the Join annotation, is a collection of equal sub-annotations that describes the field mapping of the collection to the corresponding merging relationship;

[0023] The FieldMaps property is an attribute of the Join annotation. It is a collection of Setter sub-annotations that describes the field correspondence when merging collection pairs.

[0024] The Auto attribute is a property of the Join annotation. It is a simplification of FieldMaps. When the property names and data types of fields in two collections are the same, the field values ​​of the source collection are automatically assigned to the target collection.

[0025] The AllowOneToMany property is an attribute of the Join annotation, which specifies how to handle a situation where one record in one collection matches multiple records in another collection.

[0026] Furthermore, the Equal annotation is a sub-annotation of the join annotation, and belongs to the On attribute set. It has two attributes, tgt and src, which represent the association between the target set field and the source set field, respectively.

[0027] The `@Setter` annotation is a sub-annotation of the `@join` annotation. It belongs to the `fieldMaps` attribute set and has two attributes: `set` and `get`, which represent the target set field and the source set field, respectively.

[0028] Furthermore, the process involves obtaining a list of all defined interface source files in the source code project that require merging. Based on these source files, custom annotations are parsed, and implementation classes corresponding to each interface class file are generated iteratively. Once all implementation classes are generated, they are compiled and packaged into the target package. This also includes:

[0029] The implementation class extends the AbstractProcessor class based on the compiler. During compilation, it captures the Joiner annotation. When the compiler finds a Java source file containing the Joiner annotation, it calls the Process method of this class. The method iterates through the file list and creates a new GenerateClass class for each file, which generates the implementation class.

[0030] Furthermore, the GenerateClass processing class is used to analyze and process a specified interface class source file to generate the corresponding implementation class for this interface class file, including the following steps:

[0031] Parse the list of VO annotations and generate a clone method for each collection that contains the entity class;

[0032] Parse all interface methods in this interface class file to form a method list;

[0033] Iterate through the list to generate GenerateMethod handler classes, and generate implementations of the specified interface methods in the GenerateMethod handler classes;

[0034] After all sub-methods are parsed and generated, the Java file is called to generate the class and the source file of the implementation class corresponding to the interface class is generated.

[0035] Furthermore, the GenerateMethod handler class is responsible for resolving the specified interface method and generating the concrete implementation code for the interface method, which includes the following steps:

[0036] A. Based on the definition of the On attribute in join, generate a hashcode function for quick comparison during program runtime;

[0037] B. Based on the join definition, generate the logic code for comparing and filtering individual records in the set and assigning values ​​to the corresponding fields;

[0038] C. Generate code to merge set pairs, which calls steps A and B based on stream processing to complete the merging of the result sets.

[0039] Furthermore, by using the factory pattern to automatically load specified implementation classes and complete the merging of result sets, it also includes:

[0040] The Joiners factory class obtains the implementation class from the same package based on the interface class file name with the suffix "Impl". When the application runs, the implementation class is loaded into the JOINER variable when the interface class file loads static variables, and can be directly called in the business code.

[0041] On the other hand, an apparatus for simplifying the merging of result sets is provided, which applies the method for simplifying the merging of result sets described in any of the preceding claims, including:

[0042] The interface generation module is used to add interface class files;

[0043] Define a module for a collection merging requirement. Define an interface method in the interface class file. The parameters in the parameter list of the interface method correspond to the source collection and the result collection, respectively. The merging relationship is described in the custom annotation of the interface method.

[0044] The compilation module, based on the compiler's extension of the AbstractProcessor class, captures the Joiner annotation during compilation to obtain a list of all defined interface source files in the source code project;

[0045] The analysis and processing module parses custom annotations based on the source files and generates application implementation classes for each interface file in a loop. Once all implementation classes are generated, the compiler compiles the generated implementation classes into the project target package.

[0046] The merge processing module automatically loads the specified implementation class through interface methods and the factory pattern, merges the source collections into a result collection, and completes the merging of the result collections.

[0047] Compared with existing technologies, the advantages of this invention are as follows: The invention primarily involves designing a set of annotation classes describing result set associations and field mappings. In business scenarios, programmers describe set merging rules using annotations. During program compilation, this solution intercepts and reads custom annotations through a custom compilation mechanism, generates concrete implementation classes, and compiles and packages them along with the business code. At runtime, this is implemented through injection, allowing direct invocation within the program to complete the result set merging. This invention avoids the learning cost of introducing new concepts by defining annotations similar to SQL associations. It utilizes the Java compiler extension mechanism to filter interface source files with custom annotations during extended compilation, generating result set merging methods. It uses a hash algorithm to achieve fast matching under multi-field associations between two sets. It directly generates getter and setter methods, using the stream API for reflection-free parallel processing, achieving performance consistent with methods written by the programmer alone. It eliminates the need for data copying, thus avoiding data inconsistency and increased system complexity, resulting in a lightweight implementation. Attached Figure Description

[0048] Figure 1 This is a flowchart of a method for simplifying result set merging in an embodiment of the present invention;

[0049] Figure 2 This is a connection block diagram of a simplified result set merging device in an embodiment of the present invention. Detailed Implementation

[0050] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0051] In the description of this invention, unless otherwise stated, "a plurality of" means two or more; the terms "upper," "lower," "left," "right," "inner," "outer," "front end," "rear end," "head," "tail," etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings, and are only for the convenience of describing the invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation, and therefore should not be construed as a limitation of the invention. Furthermore, the terms "first," "second," "third," etc., are used for descriptive purposes only and should not be construed as indicating or implying relative importance.

[0052] In the description of this invention, it should be noted that, unless otherwise explicitly specified and limited, the terms "connected" and "linked" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium. Those skilled in the art can understand the specific meaning of the above terms in this invention based on the specific circumstances.

[0053] Please refer to the accompanying drawings in the specification. This invention provides a technical solution: a method for simplifying the merging of result sets, applied to applications built under a modern cloud-native microservice technology architecture, comprising the following steps:

[0054] S102. In projects that require merging result sets, add an interface class file. For each set merging requirement, define an interface method in the interface class file.

[0055] S104. The parameters in the parameter list of the interface method correspond to the source set and the result set respectively. The merging relationship is described in the custom annotation of the interface method.

[0056] Specifically, an interface class file defines at least one interface method, and an interface method defines multiple merging relationships; the set pairs in the set to be merged are merged, and the merging relationship of the set pairs is described and defined in the custom annotation, where the set to be merged is the set with the set merging requirement, and the set pair is a pair of sets in the set to be merged that have the corresponding merging relationship;

[0057] In this interface class, multiple interface methods can be defined to meet the result set requirements of different business scenarios. Multiple merging relationships can be defined in an interface method. In the annotation, the merging relationship of each pair of collection objects can be described and defined. Using a hash algorithm, fast matching under multi-field association of two collections can be achieved. In the business processing, the source collection is obtained through multiple API calls or queries. After calling this interface method and passing in the source collection, the merging is completed.

[0058] Furthermore, define Result, Join, and VO in an interface class file;

[0059] The VO annotation is used to define all collection types used in an interface class file, where the collection type is a Java class and the VO annotation is a custom annotation.

[0060] The `@Result` annotation is used when an interface method has no return value. It specifies a result collection as a parameter. The `@Result` annotation is a custom annotation.

[0061] The `@Join` annotation is used on interface methods to define the corresponding merging relationship between collection pairs.

[0062] In an interface class file, a VO (Value Object) is defined to define all collection types used in the interface class file. The collection type is a Java class, and the VO annotation is a custom annotation. The interface class can be defined centrally based on business domains and entity relationships, and multiple VOs can be defined in one interface class. The VO annotation describes the merging relationship of all collection objects used in the interface. The object can be an entity, a view, or a custom POJO, and must implement getter and setter methods to be compatible with Lombok. The corresponding method parameter name is defined in this annotation [name = "collection parameter name in the method"], and the corresponding class is defined [use = the class WideTableVO.class stored in the collection]. It is mainly used for attribute definition analysis during class code generation.

[0063] Custom annotations also include the Result annotation and the Join annotation. Interface methods have no return value, so the Result annotation is used to annotate Result, specifying a parameter as the parameter to save the final merged result set. The Join annotation is a description definition of the corresponding merging relationship of the set pair, with multiple attributes to describe the merging relationship of the set pair. Among them, the Result annotation is a custom annotation of Result, and the Join annotation is a custom annotation of Join.

[0064] Specifically, the attributes in the Join annotation that describe the merging relationship between set pairs include:

[0065] The Target attribute is an attribute of the Join annotation. It points to a parameter name in the interface method, specifying this parameter as the target set. The target set is the set generated after merging the set pairs.

[0066] The Source property is an attribute of the Join annotation, pointing to one of the parameter names of the interface method, explicitly specifying this parameter as the source collection for merging the collection pairs;

[0067] The Type property is an attribute of the Join annotation. It has three values: left, right, and inner, which represent three connection methods: left join, right join, and inner join. The default value is left.

[0068] The On attribute, which is an attribute of the Join annotation, is a collection of equal sub-annotations that describes the field mapping of the collection to the corresponding merging relationship;

[0069] The FieldMaps property is an attribute of the Join annotation. It is a collection of Setter sub-annotations that describes the field correspondence when merging collection pairs.

[0070] The Auto attribute is a property of the Join annotation. It is a simplification of FieldMaps. When the property names and data types of fields in two collections are the same, the field values ​​of the source collection are automatically assigned to the target collection. Its default value is false.

[0071] The AllowOneToMany property is an attribute of the Join annotation. It specifies how to handle situations where one record in one collection matches multiple records in another collection. For example, in a left join, if there is one record in the left table and multiple records in the right table match, if this value is true, the left table will be automatically copied; if it is false, an exception will be thrown.

[0072] Specifically, the Equal annotation is a sub-annotation of the join annotation, and belongs to the On attribute set. It has two attributes, tgt and src, which represent the association between the target set field and the source set field, respectively.

[0073] The `@Setter` annotation is a sub-annotation of the `@join` annotation. It belongs to the `fieldMaps` attribute set and has two attributes: `set` and `get`, which represent the target set field and the source set field, respectively.

[0074] Among them, the key custom annotations involve three custom annotations: join, equal, and setter, which describe the association relationship and field mapping relationship between two collections.

[0075] It is understandable that this invention defines the requirement to merge collections according to business scenarios as an interface method by adding an interface file, declaring the collections to be merged in the interface parameters, and describing the collection association in the method annotation.

[0076] S106. Obtain a list of all defined interface source files in the source code project. Based on the source files, parse the custom annotations and generate the implementation class corresponding to each interface class file in a loop. After all implementation classes are generated, compile and package the implementation classes into the target package to enable runtime calling. The target package is the target GAR package.

[0077] Specifically, the implementation class, based on the compiler's extension of the AbstractProcessor class, captures the Joiner annotation during compilation to obtain a list of all defined interface source files in the project. Based on these source files, it parses custom annotations and iteratively generates application implementation classes for each interface file. Once all implementation classes are generated, the compiler compiles them into the project's target package. The JoinProcessor class, which extends the AbstractProcessor class, declares the capture annotation @SupportedAnnotationTypes("com.faw.dataset.annotation.Joiner"). When the compiler finds a Java source file containing the Joiner annotation, it calls the Process method of this class. This method iterates through the file list, creating a new GenerateClass for each file to generate the implementation class.

[0078] Specifically, the GenerateClass processing class is used to analyze and process a specified interface source file to generate the implementation class corresponding to this interface class file, including the following steps:

[0079] Parse the list of VO annotations and generate clone methods for each object containing the entity class;

[0080] Parse all interface methods in this interface class file to form a method list;

[0081] Iterate through the list to generate GenerateMethod handler classes, and generate implementations of the specified interface methods in the GenerateMethod handler classes;

[0082] After all sub-methods are parsed and generated, the Java file is called to generate the class and the source file of the implementation class corresponding to the interface class is generated.

[0083] Specifically, the GenerateMethod handler class is responsible for resolving the specified interface method and generating the concrete implementation code for the interface method, which includes the following steps:

[0084] A. Based on the definition of the On attribute in join, generate a hashcode function for quick comparison during program runtime;

[0085] B. Based on the join definition, generate the logic code for comparing and filtering individual records in the set and assigning values ​​to the corresponding fields;

[0086] C. Generate code to merge set pairs, which calls steps A and B based on stream processing to complete the merging of the result sets.

[0087] S108. Using the factory pattern, the specified implementation class is automatically loaded, the program calls the interface, and the result set is merged.

[0088] Specifically, the Joiners factory class obtains the implementation class under the same package name based on the interface class file name with the suffix "Impl". When the application runs, the implementation class is loaded into the JOINER variable when the interface class file loads static variables. It can then be directly called in the business code, hiding the entire implementation process.

[0089] During runtime, automatic class injection loading and execution are implemented. A static variable `Joiner` is defined in the interface, a static method of the `Joiners` factory class is called, and the explicit class is returned. In the business code, the interface method is called directly.

[0090] In the above embodiments, this invention utilizes custom annotations and the features of the extended compiler JDK to simplify the result set merging process while maintaining performance equivalent to the business implementation. The overall technical implementation consists of three parts: custom annotations, compiler extended source code generation, and a factory class project. Applying this invention involves three main steps: importing the solution's JAR file into the POM; creating a new interface class based on custom annotations to describe the set merging rules; and calling the interface class API at the required points. This invention relates to three development packages: an annotation package, a compilation package, and a factory package, which are published into a target JAR program for inclusion and use in projects. Publishing this invention into a single JAR file for use in business projects requires only three steps: adding the library dependency to the POM, creating a new interface class file, defining the set merging annotation, and calling the interface class API in the program. The interface method mentioned is sufficient; this invention mainly designs a set of annotation classes to describe the association of result sets and field mapping. In business scenarios, programmers describe the collection merging rules through annotations. During program compilation, this solution intercepts and reads the custom annotations through a custom compilation mechanism, generates specific implementation classes, and compiles and packages them along with the business code. At runtime, it is implemented through injection, and the program directly calls them to complete the result set merging. This solution avoids the learning cost of introducing new concepts by defining annotations for SQL association. It utilizes the Java compiler extension mechanism to filter interface source files with custom annotations during extended compilation and generates result set merging methods. It uses a hash algorithm to achieve fast matching under multi-field association of two sets. It directly generates getter and setter methods, uses the stream API, and implements parallel processing without reflection, achieving the same performance as methods written by programmers alone. It does not require data copying, so it does not cause data inconsistency or increase system complexity, resulting in a lightweight implementation.

[0091] An apparatus for simplifying result set merging, applying the simplified result set merging method described in any one of the preceding claims, includes:

[0092] The interface generation module is used to add interface class files;

[0093] Define a module for a collection merging requirement. Define an interface method in the interface class file. The parameters in the parameter list of the interface method correspond to the source collection and the result collection, respectively. The merging relationship is described in the custom annotation of the interface method.

[0094] The compilation module, based on the compiler's extension of the AbstractProcessor class, captures the Joiner annotation during compilation to obtain a list of all defined interface source files in the source code project;

[0095] The analysis and processing module parses custom annotations based on the source files and generates application implementation classes for each interface file in a loop. Once all implementation classes are generated, the compiler compiles the generated implementation classes into the project target package.

[0096] The merge processing module automatically loads the specified implementation class through interface methods and the factory pattern, merges the source collections into a result collection, and completes the merging of the result collections.

[0097] Although embodiments of the invention have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of the invention, the scope of which is defined by the appended claims and their equivalents.

Claims

1. A method for simplifying result set merging, applied to applications built under a cloud-native microservices technology architecture, characterized in that, include: In projects that require merging result sets, add an interface class file and define an interface method in the interface class file to complete a set merging according to the requirements; The parameters in the parameter list of the interface method correspond to the source set and the result set, respectively. The merging relationship is described in the custom annotation of the interface method. At least one interface method is defined in an interface class file, and multiple merging relationships are defined in an interface method to merge sets in the sets to be merged. The merging relationship of the sets is described and defined in the custom annotation. The sets to be merged are sets that have the requirement to be merged, and the sets are a pair of sets in the sets to be merged that have the corresponding merging relationship. Obtain a list of all defined interface source files in the source code project. Based on the source files, parse the custom annotations and generate the implementation class corresponding to each interface class file in a loop. After all implementation classes are generated, compile and package the implementation classes into the target package to enable runtime invocation. By using the factory pattern, the specified implementation class is automatically loaded, the program calls the interface, and the result set is merged. The implementation class extends the AbstractProcessor class based on the compiler. During compilation, it captures the Joiner annotation. When the compiler finds a Java source file containing the Joiner annotation, it calls the Process method of this class. The method iterates through the file list, creates a new GenerateClass class for each file, and generates the implementation class. During compilation, the Joiner annotation is used to obtain a list of all defined interface source files in the project after being captured. Based on the source files, it parses the custom annotations and iteratively generates the application implementation class for each interface file.

2. The method for simplifying result set merging according to claim 1, characterized in that, Custom annotations also include: Define Result, Join, and VO in an interface class file; The VO annotation is used to define all collection types used in an interface class file, where the collection type is a Java class and the VO annotation is a custom annotation. The `@Result` annotation is used when an interface method has no return value. It specifies a result collection as a parameter. The `@Result` annotation is a custom annotation. The `@Join` annotation is used on interface methods to define the corresponding merging relationship between collection pairs.

3. The method for simplifying result set merging according to claim 2, characterized in that, Also includes: The Target attribute is an attribute of the Join annotation. It points to a parameter name in the interface method, specifying this parameter as the target set. The target set is the set generated after merging the set pairs. The Source property is an attribute of the Join annotation, pointing to one of the parameter names of the interface method, explicitly specifying this parameter as the source collection for merging the collection pairs; The Type property is an attribute of the Join annotation. It has three values: left, right, and inner, which represent three connection methods: left join, right join, and inner join. The default value is left. The On attribute, which is a property of the Join annotation, is a collection of Equal sub-annotations that describes the field mapping of the collection to the corresponding merge relationship; The FieldMaps property is an attribute of the Join annotation. It is a collection of Setter sub-annotations that describes the field correspondence when merging collection pairs. The Auto attribute is a property of the Join annotation. It is a simplification of FieldMaps. When the property names and data types of fields in two collections are the same, the field values ​​of the source collection are automatically assigned to the target collection. The AllowOneToMany property is an attribute of the Join annotation, which specifies how to handle a situation where one record in one collection matches multiple records in another collection.

4. The method for simplifying result set merging according to claim 3, characterized in that, include: The `@Equal` annotation is a sub-annotation of the `@Join` annotation. It belongs to the `On` attribute set and has two attributes: `tgt` and `src`, which represent the association between the target collection field and the source collection field, respectively. The `@Setter` annotation is a sub-annotation of the `@Join` annotation. It belongs to the `FieldMaps` attribute set and has two attributes, `set` and `get`, which represent the target collection field and the source collection field, respectively.

5. The method for simplifying result set merging according to claim 3, characterized in that, The GenerateClass processing class is used to analyze and process a specified interface class source file to generate the corresponding implementation class for that interface class file, including the following steps: Parse the list of VO annotations and generate a clone method for each collection that contains the entity class; Parse all interface methods in this interface class file to form a method list; Iterate through the list to generate GenerateMethod handler classes, and generate implementations of the specified interface methods in the GenerateMethod handler classes; After all sub-methods are parsed and generated, the Java file is called to generate the class and the source file of the implementation class corresponding to the interface class is generated.

6. The method for simplifying result set merging according to claim 5, characterized in that, The GenerateMethod handler class is responsible for resolving the specified interface method and generating the concrete implementation code for the interface method, which includes the following steps: A. Based on the On attribute definition in the Join annotation, a hashcode function is generated for quick comparison during program runtime; B. Based on the Join annotation definition, generate the logic code for comparing and filtering individual records in the collection and assigning values ​​to the corresponding fields; C. Generate code to merge set pairs, which calls steps A and B based on stream processing to complete the merging of the result sets.

7. The method for simplifying result set merging according to claim 1, characterized in that, The factory pattern automatically loads specified implementation classes to merge result sets, and also includes: The Joiners factory class obtains the implementation class from the same package based on the interface class file name with the suffix "Impl". When the application runs, the implementation class is loaded into the Joiner variable when the interface class file loads static variables, and can be directly called in the business code.

8. An apparatus for simplifying result set merging, employing the method for simplifying result set merging according to any one of claims 1 to 7, characterized in that, include: The interface generation module is used to add interface class files; Define a module by defining an interface method in the interface class file to complete a collection merging as required. The parameters in the parameter list of the interface method correspond to the source collection and the result collection respectively. The merging relationship is described in the custom annotation of the interface method. The compilation module, based on the compiler's extension of the AbstractProcessor class, captures the Joiner annotation during compilation to obtain a list of all defined interface source files in the source code project. Specifically, during compilation, the Joiner annotation is used to obtain a list of all defined interface source files in the project after being captured. Based on the source files, custom annotations are parsed, and application implementation classes are generated for each interface file in a loop. The analysis and processing module parses custom annotations based on the source files and generates application implementation classes for each interface file in a loop. Once all implementation classes are generated, the compiler compiles the generated implementation classes into the project target package. The merge processing module automatically loads the specified implementation class through interface methods and the factory pattern, merges the source collections into a result collection, and completes the merging of the result collections.

Citation Information

Patent Citations

  • Java file dependency analysis method and module for distributed static detection system

    CN109033843A

  • Program annotation compiling method and corresponding device, equipment and medium

    CN112817600A