Data query method and device, storage medium and electronic equipment

By determining the query type and model in the data access object interface, combining the metadata of the query parameters, and performing query operations under the framework of the target data access object, the problem of cumbersome and lack of universality in the query parameter mapping process in the existing technology is solved, and flexible framework switching and efficient development process are realized.

CN120086253APending Publication Date: 2025-06-03NEUSOFT CORP
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202510161588.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-13
Publication Date
2025-06-03

AI Technical Summary

Technical Problem

In the prior art, the process of mapping query parameters to a unique query model of the data access object framework is cumbersome and error-prone. When switching the implementation of different data access object frameworks, the original query logic implementation needs to be modified and lacks universality.

Method used

By obtaining the query request, the general or custom query method in the target data access object interface is determined, the target query type is determined based on the method type of the query method or query operation annotation, the target query model is further determined based on the metadata of the query parameters, and the query operation is performed under the framework of the target data access object to obtain the query results.

Benefits of technology

It realizes the decoupling of the data access object interface and framework implementation, allowing the underlying framework and implementation details to be replaced or adjusted without changing the interface, reducing the implementation cost of query logic and the migration cost of framework switching, and improving development efficiency and system scalability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120086253A_ABST
    Figure CN120086253A_ABST
Patent Text Reader

Abstract

The invention relates to a data query method and device, a storage medium and electronic equipment, and belongs to the technical field of computers.The method comprises the steps that a query request is obtained, and the query request is used for calling a target data access object interface to conduct data query; according to the target data access object interface, determining a target query model and a target query type corresponding to the target data access object framework; and according to the target query model and the target query type, executing a query operation under the target data access object framework to obtain a query result. By adopting the method, the implementation cost of query logic and the migration cost of switching different data access object frameworks can be reduced, and the development efficiency of developers and the expandability of system implementation are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technologies, and in particular, to a data query method, apparatus, storage medium, and electronic device. Background Art

[0002] When developing a query interface for an application, a query parameter class is defined to receive query parameters, and then the query parameter class is carried to call the interface of a data access object (DAO). The interface of the data access object needs to implement the corresponding underlying query logic according to the query parameters, and different implementations correspond to different data access object frameworks and underlying storages.

[0003] In the query implementation methods in the related art, it is necessary to manually program to map the query parameters to the unique query model of the data access object framework. The whole process is cumbersome and error-prone. Moreover, when switching to different data access object framework implementations, the original query logic implementations need to be modified, and they do not have universality. Summary of the Invention

[0004] The purpose of the present disclosure is to provide a data query method, apparatus, storage medium, and electronic device to at least partially solve the above technical problems.

[0005] To achieve the above purpose, in a first aspect, the present disclosure provides a data query method, including:

[0006] Obtaining a query request for calling a target data access object interface to perform data query;

[0007] Determining a target query model and a target query type corresponding to a target data access object framework according to the target data access object interface;

[0008] Performing a query operation in the target data access object framework according to the target query model and the target query type to obtain a query result.

[0009] Optionally, the target data access object interface includes a general query method and / or a custom query method. The method parameter of the general query method is an instance object in a query parameter class, and the query parameter class includes query parameters, query condition annotations corresponding to the query parameters, and annotation attributes of the query condition annotations. The custom query method includes a method identifier and method parameters. A query operation annotation is marked before the method identifier, and the method parameters include query parameters, query condition annotations corresponding to the query parameters, and annotation attributes of the query condition annotations.

[0010] Optionally, according to the target data access object interface, determine the target query type corresponding to the target data access object framework, including:

[0011] In the case where the query request invokes the general query method in the target data access object interface, determine the target query type corresponding to the target data access object framework according to the method type of the invoked general query method;

[0012] In the case where the query request invokes the custom query method in the target data access object interface, determine the target query type corresponding to the target data access object framework according to the query operation annotation of the invoked custom query method.

[0013] Optionally, according to the target data access object interface, determine the target query model corresponding to the target data access object framework, including:

[0014] According to the target data access object interface, determine the metadata of each query parameter, where the metadata includes the parameter name, parameter type, parameter value, and query condition annotation;

[0015] According to the metadata of each query parameter, determine the target query model corresponding to the target data access object framework.

[0016] Optionally, the determining the target query model corresponding to the target data access object framework according to the metadata of each query parameter includes:

[0017] Group each query parameter according to the group name attribute of the query condition annotation to obtain multiple candidate query parameter groups;

[0018] For any candidate query parameter group, based on the parameter values corresponding to each query parameter in the group and the ignore condition attribute of the query parameter annotation, determine the status of each query parameter in the group, where the status of the query parameter includes the ignore status and the retain status;

[0019] For any retained query parameter group, determine the first target query parameter with a non-null parameter value from each query parameter in the group, and determine the group logical operator attribute of the query parameter annotation corresponding to the target query parameter, where the retained query parameter group is a candidate query parameter group with query parameters in the retain status;

[0020] For any retained query parameter group, based on the metadata of the query parameters in the retain status in the group, obtain the query conditions and the corresponding in-group logical operators, and generate the query condition combination corresponding to the group based on each query condition and the corresponding in-group logical operator;

[0021] Based on the query condition combinations corresponding to each reserved query parameter group respectively and the corresponding inter-group logical operators, the target query model is obtained.

