Database mapping file conversion method and system based on large model
By automatically converting the SQL statements of the MyBatis framework project into the target database syntax based on a large model method, the problems of low efficiency and poor accuracy of manual conversion are solved, and efficient and accurate database migration and adaptation are achieved.
Patent Information
- Application Number
- CN202511133790.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-14
- Publication Date
- 2025-09-12
- Estimated Expiration
- 2045-08-14
AI Technical Summary
During the database migration process, manually converting SQL statements in the MyBatis framework project to different database syntaxes is labor-intensive, inefficient, and prone to errors, affecting project progress and the stability of the application system.
Using a large model-based approach, we recursively traverse the files under the project path, use the natural language processing capabilities of the large model to construct target prompt words, convert SQL statements into target database syntax, and generate an adapted database mapping file.
It improves the efficiency and accuracy of database adaptation and conversion, ensures that the project can interact normally after migration, reduces manual intervention, and improves the stability and adaptation efficiency of the project.
Smart Images

Figure CN120631967A_ABST
Abstract
Description
Technical Field
[0001] The present 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 Art
[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 using traditional databases need to adapt and transform the database to realize the localization of the database.
[0003] For Java projects using the MyBatis framework, their code files contain numerous SQL statements for interacting with the database. However, different databases have different syntaxes. This means that when migrating a project's database, you need to manually convert the SQL statements in these files into syntax that's compatible with various databases.
[0004] The manual conversion method is labor-intensive and error-prone, with problems such as low conversion efficiency and poor compatibility of the converted code. 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] The embodiments of the present application provide a database mapping file conversion method and system based on a large model to solve the problems of low accuracy and efficiency in database code conversion.
[0006] In the first aspect, an embodiment of the present application provides a database mapping file conversion method based on a large model, the method comprising: 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 is composed of M source file paths of files to be converted that comply with the mapping file naming rules, and 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: reading the to-be-converted file content of the Nth to-be-converted file based on the file path list, 1≤N≤M; S2: constructing a target prompt word based on the read to-be-converted file content, and setting the target prompt word The target prompt word and the content of the file to be converted are input into the big model; wherein, the target prompt word is used to guide the big model to convert the SQL statement in the content of the file to be converted into a target statement that conforms to the target grammar, and obtain the content of the file to be written in a preset format; the target grammar is the grammar corresponding to the target database; the preset format refers to the format corresponding to the preset extension; S3: parse the output result of the big model to obtain the content of the file to be written in a preset format; 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; S5: write the content of the file to be written into the target file under the output path to obtain a database mapping file adapted to the target database.
[0007] In one possible implementation, recursively traverse the files under the target project path to obtain a file path list, including: recursively traversing the files under the target project path to determine M files to be converted that comply with the mapping file naming rules; obtaining the source file path of each file to be converted in turn to generate a file path list.
[0008] In one possible implementation, the file content to be converted 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; 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 file content to be converted 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 file content to be converted are input into a large model. This includes: matching 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; the target prompt word template is further used to: guide the large model to output the file content to be written without any interpretation; and inserting 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 and obtaining the target prompt word, the method further includes: constructing a request header and a 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 establishing a connection with the API of the large model through a POST request to input the target prompt word into the large model through the POST request.
[0011] In one possible implementation, an output path is generated based on a target project path, a preset root path, and a source file path, including: intercepting a relative path between the source file path and the target project path; and concatenating the preset root path and the relative path to obtain an output path.
[0012] In one possible implementation, the content of the file to be written is written into a target file under an output path to obtain a database mapping file adapted to the target database, including: determining whether an output directory corresponding to the output path exists; if the output directory corresponding to the output path does not exist, creating an 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 into 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 a user operation; the user operation includes configuring an API key for calling a large model, configuring the type of the target database, the target project path, and the preset root path; recursively traversing the files under the target project path to obtain a file path list of the files to be converted, further including: 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 a possible implementation, the preset keywords include: mapper, dao, and the preset extension is xml.
[0015] In the second aspect, the embodiment of the present application also provides a database mapping file conversion system based on a large model, and the system includes: a file scanning module, which is configured to: recursively traverse the files under the target project path to obtain a file path list of the files to be converted; wherein the file path list is composed of M source file paths of the files to be converted that comply with the mapping file naming rules, and the mapping file naming rules include: the file name contains a preset keyword and the extension is a preset extension; the control module is configured to: according to the path order in the file path list, control the content reading module, the AI interaction module, and the file generation module to loop through steps S1-S5; the content reading module is configured to execute step S1: read the file content to be converted 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 file to be converted based on the read content of the file to be converted Create a target prompt word, and input the target prompt word and the content of the file to be converted into the big model; wherein the target prompt word is used to guide the big model to convert the SQL statement in the content of the file to be converted into a target statement that conforms to the target grammar, and obtain the content of the file to be written in a preset format; the target grammar is the grammar corresponding to the target database; the preset format refers to the format corresponding to the preset extension; the AI interaction module is further configured to execute step S3: parse the output result of the big model to obtain the content of the file to be written in a preset format; the file generation module 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; the file generation module is further configured to execute step S5: write the content of the file to be written into the target file under the output path to obtain a database mapping file adapted to the target database.
[0016] From the above content, it can be seen that the embodiment of the present application provides a database mapping file conversion method and system based on a large model, the method comprising: 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 is composed of M source file paths of files to be converted that comply with the mapping file naming rules, and 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: reading the to-be-converted file content of the Nth file to be converted based on the file path list, 1≤N≤M; S2: constructing a target prompt word based on the read content of the file to be converted, and The target prompt and the content of the file to be converted are input into the large model; the target prompt is 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, obtaining the content of the file to be written in a 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; S3: parse the output results of the large model to obtain the content of the file to be written in a preset format; S4: generate the output path based on the target project path, the preset root path and the source file path; the source file path is the file path of the Nth file to be converted; S5: write the content of the file to be written into the target file under the output path to obtain a 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. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 A schematic diagram of the structure of a first large-model-based database mapping file conversion system provided in an embodiment of the present application; Figure 2 A flowchart of a method for converting a database mapping file based on a large model provided in an embodiment of the present application; Figure 3 A schematic diagram of the first module interaction of the large model-based database mapping file conversion method provided in an embodiment of the present application; Figure 4 A schematic diagram of the interaction of the second module of the large model-based database mapping file conversion method provided in an embodiment of the present application; Figure 5 A schematic diagram of the process of writing content provided in the embodiment of the present application; Figure 6 A structural diagram of the second large model-based database mapping file conversion system provided in an embodiment of the present application. DETAILED DESCRIPTION
[0018] In order 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 in conjunction with the drawings in the embodiments of this application. Obviously, the described embodiments are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of this application.
[0019] Before introducing the technical solutions of the embodiments of the present application, an exemplary introduction to the terms involved in the embodiments of the present application is first given.
[0020] 1. Java project: refers to a software application or system developed using the Java programming language and related technology stacks (such as frameworks, tools, etc.).
[0021] 2. MyBatis: A database operation framework that maps Structured Query Language (SQL) statements to Java objects. Developers can use MyBatis to conveniently store Java objects in the database, read data from the database, and convert it into Java objects.
[0022] 3. Mapper mapping file (or Mapper.xml file): It is a file in XML format 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 a bridge connecting Java interface methods and database operations, associating Java methods with SQL statements to achieve data persistence operations.
[0023] 4. SQL statement: It is a standard language for interacting with the database, used to perform various database operations, such as data query, insertion, update, deletion, and creation and modification of database structure.
[0024] In order to solve the problem of code conversion difficulties during database migration, the embodiments of the present application provide a database mapping file conversion method and system based on a large model. This method and system can utilize 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.
[0025] Figure 1 A structural diagram of the first large model-based database mapping file conversion system provided in an embodiment of the present application.
[0026] like Figure 1As shown, an embodiment of the present application can provide a database mapping file conversion system based on a large model, which can 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 can include a prompt word construction unit 1005a, an API calling unit 1005b, and a result parsing unit 1005c, and the first file generation module 1006 can include a path generation unit 1006a and a content writing unit 1006b.
[0027] Furthermore, the system can be used to execute a database mapping file conversion method based on a large model to achieve conversion of database code. The database mapping file conversion method based on a large model is described in detail below with reference to the accompanying drawings.
[0028] Figure 2 A flowchart of a large model-based database mapping file conversion method provided in an embodiment of the present application.
[0029] Figure 3 A schematic diagram of the first module interaction of the large model-based database mapping file conversion method provided in an embodiment of the present application.
[0030] like Figure 2 and Figure 3 As shown, the database mapping file conversion method based on the large model provided in the embodiment of the present application may include the following steps S100-S200.
[0031] S100: Recursively traverse the files under the target project path to obtain a file path list of the files to be converted; wherein the file path list is composed of M source file paths of the files to be converted that comply with the mapping file naming rules, and the mapping file naming rules include: the file name contains a preset keyword and the extension is a preset extension.
[0032] In the embodiment of the present application, step S100 may be executed by the first file scanning module 1003 in response to the scheduling of the first control module 1001 , and then the first file scanning module 1003 may return a file path list to the first control module 1001 .
[0033] Furthermore, the target project path is specified by the user, specifically the path of the target project. The target project may be a Java project based on the MyBatis framework. In the MyBatis framework, a mapping file (such as a Mapper mapping file) may be used to define the mapping between Java objects and a database.
[0034] Each mapping file can define multiple SQL statements, and SQL statements can be associated with Java interfaces (such as the Mapper interface) using an ID. The ID value is generally the name of the interface method, ensuring a one-to-one correspondence between interface methods and SQL statements. Furthermore, each mapping file can correspond to one or more Java interfaces.
[0035] Furthermore, the mapping file is usually an XML file with a file extension of .xml and a name related to Mapper or Dao, such as UserMapper.xml or OrderDao.xml, so as to clearly identify its function and purpose.
[0036] In the embodiment of the present application, the preset keywords can be mapper, dao, and the preset extension can be xml. In this way, the embodiment of the present application can filter out all files under the target project path that contain "mapper" and have the suffix ".xml" by recursive traversal. Mapper.xml file ( Indicates a wildcard), and filter out all files in the target project path that contain "dao" and have the suffix ".xml". Dao.xml file ( represents a wildcard character).
[0037] It's worth noting that when filtering based on preset keywords, you can use a case-insensitive approach. This means that the case of the keyword portion of the file name is ignored, and as long as the letter composition matches the preset keyword, the object is considered eligible. For example, if the file name is "UserMapper.xml" or "OrderDao.xml", even if the capitalization of the keyword portion is not exactly the same as the preset keyword, the file corresponding to the file name will be correctly filtered out. This ensures comprehensive and accurate filtering and avoids missing relevant files due to capitalization issues.
[0038] It should also be noted that recursive traversal refers to starting from the target project path and scanning each subfolder and file within that path one by one based on the mapping file naming rules until all files have been traversed, selecting M files to be converted that meet the mapping file naming rules, and then outputting a list of file paths corresponding to these M files to be converted. It is understood that the value of M depends on the file structure of the target project, and the M files to be converted are files with the extension xml and the file name containing mapper or dao.
[0039] In this way, all SQL mapping configuration files (ie, files to be converted) of the target project can be filtered out through the filtering operation.
[0040] S200: cyclically executing the following steps S1-S5 according to the order of the paths in the file path list.
[0041] It can be understood that by traversing the file path list, the file to be converted corresponding to each source file path can be sequentially accessed and converted, achieving mutual conversion between database syntax (or database dialects). The number of times the loop is executed is equal to the number of files to be converted.
[0042] S1: Read the content of the Nth file to be converted based on the file path list, 1≤N≤M; In the embodiment of the present application, this step may be performed by the first content reading module 1004 in response to the scheduling of the first control module 1001 .
[0043] Furthermore, after reading the content of the file to be converted, the embodiment of the present application can encapsulate it into a target format, such as JSON format. JSON can be understood as a special string format. During the encapsulation process, the embodiment of the present application can use the content of the file to be converted as the corresponding value to form a "key-value" correspondence, thereby forming a complete JSON data. The JSON format is concise, easy to read, and cross-platform, allowing the large model to smoothly receive and identify the content of the file to be converted, preparing for subsequent statement conversion.
[0044] S2: Construct a target prompt based on the read content of the file to be converted, and input the target prompt and the content of the file to be converted into the large model.
[0045] In the embodiment of the present application, this step can be executed by the API calling unit 1005b in response to the scheduling of the first control module 1001.
[0046] The large model is specifically a large language model (LLM), and the target database in this embodiment of the application does not make any specific limitation on this.
[0047] Furthermore, the target prompt is used to guide the large model to convert the SQL statements in the file content to be converted into target statements that conform to the target grammar, thereby obtaining the file content to be written in a preset format. The target grammar is the grammar corresponding to the target database. The preset format refers to the format corresponding to the preset extension. In other words, the target prompt is used to output the file content to be written in XML format.
[0048] For example, one of the SQL statements in the file content to be converted may be: SELECT id, name, age FROM user WHERE age>18 LIMIT 10; This is a statement that complies with the MySQL database syntax. When the target database is the DAMO database, the following statement can be obtained by converting the statement: SELECT id, name, age FROM user WHERE age>18 FETCH FIRST 10 ROWS ONLY; In this example, the target prompt word can guide the large model to identify the LIMIT clause in the original SQL statement and convert it into a FETCH FIRST 10 ROWS ONLY clause in the DM database to achieve the same query function.
[0049] In this way, the big model can be used to convert the SQL statements in the content of the file to be converted, and obtain statements that meet the user's expectations for the target database's corresponding syntax. For example, based on the solution of the embodiment of the present application, the big model can be combined with the localized database adaptation of the MyBatis framework Java project, breaking through the limitation of traditional database adaptation relying solely on rule matching. By utilizing the powerful natural language processing and data analysis capabilities of the big model, a deep understanding of complex SQL statements and business logic can be achieved, thereby accurately determining the type of adapted database.
[0050] Exemplarily, constructing the target prompt words based on the read content of the file to be converted may include matching each SQL statement in the content of the file to be converted with a corresponding SQL conversion rule and adding the matching conversion rule to the target prompt words. This avoids determining the SQL conversion rules corresponding to all target databases as target prompt words, thereby reducing the number of words in the target prompt words.
[0051] S3: Analyze the output of the large model to obtain the content of the file to be written in a preset format.
[0052] In the embodiment of the present 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 file content to be written is returned to the first control module 1001.
[0053] It should be noted that the target prompt word can also guide the large model to encapsulate the content of the file to be written into a specific field to constrain the composition of the output result. For example, the target prompt word can be used to guide the large model to write the content to be written into the "result" field. The details are as follows: "Please put the converted XML content into the 'result' field in the JSON format: {\"result\":\"[XML content]\"}".
[0054] Furthermore, step S3 may parse specific fields in the output result of the large model, for example, parse the result field, to obtain the file content to be written in XML format.
[0055] In this way, the result parsing unit 1005c can receive and parse the response result returned by the large model API. Exemplarily, the result parsing unit 1005c extracts the converted XML content according to the actual return content of the large model API, and provides the correct conversion result for subsequent file generation.
[0056] 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.
[0057] In the embodiment of the present application, this step may be performed by the path generation unit 1006 a in response to the scheduling of the first control module 1001 .
[0058] Furthermore, the preset root path is the root output location specified by the user. Subsequently, embodiments of the present application can locate the specific output location, i.e., the output path, 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 described in detail below and will not be repeated here.
[0059] S5: Write the content of the file to be written into the target file under the output path to obtain a database mapping file adapted to the target database.
[0060] In the embodiment of the present application, this step can be performed 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 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, ensuring that the directory corresponding to the output path exists, thereby completing the generation of the converted file.
[0061] After executing S1-S5, the conversion of a single file (mapping file) to be converted is complete. By looping through 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, mapping Java objects to target database tables and storing data. This ensures that the project can interact with the database normally after migration to the new database, allowing the target project to achieve multi-database support.
[0062] From the above content, it can be seen that the embodiment of the present application provides a database mapping file conversion method based on a large model, the method comprising: recursively traversing the files under the target project path to obtain a file path list of the files to be converted; wherein the file path list is composed of M source file paths of the files to be converted that comply with the mapping file naming rules, and 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: reading the to-be-converted file content of the Nth file to be converted based on the file path list, 1≤N≤M; S2: constructing a target prompt word based on the read content of the file to be converted, and converting the target prompt word into a target prompt word. The prompt word and the content of the file to be converted are input into the large model; the target prompt word is 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, obtaining the content of the file to be written in a 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; S3: parse the output results of the large model to obtain the content of the file 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; the source file path is the file path of the Nth file to be converted; S5: write the content of the file to be written into the target file under the output path, obtaining a 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 utilized 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.
[0063] The following is a further detailed introduction to each step.
[0064] Continue to see Figure 3 , step S100 may include the following steps S101-S102.
[0065] S101: recursively traverse the files under the target project path to determine M files to be converted that comply with the mapping file naming rules.
[0066] S102: Obtain the source file path of each file to be converted in sequence and generate a file path list.
[0067] In this way, the complete paths of the M files to be converted screened out in S101 can be organized into an ordered list. This file path list will serve as input in subsequent processing so as to process each file to be converted one by one.
[0068] Continue to see Figure 3 , step S1 may include the following steps S11-S12.
[0069] S11: Traverse the file path list to determine the Nth file to be converted.
[0070] The embodiment of the present application 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 the content of the file to be converted. This step ensures that each file can be accessed in an orderly manner, avoiding confusion and omissions during the file processing process.
[0071] S12: 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 to-be-converted file content of the Nth file to be converted.
[0072] 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 the character encoding rules. In the embodiments of the present application, the preset encoding rules are, for example, UTF-8 encoding or UTF-16 encoding, which is not specifically limited in the embodiments of the present application.
[0073] For example, if the file to be converted is encoded in UTF-8, the present embodiment can parse each byte sequence in the file to be converted 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 of the file to be converted for subsequent conversion steps.
[0074] In some implementations, steps S11-S12 may 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 may return the to-be-converted file content to the first control module 1001.
[0075] Continue to see Figure 3 , step S2 includes the following steps S21-S22.
[0076] S21: Matching is performed 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.
[0077] The prompt word template library includes prompt word templates corresponding to a variety of different database types. For example, the prompt word template library can include prompt word templates for databases such as MySQL, Oracle, SQL Server, DAMO Database, and Nanjing University General GBase. In addition, the prompt word template can be generated through multiple iterative tests. For some special functions, special conversion rules can be specified so that the large model can convert special functions based on preset conversion rules. For example, for the DAMO Database, the syntax for converting the DATE_ADD function to the DATEADD function can be specified. In addition, the prompt word template can also reserve placeholders for inserting the content of the file to be converted, so that the actual content of the file to be converted can be filled in later.
[0078] It's worth noting that the target prompt template also ensures that the file content to be written, output by the large model, does not include any explanation. This reduces redundant information output by the large model, speeding up its processing speed. More importantly, it reduces the burden of parsing the output results. The file content to be written can then be used directly.
[0079] In some implementations, the prompt word template can be modified based on actual needs.
[0080] S22: Inserting the read content of the file to be converted into the target prompt word template to obtain the target prompt word.
[0081] In practical applications, the embodiment of the present application can automatically identify the placeholders in the prompt word template and accurately replace the placeholder part with the content of the file to be converted read from the Nth file to be converted, thereby forming a complete and targeted target prompt word, which contains both the conversion requirements of the target database and the actual SQL statement to be converted and the file structure information.
[0082] In some implementations, steps S21 - S22 may be executed by the prompt word construction unit 1005 a in response to the scheduling of the first control module 1001 , and then the prompt word construction unit 1005 a may return the target prompt word to the first control module 1001 .
[0083] For example, the prompt word construction unit 1005a can be based on the target localization database type and the read Mapper.xml file content to be converted, build targeted target prompt words. The target prompt words can clearly indicate that the large model will The SQL statements in the Mapper.xml file are converted from the general syntax to the syntax suitable for the target domestic database, and it is required to return only the complete XML content after conversion without any explanation.
[0084] Figure 4 A schematic diagram of the second module interaction of the large model-based database mapping file conversion method provided in an embodiment of the present application.
[0085] like Figure 4 As shown, step S22 may be followed by the following steps S23-S24.
[0086] S23: Construct a request header and a 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; and the request body includes the target prompt word.
[0087] The POST request is an HTTP request with the POST method. The data format field in the request header can be named Content-Type and "application / json." Based on this setting, the target prompt word can be sent to the Big Model API in JSON format. The authentication field can be named Authorization. The Big Model API key can be configured by the user.
[0088] S24: Establishing a connection with the API of the large model through a POST request, so as to input the target prompt word into the large model through a POST request.
[0089] By sending a POST request to the Big Model API, the Big Model API can authenticate the user based on the API key included in the POST request, thus establishing a connection with the Big Model API. Furthermore, by parsing the POST request, the Big Model receives the target prompt word and performs SQL statement conversion based on the target prompt word, converting the SQL statement in the file to be converted into content adapted to the target database dialect.
[0090] In some implementations, steps S23 - S24 may be executed by the API calling unit 1005 b in response to the scheduling of the first control module 1001 .
[0091] Exemplarily, the API calling unit 1005b can send the constructed prompt words to the big model API. Specifically, it can establish a connection with the big model API by setting relevant attributes of the HTTP request, such as the request method is POST, the content type is application / json, adding Authorization header information (including the big model API key), etc., and send the prompt words to the API in json format.
[0092] In some implementations, after receiving the output result returned by the large model API, the API calling unit 1005b may send the output result to the result parsing unit 1005c for parsing. Alternatively, the output result may be saved to a shared memory so that the result parsing unit 1005c reads the output result from the shared memory.
[0093] Continue to see Figure 4 , step S4 may include the following steps S41-S42.
[0094] S41: intercept the relative path between the source file path and the target project path.
[0095] For example, the target project path may be / home / user / projects / mybatis-mysql / , and the source file path may be / home / user / projects / mybatis-mysql / src / main / resources / mapper / UserMapper.xml. Then, the relative path can be obtained by removing the target project path prefix from the source file path. The relative path may be src / main / resources / mapper / UserMapper.xml.
[0096] S42: Concatenate the preset root path and the relative path to obtain an output path.
[0097] 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.
[0098] In some implementations, steps S23-S24 may be executed by the path generation unit 1006a in response to the scheduling of the first control module 1001, and then the path generation unit 1006a may return the output path to the first control module 1001 and / or the content writing unit 1006b.
[0099] Figure 5 A flowchart of the content writing process provided in the embodiment of the present application.
[0100] like Figure 4 and Figure 5 As shown, step S5 may include the following steps S51-S53.
[0101] S51: Determine whether the output directory corresponding to the output path exists.
[0102] The embodiment of the present application can first extract the directory part in the output path (that is, remove the file name part), and then determine whether the output directory exists.
[0103] For example, if the output path is / output / mapper / user / UserMapper.xml, then the output directory corresponding to the output path is / output / mapper / user. Further, step S51 can check whether the / output / mapper / user directory exists. If it does exist, the target file can be directly created in the directory and the write operation can be performed; if it does not exist, the directory needs to be created first and then the file can be written.
[0104] S52: When the output directory corresponding to the output path does not exist, create the output directory based on the output path.
[0105] In practice, you can create the output path recursively to create all missing intermediate directories. For example, if the output directory is / output / dm-migration / src / main / resources / mapper / , if the parent directory / output / dm-migration / src / does not exist, its parent directory will be automatically created, implementing layer-by-layer creation.
[0106] S53: If the output directory corresponding to the output path exists, create a target file based on the output directory, and write the content of the file to be written into the target file according to a preset character encoding rule to obtain a database mapping file adapted to the target database.
[0107] It can be understood 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.
[0108] Specifically, after confirming that the output directory corresponding to the output path exists, a new XML file can be created in the output directory. This file is the target file to be written. After that, the content to be written can be written to the target file according to the preset character encoding rules (such as UTF-8).
[0109] In some implementations, steps S51-S53 may 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 may return a writing completion message to the first control module 1001.
[0110] Steps S51-S53 complete the final conversion and storage of the file content to be converted. The generated database mapping file can be fully adapted to the target database and can be used for subsequent database operations and project operations. The resulting database mapping file can also be called an SQL mapping configuration file.
[0111] Furthermore, the embodiment of the present application may further include a configuration step, which may be implemented by interaction between the configuration management module 1002 and the user, and specifically includes the following steps S300. Figure 3 As shown, step S300 may occur before step S100.
[0112] S300: 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.
[0113] In the embodiment of the present application, the configuration management module 1002 may provide an interactive page, and the user may interact with the configuration management module 1002 through the interactive page to complete the configuration process.
[0114] It should also be noted that the user can interact with the first control module 1001 to start the conversion task. In response to the start instruction, the control module can call the first file scanning module 1003 and other modules to run.
[0115] In some implementations, users can apply for an API key through the official Big Model platform.
[0116] For further information, see Figure 3 , the following step S400 may also be included before step S100.
[0117] S400: Obtain an API key, a target database type identifier, a target project path, and a preset root path from a configuration file.
[0118] Step S400 can be executed by the configuration management module 1002 in response to the scheduling of the first control module 1001. The configuration management module 1002 can return configuration parameters such as the API key, the type identifier of the target database, the target project path, and the preset root path to the first control module 1001.
[0119] For example, the configuration management module 1002 can configure and manage key parameters such as the large model API key, target localization database type, project path, and output path through the configuration file. Users can easily modify these parameters according to actual needs to adapt to different project conversion requirements.
[0120] Furthermore, after the file path list is traversed and all files to be converted are converted, an embodiment of the present application can provide a conversion completion message to the user, which can be specifically executed by the first control module 1001. The conversion completion message can carry a success or failure indicator to inform the user of the conversion status. The user can then view the output file.
[0121] In summary, the embodiment of the present application provides a database mapping file conversion method based on a large model. Based on this method, the database mapping file corresponding to the Java project can be converted from adapting to the original database to adapting to the target database specified by the user. In this way, when the Java project is running, the Java project can interact with the target database based on the converted database mapping file, thereby realizing accurate storage and query of data. For example, if the target database is the DAMO database, the converted mapping file will contain SQL statements adapted to the DAMO database, so that the project can smoothly connect and operate the DAMO database during operation, and complete the data persistence and retrieval tasks. Based on this solution, it is more convenient to migrate a project from one database platform to another without manually modifying a large number of database mapping files. It can make up for the lack of targeted and intelligent conversion tools.
[0122] Furthermore, the solution in this embodiment establishes a fully automated process from project file scanning, data transmission, result reception, to adaptation file generation, eliminating the need for excessive human intervention and significantly improving the efficiency and accuracy of database adaptation conversion. The modules work closely together to form an integrated whole, ensuring a smooth and efficient adaptation process.
[0123] Figure 6 A structural diagram of the second large model-based database mapping file conversion system provided in an embodiment of the present application.
[0124] like Figure 6 As shown, an embodiment of the present application provides a database mapping file conversion system based on a large model, the system comprising: The file scanning module 2001 is configured to: recursively traverse the files under the target project path to obtain a file path list of files to be converted; wherein the file path list is composed of M source file paths of the files to be converted that comply with the mapping file naming rule, and the mapping file naming rule includes: the file name contains a preset keyword and the extension is a preset extension; 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 cyclically execute steps S1-S5 according to the path order in the file path list; The content reading module 2003 is configured to execute step S1: reading the to-be-converted file content of the Nth to-be-converted file based on the file path list, 1≤N≤M; The AI interaction module 2004 is configured to execute step S2: construct a target prompt word based on the read content of the file to be converted, and input the target prompt word and the content of the file to be converted into the large model; wherein the target prompt word is used to guide the large model to convert the SQL statement in the content of the file to be converted into a target statement that conforms to the target syntax, thereby obtaining the content of the file to be written in a preset format; the target syntax is the syntax corresponding to the target database; the preset format is the format corresponding to the preset extension; The AI interaction module 2004 is further configured to execute step S3: parsing the output result of the large model to obtain the content of the file to be written in a preset format; The file generation module 2005 is configured to execute step S4: generating 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; The file generation module 2005 is further configured to execute step S5: writing the content of the file to be written into the target file under the output path to obtain a database mapping file adapted to the target database.
[0125] In a possible implementation, the file scanning module 2001 is further configured to: recursively traverse the files under the target project path to determine M files to be converted that comply with the mapping file naming rules; obtain the source file path of each file to be converted in turn to generate a file path list.
[0126] 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; 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 file content to be converted of the Nth file to be converted.
[0127] In one possible implementation, the AI interaction module 2004 is further configured to: perform a match in the 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; the target prompt word template is further used to: guide the large model to output the to-be-written file content without any explanation; and insert the read file content to be converted into the target prompt word template to obtain the target prompt word.
[0128] In one possible implementation, the AI interaction module 2004 is further configured to: construct a request header and a 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 establish a connection with the API of the large model through a POST request to input the target prompt word into the large model through a POST request.
[0129] In a possible implementation, the file generation module 2005 is further configured to: intercept 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 an output path.
[0130] 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 an output directory based on the output path; if the output directory corresponding to the output path exists, create a target file based on the output directory, and write the file content to be written into the target file according to preset character encoding rules to obtain a database mapping file adapted to the target database.
[0131] In one possible implementation, the system also includes an acquisition module 2006, which is configured to: generate a configuration file in response to user operations; user operations include configuring an API key for calling a large model, configuring the type of target database, target project path and preset root path.
[0132] Furthermore, the acquisition module 2006 is further configured to: acquire the API key, the type identifier of the target database, the target project path and the preset root path from the configuration file.
[0133] In a possible implementation, the preset keywords include mapper and dao, and the preset extension is xml.
[0134] In a specific implementation, the present invention further provides a computer storage medium, wherein the computer storage medium may store a program that, when executed, may include some or all of the steps of each embodiment of the large model-based database mapping file conversion method provided by the present invention. The storage medium may be a magnetic disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).
[0135] It is easy to understand that those skilled in the art can combine, split, reorganize, etc. the embodiments of the present application based on the several embodiments provided in the present application to obtain other embodiments, and these embodiments do not exceed the scope of protection of the present application.
[0136] The above specific implementation methods further explain in detail the purpose, technical solutions and beneficial effects of the embodiments of the present application. It should be understood that the above are only specific implementation methods of the embodiments of the present application and are not intended to limit the scope of protection of the embodiments of the present application. Any modifications, equivalent replacements, improvements, etc. made on the basis of the technical solutions of the embodiments of the present application should be included in the scope of protection of the embodiments of the present application.
Claims
1. A database mapping file conversion method based on a large model, characterized in that: The method comprises: Recursively traverse the files under the target project path to obtain a file path list of files to be converted; wherein the file path list is composed of M source file paths of files to be converted that comply with a mapping file naming rule, wherein the mapping file naming rule includes: a file name containing a preset keyword and an extension being a preset extension; According to the order of the paths in the file path list, the following steps S1-S5 are executed cyclically: S1: Read the to-be-converted file content of the Nth to-be-converted file based on the file path list, 1≤N≤M; S2: Constructing a target prompt word based on the read content of the file to be converted, and inputting the target prompt word and the content of the file to be converted into a large model; wherein the target prompt word is used to guide the large model to convert the SQL statement in the content of the file to be converted into a target statement that conforms to a target grammar, thereby obtaining the content of the file to be written in a preset format; the target grammar is the grammar corresponding to the target database; and the preset format is the format corresponding to the preset extension. S3: parsing the output result of the large model to obtain the content of the file to be written in the preset format; S4: generating 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; S5: Writing the content of the file to be written into the target file under the output path to obtain a database mapping file adapted to the target database.
2. The method for converting a database mapping file based on a large model according to claim 1, characterized in that: The recursive traversal of the files under the target project path obtains a file path list of the files to be converted, including: Recursively traverse the files under the target project path to determine M files to be converted that comply with the mapping file naming rules; The source file path of each of the files to be converted is obtained in sequence to generate the file path list.
3. The method for converting a database mapping file based on a large model according to claim 1, characterized in that: The reading the to-be-converted file content of the Nth to-be-converted file based on the file path list includes: Traversing the file path list to determine the Nth file to be converted; Based on a preset character encoding rule, the byte data in the Nth file to be converted is converted into a text string to obtain the to-be-converted file content of the Nth file to be converted.
4. The method for converting a database mapping file based on a large model according to claim 1, wherein: The step of constructing a target prompt word based on the read content of the file to be converted, and inputting the target prompt word and the content of the file to be converted into a large model includes: Based on the type identifier of the target database, a target prompt word template corresponding to the target database is matched in the prompt word template library; the target prompt word template is further used to: guide the content of the file to be written 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.
5. The method for converting a database mapping file based on a large model according to claim 4, characterized in that: After inserting the read content of the file to be converted into the target prompt word template to obtain the target prompt word, the method further includes: Constructing a POST request header and body; 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; and the request body includes the target prompt word; A connection is established with the API of the large model through the POST request, so as to input the target prompt word into the large model through the POST request.
6. The method for converting a database mapping file based on a large model according to claim 1, wherein: The generating of the output path based on the target project path, the preset root path and the source file path includes: Intercept the relative path between the source file path and the target project path; The preset root path and the relative path are concatenated to obtain the output path.
7. The method for converting a database mapping file based on a large model according to claim 1, characterized in that: Writing the content of the file to be written into the target file under the output path to obtain a database mapping file adapted to the target database includes: 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, the target file is created based on the output directory, and the content of the file to be written is written into the target file according to a preset character encoding rule to obtain a database mapping file adapted to the target database.
8. The method for converting a database mapping file based on a large model according to claim 1, characterized in that: The method further comprises: Generate a configuration file in response to a user operation; the user operation includes configuring an 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 for files to be converted, the method further includes: The API key, the type identifier of the target database, the target project path, and the preset root path are obtained from the configuration file.
9. The method for converting a database mapping file based on a large model according to any one of claims 1 to 8, characterized in that: The preset keywords include: mapper, dao, and the preset extension is xml.
10. A database mapping file conversion system based on a large model, characterized in that: The system comprises: The file scanning module is configured to: recursively traverse the files under the target project path to obtain a file path list of files to be converted; wherein the file path list is composed of M source file paths of the files to be converted that comply with a mapping file naming rule, wherein the mapping file naming rule includes: a file name containing a preset keyword and an extension being a preset extension; 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 according to the path order in the file path list; The content reading module is configured to execute step S1: reading the to-be-converted file content of the Nth to-be-converted file based on the file path list, where 1≤N≤M; The AI interaction module is configured to execute step S2: construct a target prompt word based on the read content of the file to be converted, and input the target prompt word and the content of the file to be converted into a large model; wherein the target prompt word is used to guide the large model to convert the SQL statement in the content of the file to be converted into a target statement that conforms to a target grammar, thereby obtaining the file content to be written in a preset format; the target grammar is the grammar corresponding to the target database; and the preset format is the format corresponding to the preset extension; The AI interaction module is further configured to execute step S3: parsing the output result of the large model to obtain the content of the file to be written in the preset format; The file generation module is configured to execute step S4: generating 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; The file generation module is further configured to execute step S5: writing the content of the file to be written into the target file under the output path to obtain a database mapping file adapted to the target database.
Citation Information
Patent Citations
General heterogeneous relational database SQL migration method based on parse tree
CN116450616A
Database adaptation method and device, equipment and storage medium
CN116701514A
Database statement conversion method and device, equipment and storage medium
CN117539887A
Database query method and device based on natural language and electronic equipment
CN118535679A
Database migration method, device and system based on MyBatis and storage medium
CN119127834A
Cited By
Format conversion method and device for heterogeneous data and medium
CN121092506A