A large model-based database mapping file conversion method and system
By using an automated approach based on large models, the problem of low efficiency in manually converting SQL statements during MyBatis framework database migration was solved, achieving efficient and accurate database syntax conversion and ensuring that the project runs normally in the target database.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-14
- Publication Date
- 2026-03-17
AI Technical Summary
During database migration, manually converting the SQL statements of the MyBatis framework to different database syntax is labor-intensive, inefficient, and prone to errors, affecting project progress and system stability.
The method adopts a large model-based approach, recursively traversing the files under the project path, using the natural language processing capabilities of the large model to construct target prompt words, automatically converting SQL statements into target database syntax, and generating adapted database mapping files.
It improves the efficiency and accuracy of database adaptation and conversion, reduces manual intervention, and ensures that the project can interact and run normally after database migration.
Smart Images

Figure CN120631967B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of database technology, and in particular to a method and system for converting database mapping files based on a large model. Background Technology
[0002] In the current development of information technology, with the promotion and application of diversified databases and the security requirements of wireless communication private networks, many projects that use traditional databases need to be adapted and modified to achieve database localization.
[0003] For Java projects using the MyBatis framework, their code files contain numerous SQL statements that interact with the database, and different databases have different syntaxes. This means that when migrating the project to a different database, it is necessary to manually convert the SQL statements in these files into syntax that is compatible with other diverse databases.
[0004] Manual conversion is a labor-intensive and error-prone method, with problems such as low conversion efficiency and poor code compatibility after conversion. It is difficult to complete the conversion task efficiently and accurately, which seriously affects the progress of the project and the stability of the application system. Summary of the Invention
[0005] This application provides a method and system for converting database mapping files based on a large model, in order to solve the problems of low accuracy and efficiency in database code conversion.
[0006] In a first aspect, embodiments of this application provide a database mapping file conversion method based on a large model. The method includes: recursively traversing files under the target project path to obtain a file path list of files to be converted; wherein, the file path list consists of M source file paths of files to be converted that conform to the mapping file naming rules, the mapping file naming rules including: the file name contains a preset keyword and the extension is a preset extension; and executing the following steps S1-S5 in a loop according to the path order in the file path list: S1: reading the content of the Nth file to be converted based on the file path list, 1≤N≤M; S2: constructing target prompt words based on the read content of the file to be converted, and displaying the target prompt words. The input of keywords and the content of the file to be converted is fed into the large model; among them, the target prompt keywords are used to guide the large model to convert the SQL statements in the content of the file to be converted into target statements that conform to the target syntax, so as to obtain the content to be written in the preset format; the target syntax is the syntax corresponding to the target database; the preset format refers to the format corresponding to the preset file extension; S3: parse the output result of the large model to obtain the content to be written in the preset format; S4: generate the output path based on the target project path, the preset root path and the source file path; among them, the source file path is the file path of the Nth file to be converted; S5: write the content to be written into the target file under the output path to obtain the database mapping file adapted to the target database.
[0007] In one possible implementation, the files under the target project path are recursively traversed to obtain a list of file paths, including: recursively traversing the files under the target project path to determine M files to be converted that conform to the mapping file naming rules; and sequentially obtaining the source file path of each file to be converted to generate a list of file paths.
[0008] In one possible implementation, the content of the Nth file to be converted is read based on the file path list, including: traversing the file path list to determine the Nth file to be converted; and converting the byte data in the Nth file to be converted into a text string based on a preset character encoding rule to obtain the content of the Nth file to be converted.
[0009] In one possible implementation, a target prompt word is constructed based on the read content of the file to be converted, and the target prompt word and the content of the file to be converted are input into a large model. This includes: matching the type identifier of the target database in a prompt word template library to obtain the target prompt word template corresponding to the target database; the target prompt word template is also used to: guide the output of the large model to ensure that the content of the file to be written does not contain any explanation; insert the read content of the file to be converted into the target prompt word template to obtain the target prompt word.
[0010] In one possible implementation, after inserting the read content of the file to be converted into the target prompt word template to obtain the target prompt word, the process further includes: constructing the request header and request body of a POST request; wherein, the data format field in the request header is application / json, and the data format field is used to define the data format of the request body; the authentication field in the request header contains the API key of the large model; the request body includes the target prompt word; and a connection is established with the API of the large model through a POST request to input the target prompt word into the large model via the POST request.
[0011] In one possible implementation, an output path is generated based on the target project path, a preset root path, and the source file path, including: extracting the relative path between the source file path and the target project path; and concatenating the preset root path and the relative path to obtain the output path.
[0012] In one possible implementation, the content of the file to be written is written to a target file under the output path to obtain a database mapping file adapted to the target database. This includes: determining whether the output directory corresponding to the output path exists; if the output directory corresponding to the output path does not exist, creating the output directory based on the output path; if the output directory corresponding to the output path exists, creating a target file based on the output directory, and writing the content of the file to be written to the target file according to a preset character encoding rule to obtain a database mapping file adapted to the target database.
[0013] In one possible implementation, the method further includes: generating a configuration file in response to user actions; the user actions include configuring the API key for calling the large model, configuring the type of the target database, the target project path, and the preset root path; before recursively traversing the files under the target project path to obtain a list of file paths to be converted, the method further includes: obtaining the API key, the type identifier of the target database, the target project path, and the preset root path from the configuration file.
[0014] In one possible implementation, the default keywords include: mapper, dao, and the default extension is xml.
[0015] Secondly, this application also provides a database mapping file conversion system based on a large model. The system includes: a file scanning module configured to recursively traverse the files under the target project path to obtain a list of file paths to be converted; wherein the file path list consists of M source file paths of the files to be converted that conform to the mapping file naming rules, the mapping file naming rules including: the file name contains a preset keyword and the extension is a preset extension; a control module configured to control the content reading module, AI interaction module, and file generation module to cyclically execute steps S1-S5 according to the path order in the file path list; the content reading module is configured to execute step S1: read the content of the Nth file to be converted based on the file path list, 1≤N≤M; the AI interaction module is configured to execute step S2: construct a database mapping file based on the read content of the file to be converted. The system creates target prompts and inputs them, along with the content of the file to be converted, into a large model. The target prompts guide the model to convert the SQL statements in the file content into target statements conforming to the target syntax, resulting in a pre-formatted file content to be written. The target syntax is the syntax corresponding to the target database. The pre-formatted format refers to the format corresponding to the pre-defined file extension. The AI interaction module is also configured to execute step S3: parsing the output of the large model to obtain the pre-formatted file content to be written. The file generation module is configured to execute step S4: generating an output path based on the target project path, the pre-defined root path, and the source file path. The source file path is the file path of the Nth file to be converted. The file generation module is also configured to execute step S5: writing the file content to be written into the target file under the output path, resulting in a database mapping file adapted to the target database.
[0016] As can be seen from the above, this application provides a database mapping file conversion method and system based on a large model. The method includes: recursively traversing the files under the target project path to obtain a file path list of files to be converted; wherein, the file path list consists of M source file paths of files to be converted that conform to the mapping file naming rules, the mapping file naming rules include: the file name contains a preset keyword, and the extension is a preset extension; according to the path order in the file path list, the following steps S1-S5 are executed cyclically: S1: read the content of the Nth file to be converted based on the file path list, 1≤N≤M; S2: construct target prompt words based on the read content of the file to be converted, and set the target prompt words to the target file path list. The input steps are as follows: S3: Input the target prompt words and the content of the file to be converted into the large model; S4: Analyze the output of the large model to obtain the content of the file to be converted in the preset format; S5: Generate the output path based on the target project path, the preset root path, and the source file path; S6: Write the content of the file to be converted into the target file under the output path to obtain the database mapping file adapted to the target database. In this way, the powerful natural language processing and data analysis capabilities of the large model can be used to achieve a deep understanding of complex SQL statements and business logic, thereby accurately determining the adapted database type and improving the efficiency and accuracy of database adaptation and conversion. Attached Figure Description
[0017] Figure 1 A schematic diagram of the structure of a first database mapping file conversion system based on a large model, provided for embodiments of this application;
[0018] Figure 2 A flowchart illustrating the database mapping file conversion method based on a large model provided in this application embodiment;
[0019] Figure 3 A schematic diagram of the interaction of the first module of the database mapping file conversion method based on a large model provided in this application embodiment;
[0020] Figure 4 A schematic diagram of the interaction of the second module of the database mapping file conversion method based on a large model provided in the embodiments of this application;
[0021] Figure 5 A schematic diagram illustrating the content writing process provided in this application embodiment;
[0022] Figure 6This is a schematic diagram of the structure of a second database mapping file conversion system based on a large model, provided in an embodiment of this application. Detailed Implementation
[0023] To enable those skilled in the art to better understand the technical solutions in this application, the technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments in this application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of this application.
[0024] Before introducing the technical solutions of the embodiments of this application, the terminology involved in the embodiments of this application will be introduced by way of example.
[0025] 1. Java project: refers to a software application or system developed using the Java programming language and related technology stack (such as frameworks, tools, etc.).
[0026] 2. MyBatis Framework: This is a database operation framework. The MyBatis framework maps Structured Query Language (SQL) statements to Java objects. Developers can easily store Java objects in the database and retrieve data from the database, converting it back into Java objects.
[0027] 3. Mapper mapping file (or Mapper.xml file): This is an XML file and the core configuration file of the MyBatis framework. It is used to define SQL statements, parameter mapping rules, and result set mapping rules. It is the bridge connecting Java interface methods and database operations, associating Java methods with SQL statements to achieve data persistence operations.
[0028] 4. SQL statements: These are the standard language used to interact with databases and perform various database operations, such as data querying, inserting, updating, deleting, and creating and modifying database structures.
[0029] To address the difficulty of code conversion during database migration, this application provides a database mapping file conversion method and system based on a large model. This method and system can leverage the powerful natural language processing and data analysis capabilities of the large model to achieve a deep understanding of complex SQL statements and business logic, thereby accurately determining the appropriate database type.
[0030] Figure 1This is a schematic diagram of the structure of a first database mapping file conversion system based on a large model, provided in an embodiment of this application.
[0031] like Figure 1 As shown, embodiments of this application can provide a database mapping file conversion system based on a large model. This system may include a first control module 1001, a configuration management module 1002, a first file scanning module 1003, a first content reading module 1004, a first AI interaction module 1005, and a first file generation module 1006. The first AI interaction module 1005 may include a prompt word construction unit 1005a, an API call unit 1005b, and a result parsing unit 1005c. The first file generation module 1006 may include a path generation unit 1006a and a content writing unit 1006b.
[0032] Furthermore, this system can be used to execute a database mapping file conversion method based on a large model to achieve the conversion of database code. The database mapping file conversion method based on a large model will be described in detail below with reference to the accompanying drawings.
[0033] Figure 2 This is a flowchart illustrating the database mapping file conversion method based on a large model provided in this application embodiment.
[0034] Figure 3 This is a schematic diagram of the interaction of the first module of the database mapping file conversion method based on a large model provided in the embodiments of this application.
[0035] like Figure 2 and Figure 3 As shown, the database mapping file conversion method based on a large model provided in this application embodiment may include the following steps S100-S200.
[0036] S100: Recursively traverse the files under the target project path to obtain a list of file paths of the files to be converted; where the list of file paths consists of M source file paths of the files to be converted that conform to the mapping file naming rules, including: the file name contains a preset keyword and the extension is a preset extension.
[0037] In this embodiment of the application, step S100 can be executed by the first file scanning module 1003 in response to the scheduling of the first control module 1001. After that, the first file scanning module 1003 can return a list of file paths to the first control module 1001.
[0038] Furthermore, the target project path is specified by the user, specifically the path to the target project. The target project can be a Java project based on the MyBatis framework. In the MyBatis framework, the mapping between Java objects and the database can be defined through mapping files (such as Mapper mapping files).
[0039] Each mapping file can define multiple SQL statements, and these SQL statements can be associated with Java interfaces (such as the Mapper interface) via an ID. The value of the ID is generally the name of the interface method, ensuring a one-to-one correspondence between the interface method and the SQL statement. Furthermore, each mapping file can correspond to one or more Java interfaces.
[0040] Furthermore, the mapping files are usually in XML format with the .xml extension, and the names are generally related to Mapper or Dao, such as UserMapper.xml or OrderDao.xml, in order to clearly identify their functions and uses.
[0041] In this embodiment, the preset keywords can be "mapper" or "dao," and the preset file extension can be "xml." Thus, this embodiment can recursively traverse to filter out all files in the target project path whose filenames contain "mapper" and have the ".xml" suffix. Mapper.xml file ( This indicates a wildcard character, and it filters out all files in the target project path whose filenames contain "dao" and have the ".xml" extension. Dao.xml file ( (Indicates wildcard).
[0042] It's worth noting that when filtering based on preset keywords, a case-insensitive approach can be used. This means ignoring capitalization differences in the keyword portion of the filename; as long as the letter composition matches the preset keyword, it's considered a valid file. For example, filenames like "UserMapper.xml" or "OrderDao.xml" will still be correctly filtered out even if the capitalization of the keyword portion doesn't perfectly match the preset keyword. This ensures comprehensiveness and accuracy in filtering, avoiding missing relevant files due to case sensitivity.
[0043] It should also be noted that recursive traversal refers to starting from the target project path and scanning each subfolder and its files according to the mapping file naming rules, until all files have been traversed. Then, M files that conform to the mapping file naming rules are selected as the files to be converted, and a list of file paths corresponding to these M files is output. It's understandable that the value of M depends on the file structure of the target project, and these M files to be converted are files with the .xml extension and filenames including "mapper" or "dao".
[0044] In this way, by filtering, all SQL mapping configuration files (i.e. files to be converted) of the target project can be selected.
[0045] S200: Execute the following steps S1-S5 in a loop according to the path order in the file path list.
[0046] Understandably, by iterating through the file paths, the system can sequentially access the files to be converted corresponding to each source file path in the file path list, and convert them accordingly, thus achieving mutual conversion between database syntax (or database dialects). The number of iterations equals the number of files to be converted.
[0047] S1: Read the content of the Nth file to be converted based on the file path list, where 1≤N≤M;
[0048] In this embodiment of the application, this step can be executed by the first content reading module 1004 in response to the scheduling of the first control module 1001.
[0049] Furthermore, after reading the content of the file to be converted, this embodiment can encapsulate it into a target format, such as JSON, which can be understood as a special string format. During the encapsulation process, this embodiment can use the content of the file to be converted as the corresponding value, forming a "key-value" correspondence, thereby constructing complete JSON data. The JSON format is concise, easy to read, and cross-platform, enabling large models to successfully receive and recognize the content of the file to be converted, preparing for subsequent statement conversion.
[0050] S2: Construct target prompts based on the read content of the file to be converted, and input the target prompts and the content of the file to be converted into the large model.
[0051] In this embodiment of the application, this step can be executed by the API calling unit 1005b in response to the scheduling of the first control module 1001.
[0052] The large model specifically refers to the Large Language Model (LLM), but the target database is not specifically limited in this embodiment of the application.
[0053] Furthermore, target prompts guide the large model to convert the SQL statements in the file content to be transformed into target statements that conform to the target syntax, resulting in the file content to be written in a preset format. Here, the target syntax is the syntax corresponding to the target database. The preset format refers to the format corresponding to the preset file extension. In other words, target prompts are used to output the file content to be written as XML format.
[0054] For example, one of the SQL statements for converting the content of the file to be converted could be:
[0055] SELECT id, name, age FROM user WHERE age>18 LIMIT 10;
[0056] This is a statement that conforms to MySQL database syntax. When the target database is DM database, this statement can be converted to the following statement:
[0057] SELECT id, name, age FROM user WHERE age>18 FETCH FIRST 10 ROWS ONLY;
[0058] In this example, the target prompt can guide the large model to identify the LIMIT clause in the original SQL statement and convert it into the FETCH FIRST 10 ROWS ONLY clause in the DM database to achieve the same query functionality.
[0059] In this way, the large model can be used to transform the SQL statements in the content of the file to be transformed, resulting in statements that conform to the syntax of the target database as expected by the user. For example, based on the solution of this application embodiment, the large model can be combined with the adaptation of domestic databases in the MyBatis framework Java project, breaking through the limitation of traditional database adaptation that only relies on rule matching. By utilizing the powerful natural language processing and data analysis capabilities of the large model, a deep understanding of complex SQL statements and business logic can be achieved, thereby accurately determining the adapted database type.
[0060] For example, constructing target prompts based on the read content of the file to be converted may include: matching each SQL statement in the file content with the corresponding SQL conversion rules, and adding the matched conversion rules to the target prompts. This avoids determining all SQL conversion rules corresponding to the target database as target prompts, thereby reducing the number of characters in the target prompts.
[0061] S3: Parse the output of the large model to obtain the content to be written to the file in the preset format.
[0062] In this embodiment of the application, this step can be executed by the result parsing unit 1005c in response to the scheduling of the first control module 1001, and the content of the file to be written can be returned to the first control module 1001.
[0063] It's worth noting here that target prompts can also guide large models to encapsulate the content to be written to a specific field, thus constraining the composition of the output. For example, target prompts can be used to guide large models to write the content to be written into the "result" field. Specifically:
[0064] Please put the converted XML content into the 'result' field, in JSON format: {"result":"[XML content]"}".
[0065] Furthermore, step S3 can parse specific fields in the output of the large model, such as the result field, to obtain the content of the file to be written in XML format.
[0066] In this way, the result parsing unit 1005c can receive the response result returned by the large model API and parse it. For example, the result parsing unit 1005c extracts the converted XML content based on the actual returned content of the large model API, providing the correct conversion result for subsequent file generation.
[0067] S4: Generate the output path based on the target project path, the preset root path, and the source file path; where the source file path is the file path of the Nth file to be converted.
[0068] In this embodiment of the application, this step can be executed by the path generation unit 1006a in response to the scheduling of the first control module 1001.
[0069] Furthermore, the preset root path is the root output location specified by the user. Then, in this embodiment, the specific output location, i.e., the output path, can be located based on the target project path, the preset root path, and the source file path. The specific method for generating the output path will be detailed below and will not be repeated here.
[0070] S5: Write the contents of the file to be written to the target file under the output path to obtain the database mapping file adapted to the target database.
[0071] In this embodiment, this step can be executed by the content writing unit 1006b in response to the scheduling of the first control module 1001. Furthermore, the target file can be an XML format file. The content writing unit 1006b can, provided that the directory corresponding to the output path exists, write the converted XML content parsed by the AI interaction module into the target file corresponding to the generated output path in UTF-8 encoding format, thus completing the generation of the converted file.
[0072] After S1-S5 are executed, the conversion of a single file (mapping file) can be completed. By repeatedly executing S1-S5, the conversion of all files (mapping files) related to the target project can be completed. The database mapping file adapted to the target database can be used to perform data persistence operations in the target database environment, realizing the mapping and data storage between Java objects and target database tables. This ensures that the project can interact with the database normally after migrating to a new database, enabling the target project to support multiple databases.
[0073] As can be seen from the above, this application provides a database mapping file conversion method based on a large model. The method includes: recursively traversing files under the target project path to obtain a list of file paths for files to be converted; wherein the file path list consists of M source file paths of files to be converted that conform to mapping file naming rules, including: filenames containing preset keywords and extensions containing preset extensions; and cyclically executing the following steps S1-S5 according to the path order in the file path list: S1: Reading the content of the Nth file to be converted based on the file path list, where 1≤N≤M; S2: Constructing target prompt words based on the read content of the file to be converted, and setting the target... The input steps are as follows: S3: Input prompts and the content of the file to be converted into a large model. The target prompts guide the model to convert the SQL statements in the file content into target statements that conform to the target syntax, resulting in a pre-formatted file content to be written. The target syntax is the syntax corresponding to the target database. The pre-formatted format refers to the format corresponding to the pre-defined file extension. S4: Parse the output of the large model to obtain the pre-formatted file content to be written. S5: Generate an output path based on the target project path, the pre-defined root path, and the source file path. The source file path is the file path of the Nth file to be converted. S6: Write the content to be written into the target file under the output path to obtain a database mapping file adapted to the target database. This leverages the powerful natural language processing and data analysis capabilities of the large model to achieve a deep understanding of complex SQL statements and business logic, thereby accurately determining the compatible database type and improving the efficiency and accuracy of database adaptation and conversion.
[0074] The following provides a more detailed explanation of each step.
[0075] See also Figure 3 Step S100 may include the following steps S101-S102.
[0076] S101: Recursively traverse the files under the target project path to determine M files to be converted that conform to the mapping file naming rules.
[0077] S102: Sequentially obtain the source file path of each file to be converted and generate a list of file paths.
[0078] In this way, the complete paths of the M files to be converted selected in S101 can be organized into an ordered list. This list of file paths will serve as input for subsequent processing, so that each file to be converted can be processed one by one.
[0079] See also Figure 3 Step S1 may include the following steps S11-S12.
[0080] S11: Traverse the list of file paths and determine the Nth file to be converted.
[0081] This application embodiment can locate the Nth file to be converted based on the source file path in the file path list, find and open the file to read its content. This step ensures that each file can be accessed in an orderly manner, avoiding chaos and omissions during file processing.
[0082] S12: Based on the preset character encoding rules, convert the byte data in the Nth file to be converted into a text string to obtain the content of the Nth file to be converted.
[0083] It is understood that the content of the file to be converted exists in the form of byte data during storage and transmission. In order to correctly read and process this data, the byte data must be converted into a text string according to character encoding rules. In the embodiments of this application, the preset encoding rule is, for example, UTF-8 encoding or UTF-16 encoding, and this embodiment of the application does not specifically limit it.
[0084] For example, if the file to be converted uses UTF-8 encoding, this embodiment of the application can parse each byte sequence in the file into the corresponding Unicode characters, thereby forming readable text content. The purpose of this is to ensure that the content of the file to be converted can be accurately parsed and understood by the large model, providing accurate content for subsequent conversion steps.
[0085] In some implementations, steps S11-S12 can be executed by the first content reading module 1004 in response to the scheduling of the first control module 1001. Afterwards, the first content reading module 1004 can return the file content to be converted to the first control module 1001.
[0086] See also Figure 3 Step S2 includes the following steps S21-S22.
[0087] S21: Match the target prompt word template in the prompt word template library based on the type identifier of the target database to obtain the target prompt word template corresponding to the target database.
[0088] The prompt word template library includes prompt word templates for various database types, such as MySQL, Oracle, SQL Server, DM Database, and Nanda General GBase. Furthermore, the prompt word templates are generated through multiple iterative tests. For certain special functions, specific conversion rules can be specified, allowing the large model to convert these special functions based on the preset rules. For example, for DM Database, the syntax for converting the DATE_ADD function to the DATEADD function can be specified. Additionally, the prompt word templates can reserve placeholders for inserting the content of the file to be converted, allowing for subsequent filling of the actual content.
[0089] It's worth noting that the target prompt word template is also used to guide the large model's output, ensuring the written file content contains no explanation. This reduces redundant information in the large model's output, speeds up processing, and, more importantly, alleviates the burden of parsing the output results. Furthermore, the written file content can be used directly.
[0090] In some implementations, the prompt word template can be modified based on actual needs.
[0091] S22: Insert the read content of the file to be converted into the target prompt word template to obtain the target prompt word.
[0092] In practical applications, the embodiments of this application can automatically identify placeholders in the prompt word template and accurately replace the placeholder parts using the content of the file to be converted read from the Nth file to be converted, thereby forming a complete and targeted prompt word. The prompt word contains both the conversion requirements of the target database and the actual SQL statement and file structure information to be converted.
[0093] In some implementations, steps S21-S22 can be executed by the prompt word construction unit 1005a in response to the scheduling of the first control module 1001. After that, the prompt word construction unit 1005a can return the target prompt word to the first control module 1001.
[0094] For example, the prompt word construction unit 1005a can be based on the target domestic database type and the read information. The Mapper.xml file contains the content of the file to be transformed, and targeted cue words are constructed. These cue words can clearly instruct the large model to... The SQL statements in the Mapper.xml file are converted from general syntax to syntax suitable for the target domestic database, and it is required that only the converted complete XML content be returned, without any interpretation.
[0095] Figure 4 This is a schematic diagram of the interaction of the second module of the database mapping file conversion method based on a large model provided in the embodiments of this application.
[0096] like Figure 4 As shown, step S22 may be followed by steps S23-S24.
[0097] S23: Construct the request header and request body of the POST request; wherein, the data format field in the request header is application / json, and the data format field is used to define the data format of the request body; the authentication field in the request header contains the API key of the large model; the request body includes the target prompt word.
[0098] Here, a POST request is an HTTP request using the POST method. The data format field in the request header can be named Content-Type, and if the data format field is set to "application / json", the target message can be sent to the large model API in JSON format. The authentication field can be named Authorization. The large model's API key can be configured by the user.
[0099] S24: Establish a connection with the API of the large model via a POST request to input the target prompt words into the large model via a POST request.
[0100] By sending a POST request to the large model API, the API can authenticate itself based on the API key carried in the POST request, thus establishing a connection with the large model API. Furthermore, by parsing the POST request, the large model can receive target prompts and perform SQL statement conversion tasks based on these prompts, generating adapted content to be written from the SQL statements of the file to be converted according to the target database's dialect rules.
[0101] In some implementations, steps S23-S24 can be executed by API calling unit 1005b in response to the scheduling of the first control module 1001.
[0102] For example, API call unit 1005b can send the constructed prompt to the large model API. Specifically, it can establish a connection with the large model API by setting relevant HTTP request attributes, such as request method as POST, content type as application / json, adding Authorization header information (containing the large model API key), etc., and send the prompt to the API in JSON format.
[0103] In some implementations, after receiving the output returned by the large model API, the API calling unit 1005b can send the output to the result parsing unit 1005c for parsing. Alternatively, the output can be saved to shared memory so that the result parsing unit 1005c can read the output from the shared memory.
[0104] See also Figure 4 Step S4 may include the following steps S41-S42.
[0105] S41: Extract the relative path between the source file path and the target project path.
[0106] For example, the target project path could be / home / user / projects / mybatis-mysql / , and the source file path could be / home / user / projects / mybatis-mysql / src / main / resources / mapper / UserMapper.xml. Then, by removing the target project path prefix from the source file path, we can obtain the relative path, which could be src / main / resources / mapper / UserMapper.xml.
[0107] S42: Concatenate the preset root path and relative path to obtain the output path.
[0108] The default root path is specified by the user, for example, / output / dm-migration / . After concatenation, the final output path is / output / dm-migration / src / main / resources / mapper / UserMapper.xml.
[0109] In some implementations, steps S23-S24 can be executed by the path generation unit 1006a in response to the scheduling of the first control module 1001. After that, the path generation unit 1006a can return the output path to the first control module 1001 and / or the content writing unit 1006b.
[0110] Figure 5 A schematic diagram illustrating the process of writing content provided in the embodiments of this application.
[0111] like Figure 4 and Figure 5 As shown, step S5 may include the following steps S51-S53.
[0112] S51: Determine if the output directory corresponding to the output path exists.
[0113] In this embodiment, the directory portion of the output path (i.e., the portion excluding filenames) can be extracted first, and then it can be determined whether the output directory exists.
[0114] For example, if the output path is / output / mapper / user / UserMapper.xml, then the corresponding output directory is / output / mapper / user. Further, step S51 can check if the / output / mapper / user directory exists. If it exists, the target file can be created directly in that directory and written; if it does not exist, the directory needs to be created first, and then the file can be written.
[0115] S52: If the output directory corresponding to the output path does not exist, create the output directory based on the output path.
[0116] In practical applications, output paths can be created recursively to include any missing intermediate directories. For example, if the output directory is / output / dm-migration / src / main / resources / mapper / , and the parent directory / output / dm-migration / src / does not exist, the parent directory will be automatically created, thus achieving layer-by-layer creation.
[0117] S53: If the output directory corresponding to the output path exists, create a target file based on the output directory, and write the content to be written to the target file according to the preset character encoding rules to obtain a database mapping file adapted to the target database.
[0118] It is understandable that after step S51, if the output directory corresponding to the output path exists, then step S53 can be executed directly. If the output directory corresponding to the output path does not exist, then step S52 should be executed first to create the output directory, and then S53 should be executed to finally complete the writing process.
[0119] Specifically, after confirming that the output directory corresponding to the output path exists, a new XML file can be created in that output directory. This file will be the final target file to be written. Then, the content to be written can be written to the target file according to a preset character encoding rule (such as UTF-8).
[0120] In some implementations, steps S51-S53 can be executed by the content writing unit 1006b in response to the scheduling of the first control module 1001. After the writing is completed, the content writing unit 1006b can return a writing completion message to the first control module 1001.
[0121] Steps S51-S53 complete the final conversion and storage of the content of the file to be converted. The generated database mapping file is fully compatible with the target database and can be used for subsequent database operations and project execution. The final generated database mapping file can also be called an SQL mapping configuration file.
[0122] Furthermore, embodiments of this application may also include a configuration step, which can be specifically implemented through interaction between the configuration management module 1002 and the user, specifically including the following steps S300. For example... Figure 3 As shown, step S300 can occur before step S100.
[0123] S300: In response to user actions, generate configuration files; user actions include configuring the API key for calling large models, configuring the type of target database, the target project path, and the preset root path.
[0124] In this embodiment of the application, the configuration management module 1002 can provide an interactive page, through which users can interact with the configuration management module 1002 to complete the configuration process.
[0125] It should also be noted that users can interact with the first control module 1001 to initiate the conversion task. In response to the start command, the control module can call upon modules such as the first file scanning module 1003 to run.
[0126] In some implementations, users can apply for API keys through the official platform of the large model.
[0127] Further details can be found by referring to [link / reference]. Figure 3 The step S400 may be included before step S100.
[0128] S400: Retrieves the API key, target database type identifier, target project path, and default root path from the configuration file.
[0129] Step S400 can be executed in response to the scheduling of the first control module 1001 via the configuration management module 1002. The configuration management module 1002 can return configuration parameters such as API key, target database type identifier, target project path, and preset root path to the first control module 1001.
[0130] For example, the configuration management module 1002 can configure and manage key parameters such as the large model API key, the target domestic database type, the project path, and the output path through configuration files. Users can easily modify these parameters according to their actual needs to adapt to different project conversion requirements.
[0131] Furthermore, after the file path list traversal is complete and all files to be converted have been converted, this embodiment of the application can send a conversion completion message to the user, which can be executed by the first control module 1001. The conversion completion message can carry a success flag or a failure flag so that the user is aware of the conversion status. Afterwards, the user can view the output file.
[0132] In summary, this application provides a database mapping file conversion method based on a large model. Based on this method, the database mapping file corresponding to a Java project can be converted from being adapted to the original database to being adapted to a user-specified target database. Thus, when the Java project runs, it can interact with the target database based on the converted database mapping file, thereby achieving accurate data storage and retrieval. For example, if the target database is DM Database, the converted mapping file will contain SQL statements adapted to DM Database, enabling the project to successfully connect to and operate on the DM Database during runtime, completing data persistence and retrieval tasks. Based on this solution, projects can be migrated more easily from one database platform to another without manually modifying a large number of database mapping files. This fills the gap in the lack of targeted and intelligent conversion tools.
[0133] Furthermore, the solution in this application constructs a fully automated processing flow from project file scanning, data sending, result receiving to adaptation file generation, requiring minimal manual intervention and significantly improving the efficiency and accuracy of database adaptation and conversion. The modules collaborate closely to form an organic whole, ensuring a smooth and efficient adaptation process.
[0134] Figure 6 This is a schematic diagram of the structure of a second database mapping file conversion system based on a large model, provided in an embodiment of this application.
[0135] like Figure 6 As shown in the figure, this application embodiment provides a database mapping file conversion system based on a large model. The system includes:
[0136] The file scanning module 2001 is configured to recursively traverse the files under the target project path to obtain a list of file paths to be converted; wherein, the file path list consists of M source file paths of the files to be converted that conform to the mapping file naming rules, the mapping file naming rules include: the file name contains a preset keyword and the extension is a preset extension;
[0137] The control module 2002 is configured to control the content reading module 2003, the AI interaction module 2004, and the file generation module 2005 to execute steps S1-S5 in a loop according to the path order in the file path list.
[0138] Content reading module 2003 is configured to execute step S1: read the content of the Nth file to be converted based on the file path list, where 1≤N≤M;
[0139] The AI interaction module 2004 is configured to execute step S2: construct target prompt words based on the read content of the file to be converted, and input the target prompt words and the content of the file to be converted into the large model; wherein, the target prompt words are used to guide the large model to convert the SQL statements in the content of the file to be converted into target statements that conform to the target syntax, so as to obtain the content to be written in the preset format; the target syntax is the syntax corresponding to the target database; the preset format refers to the format corresponding to the preset extension;
[0140] The AI interaction module 2004 is also configured to execute step S3: parse the output of the large model to obtain the content of the file to be written in a preset format;
[0141] The file generation module 2005 is configured to execute step S4: generate an output path based on the target project path, the preset root path, and the source file path; wherein, the source file path is the file path of the Nth file to be converted.
[0142] The file generation module 2005 is also configured to execute step S5: write the content of the file to be written to the target file under the output path to obtain a database mapping file adapted to the target database.
[0143] In one possible implementation, the file scanning module 2001 is further configured to: recursively traverse the files under the target project path, determine M files to be converted that conform to the mapping file naming rules; sequentially obtain the source file path of each file to be converted, and generate a file path list.
[0144] In one possible implementation, the content reading module 2003 is further configured to: traverse the file path list to determine the Nth file to be converted; and based on a preset character encoding rule, convert the byte data in the Nth file to be converted into a text string to obtain the content of the Nth file to be converted.
[0145] In one possible implementation, the AI interaction module 2004 is further configured to: match the target prompt word template library based on the type identifier of the target database to obtain the target prompt word template corresponding to the target database; the target prompt word template is also used to: guide the content of the file to be written to be output by the large model to not contain any explanation; insert the read content of the file to be converted into the target prompt word template to obtain the target prompt word.
[0146] In one possible implementation, the AI interaction module 2004 is further configured to: construct a request header and request body for a POST request; wherein the data format field in the request header is application / json, and the data format field is used to define the data format of the request body; the authentication field in the request header contains the API key of the large model; the request body includes the target prompt word; and establish a connection with the API of the large model through the POST request to input the target prompt word into the large model through the POST request.
[0147] In one possible implementation, the file generation module 2005 is further configured to: extract the relative path between the source file path and the target project path; and concatenate the preset root path and the relative path to obtain the output path.
[0148] In one possible implementation, the file generation module 2005 is further configured to: determine whether the output directory corresponding to the output path exists; if the output directory corresponding to the output path does not exist, create the output directory based on the output path; if the output directory corresponding to the output path exists, create the target file based on the output directory, and write the content to be written to the target file according to a preset character encoding rule to obtain a database mapping file adapted to the target database.
[0149] In one possible implementation, the system further includes an acquisition module 2006, which is configured to generate a configuration file in response to user operations; the user operations include configuring the API key for calling the large model, configuring the type of the target database, the target project path, and the preset root path.
[0150] In addition, the acquisition module 2006 is also configured to: obtain the API key, the type identifier of the target database, the target project path, and the preset root path from the configuration file.
[0151] In one possible implementation, the default keywords include mapper and dao, and the default extension is xml.
[0152] In a specific implementation, the present invention also provides a computer storage medium, wherein the computer storage medium may store a program, and when the program is executed, it may include some or all of the steps of the various embodiments of the database mapping file conversion method based on a large model provided by the present invention. The storage medium may be a magnetic disk, optical disk, read-only memory (ROM), or random access memory (RAM), etc.
[0153] It is readily understood that, based on the several embodiments provided in this application, those skilled in the art can combine, split, or reorganize the embodiments of this application to obtain other embodiments, none of which exceed the protection scope of this application.
[0154] The above detailed embodiments further illustrate the purpose, technical solution, and beneficial effects of the embodiments of this application. It should be understood that the above are merely specific embodiments of the embodiments of this application and are not intended to limit the protection scope of the embodiments of this application. Any modifications, equivalent substitutions, improvements, etc., made on the basis of the technical solutions of the embodiments of this application should be included within the protection scope of the embodiments of this application.
Claims
1. A large model-based database mapping file conversion method, characterized by, The method comprises: obtaining an API key, a type identifier of a target database, a target project path and a preset root path from a configuration file; wherein the API key is obtained by a user from a large model platform; recursively traversing files under the target project path to obtain a file path list of to-be-converted files; wherein the file path list is composed of M source file paths of to-be-converted files that meet a mapping file naming rule, and the mapping file naming rule comprises: the file name contains a preset keyword, and the extension is a preset extension; the to-be-converted file is a Mapper mapping file, and the Mapper mapping file is used to define a SQL statement, a parameter mapping rule and a result set mapping rule; performing the following steps S1-S5 in a loop according to the order of the paths in the file path list: S1: reading to-be-converted file content of an Nth to-be-converted file based on the file path list, 1≤N≤M; specifically comprising: traversing the file path list to determine the Nth to-be-converted file; converting byte data in the Nth to-be-converted file into a text string based on a preset character encoding rule to obtain to-be-converted file content of the Nth to-be-converted file; the preset character encoding rule is UTF-8 encoding or UTF-16 encoding, and the text string is composed of Unicode characters; S2: matching in a prompt word template library based on the type identifier of the target database to obtain a target prompt word template corresponding to the target database, inserting the read to-be-converted file content into the target prompt word template to obtain a target prompt word, and establishing a connection with an API of the large model through a POST request to input the target prompt word and the to-be-converted file content into the large model; wherein the target prompt word is used to guide the large model to convert a SQL statement in the to-be-converted file content into a target statement that meets a target syntax to obtain to-be-written file content in a preset format; the target prompt word also guides the large model to encapsulate the to-be-written file content in a specific field; the target syntax is a syntax corresponding to the target database; the preset format refers to a format corresponding to the preset extension; an authentication field of a request header of the POST request contains the API key of the large model; wherein the large model API is used for identity authentication based on the API key carried in the POST request, and the large model is used to receive the target prompt word by analyzing the POST request, and perform a SQL statement conversion task based on the target prompt word to generate adapted to-be-written content according to the SQL statement in the to-be-converted file content and the dialect rule of the target database; S3: parsing a specific field in the output result of the large model to obtain the to-be-written file content in the preset format; the specific field is a result field; S4: generating an output path based on the target project path, the preset root path and a source file path; wherein the source file path is a file path of the Nth to-be-converted file; S5: writing the to-be-written file content into a target file under the output path to obtain a database mapping file adapted to the target database; specifically comprising: determining whether an output directory corresponding to the output path exists; in a case where the output directory corresponding to the output path does not exist, creating the output directory based on the output path; in a case where the output directory corresponding to the output path exists, creating the target file based on the output directory, and writing the to-be-written file content into the target file through the preset character encoding rule to obtain a database mapping file adapted to the target database. 2.The large model-based database mapping file conversion method of claim 1, wherein, The recursive traversal of the files under the target project path to obtain a file path list of the to-be-converted files comprises: recursively traversing the files under the target project path to determine M to-be-converted files that meet the mapping file naming rule; sequentially obtaining a source file path of each to-be-converted file to generate the file path list. 3.The large model-based database mapping file conversion method of claim 1, wherein, The target prompt word template is further used to guide the to-be-written file content output by the large model to not contain any explanation.
4. The large model-based database mapping file conversion method of claim 3, wherein, The connection establishment through the POST request and the API of the large model comprises: constructing a request header and a request body of the POST request; wherein a data format field in the request header is application / json, and the data format field is used to define a data format of the request body; the request body includes the target prompt word; establishing the connection through the POST request and the API of the large model, so as to input the target prompt word into the large model through the POST request. 5.The large model-based database mapping file conversion method of claim 1, wherein, The generation of the output path based on the target project path, the preset root path and the source file path comprises: intercepting a relative path of the source file path and the target project path; splicing the preset root path and the relative path to obtain the output path. 6.The large model-based database mapping file conversion method of claim 1, wherein, The method further comprises: generating a configuration file in response to a user operation; the user operation comprises configuring an API key for calling the large model, configuring a type of the target database, the target project path and the preset root path.
7. The large model-based database mapping file conversion method according to any one of claims 1-6, characterized in that, The preset keyword comprises: mapper, dao, and the preset extension is xml.
8. A large model-based database mapping file conversion system, characterized by, The system comprises: an acquisition module configured to acquire an API key, a type identifier of a target database, a target project path and a preset root path from a configuration file; wherein the API key is obtained by a user from a large model platform; a file scanning module configured to recursively traverse files under the target project path to obtain a file path list of to-be-converted files; wherein the file path list is composed of source file paths of M to-be-converted files that meet a mapping file naming rule, and the mapping file naming rule comprises: a file name includes a preset keyword, and an extension is a preset extension; the to-be-converted file is a Mapper mapping file, and the Mapper mapping file is used to define a SQL statement, a parameter mapping rule and a result set mapping rule; The control module is configured to control the content reading module, the AI interaction module, and the file generation module to cyclically execute steps S1-S5 in the order of the paths in the file path list. The content reading module is configured to execute step S1 of reading, based on the file path list, file content to be converted of an Nth file to be converted, 1≤N≤M. Specifically, the file path list is traversed to determine the Nth file to be converted. The byte data in the Nth file to be converted is converted into a text string based on a preset character encoding rule to obtain the file content to be converted of the Nth file to be converted; the preset character encoding rule is UTF-8 encoding or UTF-16 encoding, and the text string is composed of Unicode characters. The AI interaction module is configured to execute step S2 of matching in a prompt word template library based on a type identifier of the target database to obtain a target prompt word template corresponding to the target database, inserting the read file content to be converted into the target prompt word template to obtain the target prompt word, and establishing a connection with an API of the large model through a POST request to input the target prompt word and the file content to be converted into the large model. The target prompt word is used to guide the large model to convert SQL statements in the file content to be converted into target statements conforming to a target syntax to obtain file content to be written in a preset format; the target prompt word also guides the large model to encapsulate the file content to be written in a specific field; the target syntax is a syntax corresponding to the target database; the preset format refers to a format corresponding to the preset extension; an authentication field of a request header of the POST request contains the API key of the large model; the large model API is used for identity authentication based on the API key carried in the POST request, and the large model is used to receive the target prompt word by analyzing the POST request and perform a SQL statement conversion task based on the target prompt word to generate adapted file content to be written by converting SQL statements in the file content to be converted according to a dialect rule of the target database; the AI interaction module is also configured to execute step S3 of analyzing a specific field in an output result of the large model to obtain the file content to be written in the preset format; the specific field is a result field. The file generation module is configured to execute step S4 of generating an output path based on the target project path, the preset root path, and a source file path; the source file path is a file path of the Nth file to be converted. The file generation module is also configured to execute step S5 of writing the file content to be written into a target file under the output path to obtain a database mapping file adapted to the target database; specifically including: determining whether an output directory corresponding to the output path exists; in a case where the output directory corresponding to the output path does not exist, creating the output directory based on the output path. In the case that the output directory corresponding to the output path exists, the target file is created based on the output directory, and the file content to be written is written into the target file through the preset character coding rule, so as to obtain a database mapping file adapted to the target database.
Citation Information
Patent Citations
Database adaptation method and device, equipment and storage medium
CN116701514A