[0022] Optionally, for any reserved query parameter group, based on the metadata of the query parameters in the reserved state in this group, query conditions and the corresponding intra-group logical operators are obtained, including:

[0023] Determine the parameter name of the query parameter in the reserved state in this group or the name attribute of the query condition annotation as the column name query condition;

[0024] Determine the parameter value of the query parameter in the reserved state in this group as the matching value query condition;

[0025] Determine the type of the query condition annotation of the query parameter in the reserved state in this group as the matching method query condition;

[0026] Determine the logical operator attribute of the query condition annotation of the query parameter in the reserved state in this group as the intra-group logical operator of the corresponding query condition.

[0027] Optionally, according to the target query model and the target query type, performing a query operation under the target data access object framework to obtain a query result, including:

[0028] Determine a target query script, where the target query script includes query condition placeholders, and the target query script is the query script corresponding to the target query type in the target data access object framework;

[0029] Replace the query condition placeholders in the target query script with the target query model to obtain a replaced query script;

[0030] Execute the replaced query script to obtain the query result.

[0031] In a second aspect, an embodiment of the present disclosure provides a data query device, including:

[0032] An acquisition module, configured to acquire a query request, where the query request is used to call a target data access object interface to perform data query;

[0033] A determination module, configured to determine a target query model and a target query type corresponding in the target data access object framework according to the target data access object interface;

[0034] A query module, configured to perform a query operation under the target data access object framework according to the target query model and the target query type to obtain a query result.

[0035] In a third aspect, embodiments of the present disclosure provide a computer-readable storage medium, on which a computer program is stored, and when the program is executed by a processor, the steps of the method according to any one of the first aspect are implemented.

[0036] In a fourth aspect, embodiments of the present disclosure provide an electronic device, including:

[0037] a memory, on which a computer program is stored;

[0038] a processor, configured to execute the computer program in the memory to implement the steps of the method according to any one of the first aspect.

[0039] Through the above technical solutions, after obtaining a query request for invoking a target data access object interface for data query, since the target query model and the target query type corresponding to the target data access object framework are first determined according to the target data access object interface, and then the query operation is executed in the target data access object framework according to the target query model and the target query type to obtain a query result, it is equivalent to decoupling the data access object interface from the implementation of the data access object framework, so that the underlying data access object framework and implementation details can be flexibly replaced or adjusted without changing the data access object interface, thereby greatly reducing the implementation cost of the query logic and the migration cost of switching different data access object frameworks, and improving the development efficiency of developers and the scalability of system implementation.

[0040] Other features and advantages of the present disclosure will be described in detail in the subsequent specific implementation part. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] The drawings are used to provide a further understanding of the present disclosure, and constitute a part of the specification, and are used to explain the present disclosure together with the following specific implementation, but do not constitute a limitation to the present disclosure. In the drawings:

[0042] Figure 1 is a flowchart of a data query method shown in an exemplary embodiment of the present disclosure.

[0043] Figure 2 is a flowchart of a method for determining a target query model shown in an exemplary embodiment of the present disclosure.

[0044] Figure 3 is a block diagram of a data query device shown in an exemplary embodiment of the present disclosure.

[0045] Figure 4 is a block diagram of an electronic device shown in an exemplary embodiment of the present disclosure. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0046] The following will describe in detail the specific embodiments of the present disclosure with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are only for explaining and illustrating the present disclosure, and are not used to limit the present disclosure.

[0047] In long-term research, the inventor found that for a query interface, its essence is to call a data access object interface through query parameters to implement a query. The implementation logic of a specific data access object interface will change according to different data access object frameworks, but the query parameters and the method declarations of the data access object interface remain unchanged (i.e., they will not change with the change of the data access object framework).

[0048] Based on the above discovery, the inventor proposed a data query method, device, storage medium, and electronic device according to the embodiments of the present disclosure. After obtaining a query request for calling a target data access object interface to perform a data query, first determine the target query model and target query type corresponding to the target data access object framework according to the target data access object interface, and then execute a query operation in the target data access object framework according to the target query model and target query type to obtain a query result. That is, the data access object interface and the implementation of the data access object framework are decoupled, so that without changing the data access object interface (i.e., without changing the query parameters and the method declarations of the data access object interface), the underlying data access object framework and implementation details can be flexibly replaced or adjusted, thereby greatly reducing the implementation cost of the query logic and the migration cost of switching different data access object frameworks, and improving the development efficiency of developers and the scalability of system implementation.

[0049] Before elaborating on the embodiments of the present disclosure in detail, the module architecture involved in the embodiments of the present disclosure will be described first. The module architecture involved in the embodiments of the present disclosure may include a query annotation module, a query interface module, and a query adapter module. Among them:

[0050] The query annotation module defines general query condition annotations and query operation annotations. Through the annotations, query parameters and query methods can be mapped to a unified query model. Among them, the query condition annotation is marked before the definition of the query parameter class attribute or before the query method parameter. Through the query condition annotation, the query parameter can be mapped to the corresponding query condition. The query operation annotation is marked on a custom query method and is used to represent the corresponding query type (such as querying multiple records, querying a single record, etc.).

