Entity class file updating system, method, corresponding computer equipment and storage medium
By analyzing and comparing the physical data model PDM file with the entity class file, generating and inserting JAVA code, and automatically updating the entity class file, the problem of inefficient development caused by frequent updates of entity class files is solved, and development efficiency is improved and errors are reduced.
Patent Information
- Application Number
- CN202211258509.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-14
- Publication Date
- 2025-08-12
- Estimated Expiration
- 2042-10-14
AI Technical Summary
In JAVA software development, entity class files need to be updated frequently to adapt to changes in database table structure, resulting in inefficient code development.
By analyzing the physical data model PDM files and entity class files, comparing differences, generating JAVA code and automatically updating entity class files, including parsing modules, generation modules and inserting modules, and automatically updating entity class files using preset templates and rule files.
It realizes automatic update of entity-class files, reduces human errors and improves code development efficiency.
Smart Images

Figure CN115686589B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of electronic digital data processing, and in particular to a physical file updating system, method, and corresponding computer equipment and storage medium. Background Art
[0002] Entity classes primarily serve as categories for data management and business logic processing. In typical Java software development projects, each table requires a manually created entity class within the code, ensuring a one-to-one correspondence. During the writing of entity class code, table structures frequently change due to business changes, and adding new fields is a common practice. Consequently, entity classes must be updated in real time. With the increasing number of database tables and frequent changes to table fields, a significant portion of code writing time is wasted on modifying entity classes, significantly reducing code development efficiency.
[0003] Therefore, it is crucial to provide a tool that can automatically update annotated entity class files. Summary of the Invention
[0004] The present invention provides an entity class file updating system, method, corresponding computer equipment and storage medium, which solve the problem of automatic updating of annotation form entity class files.
[0005] In a first aspect of the present invention, a system for updating entity files is provided, the system comprising:
[0006] The first parsing module is used to parse the physical data model PDM file to obtain the table name, field name and field type in the database;
[0007] The second parsing module is used to parse the entity class file to obtain the corresponding database table name, attribute name, attribute type and the corresponding field name of the attribute database;
[0008] A comparison module, used for comparing the parsing result of the physical data model PDM file with the parsing result of the entity class file and determining the newly added fields in the physical data model PDM file according to the comparison result;
[0009] A first generating module, configured to generate an attribute name for the newly added field according to the entity class attribute naming rule in the first rule file;
[0010] A second generating module is configured to generate an attribute data type of the newly added field according to a second rule file, wherein the second rule file records a mapping relationship between a table field type in a database and a data type of an attribute in an entity class;
[0011] The third generation module is used to generate a JAVA code according to a preset template based on the field name of the newly added field and the generated attribute name and attribute data type;
[0012] The insert module is used to insert the generated JAVA code into the entity class file and save it to update the entity class file.
[0013] In a second aspect of the present invention, a method for updating an entity class file is provided, the method comprising:
[0014] Parse the physical data model PDM file to obtain the table name, field name and field type in the database;
[0015] Parse the entity class file to obtain the corresponding database table name, attribute name, attribute type and the corresponding field name of the attribute database;
[0016] Comparing the parsing results of the physical data model PDM file with the parsing results of the entity class file and determining the new fields in the physical data model PDM file according to the comparison results;
[0017] Generate the attribute name of the newly added field according to the entity class attribute naming rule in the first rule file;
[0018] Generate an attribute data type of the newly added field according to a second rule file, wherein the second rule file records a mapping relationship between a table field type in a database and a data type of an attribute in an entity class;
[0019] Generate a JAVA code based on the field name of the newly added field and the generated attribute name and attribute data type according to the preset template;
[0020] Insert the generated JAVA code into the entity class file and save the file to update the entity class file.
[0021] In a third aspect of the present invention, a computer device is provided, comprising a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the functions of the system according to the first aspect of the present invention or the steps of the method according to the second aspect of the present invention are implemented.
[0022] According to a fourth aspect of the present invention, a computer-readable storage medium is provided, on which a computer program is stored, which, when executed by a processor, implements the functions of the system according to the first aspect of the present invention or implements the steps of the method according to the second aspect of the present invention.
[0023] According to the present invention, by respectively parsing the physical data model PDM file and the entity class file, comparing the parsing results of the physical data model PDM file and the parsing results of the entity class file and determining the newly added fields in the physical data model PDM file based on the comparison results, generating the attribute names of the newly added fields according to the entity class attribute naming rules in the first rule file, generating the attribute data types of the newly added fields according to the second rule file, generating a section of JAVA code according to a preset template based on the field names of the newly added fields and the generated attribute names and attribute data types, and inserting the generated JAVA code into the entity class file and saving it to update the entity class file, the entity class file can be automatically updated based on the physical data model file, which greatly reduces the chance of errors and greatly improves the code development efficiency.
[0024] Other features and advantages of the present invention will become more apparent after reading the detailed description of the embodiments of the present invention in conjunction with the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] Figure 1 is a block diagram of an embodiment of a system according to the present invention;
[0026] Figure 2 FIG. 1 is a flow chart of an embodiment of a method according to the present invention.
[0027] The figures are schematic and simplified for clarity, and they merely show details which are essential to the understanding of the invention, while other details are left out. DETAILED DESCRIPTION
[0028] The following describes in detail the embodiments and examples of the present invention with reference to the accompanying drawings.
[0029] The scope of applicability of the present invention will become apparent from the detailed description given below. However, it should be understood that while the detailed description and specific examples indicate preferred embodiments of the invention, they are given for illustration purposes only.
[0030] Figure 1 A block diagram showing a preferred embodiment of an entity class file updating system according to the present invention is shown.
[0031] Due to the strict management of some business line databases and the strictly confidential passwords required for connection, it is usually impossible to directly connect and read the information in the database tables. Developers only have the latest version of the Physical Data Model (PDM) file. Here, we propose to automatically update entity class files based on the PDM file.
[0032] Figure 1 The entity class file update system of the preferred embodiment shown includes:
[0033] The first parsing module 102 is used to parse the physical data model (PDM) file to obtain the table names, field names, and field types in the database. Developers can configure the path information of the PDM file. Since PDM files are stored in DOM format, DOM4J technology can be used to parse the PDM file to obtain the latest table and field information in the PDM file, such as table names, field names, and field types.
[0034] The second parsing module 104 is used to parse the entity class file to obtain the corresponding database table name, attribute name, attribute type, and the corresponding field name of the attribute database. Java reflection technology can be used to parse the entity class file to obtain the Table annotation content of the class and the attribute name, type, and Column annotation content of the attribute. The Table annotation of the class can be parsed to obtain the database table name corresponding to the entity class. The Column annotation of the attribute can be parsed to obtain the table field name corresponding to the attribute.
[0035] Comparison module 106 is configured to compare the parsing results of the physical data model (PDM) file with the parsing results of the entity class file and determine the newly added fields in the physical data model (PDM) file based on the comparison results. Specifically, the field names parsed from the PDM file are compared with the table field names parsed from the entity class file. Field names that do not exist in the table field names parsed from the entity class file, i.e., additional field names in the PDM file, are newly added fields in the PDM file compared to the entity class file.
[0036] The first generating module 108 is configured to generate attribute names of newly added fields according to the entity class attribute naming rules in the first rule file.
[0037] In one embodiment, the first rule file may be predefined and may include, for example, configuration information (also referred to as rules) regarding whether to use camelCase naming for entity class attributes. The first rule file may also include configuration information regarding whether to automatically learn the mapping relationship between table field types and data types of entity class attributes, and / or configuration information regarding whether to pop up an edit box after the comparison module 106 completes the comparison, allowing the user to customize the changes. In another embodiment, each of the aforementioned configuration information may also be user-configurable.
[0038] When the "Whether to use camel case naming for entity class attributes (configuration)" is set to "Yes", camel case naming is used when adding new fields to generate entity class attributes. For example, the user_desc field is named userDesc in the entity class.
[0039] When the CamelCase naming convention is set to "No" for naming entity class attributes (configuration), the field name is used by default when adding new fields to generate entity class attributes. For example, for the user_desc field, the attribute in the entity class is named user_desc.
[0040] The second generation module 110 is used to generate the attribute data type of the newly added field based on the second rule file. The second rule file records the mapping relationship between the table field type in the database and the data type of the attribute in the entity class. The second rule file can be predefined or configured by the user. The predefined second rule file is shown in the following table:
[0041]
[0042]
[0043] After the new field is determined, the corresponding database field type can be obtained from the parsing result of the first parsing module, and then the data type of the attribute in the entity class corresponding to the new field can be generated through the second rule file, that is, the mapping relationship in the above table.
[0044] In an embodiment, the system of the present invention also includes an update module, which is used to determine whether the mapping relationship (configuration) between the table field type and the attribute type in the entity class is automatically learned in the first rule file. When the second parsing module 104 automatically parses the entity class, it can parse the existing table field and the corresponding attribute type. Then, based on the parsed existing table field, the corresponding data type of the corresponding table field can be determined from the parsing result of the PDM file, and then the corresponding relationship between the existing attribute type and the data type of the table field in the database is recorded and updated to the second rule file. If there are multiple corresponding relationships, the most frequently used corresponding relationship is recorded in the configuration file, so that the method of the present invention has an automatic learning function. In other words, the predefined or configured second rule file can then be updated through the aforementioned automatic learning function when the mapping relationship (configuration) between the table field type and the attribute type in the entity class is automatically learned is "yes".
[0045] When the automatic learning of the mapping relationship between table field types and attribute types in the entity class (configuration) is "No", when generating the data type of the attribute through the table field, the corresponding relationship configured in the second rule file is directly used for mapping.
[0046] In an embodiment, the system of the present invention also includes an editing module, which is used to pop up an edit box to allow the user to customize the modification (configuration) after the comparison in the first rule file is completed. When it is set to "yes", a list box will pop up to display the field name of the newly added field and the generated attribute name and attribute data type for the user to customize the modification, and then update the entity class according to the final modification content.
[0047] After the comparison is completed, whether to pop up an edit box to allow users to customize (configure) it is "No", and the entity class is directly updated according to the field name of the newly added field and the generated attribute name and attribute data type.
[0048] The third generation module 112 is used to generate a section of JAVA code based on the field name of the newly added field and the generated attribute name and attribute data type according to a preset template. The content of the preset template defines an attribute, and the annotation content is the corresponding table field name and the get and set methods of the attribute. The preset template is shown below:
[0049]
[0050] The inserting module 114 is used to insert the generated JAVA code into the entity class file of the existing version (by default, insert it into the line above the last “}” in the entity class file) and save it to update the entity class file.
[0051] The system of the present invention reads PDM files, automatically extracts table field information, and then compares it with existing entity class content to automatically update annotation-based entity class files, greatly improving software development efficiency and avoiding human errors.
[0052] The system of the present invention can be built into and packaged into code development tools for easy use by developers. Taking Eclipse development tools as an example, Eclipse plug-in development adds wizard extension points, expands the New function of right-clicking JAVA entity class files, and adds a new "Update Entity Class" function button.
[0053] Figure 2 A flow chart of a preferred embodiment of the entity class file updating method according to the present invention is shown.
[0054] In step S202, the physical data model PDM file is parsed to obtain the table name, field name and field type in the database;
[0055] In step S204, the entity class file is parsed to obtain the corresponding database table name, attribute name, attribute type and the corresponding field name of the attribute database;
[0056] In step S206, the parsing result of the physical data model PDM file is compared with the parsing result of the entity class file and a new field in the physical data model PDM file is determined according to the comparison result;
[0057] In step S208, the attribute name of the newly added field is generated according to the entity class attribute naming rule in the first rule file;
[0058] In step S210, the attribute data type of the newly added field is generated according to the second rule file, wherein the second rule file records the mapping relationship between the table field type in the database and the data type of the attribute in the entity class;
[0059] In step S212, a JAVA code is generated according to a preset template based on the field name of the newly added field and the generated attribute name and attribute data type;
[0060] In step S214, the generated JAVA code is inserted into the entity class file and saved to update the entity class file.
[0061] In another embodiment, the present invention provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program is executed by a processor to implement the Figure 1 The functions or implementation combinations of the system embodiments shown or other corresponding system embodiments Figure 2 The steps of the method embodiment or other corresponding method embodiments described are not repeated here.
[0062] In another embodiment, the present invention provides a computer device comprising a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the combined Figure 1 The functions or implementation combinations of the system embodiments shown or other corresponding system embodiments Figure 2 The steps of the method embodiment or other corresponding method embodiments described are not repeated here.
[0063] The multiple different embodiments described herein or their specific features, structures or characteristics can be appropriately combined in one or more embodiments of the present invention. In addition, in some cases, as long as it is appropriate, the order of steps in the flow chart and / or the pipeline process description can be modified and does not have to be performed in the exact order described. In addition, the multiple different aspects of the present invention can be implemented using software, hardware, firmware or a combination thereof and / or other computer-implemented modules or devices that perform the functions described. The software implementation of the present invention may include executable code stored in a computer-readable medium and executed by one or more processors. The computer-readable medium may include a computer hard drive, ROM, RAM, flash memory, portable computer storage medium such as CD-ROM, DVD-ROM, flash drive and / or other devices with a universal serial bus (USB) interface, and / or any other suitable tangible or non-transient computer-readable medium or executable code can be stored thereon and a computer memory executed by a processor. The present invention can be used in conjunction with any suitable operating system.
[0064] Unless otherwise specified, the singular forms "a", "an", and "the" used herein include the plural meaning (i.e., having "at least one"). It should be further understood that the terms "having", "including", and / or "comprising" used in this specification indicate the presence of the recited features, steps, operations, elements, and / or components, but do not preclude the presence or addition of one or more other features, steps, operations, elements, components, and / or combinations thereof. As used herein, the term "and / or" includes any and all combinations of one or more of the listed items.
[0065] While some preferred embodiments of the present invention have been described above, it should be emphasized that the present invention is not limited to these embodiments and may be implemented in other ways within the scope of the present invention. Those skilled in the art may make various variations and modifications to the present invention based on the technical concept of the present invention and without departing from the scope of the present invention, and such variations and modifications shall still fall within the scope of protection of the present invention.
Claims
1. An entity class file update system, characterized in that: The system comprises: The first parsing module is used to parse the physical data model PDM file to obtain the table name, field name and field type in the database; The second parsing module is used to parse the entity class file to obtain the corresponding database table name, attribute name, attribute type and the corresponding field name of the attribute database; A comparison module, used for comparing the parsing result of the physical data model PDM file with the parsing result of the entity class file and determining the newly added fields in the physical data model PDM file according to the comparison result; A first generating module, configured to generate an attribute name for the newly added field according to the entity class attribute naming rule in the first rule file; A second generating module is configured to generate an attribute data type of the newly added field according to a second rule file, wherein the second rule file records a mapping relationship between a table field type in a database and a data type of an attribute in an entity class; The third generation module is used to generate a JAVA code according to a preset template based on the field name of the newly added field and the generated attribute name and attribute data type; The insert module is used to insert the generated JAVA code into the entity class file and save it to update the entity class file.
2. The system according to claim 1, wherein: The system further comprises: An update module is used to respond to the first rule file including rules for automatically learning the mapping relationship between table field types and data types of attributes in the entity class. When parsing the entity class file, it records the correspondence between the existing attribute data types and database table field types and updates them to the second rule file.
3. The system according to claim 2, characterized in that The updating module is further configured to select the most frequently used correspondence to update to the second rule file in response to the existence of more than two correspondences between existing attribute data types and database table field types.
4. The system according to claim 1, wherein: The system further comprises: The editing module is used to list and enable the user to edit the field names of the newly added fields and the generated attribute names and attribute data types in response to the first rule file including the rules allowing the user to customize the modifications after the comparison is completed.
5. The system according to claim 1, wherein: The entity class attribute naming rule includes a rule configuration for whether to use camel case naming to name entity class attributes.
6. The system according to claim 1, wherein: The system further comprises: The first configuration module is used to configure the rules of the first rule file.
7. The system according to claim 6, characterized in that The system further comprises: The second configuration module is used to configure the mapping relationship between the table field type in the database and the data type of the attribute in the entity class in the second rule file.
8. A method for updating entity class files, characterized in that: The method comprises: Parse the physical data model PDM file to obtain the table name, field name and field type in the database; Parse the entity class file to obtain the corresponding database table name, attribute name, attribute type and the corresponding field name of the attribute database; Comparing the parsing results of the physical data model PDM file with the parsing results of the entity class file and determining the new fields in the physical data model PDM file according to the comparison results; Generate the attribute name of the newly added field according to the entity class attribute naming rule in the first rule file; Generate an attribute data type of the newly added field according to a second rule file, wherein the second rule file records a mapping relationship between a table field type in a database and a data type of an attribute in an entity class; Generate a JAVA code based on the field name of the newly added field and the generated attribute name and attribute data type according to the preset template; Insert the generated JAVA code into the entity class file and save the file to update the entity class file.
9. A computer device comprising a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the processor implements the functions of the system according to any one of claims 1 to 7 or the steps of the method according to claim 8 when executing the computer program.
10. A computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the computer program implements the functions of the system according to any one of claims 1 to 7 or the steps of the method according to claim 8.
Citation Information
Patent Citations
Java file conflict management method and device, electronic equipment and medium
CN113885874A
Persistent layer code updating method and system, terminal equipment and computer storage medium
CN114089979A