Java-based database and entity class automatic mapping method
By using an automated Java database and entity class mapping method, and leveraging data tag information from XML business data to construct mapping associations, this solves the problem of time-consuming and labor-intensive mapping relationship construction in existing technologies, achieving efficient and accurate database updates and development applicability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- HUIZHIAN INFORMATION TECH CO LTD
- Filing Date
- 2022-10-19
- Publication Date
- 2026-06-09
AI Technical Summary
In existing technologies, the mapping relationship between Java databases and entity classes needs to be manually matched, which is labor-intensive and time-consuming, and it is difficult to guarantee the accuracy and efficiency of development.
By authenticating user terminals and verifying data, the system automatically extracts data tag information from XML business data in the business database, constructs mapping association information, and generates SQL statements to achieve automatic mapping of Java entity classes.
It improves the efficiency and accuracy of constructing mapping and association information, enhances the applicability of business databases in different development scenarios, and ensures data security and accuracy.
Smart Images

Figure CN115687390B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of database processing technology, and in particular to a Java-based method for automatic mapping between databases and entity classes. Background Technology
[0002] In Java programming, to adapt to the runtime requirements of different frameworks, it's necessary to establish a mapping relationship between the Java database and entity classes for each framework, thus ensuring a suitable language for framework construction. Currently, the mapping relationship between Java databases and entity classes is built manually. Programmers must manually verify the character matching between the Java database and entity classes to construct the mapping relationship. This is not only time-consuming and labor-intensive, but also requires subsequent manual correction, slowing down framework development, reducing efficiency, and compromising accuracy. Summary of the Invention
[0003] To address the shortcomings of existing technologies, this invention provides a Java-based automatic mapping method for databases and entity classes. This method updates the business database based on uploaded business data with data update permissions, thereby enriching the database's data content. It extracts corresponding data tag information from the business database's XML business data with data integrity, converting the XML business data into Java entity classes. Based on the data tag information, it constructs a mapping association between the XML business data and the Java entity classes. Then, based on the mapping association, it retrieves the matching Java entity class to generate the corresponding SQL statement. This method automatically updates the business database, improving its applicability to different development scenarios. Furthermore, by automatically matching and constructing the mapping association between XML business data and Java entity classes based on the data tag information, it improves the efficiency and accuracy of the mapping association construction.
[0004] This invention provides a Java-based method for automatic mapping between databases and entity classes, which includes the following steps:
[0005] Step S1: Authenticate the user terminal to determine whether the user terminal has the authority to update the business database; verify the business data uploaded by the user terminal with the data update authority to determine whether the business data matches the business database, and merge the matching business data into the business database.
[0006] Step S2: Extract the corresponding XML business data from the business database and perform a data integrity check on the XML business data; repair the XML business data according to the results of the data integrity check; extract the corresponding data tag information from the intact XML business data;
[0007] Step S3: Based on the data tag information, convert the complete XML business data into Java entity classes; and construct the mapping association information between the complete XML business data and the Java entity classes;
[0008] Step S4: Based on the mapping association information, retrieve the matching Java entity class to generate the corresponding SQL statement.
[0009] Furthermore, in step S1, authenticating the user terminal and determining whether the user terminal has the permission to update data in the business database specifically includes:
[0010] Obtain the terminal device identity information of the user terminal, and extract the operation log information of the user terminal in the business database from the operation log set of the business database based on the terminal device identity information;
[0011] Based on the operation log information, determine whether the user terminal is denied access to the business database. If so, determine that the user terminal does not have permission to update data in the business database; otherwise, determine that the user terminal has permission to update data in the business database.
[0012] Furthermore, in step S1, verifying the business data uploaded by user terminals with data update permissions, determining whether the business data matches the business database, and merging the matching business data into the business database specifically includes:
[0013] Identify the data format and content of business data uploaded by user terminals with data update permissions;
[0014] Determine whether the data format of the business data is consistent with the data format type compatible with the business database. If they are inconsistent, instruct the business database to refuse to receive the business data.
[0015] If they match, determine whether the data content of the business data is the same as the data content of the business data already existing in the business database; if they match, instruct the business database to refuse to receive the business data; if they do not match, instruct the business database to receive the business data and merge the business data into the business database.
[0016] Further, in step S2, the corresponding XML business data is extracted from the business database, and a data integrity check is performed on the XML business data; based on the result of the data integrity check, the XML business data is repaired, specifically including:
[0017] Extract corresponding XML business data from the business data, analyze and process the XML business data, and determine whether there are blank fields in the XML business data. If there are blank fields, it is determined that the XML business data lacks data integrity; if there are no blank fields, it is determined that the XML business data has data integrity.
[0018] If the XML business data lacks data integrity, the source terminal of the XML business data is determined based on the set of operation logs, and another XML business data that is consistent with and complete with the XML business data is obtained from the source terminal to replace the XML business data.
[0019] Furthermore, in step S2, extracting the corresponding data tag information from the complete XML business data specifically includes:
[0020] Extract the corresponding data fields from the complete XML business data, and combine the data field itself, the field length of the data field, and the field type of the data field to form the corresponding data tag information.
[0021] Furthermore, in step S3, converting the complete XML business data into Java entity classes based on the data tag information specifically includes:
[0022] Based on the data tag information, a corresponding XML parser is constructed, and the complete XML business data is input into the XML parser for parsing and processing, thereby converting the complete XML business data into Java entity classes.
[0023] Furthermore, in step S3, constructing the mapping association information between the complete XML business data and the Java entity class specifically includes:
[0024] Based on the data tag information, a mapping association information is constructed between the complete XML business data and the Java entity class; wherein, the mapping association information includes the character content association information between the data fields of the complete XML business data and the entity elements of the Java entity class.
[0025] Furthermore, in step S4, retrieving the matching Java entity class based on the mapping association information to generate the corresponding SQL statement specifically includes:
[0026] Obtain a statement invocation request from the server terminal, and extract the character content of the statement that the server terminal expects to invoke from the statement invocation request;
[0027] The character content of the statement to be invoked is matched with the mapping association information to retrieve the matching Java entity class, and the retrieved Java entity class is converted into an SQL statement.
[0028] Compared to existing technologies, this Java-based automatic database-entity class mapping method updates the business database based on business data uploaded with data update permissions, thereby enriching the data content of the business database. It extracts corresponding data tag information from the business database's XML business data with data integrity, converts the XML business data into Java entity classes, and constructs a mapping association between the XML business data and the Java entity classes based on the data tag information. Then, based on the mapping association information, it retrieves the matching Java entity class to generate the corresponding SQL statement. This method can automatically update the business database, improving its applicability to different development scenarios. Furthermore, by automatically matching and constructing the mapping association information between XML business data and Java entity classes based on the data tag information of the XML business data, it improves the efficiency and accuracy of the mapping association information construction.
[0029] Other features and advantages of the invention will be set forth in the description which follows, and will be apparent in part from the description, or may be learned by practicing the invention. The objects and other advantages of the invention may be realized and obtained by means of the structures particularly pointed out in the written description, claims, and drawings.
[0030] The technical solution of the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. Attached Figure Description
[0031] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0032] Figure 1 This is a flowchart illustrating the Java-based automatic mapping method for databases and entity classes provided by the present invention. Detailed Implementation
[0033] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0034] See Figure 1 This is a flowchart illustrating a Java-based automatic database-entity class mapping method provided in an embodiment of the present invention. The Java-based automatic database-entity class mapping method includes the following steps:
[0035] Step S1: Authenticate the user terminal to determine whether it has the authority to update the business database; verify the business data uploaded by the user terminal with the data update authority to determine whether the business data matches the business database, and merge the matching business data into the business database.
[0036] Step S2: Extract the corresponding XML business data from the business database and perform a data integrity check on the XML business data; repair the XML business data based on the results of the data integrity check; extract the corresponding data tag information from the intact XML business data.
[0037] Step S3: Based on the data tag information, convert the complete XML business data into a Java entity class; and construct the mapping association information between the complete XML business data and the Java entity class.
[0038] Step S4: Based on the mapping association information, retrieve the matching Java entity class to generate the corresponding SQL statement.
[0039] The beneficial effects of the above technical solution are as follows: This Java-based automatic mapping method for databases and entity classes updates the business database based on business data uploaded with data update permissions, thereby enriching the data content of the business database; it extracts corresponding data tag information from the XML business data with data integrity in the business database, converts the XML business data into Java entity classes, and constructs mapping association information between XML business data and Java entity classes based on the data tag information; then, based on the mapping association information, it retrieves the matching Java entity class to generate the corresponding SQL statement; the above method can automatically update the business database, improve the applicability of the business database to different development scenarios, and automatically match and construct mapping association information between XML business data and Java entity classes based on the data tag information of XML business data, improving the efficiency and accuracy of the construction of mapping association information.
[0040] Preferably, in step S1, authenticating the user terminal and determining whether the user terminal has the permission to update data in the business database specifically includes:
[0041] Obtain the terminal device identity information of the user terminal, and based on the terminal device identity information, extract the operation log information of the user terminal in the business database from the operation log set of the business database;
[0042] Based on the operation log information, determine whether the user terminal is denied access to the business database. If so, determine that the user terminal does not have permission to update data in the business database; otherwise, determine that the user terminal has permission to update data in the business database.
[0043] The beneficial effects of the above technical solution are as follows: By using the user terminal's terminal device identity information and the business database's operation log set as a basis, it is determined whether the user terminal has the authority to update the business database, thus preventing user terminals without data update authority from illegally tampering with the business database and affecting the data security of the business database.
[0044] Preferably, in step S1, verifying the business data uploaded by the user terminal with data update permissions, determining whether the business data matches the business database, and merging the matching business data into the business database specifically includes:
[0045] Identify the data format and content of business data uploaded by user terminals with data update permissions;
[0046] Determine whether the data format of the business data is consistent with the data format type compatible with the business database. If they are inconsistent, instruct the business database to refuse to accept the business data.
[0047] If they match, determine whether the data content of the business data is the same as the data content of the business data that already exists in the business database; if they match, instruct the business database to refuse to accept the business data; if they do not match, instruct the business database to accept the business data and merge it into the business database.
[0048] The beneficial effects of the above technical solution are as follows: Through the above method, the data format and data content of the business data uploaded by the user terminal can be verified, ensuring that the uploaded business data is compatible with the business database in terms of data format and data content, ensuring the standardization of the business data format in the business database, avoiding data duplication in the business database, and reducing the data redundancy of the business database.
[0049] Preferably, in step S2, the corresponding XML business data is extracted from the business database, and a data integrity check is performed on the XML business data; based on the result of the data integrity check, the XML business data is repaired, specifically including:
[0050] Extract the corresponding XML business data from the business data, analyze and process the XML business data, and determine whether there are blank fields in the XML business data. If there are blank fields, it is determined that the XML business data does not have data integrity; if there are no blank fields, it is determined that the XML business data has data integrity.
[0051] If the XML business data lacks data integrity, the source terminal of the XML business data is determined based on the set of operation logs, and another XML business data that is consistent with and complete with the original XML business data is obtained from the source terminal to replace the original XML business data.
[0052] The beneficial effects of the above technical solution are as follows: by using the above method, the data integrity of XML business data in the business database can be guaranteed, and the data accuracy and availability of the business database can be improved.
[0053] Preferably, in step S2, extracting the corresponding data tag information from the complete XML business data specifically includes:
[0054] Extract the corresponding data fields from the complete XML business data, and combine the data field itself, the field length, and the field type to form the corresponding data tag information.
[0055] The beneficial effects of the above technical solution are as follows: through the above method, the XML business data can be uniquely identified, and the data tag information corresponding to the XML business data can be obtained, thereby effectively representing the XML business data.
[0056] Preferably, in step S3, converting the complete XML business data into a Java entity class based on the data tag information specifically includes:
[0057] Based on the data tag information, a corresponding XML parser is constructed, and the complete XML business data is input into the XML parser for parsing and processing, thereby converting the complete XML business data into Java entity classes.
[0058] The beneficial effects of the above technical solution are as follows: by using the above method and based on the data tag information, an XML parser compatible with the data structure of XML business data is constructed, thereby obtaining the Java entity class corresponding to the XML business data and ensuring the unique correspondence between the Java entity class and the XML business data.
[0059] Preferably, in step S3, constructing the mapping association information between the complete XML business data and the Java entity class specifically includes:
[0060] Based on the data tag information, a mapping association information is constructed between the complete XML business data and the Java entity class; wherein, the mapping association information includes the character content association information between the data fields of the complete XML business data and the entity elements of the Java entity class.
[0061] The beneficial effects of the above technical solution are as follows: by using the above method and data tag information as a basis, a mapping association information between XML business data and Java entity classes in terms of character content is constructed, which facilitates the accurate retrieval of Java entity classes through the mapping association information in the future.
[0062] Preferably, in step S4, retrieving the matching Java entity class based on the mapping association information to generate the corresponding SQL statement specifically includes:
[0063] Obtain the statement call request from the server terminal, and extract the character content of the statement that the server terminal expects to call from the statement call request;
[0064] The character content of the expected statement is matched with the mapping association information to retrieve the matching Java entity class, and the retrieved Java entity class is converted into an SQL statement.
[0065] The beneficial effects of the above technical solution are as follows: By using the above method, the appropriate Java entity class can be accurately located and called, and the corresponding SQL statement can be generated. This makes it easier for the server terminal to directly use SQL statements for development, thereby improving development efficiency.
[0066] As can be seen from the above embodiments, this Java-based automatic database-entity class mapping method updates the business database based on business data uploaded with data update permissions, thereby enriching the data content of the business database; it extracts corresponding data tag information from the XML business data with data integrity in the business database, thereby converting the XML business data into Java entity classes, and constructs mapping association information between the XML business data and the Java entity classes based on the data tag information; then, based on the mapping association information, it retrieves the matching Java entity class to generate the corresponding SQL statement; the above method can automatically update the business database, improve the applicability of the business database to different development scenarios, and automatically match and construct the mapping association information between XML business data and Java entity classes based on the data tag information of the XML business data, improving the efficiency and accuracy of the construction of the mapping association information.
[0067] Obviously, those skilled in the art can make various modifications and variations to this invention without departing from its spirit and scope. Therefore, if these modifications and variations fall within the scope of the claims of this invention and their equivalents, this invention also intends to include these modifications and variations.
Claims
1. A Java-based method for automatic mapping between databases and entity classes, characterized in that: It includes the following steps: Step S1: Authenticate the user terminal to determine whether the user terminal has the permission to update the business database; verify the business data uploaded by the user terminal with the data update permission to determine whether the business data matches the business database, and merge the matching business data into the business database. Step S2: Extract the corresponding XML business data from the business database and perform a data integrity check on the XML business data; repair the XML business data according to the results of the data integrity check; extract the corresponding data tag information from the intact XML business data; Step S3: Based on the data tag information, convert the complete XML business data into Java entity classes; and construct the mapping association information between the complete XML business data and the Java entity classes; Step S4: Based on the mapping association information, retrieve the matching Java entity class to generate the corresponding SQL statement; In step S2, the corresponding XML business data is extracted from the business database, and a data integrity check is performed on the XML business data. Based on the results of the data integrity check, the XML business data is repaired, specifically including: Extract corresponding XML business data from the business data, analyze and process the XML business data, and determine whether there are blank fields in the XML business data. If there are blank fields, it is determined that the XML business data lacks data integrity; if there are no blank fields, it is determined that the XML business data has data integrity. If the XML business data lacks data integrity, the source terminal of the XML business data is determined based on the set of operation logs, and another XML business data that is consistent with and complete with the XML business data is obtained from the source terminal to replace the XML business data.
2. The Java-based automatic mapping method for databases and entity classes as described in claim 1, characterized in that: In step S1, authenticating the user terminal and determining whether the user terminal has the permission to update data in the business database specifically includes: Obtain the terminal device identity information of the user terminal, and extract the operation log information of the user terminal in the business database from the operation log set of the business database based on the terminal device identity information; Based on the operation log information, determine whether the user terminal is denied access to the business database. If so, determine that the user terminal does not have permission to update data in the business database; otherwise, determine that the user terminal has permission to update data in the business database.
3. The Java-based automatic mapping method for databases and entity classes as described in claim 2, characterized in that: In step S1, verifying the business data uploaded by user terminals with data update permissions, determining whether the business data matches the business database, and merging the matching business data into the business database specifically includes: Identify the data format and content of business data uploaded by user terminals with data update permissions; Determine whether the data format of the business data is consistent with the data format type compatible with the business database. If they are inconsistent, instruct the business database to refuse to receive the business data. If they match, determine whether the data content of the business data is the same as the data content of the business data already existing in the business database; if they match, instruct the business database to refuse to receive the business data; if they do not match, instruct the business database to receive the business data and merge the business data into the business database.
4. The Java-based automatic mapping method for databases and entity classes as described in claim 1, characterized in that: In step S2, extracting the corresponding data tag information from the complete XML business data specifically includes: Extract the corresponding data fields from the complete XML business data, and combine the data field itself, the field length of the data field, and the field type of the data field to form the corresponding data tag information.
5. The Java-based automatic mapping method for databases and entity classes as described in claim 4, characterized in that: In step S3, converting the complete XML business data into Java entity classes based on the data tag information specifically includes: Based on the data tag information, a corresponding XML parser is constructed, and the complete XML business data is input into the XML parser for parsing and processing, thereby converting the complete XML business data into Java entity classes.
6. The Java-based automatic mapping method for databases and entity classes as described in claim 5, characterized in that: In step S3, constructing the mapping association information between the complete XML business data and the Java entity class specifically includes: Based on the data tag information, a mapping association information is constructed between the complete XML business data and the Java entity class; wherein, the mapping association information includes the character content association information between the data fields of the complete XML business data and the entity elements of the Java entity class.
7. The Java-based automatic mapping method for databases and entity classes as described in claim 6, characterized in that: In step S4, retrieving the matching Java entity class based on the mapping association information to generate the corresponding SQL statement specifically includes: Obtain a statement invocation request from the server terminal, and extract the character content of the statement that the server terminal expects to invoke from the statement invocation request; The character content of the statement to be invoked is matched with the mapping association information to retrieve the matching Java entity class, and the retrieved Java entity class is converted into an SQL statement.