[0051] The query condition annotation is a unified abstraction of the matching methods (equal, contains, greater than, etc.) of query parameters. Next, the query condition annotation will be described with examples. Suppose there are n query parameters, represented by P1 to Pn respectively, then the following description can be made:

[0052] 1) Any one or more query parameters can correspond to a matching condition stored at the bottom layer. For example, P1 means that a certain column stored at the bottom layer needs to be equal to P1, P2 means that a certain column stored at the bottom layer needs to include P2 (the text content of a certain column contains a certain text segment), and P3 and P4 mean that a certain column stored at the bottom layer needs to be between P3 and P4;

[0053] 2) There are logical combination relationships among multiple query parameters. For example, the matching conditions represented by P1 and P2 must be satisfied simultaneously (AND relationship), or the matching conditions represented by any one of P1 and P2 must be satisfied (OR relationship);

[0054] 3) There are grouping relationships among multiple query parameters. For example, P1 and P2 are in Group 1, and multiple query parameters within Group 1 need to be satisfied simultaneously (AND relationship within the group). P3 and P4 are in Group 2, and any one of the multiple query parameters within Group 2 can be satisfied (OR relationship within the group). However, it is required to satisfy both Group 1 and Group 2 simultaneously (AND relationship between groups), or any one of the groups can be satisfied (OR relationship between groups).

[0055] 4) It should be particularly noted that when the value of P1 is empty, the matching condition represented by P1 may be ignored, and when multiple query parameters within a group are all empty, all query parameters within that group will be ignored.

[0056] For the above process, the matching conditions of query parameters are represented as query condition annotations, such as @Equal for equality, @Contain for inclusion, @Between for within a range, etc. The corresponding column names in the underlying storage are represented as the name attribute of the query condition annotation. The logical combination relationships of the matching conditions of multiple query parameters (or multiple query parameters within a group) are represented as the logical operator attribute logical of the query condition annotation. The groups to which multiple query parameters belong are represented as the group name attribute group of the query condition annotation. The logical combination relationship between multiple groups is represented as the group logical operator attribute groupLogical of the query condition annotation. The ignore condition of the query parameter is represented as the ignore condition attribute igonre of the query condition annotation.

[0057] Next, some query condition annotations proposed in the embodiments of the present disclosure and their specific definitions will be described in combination with the following table:

[0058]

[0059] Next, the general attributes supported by the condition annotation will be described in combination with the following table:

[0060]

[0061]

[0062] The query operation annotation is an abstraction of the query type. Below, some query operation annotations proposed in the embodiments of the present disclosure and their specific definitions will be described in conjunction with the following table:

[0063]

[0064] The query interface module defines a general query interface, query methods, and a base class for query parameters. As long as the data access object interface inherits this query interface, it can use the built-in query methods in the interface combined with the query parameter class annotated with the query condition annotation to implement the automatic generation of queries. It can also implement the automatic generation of queries by customizing query methods in the data access object interface in combination with query annotations (query condition annotations, query operation annotations).

[0065] The general base class for query parameters is used to mark query parameter classes, including BaseQuery and BasePageQuery. And BasePageQuery has built-in paging parameters and sorting parameters. The specific implementation of the query parameter class can inherit the base class for query parameters. The general query interface QueryRepo is used to mark the query interface and has built-in general query methods. The specific implementation of the data access object interface can inherit this interface. Below, some general query methods built in the general query interface QueryRepo proposed in the embodiments of the present disclosure and their specific definitions will be described in conjunction with the following table:

[0066]

[0067] The query adapter module is used to proxy the query interfaces in the query interface module, converting query methods, query parameters, and query annotations into specific data access object framework query implementations. Each data access object framework corresponds to a query adapter implementation. The query adapter implementations for data access object frameworks include but are not limited to: relational databases (Mybatis-Plus, Mybatis-Flex, Spring Data JPA), Redis Search (Jedis, Spring RedisOM, Redisson), Elastic Search.

[0068] The implementation of the query adapter is divided into two types: built-in method implementation and custom method implementation. The built-in method implementation is to proxy the built-in query methods in the query interface. By using the way of implementing the default methods of the interface, the query parameter class is converted into the query model of the corresponding data access object framework. Different built-in method implementations correspond to corresponding query operation types (for example, the FindMany method corresponds to querying multiple records, and the FindOne method corresponds to querying a single record, etc.). The custom method implementation is to proxy the custom query methods in the implementation of the data access object interface. By using the Aspect-Oriented Programming (AOP) Around aspect method to proxy the custom query methods, the corresponding data access object framework query model is converted according to the query parameter list and query condition annotations of the custom query methods, and the corresponding query operation type is confirmed according to the query operation annotations marked on the custom query methods (for example, @FindMany corresponds to querying multiple records, and @FindOne corresponds to querying a single record, etc.).

[0069] Figure 1 FIG. is a flowchart of a data query method shown according to an exemplary embodiment of the present disclosure. The data query method can be executed by various stationary or mobile electronic devices, which may include terminal devices or servers. Among them, the terminal devices may be, for example, desktop computers, laptop computers, tablet devices, etc., or a combination thereof. Referring to Figure 1 , the data query method includes:

[0070] S110, obtain a query request, where the query request is used to call a target data access object interface to perform a data query.

[0071] S120, according to the target data access object interface, determine a target query model and a target query type corresponding to the target data access object framework.

