Method and apparatus for generating data persistence layer input parameter, device and medium
By generating data persistence layer input parameters and devices, the input parameter data of SQL statements is automatically parsed and constructed, solving the difficulty for testers to manually construct DAO layer file input parameters, and realizing efficient and accurate data persistence layer interface testing.
Patent Information
- Application Number
- CN202211131430.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-15
- Publication Date
- 2026-07-14
- Estimated Expiration
- 2042-09-15
AI Technical Summary
When modifying the syntax of SQL statements in the project code, testers need to manually build the input parameters of the DAO layer file, which leads to high labor costs and difficulties, especially when there are many DAO layer files and interfaces, making the verification work complex.
A method and apparatus for generating data persistence layer input parameters are provided. By obtaining the data persistence layer and mapping folder path, reading interface and query statement information, parsing target placeholders, constructing input parameter data in a preset format, and merging them into an interface input parameter file, manual writing work is reduced.
It simplifies the work of testers, saves labor costs, obtains accurate input parameter data, and shortens the testing cycle.
Smart Images

Figure CN115809290B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of data processing technology, and in particular to a method, apparatus, device, and medium for generating persistent data layer input parameters. Background Technology
[0002] Currently, the project code manipulates SQL statements in various XML files through interfaces in the DAO layer's Java files. The main task of removing Oracle syntax involves modifying the SQL statements in the XML files, changing the Oracle-related syntax to MySQL-related syntax. After the SQL syntax modification is complete, the DAO layer files that call the SQL statements need to be validated.
[0003] Since the modification involves the lowest-level SQL statement, but verification requires an interface in the DAO layer file, this leads to the following problem:
[0004] The syntax modification of SQL statements is done by developers, while the verification of DAO layer files is done by testers. This makes it more troublesome and difficult for testers to construct the input parameters of DAO layer files, resulting in high manual costs.
[0005] The sheer number of DAO layer files in each project, along with the numerous interfaces within each DAO layer file, makes it more cumbersome and difficult for testers to construct the input parameters for these interfaces, resulting in higher manual costs. Summary of the Invention
[0006] In view of the shortcomings of the prior art described above, the purpose of the present invention is to provide a method, apparatus, device and medium for generating data persistence layer input parameters, thereby overcoming at least to some extent one or more problems caused by the limitations and defects of related technologies.
[0007] Firstly, a method for generating data persistence layer input parameters based on query statements is provided, including:
[0008] Get the data persistence layer folder path and the mapped folder path;
[0009] All data access object files are read according to the data persistence layer folder path, and all mapping files are read according to the mapping folder path, wherein each data access object file includes at least one interface, and each mapping file includes at least one query statement;
[0010] Obtain the interface information of all interfaces in each of the data access object files to obtain an interface information list; obtain the statement information of all query statements in each of the mapping files to obtain a statement information list.
[0011] The interface information is matched with the statement information to obtain the correspondence between the interface and the query statement;
[0012] Each query statement is parsed to find the parameter field corresponding to each target placeholder, which is then used as the parameter field of the corresponding query statement.
[0013] The parameter fields of each query statement are constructed into data in a preset format and used as the input parameter data of the interface corresponding to the query statement.
[0014] Secondly, a device for generating data persistence layer input parameters based on query statements is provided, including:
[0015] The path acquisition module is used to obtain the data persistence layer folder path and the mapped folder path;
[0016] The file reading module is used to read all data access object files according to the data persistence layer folder path and all mapping files according to the mapping folder path, wherein each data access object file includes at least one interface and each mapping file includes at least one query statement;
[0017] The information list acquisition module is used to acquire the interface information of all interfaces in each data access object file to obtain an interface information list, and to acquire the statement information of all query statements in each mapping file to obtain a statement information list.
[0018] The information matching module is used to match the interface information with the statement information to obtain the correspondence between the interface and the query statement;
[0019] The parameter field acquisition module is used to parse each of the query statements, find the parameter field corresponding to each target placeholder, and use it as the parameter field of the corresponding query statement.
[0020] The input parameter data construction module is used to construct the parameter fields of each query statement into data in a preset format, which serves as the input parameter data of the interface corresponding to the query statement.
[0021] Thirdly, an electronic device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the above-described method for generating data persistence layer input parameters based on query statements.
[0022] Fourthly, a computer-readable storage medium is provided, which stores a computer program that, when executed by a processor, implements the steps of the above-described method for generating data persistence layer input parameters based on query statements.
[0023] The above-described method, apparatus, device, and medium for generating data persistence layer input parameters based on query statements involve: obtaining the data persistence layer folder path and the mapping folder path; reading all data access object files according to the data persistence layer folder path and all mapping files according to the mapping folder path; wherein each data access object file includes at least one interface and each mapping file includes at least one query statement; obtaining the interface information of all interfaces in each data access object file to obtain an interface information list; obtaining the statement information of all query statements in each mapping file to obtain a statement information list; and performing a comparison between the interface information and the statement information. The information is matched to obtain the correspondence between the interface and the query statement; each query statement is parsed to find the parameter field corresponding to each target placeholder, which is used as the parameter field of the corresponding query statement; the parameter field of each query statement is constructed into preset format data as the input parameter data of the interface corresponding to the query statement, thereby conveniently obtaining the input parameter data of the data persistence layer interface, saving testers from manually writing the input parameter data of the data persistence layer interface, saving manpower and manual costs; and since the present invention constructs the input parameter data of the data persistence layer interface based on the condition parameters in the query statement, the obtained input parameter data of the data persistence layer interface is very accurate. Attached Figure Description
[0024] Figure 1 This diagram illustrates how the DAO layer interface interacts with SQL statements in the XML mapping file.
[0025] Figure 2 A schematic diagram of an application environment for the method of generating data persistence layer input parameters based on query statements according to the present invention is shown.
[0026] Figure 3 A flowchart illustrating the method for generating data persistence layer input parameters based on query statements according to the present invention.
[0027] Figure 4 A functional block diagram of the device for generating data persistence layer input parameters based on query statements according to the present invention is shown.
[0028] Figure 5 A schematic diagram of an electronic device based on the query statement-based method for generating data persistence layer input parameters according to the present invention is shown. Detailed Implementation
[0029] The following specific examples illustrate the implementation of the present invention. Those skilled in the art can easily understand other advantages and effects of the present invention from the content disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and various details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of the present invention.
[0030] Please see Figure 1-5 It should be noted that the illustrations provided in this embodiment are only schematic representations of the basic concept of the present invention. Therefore, the drawings only show the components related to the present invention and are not drawn according to the actual number, shape and size of the components in the actual implementation. In the actual implementation, the form, quantity and proportion of each component can be arbitrarily changed, and the layout of the components may also be more complex.
[0031] like Figure 1 As shown, the current project code is all written in various DAO files within the DAO layer. Figure 1 The interfaces in the Java files UserDao.java, BranchDao.java, OrderDao.java, etc., are used to manipulate the various mapping files below. Figure 1 The SQL statements in XML files such as UserMapper.xml, BranchMapper.xml, and OrderMapper.xml. The main task of de-Oracle is to modify the SQL statements in the mapping files, changing the Oracle-related syntax to MySQL-related syntax. After the syntax modification is complete, the DAO file in the DAO layer that calls the SQL statements needs to be modified. Figure 1 The UserDao.java, BranchDao.java, and OrderDao.java files are used for verification.
[0032] Since the modification involves the lowest-level SQL statements, verification requires checking the interfaces in the DAO layer files. The SQL syntax modification is done by developers, while the verification of the DAO layer files is done by testers. Because each project has many DAO layer files, and each DAO layer file contains many interfaces, this makes it more cumbersome and difficult for testers to construct the input parameters for these interfaces, resulting in higher manual costs.
[0033] Based on this, embodiments of the present invention provide a method for generating data persistence layer input parameters based on query statements, which can be applied to applications such as... Figure 1The application environment shown is illustrated. The statement conversion plugin can convert query statements in the code into preset format files, which testers can use to test the data persistence layer interface. Specifically, the SQL-to-JSON plugin obtains the data persistence layer folder path and the mapping folder path; it reads all data access object files based on the data persistence layer folder path and all mapping files based on the mapping folder path. Each data access object file includes at least one interface, and each mapping file includes at least one query statement. It obtains the interface information of all interfaces in each data access object file to obtain an interface information list, and obtains the statement information of all query statements in each mapping file to obtain a statement information list. It matches the interface information with the statement information to obtain the correspondence between the interface and the query statement. It parses each query statement, finds the parameter field corresponding to each target placeholder, and uses it as the parameter field of the corresponding query statement. It constructs the parameter field of each query statement into a preset format data, which serves as the input parameter data of the interface corresponding to the query statement. This conveniently obtains the input parameter data of the data persistence layer interface, saving testers the trouble of manually writing the input parameter data and reducing labor costs. Furthermore, this invention constructs the input parameter data of the data persistence layer interface based on the conditional parameters in the query statement, thus obtaining highly accurate input parameter data. Furthermore, the statement conversion plugin can merge the interface information and input parameter data of each interface with the statement information of the query statement corresponding to that interface into a whole, which serves as the interface input parameter file for that interface. It also saves all the interface input parameter files of the interfaces into a preset format file, which serves as the data persistence layer input parameter file. This allows for convenient testing of the data persistence layer interface using the data persistence layer input parameter file, greatly shortening the testing cycle.
[0034] In this embodiment, as Figure 2 As shown, the statement conversion plugin is SQL to JSON, the query statement can be an SQL statement, the preset format file can be a JSON file, the data persistence layer is a DAO layer, and the data access object file is a DAO file.
[0035] Please see Figure 3 As shown, Figure 3 This is a flowchart illustrating a method for generating data persistence layer input parameters based on a query statement, as provided in an embodiment of the present invention. The method for generating data persistence layer input parameters based on a query statement, according to an embodiment of the present invention, includes the following steps:
[0036] Step S10: Obtain the data persistence layer folder path and the mapping folder path;
[0037] Step S20: Read all data access object files according to the data persistence layer folder path, and read all mapping files according to the mapping folder path, wherein each data access object file includes at least one interface, and each mapping file includes at least one query statement;
[0038] Step S30: Obtain the interface information of all interfaces in each data access object file to obtain an interface information list; obtain the statement information of all query statements in each mapping file to obtain a statement information list.
[0039] Step S40: Match the interface information with the statement information to obtain the correspondence between the interface and the query statement;
[0040] Step S50: Parse each query statement and find the parameter field corresponding to each target placeholder, which is then used as the parameter field of the corresponding query statement;
[0041] Step S60: Construct the parameter fields of each query statement into data in a preset format, and use it as the input parameter data of the interface corresponding to the query statement;
[0042] Step S70: Combine the interface information and input parameter data of each interface with the statement information of the query statement corresponding to that interface into a whole, which is used as the interface input parameter file of that interface;
[0043] Step S80: Save the interface parameter files of all the interfaces into a preset format file as the data persistence layer parameter file.
[0044] In this embodiment, the technical solution of the present invention will be described in detail using the statement conversion plugin as SQL to JSON, the query statement as SQL statement, the preset format file as JSON file, the data persistence layer as DAO layer, and the data access object file as DAO file.
[0045] First, perform step S10: obtain the data persistence layer folder path and the mapping folder path. In this embodiment, the data persistence layer can be a DAO layer, the mapping file is an XML file, the data persistence layer folder path is the DAO layer folder path, and the mapping folder path is the XML folder path.
[0046] Please see Figure 1 , Figure 1The middle DAO layer includes different Java files (defined as DAO files) such as UserDao.java, BranchDao.java, and OrderDao.java. Each DAO layer folder path refers to the disk folder path (also called a directory) for these DAO files. The DAO layer folder path can include different disk folder paths, but generally includes one or two.
[0047] Continue reading Figure 1 Each DAO file corresponds to an XML file (defined as a mapping file). The mapping folder path refers to the disk folder path of XML files such as UserMapper.xml, BranchMapper.xml, and OrderMapper.xml. Similarly, the mapping folder path can include different disk folder paths, but generally includes one or two disk folder paths.
[0048] Next, step S20 is executed: all data access object files are read according to the data persistence layer folder path, and all mapping files are read according to the mapping folder path, wherein each data access object file includes at least one interface, and each mapping file includes at least one query statement.
[0049] Once the DAO layer folder path is obtained, all Java files can be read from the directory corresponding to the DAO layer folder path. Each Java file is recorded as a DAO file, and each DAO file includes at least one interface.
[0050] Similarly, after obtaining the mapping folder path, all XML files can be read from the directory corresponding to the mapping folder path. Each XML file is recorded as a mapping file, and each mapping file includes at least one SQL statement interface.
[0051] Next, step S30 is executed: obtain the interface information of all interfaces in each data access object file to obtain an interface information list, and obtain the statement information of all query statements in each mapping file to obtain a statement information list.
[0052] Since the DAO file contains interfaces, it is easy to read the interface information of all interfaces from the DAO file, thus obtaining an interface information list. Similarly, since the mapping file contains SQL statements, it is easy to read the SQL information (defined as statement information) of all SQL statements from the mapping file, thus obtaining an SQL information list (defined as a statement information list).
[0053] In one specific embodiment, the interface information includes the interface class name and the interface method name, and the SQL information includes the file name of the SQL statement (defined as the file name of the statement) and the SQL identifier (defined as the statement identifier). The step of obtaining the interface information of all interfaces in each DAO file to obtain an interface information list, and obtaining the SQL information of all SQL statements in each mapping file to obtain an SQL information list, may further include: obtaining the interface class name and interface method name of all interfaces in each DAO file as the interface information of the corresponding interfaces to obtain the interface information list; and obtaining the file name of the SQL statement and the SQL identifier of all SQL statements in each mapping file as the SQL information of the corresponding SQL statements to obtain the SQL information list.
[0054] As an example, in a DAO file
[0055] The interface class name is: com.pinganfu.fcscgw.common.dal.dao.ConfigDAO;
[0056] The interface method name is: Integer replaceDataByPK(ConfigDO configDO).
[0057] in,
[0058]
[0059]
[0060] The corresponding SQL statement for this interface is as follows:
[0061]
[0062] In the SQL statement above, the namespace value is read as the filename of the SQL statement, which is: com.pinganfu.fcscgw.common.dal.dao.ConfigDAO; the id value is read as the SQL identifier, which is: replaceDataByPK. It can be seen that the interface class name is the same as the filename of the SQL statement, and the interface method name is the same as the identifier of the SQL statement.
[0063] Next, step S40 is executed: the interface information is matched with the statement information to obtain the correspondence between the interface and the query statement.
[0064] In an exemplary embodiment, step S40 further includes: for each interface, finding in the statement information list the statement file name that matches the interface class name in the interface information of the interface and the statement identifier that matches the interface method name in the interface information of the interface, and establishing a correspondence between the query statement corresponding to the found statement information and the interface.
[0065] Following the example above, since the interface class name is the same as the filename of the corresponding SQL statement, and the interface method name is the same as the SQL identifier of the corresponding SQL statement, a correspondence between interfaces and SQL statements can be established. Specifically, for each interface, the SQL information whose filename matches the interface class name in the interface information and whose SQL identifier matches the interface method name in the interface information is found in the SQL information list. The SQL statement corresponding to the found SQL information is then associated with that interface.
[0066] Next, step S50 is executed: each query statement is parsed to find the parameter field corresponding to each target placeholder, which is then used as the parameter field of the corresponding query statement.
[0067] In an exemplary embodiment, step S50 further includes: parsing each of the query statements to find all the target placeholders in the query statements; and obtaining the parameter field associated with each target placeholder through an operator as the parameter field of the corresponding query statement.
[0068] In this embodiment, the target placeholder includes a "?" sign. Parsing each SQL statement to find the parameter field corresponding to each target placeholder, and using it as the parameter field of the corresponding SQL statement, may further include: parsing each SQL statement to find all "?" signs in the SQL statement; obtaining the parameter field associated with each "?" sign through an operator, and using it as the parameter field of the corresponding SQL statement. The operator can be, for example, equals sign "=", not equals sign "<>", greater than sign ">", less than sign "<", greater than or equal to sign ">=", less than or equal to sign "<=", etc.
[0069] Using the SQL statement from the example above, we can first find all the question marks (?) in the SQL statement and then obtain the parameter fields associated with each question mark by the operator. These fields are "CONFIG_KEY", "CONFIG_VALUE", "CONFIG_DESC", "EXT_FIELD", "STATUS", "UPDATOR", and "ID". Converting these parameter fields to camelCase, they are "configKey", "configValue", "configDesc", "extField", "status", "updator", and "id".
[0070] Next, step S60 is executed: the parameter fields of each query statement are constructed into data in a preset format, which are used as the input parameter data of the interface corresponding to the query statement.
[0071] Specifically, the preset format is JSON format. Therefore, constructing the parameter fields of each SQL statement into preset format data and using them as input parameter data of the interface corresponding to the SQL statement may specifically include constructing the parameter fields of each SQL statement into JSON format data and using them as input parameter data of the interface corresponding to the SQL statement.
[0072] Continuing with the example above, the obtained parameter fields such as "configKey", "configValue", "configDesc", "extField", "status", "updator", and "id" can be converted into JSON data in the following format:
[0073] {
[0074] "configKey":"xxx",
[0075] "configValue": "xxx",
[0076] "configDesc":"xxx",
[0077] "extField": "xxx",
[0078] "status": "xxx",
[0079] "updator": "xxx",
[0080] "id": "xxx"
[0081] }
[0082] Testers can then obtain this JSON-formatted data to request the corresponding DAO layer interface for the SQL statement.
[0083] Since the input parameter data is constructed based on the parameter fields (condition parameters) in the SQL statement, the input parameter data of the DAO layer interface obtained is very accurate.
[0084] Next, step S70 is executed: the interface information and input parameter data of each interface are merged with the statement information of the query statement corresponding to that interface into a whole, which serves as the interface input parameter file for that interface. Thus, through the interface input parameter file of one interface, interface information, SQL information, and JSON-formatted input parameter data can be obtained.
[0085] Finally, execute step S80: save the interface parameter files of all the interfaces into a preset format file as the data persistence layer parameter file.
[0086] Since the entire DAO layer contains many DAO files, and each DAO file includes at least one interface, the DAO layer input parameter file includes the input parameters of all interfaces in the DAO layer. Therefore, it is convenient to use the DAO layer input parameter file to perform DAO layer interface testing, which greatly shortens the testing cycle.
[0087] It should be noted that the steps of the various methods described above are only for clarity. In practice, they can be combined into one step or some steps can be split into multiple steps. As long as they contain the same logical relationship, they are all within the scope of protection of this patent. Adding insignificant modifications or introducing insignificant designs to the algorithm or process, but without changing the core design of the algorithm and process, are also within the scope of protection of this patent.
[0088] In summary, the method for generating data persistence layer input parameters based on query statements of the present invention obtains the data persistence layer folder path and the mapping folder path; reads all data access object files according to the data persistence layer folder path and all mapping files according to the mapping folder path, wherein each data access object file includes at least one interface and each mapping file includes at least one query statement; obtains the interface information of all interfaces in each data access object file to obtain an interface information list, and obtains the statement information of all query statements in each mapping file to obtain a statement information list; matches the interface information with the statement information to obtain the correspondence between the interface and the query statement; parses each query statement to find the parameter field corresponding to each target placeholder, and uses it as the parameter field of the corresponding query statement; constructs the parameter field of each query statement into a preset format data, which serves as the input parameter data of the interface corresponding to the query statement. This method conveniently obtains the input parameter data of the data persistence layer interface, saving testers the trouble of manually writing the data persistence layer interface input parameter data and reducing labor costs.
[0089] The method for generating data persistence layer input parameters based on query statements in this invention constructs the input parameter data of the DAO layer interface according to the condition parameters in the SQL statement, thus obtaining very accurate input parameter data of the DAO layer interface.
[0090] The present invention provides a method for generating data persistence layer input parameters based on query statements. It merges the interface information and input parameter data of each interface with the SQL information of the corresponding SQL statement into a whole, which serves as the interface input parameter file of that interface. All interface input parameter files are saved into a preset format file as the DAO layer input parameter file. This allows for convenient use of the DAO layer input parameter file for DAO layer interface testing, greatly shortening the testing cycle.
[0091] Figure 4 This is a functional module diagram of a data persistence layer input parameter generation device 11 based on query statements provided in an embodiment of the present invention. Please refer to... Figure 5 As shown, the device 11 for generating persistent data input parameters based on query statements includes a path acquisition module 111, a file reading module 112, an information list acquisition module 113, an information matching module 114, a parameter field acquisition module 115, an input parameter data construction module 116, an interface input parameter file acquisition module 117, and a DAO layer input parameter file acquisition module 118.
[0092] The path acquisition module 111 is used to acquire the data persistence layer folder path and the mapping folder path. In this embodiment, the data persistence layer can be a DAO layer, the mapping file is an XML file, the data persistence layer folder path is the DAO layer folder path, and the DAO layer folder path is the disk folder path of the DAO file in the DAO layer; the mapping folder path is the XML folder path, and the XML folder path is the disk folder path of the XML file.
[0093] The file reading module 112 is used to read all data access object files according to the data persistence layer folder path and to read all mapping files according to the mapping folder path, wherein each data access object file includes at least one interface and each mapping file includes at least one query statement.
[0094] After obtaining the DAO layer folder path, the file reading module 112 can read all Java files from the directory corresponding to the DAO layer folder path. Each Java file is recorded as a DAO file, and each DAO file includes at least one interface.
[0095] Similarly, after the path acquisition module 111 obtains the mapped folder path, the file reading module 112 can read all XML files from the directory corresponding to the mapped folder path. Each XML file is recorded as a mapped file, and each mapped file includes at least one SQL statement interface.
[0096] The information list acquisition module 113 is used to acquire the interface information of all interfaces in each data access object file to obtain an interface information list, and to acquire the statement information of all query statements in each mapping file to obtain a statement information list.
[0097] Since the DAO file contains interfaces, it is easy to read the interface information of all interfaces from the DAO file, thus obtaining an interface information list. Similarly, since the mapping file contains SQL statements, it is easy to read the SQL information (defined as statement information) of all SQL statements from the mapping file, thus obtaining an SQL information list (defined as a statement information list).
[0098] In one specific embodiment, the interface information includes the interface class name and the interface method name, and the SQL information includes the file name of the SQL statement (defined as the file name of the statement) and the SQL identifier (defined as the statement identifier). The step of obtaining the interface information of all interfaces in each DAO file to obtain an interface information list, and obtaining the SQL information of all SQL statements in each mapping file to obtain an SQL information list, may further include: obtaining the interface class name and interface method name of all interfaces in each DAO file as the interface information of the corresponding interfaces to obtain the interface information list; and obtaining the file name of the SQL statement and the SQL identifier of all SQL statements in each mapping file as the SQL information of the corresponding SQL statements to obtain the SQL information list.
[0099] As an example, in a DAO file
[0100] The interface class name is: com.pinganfu.fcscgw.common.dal.dao.ConfigDAO;
[0101] The interface method name is: Integer replaceDataByPK(ConfigDO configDO).
[0102] in,
[0103]
[0104]
[0105] The corresponding SQL statement for this interface is as follows:
[0106]
[0107] In the SQL statement above, the namespace value is read as the filename of the SQL statement, which is: com.pinganfu.fcscgw.common.dal.dao.ConfigDAO; the id value is read as the SQL identifier, which is: replaceDataByPK. It can be seen that the interface class name is the same as the filename of the SQL statement, and the interface method name is the same as the identifier of the SQL statement.
[0108] The information matching module 114 is used to match the interface information with the statement information to obtain the correspondence between the interface and the query statement.
[0109] In an exemplary embodiment, for each interface, the information matching module 114 searches the statement information list for statement information whose file name matches the interface class name in the interface information of that interface and whose statement identifier matches the interface method name in the interface information of that interface, and establishes a correspondence between the query statement corresponding to the found statement information and the interface.
[0110] Following the example above, since the interface class name is the same as the filename of the corresponding SQL statement, and the interface method name is the same as the SQL identifier of the corresponding SQL statement, a correspondence between the interface and the SQL statement can be established. Specifically, for each interface, the information matching module 114 searches the SQL information list for SQL information where the filename of the SQL statement matches the interface class name in the interface information of that interface, and the SQL identifier matches the interface method name in the interface information of that interface. The module then establishes a correspondence between the SQL statement corresponding to the found SQL information and the interface.
[0111] The parameter field acquisition module 115 is used to parse each query statement and find the parameter field corresponding to each target placeholder, which is then used as the parameter field of the corresponding query statement. In an exemplary embodiment, the parameter field acquisition module 115 first parses each query statement and finds all the target placeholders in the query statement; then, it acquires the parameter field associated with each target placeholder through an operator, which is then used as the parameter field of the corresponding query statement.
[0112] In this embodiment, the target placeholder includes a "?" sign. Parsing each SQL statement to find the parameter field corresponding to each target placeholder, and using it as the parameter field of the corresponding SQL statement, may further include: parsing each SQL statement to find all "?" signs in the SQL statement; obtaining the parameter field associated with each "?" sign through an operator, and using it as the parameter field of the corresponding SQL statement. The operator can be, for example, equals sign "=", not equals sign "<>", greater than sign ">", less than sign "<", greater than or equal to sign ">=", less than or equal to sign "<=", etc.
[0113] Using the SQL statement from the example above, we can first find all the question marks (?) in the SQL statement and then obtain the parameter fields associated with each question mark by the operator. These fields are "CONFIG_KEY", "CONFIG_VALUE", "CONFIG_DESC", "EXT_FIELD", "STATUS", "UPDATOR", and "ID". Converting these parameter fields to camelCase, they are "configKey", "configValue", "configDesc", "extField", "status", "updator", and "id".
[0114] The input parameter data construction module 116 is used to construct the parameter fields of each query statement into preset format data, which serves as the input parameter data of the interface corresponding to the query statement.
[0115] Specifically, the preset format is JSON format. Therefore, the input parameter data construction module 116 can be specifically used to construct the parameter fields of each SQL statement into JSON format data, which serves as the input parameter data of the interface corresponding to the SQL statement.
[0116] Continuing with the example above, the obtained parameter fields such as "configKey", "configValue", "configDesc", "extField", "status", "updator", and "id" can be converted into JSON data in the following format:
[0117] {
[0118] "configKey":"xxx",
[0119] "configValue": "xxx",
[0120] "configDesc":"xxx",
[0121] "extField": "xxx",
[0122] "status": "xxx",
[0123] "updator": "xxx",
[0124] "id": "xxx"
[0125] }
[0126] Testers can then obtain this JSON-formatted data to request the corresponding DAO layer interface for the SQL statement.
[0127] Since the input parameter data is constructed based on the parameter fields (condition parameters) in the SQL statement, the input parameter data of the DAO layer interface obtained is very accurate.
[0128] The interface parameter file acquisition module 117 is used to merge the interface information and input parameter data of each interface with the statement information of the query statement corresponding to that interface into a whole, which serves as the interface parameter file for that interface. Thus, through the interface parameter file of one interface, interface information, SQL information, and JSON-formatted input parameter data can be obtained.
[0129] The DAO layer input parameter file acquisition module 118 is used to save the interface input parameter files of all the interfaces into a preset format file as the data persistence layer input parameter file.
[0130] Since the entire DAO layer contains many DAO files, and each DAO file includes at least one interface, the DAO layer input parameter file includes the input parameters of all interfaces in the DAO layer. Therefore, it is convenient to use the DAO layer input parameter file to perform DAO layer interface testing, which greatly shortens the testing cycle.
[0131] It should be noted that the query-based data persistence layer input parameter generation device in this embodiment corresponds to the query-based data persistence layer input parameter generation method described above. The functional modules in the query-based data persistence layer input parameter generation device may correspond to the corresponding steps in the query-based data persistence layer input parameter generation method. The query-based data persistence layer input parameter generation device in this embodiment can be implemented in conjunction with the query-based data persistence layer input parameter generation method. Accordingly, the relevant technical details mentioned in the query-based data persistence layer input parameter generation device of this embodiment can also be applied to the query-based data persistence layer input parameter generation method described above.
[0132] It should be noted that the aforementioned functional modules can be fully or partially integrated into a single physical entity, or they can be physically separated. Furthermore, these modules can be implemented entirely in software via processing element calls; they can be fully implemented in hardware; or some modules can be implemented by processing element calls to software, while others are implemented in hardware. Additionally, these modules can be fully or partially integrated together, or implemented independently. The processing element mentioned here can be an integrated circuit with signal processing capabilities. In the implementation process, some or all of the steps of the above method, or the aforementioned functional modules, can be completed through integrated logic circuits in the hardware of the processor element or through software instructions.
[0133] In summary, the data persistence layer input parameter generation device based on query statements of the present invention obtains the data persistence layer folder path and the mapping folder path; reads all data access object files according to the data persistence layer folder path and all mapping files according to the mapping folder path, wherein each data access object file includes at least one interface and each mapping file includes at least one query statement; obtains the interface information of all interfaces in each data access object file to obtain an interface information list, and obtains the statement information of all query statements in each mapping file to obtain a statement information list; matches the interface information with the statement information to obtain the correspondence between the interface and the query statement; parses each query statement to find the parameter field corresponding to each target placeholder, and uses it as the parameter field of the corresponding query statement; constructs the parameter field of each query statement into a preset format data, which serves as the input parameter data of the interface corresponding to the query statement. This method conveniently obtains the input parameter data of the data persistence layer interface, saving testers the trouble of manually writing the data persistence layer interface input parameter data and reducing labor costs.
[0134] The device for generating data persistence layer input parameters based on query statements of the present invention constructs input parameter data of DAO layer interface according to the condition parameters in SQL statement, thus obtaining very accurate input parameter data of DAO layer interface.
[0135] The present invention provides a data persistence layer input parameter generation device based on query statements. It merges the interface information and input parameter data of each interface with the SQL information of the corresponding SQL statement into a whole, which serves as the interface input parameter file of that interface. It also saves all the interface input parameter files of the interfaces into a preset format file, which serves as the DAO layer input parameter file. This allows for convenient use of the DAO layer input parameter file to perform DAO layer interface testing, greatly shortening the testing cycle.
[0136] like Figure 5 The diagram shown is a structural schematic of an electronic device that implements the method for generating data persistence layer input parameters based on query statements according to the present invention.
[0137] The electronic device 1 may include a memory 12, a processor 13 and a bus, and may also include a computer program stored in the memory 12 and capable of running on the processor 13, such as a program for generating data persistence layer input parameters based on query statements.
[0138] The memory 12 includes at least one type of readable storage medium, such as flash memory, portable hard drive, multimedia card, card-type memory (e.g., SD or DX memory), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, the memory 12 can be an internal storage unit of the electronic device 1, such as a portable hard drive. In other embodiments, the memory 12 can be an external storage device of the electronic device 1, such as a plug-in portable hard drive, smart media card (SMC), secure digital (SD) card, flash card, etc., equipped on the electronic device 1. Furthermore, the memory 12 can include both internal and external storage units of the electronic device 1. The memory 12 can be used not only to store application software and various types of data installed on the electronic device 1, such as code for generating persistent data layer input parameters based on query statements, but also to temporarily store data that has been output or will be output.
[0139] In some embodiments, the processor 13 may be composed of integrated circuits, such as a single packaged integrated circuit or multiple integrated circuits with the same or different functions, including combinations of one or more central processing units (CPUs), microprocessors, digital processing chips, graphics processors, and various control chips. The processor 13 is the control unit of the electronic device 1, connecting various components of the electronic device 1 through various interfaces and lines. It executes programs or modules stored in the memory 12 (e.g., programs for generating persistent data layer input parameters based on query statements) and calls data stored in the memory 12 to perform various functions and process data in the electronic device 1.
[0140] The processor 13 executes the operating system of the electronic device 1 and various installed applications. The processor 13 executes these applications to implement the steps in the above-described method for generating data persistence layer input parameters based on query statements, for example... Figure 3 The steps are shown.
[0141] For example, the computer program can be divided into one or more modules, which are stored in the memory 12 and executed by the processor 13 to complete the present invention. The one or more modules can be a series of computer program instruction segments capable of performing specific functions, which describe the execution process of the computer program in the electronic device 1. For example, the computer program can be divided into a path acquisition module 111, a file reading module 112, an information list acquisition module 113, an information matching module 114, a parameter field acquisition module 115, an input parameter data construction module 116, an interface input parameter file acquisition module 117, and a DAO layer input parameter file acquisition module 118.
[0142] The integrated unit implemented as a software functional module described above can be stored in a computer-readable storage medium, which can be non-volatile or volatile. The software functional module stored in the storage medium includes several instructions to cause a computer device (which may be a personal computer, computer equipment, or network device, etc.) or processor to execute some functions of the data persistence layer input parameter generation method based on query statements described in various embodiments of the present invention.
[0143] The present invention provides a method for generating data persistence layer input parameters based on query statements. This method involves: obtaining the DAO layer folder path and the mapping folder path; reading all DAO files according to the DAO layer folder path and all mapping files according to the mapping folder path, wherein each DAO file includes at least one interface and each mapping file includes at least one SQL statement; obtaining the interface information of all interfaces in each DAO file to obtain an interface information list, and obtaining the SQL information of all SQL statements in each mapping file to obtain an SQL information list; matching the interface information with the SQL information to obtain the correspondence between the interface and the SQL statement; parsing each SQL statement to find the parameter field corresponding to each target placeholder, which is then used as the parameter field of the corresponding SQL statement; and constructing the parameter field of each SQL statement into preset format data as the input parameter data of the interface corresponding to the SQL statement. This method conveniently obtains the input parameter data of the DAO layer interface, eliminating the need for testers to manually write the DAO layer interface input parameter data and saving manpower costs.
[0144] The present invention provides a method, apparatus, device, and medium for generating data persistence layer input parameters based on query statements. It constructs the input parameter data of the DAO layer interface based on the conditional parameters in the SQL statement, thus obtaining highly accurate input parameter data of the DAO layer interface.
[0145] The present invention provides a method, apparatus, device, and medium for generating persistent data layer input parameters based on query statements. It merges the interface information and input parameter data of each interface with the SQL information of the corresponding SQL statement into a single whole, serving as the interface input parameter file for that interface. All interface input parameter files are then saved into a preset format file as the DAO layer input parameter file. This allows for convenient use of the DAO layer input parameter file for DAO layer interface testing, significantly shortening the testing cycle.
[0146] It will be apparent to those skilled in the art that the present invention is not limited to the details of the exemplary embodiments described above, and that the present invention can be implemented in other specific forms without departing from the spirit or essential characteristics of the present invention.
[0147] The above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit it. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention.
Claims
1. A method for generating data persistence layer input parameters based on query statements, characterized in that, include: Get the data persistence layer folder path and the mapped folder path; All data access object files are read according to the data persistence layer folder path, and all mapping files are read according to the mapping folder path, wherein each data access object file includes at least one interface, and each mapping file includes at least one query statement; Obtain the interface information of all interfaces in each of the data access object files to obtain an interface information list; obtain the statement information of all query statements in each of the mapping files to obtain a statement information list. The interface information and the statement information are matched to obtain the correspondence between the interface and the query statement. The interface class name of the interface is the same as the file name of the corresponding query statement, and the interface method name of the interface is the same as the statement identifier of the corresponding query statement. For each interface, the statement information whose file name matches the interface class name in the interface information and whose statement identifier matches the interface method name in the interface information is found in the statement information list. The query statement corresponding to the found statement information is then matched with the interface. Each query statement is parsed to find the parameter field corresponding to each target placeholder, which is then used as the parameter field of the corresponding query statement. The parameter fields of each query statement are constructed into data in a preset format and used as the input parameter data of the interface corresponding to the query statement.
2. The method for generating data persistence layer input parameters based on query statements according to claim 1, characterized in that, The step of obtaining interface information for all interfaces in each data access object file to obtain an interface information list, and obtaining statement information for all query statements in each mapping file to obtain a statement information list, specifically includes: Obtain the interface class name and interface method name of all interfaces in each data access object file as the interface information of the corresponding interface to obtain the interface information list. Obtain the filename and statement identifier of all query statements in each of the mapping files, and use them as the statement information for the corresponding query statements to obtain the statement information list.
3. The method for generating data persistence layer input parameters based on query statements according to claim 1, characterized in that, The step of parsing each query statement to find the parameter field corresponding to each target placeholder, and using it as the parameter field of the corresponding query statement, specifically includes: Parse each query statement to find all the target placeholders in the query statement; Obtain the parameter field associated with each of the target placeholders through an operator, and use it as the parameter field of the corresponding query statement.
4. The method for generating data persistence layer input parameters based on query statements according to claim 1, characterized in that, The step of constructing the parameter fields of each query statement into data in a preset format, and using it as the input parameter data of the interface corresponding to the query statement, specifically includes: The parameter fields of each query statement are constructed into JSON format data and used as the input parameter data of the interface corresponding to the query statement.
5. The method for generating data persistence layer input parameters based on query statements according to claim 1, characterized in that, Also includes: The interface information and input parameter data of each interface are combined with the statement information of the query statement corresponding to that interface into a whole, which is used as the interface input parameter file of that interface.
6. The method for generating data persistence layer input parameters based on query statements according to claim 5, characterized in that, Also includes: All the interface parameter files are saved into a preset format file and used as the data persistence layer parameter file.
7. A device for generating data persistence layer input parameters based on query statements, characterized in that, include: The path acquisition module is used to obtain the data persistence layer folder path and the mapped folder path; The file reading module is used to read all data access object files according to the data persistence layer folder path and all mapping files according to the mapping folder path, wherein each data access object file includes at least one interface and each mapping file includes at least one query statement; The information list acquisition module is used to acquire the interface information of all interfaces in each data access object file to obtain an interface information list, and to acquire the statement information of all query statements in each mapping file to obtain a statement information list. The information matching module is used to match the interface information with the statement information to obtain the correspondence between the interface and the query statement. The interface class name of the interface is the same as the file name of the corresponding query statement, and the interface method name of the interface is the same as the statement identifier of the corresponding query statement. For each interface, the module searches the statement information list for statements whose file name matches the interface class name in the interface information and whose statement identifier matches the interface method name in the interface information. The module then establishes a correspondence between the query statement corresponding to the found statement information and the interface. The parameter field acquisition module is used to parse each of the query statements, find the parameter field corresponding to each target placeholder, and use it as the parameter field of the corresponding query statement. The input parameter data construction module is used to construct the parameter fields of each query statement into data in a preset format, which serves as the input parameter data of the interface corresponding to the query statement.
8. An electronic device, characterized in that, The method includes a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that the processor, when executing the computer program, implements the steps of the method according to any one of claims 1 to 6.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 6.
Citation Information
Patent Citations
SQL statement analysis method and device, computer equipment and storage medium
CN114296734A
System and method for communicating with a structured query language statement generator
US20060041584A1