[0072] S130, according to the target query model and the target query type, perform a query operation in the target data access object framework to obtain a query result.

[0073] In the above technical solution, after obtaining a query request for invoking a target data access object interface to perform data query, since the target query model and target query type corresponding to the target data access object framework are first determined according to the invoked target data access object interface, and then the query operation is performed in the target data access object framework according to the target query model and target query type to obtain a query result, it is equivalent to decoupling the data access object interface from the data access object framework implementation. This enables flexible replacement or adjustment of the underlying data access object framework and implementation details without changing the data access object interface, thereby greatly reducing the implementation cost of the query logic and the migration cost of switching different data access object frameworks, and improving the development efficiency of developers and the scalability of system implementation.

[0074] In some embodiments, the target data access object interface includes a general query method and / or a custom query method. Among them, the method parameter of the general query method is an instance object in the query parameter class, and the query parameter class includes query parameters, query condition annotations corresponding to the query parameters, and annotation attributes of the query condition annotations. The custom query method includes a method identifier and method parameters. The method identifier is marked with a query operation annotation in front, and the method parameters include query parameters, query condition annotations corresponding to the query parameters, and annotation attributes of the query condition annotations.

[0075] In the embodiments of the present disclosure, the methods in the target data access object interface can include two types, one is a general query method, and the other is a custom query method.

[0076] For the general query method, multiple query parameters can be encapsulated into a query parameter class, and each query parameter is used as an attribute in the query parameter class. Corresponding query condition annotations are marked on the attribute definition (i.e., query parameter) of the query parameter class. Then, an instance object of the query parameter class marked with the query condition annotation is used as the parameter of the general query method (for example, the built-in query methods FindOne, FindMany, FindCount, FindExists, FindPage in the predefined query interfaces in the query interface module). Such a setting enables subsequent determination of the target query model and target query type corresponding to the target data access object framework according to the target data access object interface.

[0077] In some embodiments, the target data access object interface can obtain the built-in general query methods, query parameter base classes, etc. in the query interface by inheriting a general query interface.

[0078] Next, an example of marking corresponding query condition annotations on the attribute definition of the query parameter class is given:

[0079] Java

[0080] / / Example 1

[0081]

[0082] / / Example 2

[0083]

[0084] / / Example 3

[0085]

[0086] In the above definition of the MyQuery1 query parameter class, the id attribute is marked with the @Equal query condition annotation, which means that the id parameter will be converted into an equal matching condition. The column name stored at the bottom layer is the name value of the query condition annotation. If the name value is not specified, it defaults to the parameter attribute name. When the parameter value meets the ignore condition attribute (ignore) of the query condition annotation (such as @Equal.ignore defaults to NULL, that is, null values are ignored), the condition concatenation of the current parameter value is ignored. That is, when the id attribute value is empty, the query condition concatenation of the id parameter value is ignored. Similarly, the userAccount parameter will be converted into a contains matching condition, and multiple attributes in the query parameter class will be combined according to the logical operator attribute (logical) in the query condition annotation (the default is not set, which is AND). For MyQuery1, it will be mapped to the following query conditions:

[0087] id = id attribute value

[0088] AND userAccount LIKE "%userAccount attribute value%"

[0089] Similarly, for MyQuery2, it will be mapped to the following query conditions:

[0090] userAccount LIKE "%userAccount attribute value%"

[0091] OR createTime between startDate attribute value AND endDate attribute value

[0092] In the above definition of the MyQuery3 query parameter class, if the grouping name property (group) value is not set for the query condition annotation, it is default to belong to the DEFAULT group. Among them, the parameters id and userAccount default to belong to the DEFAULT group, while deptName and deptCode belong to the ONE group according to the group setting. If the grouping logical operator property (groupLogical) of the query parameter annotation is not set, it defaults to AND. Otherwise, the set groupLogical is used as the inter-group logical operator, and only one groupLogical needs to be set for multiple duplicate groups with the same name. For MyQuery3, it will be mapped to the following query conditions:

[0093] (id = id property value AND userAccount LIKE "%userAccount property value%")

[0094] AND (deptName LIKE "%deptName property value%" OR deptCode = "deptCode property value")

[0095] Next, an example is given for the case where an instance object of a query parameter class annotated with a query condition annotation is used as a parameter of a general query method:

[0096] Java

[0097] / / Query multiple records id =? and userAccount like?

[0098] List <myobj>myObjs=myQueryRepo.FindMany(new MyQuery1(1L,"tom"))

[0099] / / Query a single record userAccount like? or createTime before? and?

[0100] MyObjmyobj=myQueryRepo.FindOne(new MyQuery2("tom",DateUtils.parseDate("2024-01-01"),DateUtils.parseDate("2024-12-01")))

[0101] / / Query quantity (id=? and userAccount like?) and (deptName like? or deptCode=?)

[0102] Long count = myQueryRepo.FindCount(new MyQuery3(1L,"tom","部门1","dept1"));

[0103] / / For more built-in methods, see the description of the query interface module

[0104] For custom query methods, each query parameter is used as a method parameter of the custom query method. The corresponding query condition annotation can be marked before the method parameter. In addition to marking the query condition annotation before the method parameter, the corresponding query operation annotation also needs to be marked before the query method identifier to mark the specific query type.

[0105] Below, some custom query methods proposed in the embodiments of the present disclosure are exemplified:

[0106]

[0107]

[0108] The above custom query methods Find1, Find2, and Find3 have exactly the same effect as the automatically generated queries in the aforementioned MyQuery1, MyQuery2, and MyQuery3 examples. The specific analysis process will not be repeated here.

[0109] In the above embodiments, the target data access object interface has been described. Next, the process of determining the target query model and target query type corresponding to the target data access object framework according to the target data access object interface in step S120 will be described. Here, the process of step S120 can be understood as a process of converting based on general query parameters and method declarations to obtain the query model and query type corresponding to the target data access object interface. In some embodiments, this process can be specifically implemented by the query adapter module in the foregoing embodiments.

[0110] In some embodiments, in step S120, determining the target query type corresponding to the target data access object framework according to the target data access object interface may include the following steps:

[0111] In the case where the query request calls the general query method in the target data access object interface, determine the target query type corresponding to the target data access object framework according to the method type of the called general query method;

[0112] In the case where the query request calls the custom query method in the target data access object interface, determine the target query type corresponding to the target data access object framework according to the query operation annotation of the called custom query method.

[0113] In the embodiments of the present disclosure, when the query request calls the general query method in the target data access object interface, the target query type corresponding to the target data access object framework can be determined according to the method type of the called general query method. For example, if the general query method FindMany is called, it corresponds to querying multiple in the target data access object framework; if the general query method FindOne is called, it corresponds to querying a single in the target data access object framework.

[0114] When the query request calls the custom query method in the target data access object interface, the target query type corresponding to the target data access object framework can be determined according to the query operation annotation of the called custom query method. For example, if the query operation annotation is @FindMany, it corresponds to querying multiple in the target data access object framework; if the query operation annotation is @FindOne, it corresponds to querying a single in the target data access object framework.

[0115] In some embodiments, in step S120, determining the target query model corresponding to the target data access object framework according to the target data access object interface may include the following steps:

[0116] Determine the metadata of each query parameter according to the target data access object interface, where the metadata includes the parameter name, parameter type, parameter value, and query condition annotation;

[0117] Determine a target query model corresponding to the target data access object framework according to the metadata of each query parameter.

[0118] In the embodiments of the present disclosure, the metadata of each query parameter can be determined according to the target data access object interface, that is, the parameter name, parameter type, parameter value, and query condition annotation corresponding to the query parameter are determined. Then, according to the metadata of each query parameter, a target query model corresponding to the target data access object framework can be determined.

[0119] Combined with the foregoing content, it can be seen that in some embodiments, the methods in the target data access object interface can include two types. One is a general query method, and the other is a custom query method. For the general query method, the query parameters correspond to all attributes in the query parameter class. For the custom query method, the query parameters correspond to the parameter list of the custom query method.

[0120] In some embodiments, referring to Figure 2 , determining a target query model corresponding to the target data access object framework according to the metadata of each query parameter may include the following steps:

[0121] S210, group each query parameter according to the group name attribute of the query condition annotation to obtain a plurality of candidate query parameter groups;

[0122] S220, for any candidate query parameter group, determine the status of each query parameter in the group based on the parameter value corresponding to each query parameter in the group and the ignore condition attribute of the query parameter annotation. The status of the query parameter includes an ignore status and a retain status;

[0123] S230, for any retained query parameter group, determine the first target query parameter with a non-null parameter value from each query parameter in the group, and determine the group logical operator attribute of the query parameter annotation corresponding to the target query parameter as the group logical operator. The retained query parameter group is a candidate query parameter group in which there are query parameters in the retain status;

[0124] S240, for any retained query parameter group, obtain the query condition and the corresponding in-group logical operator based on the metadata of the query parameters in the retain status in the group, and generate a query condition combination corresponding to the group based on each query condition and the corresponding in-group logical operator;

[0125] S250, obtain the target query model based on the query condition combinations corresponding to each retained query parameter group and the corresponding group logical operators.

[0126] In the embodiments of the present disclosure, first, according to the group name attribute (Group) of the query condition annotation, each query parameter with the same group name attribute can be divided into a group, so that multiple candidate query parameter groups can be obtained. Then, each candidate query parameter group is traversed in turn. For any one of the candidate query parameter groups, according to the parameter value of the query parameter in the candidate query parameter group and the ignore condition attribute (ignore) of the query parameter annotation, it is determined whether to ignore a certain query parameter in the candidate query parameter group, that is, to determine the status (ignore status or retention status) of a certain query parameter in the candidate query parameter group. If the status of all query parameters in the group is the ignore status, then the candidate query parameter group is ignored; otherwise, the candidate query parameter group is retained. Here, the retained candidate query parameter group is the retained query parameter group.

[0127] After obtaining the retained query parameter groups, each retained query parameter group is traversed in turn. For any one of the retained query parameter groups, the first target query parameter with a non-null parameter value is determined from the retained query parameter group, and the group logical operator attribute (groupLogical) of the query parameter annotation corresponding to the target query parameter is determined as the inter-group logical operator. If the parameter values of all query parameters in the retained query parameter group are null values, the inter-group logical operator of the retained query parameter group is AND.

[0128] Further, each retained query parameter group is traversed in turn. For any one of the retained query parameter groups, based on the metadata of the query parameters in the group that are in the retained state, the query conditions and the corresponding intra-group logical operators in the query model (such as QueryWrapper, Specification, etc.) under the target data access object framework are obtained, and based on each query condition and the corresponding intra-group logical operator, a query condition combination corresponding to the group is generated. Then, the query condition combinations of each retained query parameter group can be logically combined according to the corresponding inter-group logical operator to obtain the target query model corresponding to the target data access object framework.

[0129] In some embodiments, for any one of the retained query parameter groups, obtaining the query conditions and the corresponding intra-group logical operators based on the metadata of the query parameters in the group that are in the retained state may include the following steps:

[0130] Determine the column name query condition as the parameter name of the query parameter in the group that is in the retained state or the name attribute of the query condition annotation;

[0131] Determine the matching value query condition as the parameter value of the query parameter in the group that is in the retained state;

[0132] Determine the type of the query condition annotation of the query parameter in the reserved state within the group as a matching method query condition;

[0133] Determine the logical operator attribute of the query condition annotation of the query parameter in the reserved state within the group as the in-group logical operator of the corresponding query condition.

[0134] In the embodiments of the present disclosure, the query condition may include a column name, a matching value, a matching method, etc. For any reserved query parameter group, the parameter name of the query parameter in the reserved state within the group or the name attribute (Name) of the query condition annotation may be determined as the column name query condition, the parameter value of the query parameter in the reserved state within the group may be determined as the matching value query condition, the type of the query condition annotation of the query parameter in the reserved state within the group (such as @Equal, @NotEqual, @Between, etc.) may be determined as the matching method query condition, and the logical operator attribute (Logical) of the query condition annotation of the query parameter in the reserved state within the group may be determined as the in-group logical operator of the corresponding query condition.

[0135] Through the above process, the target query model and the target query type corresponding to the target data access object framework can be determined. Subsequently, the query operation can be further performed according to the target query model and the target query type within the target data access object framework to obtain a query result.

[0136] In the method of the embodiments of the present disclosure, in addition to supporting fully automated query generation based on query annotations, it also supports referring to the corresponding query conditions in the form of query condition placeholders in the query script corresponding to the custom query method. Therefore, in some embodiments, in step S130, performing the query operation according to the target query model and the target query type within the target data access object framework to obtain a query result may include the following steps:

[0137] Determine a target query script, where the target query script includes query condition placeholders, and the target query script is the query script corresponding to the target query type in the target data access object framework;

[0138] Replace the query condition placeholders in the target query script with the target query model to obtain a replaced query script;

[0139] Execute the replaced query script to obtain a query result.

[0140] In the embodiments of the present disclosure, a query script corresponding to the obtained target query type, i.e., the target query script, can be determined in the target data access object framework. By replacing the query condition placeholder in the target query script with the target query model, the replaced query script can be obtained. Then, by executing the replaced query script, the query result can be obtained.

[0141] Exemplarily, in the Mybatis implementation, a custom query method (query type) FindList is defined. The target query model obtained can be referenced through the query condition placeholder ${customCondition} in the mapper.xml script corresponding to the query method. The specific usage example is as follows:

[0142]

[0143] Using the above method, developers only need to use query condition annotations on the query parameters, use query operation annotations on the custom query methods, and combine general query interfaces, query methods, etc., to map the query parameters and query methods into a unified query model.

[0144] In addition, through the proxy implementation of the query interface, the query method, query parameters, and query annotations are converted into the query implementation of the specific data access object framework. Each data access object framework corresponds to one implementation. In this way, the query is defined only once through the query annotation, and then seamless switching across different data access object frameworks and underlying storage can be completed by switching the implementations of different data access object frameworks, greatly reducing the implementation cost of the query logic and the migration cost of switching different data access object frameworks and underlying storage, and improving the development efficiency of developers and the scalability of system implementation.

[0145] Based on the same inventive concept, the embodiments of the present disclosure provide a data query device. Figure 3 It is a block diagram of a data query device 300 shown in an exemplary embodiment of the present disclosure. Referring to Figure 3 , the data query device 300 includes:

[0146] An acquisition module 301, configured to acquire a query request, where the query request is used to call a target data access object interface for data query;

[0147] A determination module 302, configured to determine a target query model and a target query type corresponding to the target data access object framework according to the target data access object interface;

[0148] A query module 303, configured to perform a query operation in the target data access object framework according to the target query model and the target query type to obtain a query result.

[0149] Optionally, the target data access object interface includes a general query method and / or a custom query method. The method parameter of the general query method is an instance object in a query parameter class. The query parameter class includes query parameters, query condition annotations corresponding to the query parameters, and annotation attributes of the query condition annotations. The custom query method includes a method identifier and method parameters. A query operation annotation is marked before the method identifier. The method parameters include query parameters, query condition annotations corresponding to the query parameters, and annotation attributes of the query condition annotations.

[0150] Optionally, the determination module 302 includes:

[0151] A first determination sub-module, configured to, when the query request invokes the general query method in the target data access object interface, determine a target query type corresponding in the target data access object framework according to the method type of the invoked general query method;

[0152] A second determination sub-module, configured to, when the query request invokes the custom query method in the target data access object interface, determine a target query type corresponding in the target data access object framework according to the query operation annotation of the invoked custom query method.

[0153] Optionally, the determination module 302 includes:

[0154] A third determination sub-module, configured to determine metadata of each query parameter according to the target data access object interface. The metadata includes a parameter name, a parameter type, a parameter value, and a query condition annotation;

[0155] A fourth determination sub-module, configured to determine a target query model corresponding to the target data access object framework according to the metadata of each query parameter.

[0156] Optionally, the fourth determination sub-module includes:

[0157] A first determination unit, configured to group each query parameter according to the group name attribute of the query condition annotation to obtain a plurality of candidate query parameter groups;

[0158] A second determination unit, configured to, for any one of the candidate query parameter groups, determine the status of each query parameter in the group based on the parameter value corresponding to each query parameter in the group and the ignore condition attribute of the query parameter annotation. The status of the query parameter includes an ignore status and a retention status;

[0159] A third determination unit, configured to, for any reserved query parameter group, determine a target query parameter with a non-empty parameter value from each query parameter in the group, and determine the grouping logical operator attribute of the query parameter annotation corresponding to the target query parameter as the inter-group logical operator, where the reserved query parameter group is a candidate query parameter group in which there are query parameters in a reserved state;

[0160] A fourth determination unit, configured to, for any reserved query parameter group, obtain a query condition and a corresponding intra-group logical operator based on the metadata of the query parameters in the reserved state in the group, and generate a query condition combination corresponding to the group based on each query condition and the corresponding intra-group logical operator;

[0161] A fifth determination unit, configured to obtain the target query model based on the query condition combinations respectively corresponding to each reserved query parameter group and the corresponding inter-group logical operators;

[0162] Optionally, the fourth determination unit is further configured to determine the parameter name of the query parameter in the reserved state in the group or the name attribute of the query condition annotation as the column name query condition; determine the parameter value of the query parameter in the reserved state in the group as the matching value query condition; determine the type of the query condition annotation of the query parameter in the reserved state in the group as the matching method query condition; and determine the logical operator attribute of the query condition annotation of the query parameter in the reserved state in the group as the intra-group logical operator corresponding to the corresponding query condition.

[0163] Optionally, the query module 303 includes:

[0164] A fifth determination sub-module, configured to determine a target query script, where the target query script includes query condition placeholders, and the target query script is a query script corresponding to the target query type in the target data access object framework;

[0165] A replacement sub-module, configured to replace the query condition placeholders in the target query script with the target query model to obtain a replaced query script;

[0166] An execution sub-module, configured to execute the replaced query script to obtain the query result.

[0167] Regarding the data query device 300 in the above embodiments, the specific manners in which each module performs operations have been described in detail in the embodiments related to the method, and will not be elaborated herein.

[0168] Based on the same inventive concept, an embodiment of the present disclosure further provides a computer-readable storage medium, on which a computer program is stored, and when the program is executed by a processor, the steps of the data query method described in any embodiment of the present disclosure are implemented.

[0169] Based on the same inventive concept, an embodiment of the present disclosure further provides an electronic device, including:

[0170] A memory storing a computer program thereon;

[0171] A processor configured to execute the computer program in the memory to implement the steps of the data query method in any one of the embodiments of the present disclosure.

[0172] Figure 4 is a block diagram of an electronic device 400 shown according to an exemplary embodiment. As Figure 4 shown, the electronic device 400 may include: a processor 401, a memory 402. The electronic device 400 may further include one or more of a multimedia component 403, an input / output (I / O) interface 404, and a communication component 405.

[0173] Among them, the processor 401 is used to control the overall operation of the electronic device 400 to complete all or part of the steps in the above data query method. The memory 402 is used to store various types of data to support the operation of the electronic device 400. These data may include, for example, instructions for any application or method operating on the electronic device 400, as well as application-related data, such as contact data, received and sent messages, pictures, audio, video, and so on. The memory 402 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disks, or optical discs. The multimedia component 403 may include a screen and an audio component. Among them, the screen may be a touch screen, and the audio component is used to output and / or input audio signals. For example, the audio component may include a microphone for receiving external audio signals. The received audio signals may be further stored in the memory 402 or sent through the communication component 405. The audio component further includes at least one speaker for outputting audio signals. The I / O interface 404 provides an interface between the processor 401 and other interface modules, and the above other interface modules may be a keyboard, a mouse, buttons, etc. These buttons may be virtual buttons or physical buttons. The communication component 405 is used for wired or wireless communication between the electronic device 400 and other devices. Wireless communication, such as Wi-Fi, Bluetooth, near field communication (NFC), 2G, 3G, or 4G, or a combination of one or more of them. Accordingly, the communication component 405 may include: a Wi-Fi module, a Bluetooth module, and an NFC module.

[0174] In an exemplary embodiment, the electronic device 400 can be implemented by one or more application specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors or other electronic components, and is used to execute the above data query method.

[0175] In another exemplary embodiment, a computer-readable storage medium including program instructions is further provided. When the program instructions are executed by a processor, the steps of the above data query method are implemented. For example, the computer-readable storage medium can be the above-mentioned memory 402 including program instructions, and the above program instructions can be executed by the processor 401 of the electronic device 400 to complete the above data query method.

[0176] In another exemplary embodiment, a computer program product is further provided. The computer program product includes a computer program that can be executed by a programmable device, and the computer program has a code portion for executing the above data query method when executed by the programmable device.

[0177] The preferred embodiments of the present disclosure have been described in detail above in conjunction with the accompanying drawings. However, the present disclosure is not limited to the specific details in the above embodiments. Within the scope of the technical concept of the present disclosure, various simple modifications can be made to the technical solutions of the present disclosure, and these simple modifications all fall within the protection scope of the present disclosure.

[0178] In addition, it should be noted that, in the various specific technical features described in the above specific embodiments, without contradiction, they can be combined in any appropriate manner. To avoid unnecessary repetition, the present disclosure will not separately describe various possible combination methods.

[0179] In addition, any combination can be made between various different embodiments of the present disclosure, as long as it does not violate the idea of the present disclosure, and it should also be regarded as the content disclosed by the present disclosure.< / myobj>

Claims

1. A data query method, characterized in that: include: Obtaining a query request, wherein the query request is used to call a target data access object interface to perform data query; According to the target data access object interface, determining a target query model and a target query type corresponding to the target data access object framework; According to the target query model and the target query type, a query operation is performed under the target data access object framework to obtain a query result.

2. The method according to claim 1, characterized in that The target data access object interface includes a general query method and / or a custom query method. The method parameters of the general query method are instance objects in a query parameter class. The query parameter class includes query parameters, query condition annotations corresponding to the query parameters, and annotation attributes of the query condition annotations. The custom query method includes a method identifier and method parameters. The method identifier is annotated with a query operation annotation. The method parameters include query parameters, query condition annotations corresponding to the query parameters, and annotation attributes of the query condition annotations.

3. The method according to claim 2, characterized in that According to the target data access object interface, determining a target query type corresponding to the target data access object framework includes: In the case where the query request calls a general query method in the target data access object interface, determining a target query type corresponding to the target data access object framework according to a method type of the general query method called; In the case where the query request calls the custom query method in the target data access object interface, the target query type corresponding to the target data access object framework is determined according to the query operation annotation of the called custom query method.

4. The method according to claim 1, characterized in that According to the target data access object interface, determining a target query model corresponding to the target data access object framework includes: Determine metadata of each query parameter according to the target data access object interface, wherein the metadata includes parameter name, parameter type, parameter value and query condition annotation; According to the metadata of each query parameter, a target query model corresponding to the target data access object framework is determined.

5. The method according to claim 4, characterized in that The step of determining a target query model corresponding to a target data access object framework according to the metadata of each query parameter includes: Grouping the query parameters according to the group name attribute of the query condition annotation to obtain multiple candidate query parameter groups; For any candidate query parameter group, based on the parameter values ​​corresponding to the query parameters of the group and the ignore condition attribute of the query parameter annotation, determine the status of each query parameter of the group, where the status of the query parameter includes an ignore status and a retain status; For any reserved query parameter group, determine the first target query parameter having a non-empty parameter value from the query parameters in the group, and determine the grouping logic operator attribute of the query parameter annotation corresponding to the target query parameter as an inter-group logic operator, wherein the reserved query parameter group is a candidate query parameter group having a query parameter in a reserved state; For any reserved query parameter group, based on the metadata of the query parameters in the reserved state in the group, the query conditions and the corresponding intra-group logical operators are obtained, and based on each query condition and the corresponding intra-group logical operator, a query condition combination corresponding to the group is generated; The target query model is obtained based on the query condition combinations corresponding to the respective reserved query parameter groups and the corresponding inter-group logical operators.

6. The method according to claim 5, characterized in that The step of obtaining a query condition and a corresponding intra-group logical operator for any reserved query parameter group based on metadata of the query parameters in the group that are in a reserved state includes: Determine the parameter name of the query parameter in the reserved state or the name attribute of the query condition annotation in the group as the column name query condition; Determine the parameter value of the query parameter in the reserved state in the group as the matching value query condition; Determine the type of the query condition annotation of the query parameter in the reserved state in the group as a matching mode query condition; The logical operator attribute of the query condition annotation of the query parameter in the reserved state in the group is determined as the in-group logical operator of the corresponding query condition.

7. The method according to any one of claims 1 to 6, characterized in that: The step of performing a query operation under the target data access object framework according to the target query model and the target query type to obtain a query result includes: Determine a target query script, wherein the target query script includes a query condition placeholder, and the target query script is a query script corresponding to the target query type in the target data access object framework; Replacing the query condition placeholder in the target query script with the target query model to obtain a replaced query script; The replaced query script is executed to obtain the query result.

8. A data query device, characterized in that: The device comprises: An acquisition module, used to acquire a query request, wherein the query request is used to call a target data access object interface to perform data query; A determination module, used to determine a target query model and a target query type corresponding to a target data access object framework according to the target data access object interface; The query module is used to perform query operations under the target data access object framework according to the target query model and the target query type to obtain query results.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the steps of the method described in any one of claims 1 to 7 are implemented.

10. An electronic device, characterized in that: include: a memory having a computer program stored thereon; A processor, configured to execute the computer program in the memory to implement the steps of the method according to any one of claims 1 to 7.

Citation Information

Cited By

  • Data query method and device supporting multi-valued screening, equipment and medium

    CN120407626A