Method and system for dynamically adding table data based on relational database
By creating business tables in a relational database and using the reflection mechanism to dynamically maintain fields, we solve the problems of cumbersome new business fields and low stability in the existing technology, achieve flexible field management and information storage, and improve the system's efficiency. stability and storage efficiency.
Patent Information
- Application Number
- CN202410856396.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-28
- Publication Date
- 2024-09-17
AI Technical Summary
When the existing technology dynamically adds business fields, the process is cumbersome and time-consuming, and it is easy to introduce faults and reduce the stability of the business system. Too many reserved fields waste storage space, and too few reserved fields cannot meet the demand.
By creating business tables in a relational database, adding JSON type field information, and using the reflection mechanism to import data into template files and assigning parameters to database objects, dynamically generate and maintain fields, avoid modifying table structures and codes, and realize field optimization. Add, delete, modify.
It realizes the flexible addition of business fields and information storage, shortens operation time, improves system stability, avoids waste of storage space, and meets diverse business needs.
Smart Images

Figure CN118656373A
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of relational databases, and in particular to a method and system for dynamically adding table data based on a relational database. Background Art
[0002] A relational database (RDBMS) is a database based on a relational model. In the process of using a business system based on a relational database, due to business needs, it is often necessary to meet the need to record more data information by adding business fields. The prior art usually uses two methods to achieve dynamic addition of business fields: 1. The method of adding conventional business fields; 2. The method of reserving business fields. The method of adding conventional business fields first requires modifying the table structure, then modifying the code, and finally testing the packaging and deployment. The whole process has many steps and takes a long time. It also needs to be redeployed and started, which is easy to introduce faults and reduce the stability of the business system. When creating a business table by reserving business fields, it is necessary to reserve enough fields. When a new business field is needed, the new business field value is filled into the reserved field to complete the storage of the new business field information; however, too many reserved fields will cause a lot of waste of storage space, and too few reserved fields may not meet all new needs. Summary of the invention
[0003] The present invention provides a method and system for dynamically adding table data based on a relational database, which solves the problem that when the prior art realizes the dynamic addition of business fields, there are many new addition processes, it takes a long time, and redeployment and startup are prone to introduce failures, which reduces the stability of the business system.
[0004] In a first aspect, an embodiment of the present invention provides a method for dynamically adding table data based on a relational database, the method comprising the following steps:
[0005] Create a business table and add field information to the business table, where the newly added field information corresponds to the newly added business information;
[0006] Add new attributes to the relational database object and correspond the new attributes to the new field information one by one;
[0007] Dynamically generate a data import template file based on the newly added field information in the business table, and upload the data import template file to the relational database;
[0008] The assignment parameters are obtained by parsing the data import template file, and the reflection mechanism is used to reflect the assignment parameters to the newly added attributes of the relational database object.
[0009] In the above embodiment, the present invention maintains the field information of the newly added business during the use of the business system by adding a new business table. This business table is independent of the original business table, and can reflect the assignment to the relevant attributes of the relational database object, realize the addition, deletion, modification and other maintenance of the relevant attributes of the relational database object, solve the addition of business fields and the preservation of information at the user level, and solve the problem that when the existing technology realizes the dynamic addition of business fields, there are many new processes, it takes a long time, and it is necessary to redeploy and start up, which is easy to introduce failures and reduces the stability of the business system.
[0010] As some optional implementation modes of the present application, the newly added field information in the business table is field information of JSON type.
[0011] In the above embodiment, the newly added field information of the present invention is field information of JSON type, and is therefore used to store structured data.
[0012] As some optional implementations of the present application, the newly added JSON type field information in the business table corresponds to the newly added business information; wherein, one newly added business information can correspond to one or more JSON type field information, and one newly added business information can only enable one JSON type field information.
[0013] In the above embodiment, a newly added business information of the present invention can correspond to one or more fields, and a newly added business information can only enable one field information, so that different businesses have different table structures for the same business table, and there will be no interference between the same business or different businesses.
[0014] As some optional implementation modes of the present application, the newly added attribute in the relational database object is an attribute of string type.
[0015] In the above embodiment, the attribute name of the newly added attribute in the relational database object of the present invention is ext_field, and the attribute name ext_field indicates that the attribute corresponds to the field named ext_field.
[0016] As some optional implementation modes of the present application, the data import template file is an Excel type data import template file.
[0017] In the above embodiment, the present invention uses an Excel-type data import template file to ensure data accuracy, unify data formats, and facilitate data comparison and analysis.
[0018] As some optional implementation methods of the present application, the process of obtaining assignment parameters based on data import template file parsing and using reflection mechanism to reflectively assign the assignment parameters to the newly added attributes of the relational database object is as follows:
[0019] Use Excel processing tools to parse the Excel data import template file to obtain the newly added JSON field information;
[0020] Determine whether the newly added JSON type field information is enabled. If the JSON type field information is enabled, terminate the process. If the JSON type field information is not enabled, use the reflection mechanism to parse the field name and field value of the JSON type field information from the Excel type data import template file, and assemble the field name and field value of the JSON type field information into a string and assign it to the new attribute of the relational database object.
[0021] In the above embodiment, the present invention can parse the Excel type data import template file through the Excel processing tool (Easy Excel), and reflect the parsing parameters to the properties of the relational database object to achieve the maintenance of adding, deleting, modifying and other related properties of the relational database object.
[0022] As some optional implementations of the present application, after the assignment parameters are reflectively assigned to the newly added attributes of the relational database object using a reflection mechanism, data is displayed according to the enabled field information.
[0023] In the above embodiment, the present invention visualizes the returned field name, field value and other information according to the enabled field information, so as to facilitate the analysis and verification of the newly added fields of the business field.
[0024] In a second aspect, the present invention provides a system for dynamically adding table data based on a relational database, the system comprising:
[0025] A business field creation unit, the business field creation unit is used to create a business table and add field information to the business table, wherein the newly added field information corresponds to the newly added business information;
[0026] A database attribute adding unit, the database attribute adding unit is used to add attributes to a relational database object and to make a one-to-one correspondence between the newly added attributes and the newly added field information;
[0027] A data import template unit, which dynamically generates a data import template file based on the newly added field information in the business table, and uploads the data import template file to the relational database;
[0028] A parameter reflection assignment unit, wherein the parameter reflection assignment unit obtains assignment parameters based on data import template file parsing, and uses a reflection mechanism to reflectively assign the assignment parameters to newly added attributes of a relational database object.
[0029] In a third aspect, the present invention provides a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method for dynamically adding table data based on a relational database when executing the computer program.
[0030] In a fourth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the method for dynamically adding table data based on a relational database is implemented.
[0031] The beneficial effects of the present invention are as follows: the present invention adds a new business table, adds, deletes, modifies and maintains fields in the business table, reflects the attributes assigned to the relational database object, realizes the addition, deletion, modification and other maintenance of the related attributes of the relational database object, and solves the addition of business fields and the preservation of information at the user level. There is no need to modify the table structure, modify the code, and package the deployment. The operation is flexible, the time consumption is short, and there is no need to redeploy and start; and there is no need to reserve too many fields on the basis of the original business table, which will not cause a waste of storage space. The corresponding new operations can be performed according to the number of fields, and all new needs can be met. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0033] Figure 1 is a schematic diagram of the computer device structure of the hardware operating environment described in the embodiment of the present invention;
[0034] Figure 2 It is a flow chart of a method for dynamically adding table data based on a relational database according to an embodiment of the present invention;
[0035] Figure 3 It is a structural block diagram of a system for dynamically adding table data based on a relational database according to an embodiment of the present invention. DETAILED DESCRIPTION
[0036] It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0037] In order to solve the problem that when the existing technology realizes the dynamic addition of business fields, there are many new processes, which takes a long time and requires redeployment and startup, which easily introduces failures and reduces the stability of the business system. The embodiment of the present invention provides a method and system for realizing dynamic addition of table data based on a relational database. Before introducing the specific technical solution of the present application, the hardware operating environment involved in the embodiment of the present application is first introduced.
[0038] See also Figure 1 , Figure 1 The figure is a schematic diagram of the computer device structure of the hardware operating environment involved in the embodiment of the present invention.
[0039] like Figure 1 As shown, the computer device may include: a processor, such as a central processing unit (CPU), a communication bus, a user interface, a network interface, and a memory. Among them, the communication bus is used to realize the connection and communication between these components. The user interface may include a display screen (Display), an input unit such as a keyboard (Keyboard), and optionally, the user interface may also include a standard wired interface and a wireless interface. The network interface may be a wired interface or a wireless interface (such as a wireless fidelity interface). The memory may be a high-speed random access memory (Random Access Memory, RAM), or a stable non-volatile memory (Non-Volatile Memory, NVM), such as a disk storage. The memory may optionally be a storage device independent of the aforementioned processor.
[0040] Those skilled in the art will understand that Figure 1 The structure shown in the figure does not constitute a limitation on the computer device, and may include more or less components than shown in the figure, or combine some components, or arrange the components differently.
[0041] like Figure 1 As shown, the memory as a storage medium may include an operating system module, a network communication module, a user interface module and a data storage module.
[0042] exist Figure 1In the computer device shown, the network interface is mainly used for data communication with the network server; the user interface is mainly used for data interaction with the user; the processor and memory in the computer device of the present application can be set in the computer device, and the computer device calls the system for dynamically adding table data based on a relational database stored in the data storage module through the processor, and executes the method for dynamically adding table data based on a relational database provided in the embodiment of the present application.
[0043] Based on the hardware environment of the aforementioned embodiment, the embodiment of the present application provides a method for dynamically adding table data based on a relational database. Figure 2 , Figure 2 The flowchart of the method for dynamically adding table data based on a relational database is as follows:
[0044] (1) Add a new business table, and maintain the JSON type field information corresponding to each newly added business in each business table, where the field name of the JSON type field information is ext_field. In the JAVA database, the field name ext_field indicates that the field is an extended field, which is used to store additional information in addition to the main information. Since the field is of JSON type, it is used to store structured data. The JSON type field information includes but is not limited to key values, arrays, and objects.
[0045] Specifically, a newly added business information can correspond to one or more JSON type field information; however, a newly added business information can only enable one JSON type field information.
[0046] In an embodiment of the present invention, JSON type field information is used to associate business information, making the addition of fields more flexible. Field information with a field name of ext_field can be added, deleted or modified as needed without modifying the relational database structure. This enables different businesses to have different table structures for the same business table, and there will be no interference between the same business or different businesses.
[0047] (2) Add a string type attribute to the relational database object, and correspond the newly added string type attribute to the newly added JSON type field information one by one; wherein the attribute name is ext_field, and the attribute name is ext_field, indicating that the attribute corresponds to the field whose field name is ext_field.
[0048] (3) Dynamically generate a data import template file based on the newly added JSON type field information in the business table, and upload the data import template file to the relational database. Specifically, the data import template file is an Excel type data import template file. Using an Excel type data import template file can ensure data accuracy, unify data formats, and facilitate data comparison and analysis.
[0049] (4) The assignment parameters are obtained by parsing the data import template file, and the reflection mechanism is used to reflect the assignment parameters to the newly added attributes of the string type of the relational database object.
[0050] In an embodiment of the present invention, the process of obtaining assignment parameters based on data import template file parsing and using reflection mechanism to reflectively assign the assignment parameters to the newly added attributes of the relational database object is as follows:
[0051] (4.1) Use the Excel processing tool (Easy Excel) to parse the Excel type data import template file to obtain the newly added JSON type field information.
[0052] (4.2) Determine whether the newly added JSON type field information is in an enabled state. If the JSON type field information is in an enabled state, terminate the process and give a prompt. If the JSON type field information is not in an enabled state, use the reflection mechanism to parse the field name, field value, etc. of the JSON type field information from the Excel type data import template file, and assemble the field name and field value of the JSON type field information into a string and assign it to the newly added attribute of the relational database object.
[0053] In an embodiment of the present invention, after the reflection mechanism is used to reflectively assign the assignment parameters to the newly added attributes of the relational database object, data is displayed according to the enabled field information, that is, the returned field name, field value and other information are visually displayed according to the enabled field information, which facilitates the analysis and verification of the newly added fields of the business fields.
[0054] In summary, the present invention adds a new business table, adds, deletes, modifies and maintains fields in the business table, reflects the attributes assigned to the relational database object, realizes the addition, deletion, modification and other maintenance of the related attributes of the relational database object, and solves the addition of business fields and the preservation of information at the user level. There is no need to modify the table structure, modify the code, and package the deployment. The operation is flexible and time-consuming, and there is no need to redeploy and start; and there is no need to reserve too many fields on the basis of the original business table, which will not cause a waste of storage space. The corresponding new operations can be performed according to the number of business fields, which can meet all new needs.
[0055] In addition, in one embodiment, based on the same inventive concept as the above embodiment, the embodiment of the present invention provides a system for displaying front-end pages with multiple tabs, see Figure 3 , Figure 3 The structure diagram of the system for implementing dynamic addition of table data based on a relational database is shown in FIG. 1 , and the system corresponds to the method in Example 1 one by one. The system includes:
[0056] The business field creation unit is used to create a business table and add JSON type field information to the business table, wherein the newly added JSON type field information corresponds to the newly added business information.
[0057] The database attribute adding unit is used to add a string type attribute in a relational database object, and to make a one-to-one correspondence between the newly added string type attribute and the newly added JSON type field information.
[0058] The data import template unit dynamically generates a data import template file based on the newly added JSON type field information in the business table, and uploads the data import template file to the relational database.
[0059] A parameter reflection assignment unit obtains assignment parameters based on data import template file parsing, and uses a reflection mechanism to reflectively assign the assignment parameters to newly added string type attributes of a relational database object.
[0060] It should be noted that each unit in the system for dynamically adding table data based on a relational database in this embodiment corresponds one-to-one to each step in the method for dynamically adding table data based on a relational database in the aforementioned embodiment. Therefore, the specific implementation method and technical effects achieved by this embodiment can refer to the implementation method of the aforementioned method for dynamically adding table data based on a relational database, and will not be repeated here.
[0061] In addition, in one embodiment, the present application also provides a computer device, which includes a processor, a memory, and a computer program stored in the memory, and the computer program implements the method in the aforementioned embodiment when executed by the processor.
[0062] In addition, in one embodiment, the present application further provides a computer storage medium, on which a computer program is stored, and the computer program implements the method in the aforementioned embodiment when executed by a processor.
[0063] In some embodiments, the computer readable storage medium may be a memory such as FRAM, ROM, PROM, EPROM, EEPROM, flash memory, magnetic surface memory, optical disk, or CD-ROM; or various devices including one or any combination of the above memories. The computer may be various computing devices including intelligent terminals and servers.
[0064] In some embodiments, executable instructions may be in the form of a program, software, software module, script or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including as a stand-alone program or as a module, component, subroutine or other unit suitable for use in a computing environment.
[0065] As an example, executable instructions may, but need not, correspond to a file in a file system, may be stored as part of a file that stores other programs or data, such as in one or more scripts in a HyperText Markup Language (HTML) document, in a single file dedicated to the program in question, or in multiple coordinated files (e.g., files storing one or more modules, subroutines, or code portions).
[0066] By way of example, executable instructions may be deployed to be executed on one computing device, or on multiple computing devices located at one site, or on multiple computing devices distributed across multiple sites and interconnected by a communication network.
[0067] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or system. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or system including the element.
[0068] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0069] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as a read-only memory / random access memory, a magnetic disk, or an optical disk), and includes a number of instructions for enabling a multimedia terminal device (which can be a mobile phone, a computer, a television receiver, or a network device, etc.) to execute the methods described in each embodiment of the present application.
[0070] The above are only preferred embodiments of the present application, and are not intended to limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. A method for dynamically adding table data based on a relational database, characterized in that: The method comprises the following steps: Create a business table and add field information to the business table, where the newly added field information corresponds to the newly added business information; Add new attributes to the relational database object and correspond the new attributes to the new field information one by one; Dynamically generate a data import template file based on the newly added field information in the business table, and upload the data import template file to the relational database; The assignment parameters are obtained by parsing the data import template file, and the reflection mechanism is used to reflect the assignment parameters to the newly added attributes of the relational database object.
2. A method for dynamically adding table data based on a relational database according to claim 1, characterized in that: The newly added field information in the business table is field information of JSON type.
3. A method for dynamically adding table data based on a relational database according to claim 2, characterized in that: The newly added JSON type field information in the business table corresponds to the newly added business information; wherein, one newly added business information can correspond to one or more JSON type field information, and one newly added business information can only enable one JSON type field information.
4. The method for dynamically adding table data based on a relational database according to claim 1, characterized in that: The newly added attribute in the relational database object is an attribute of string type.
5. The method for dynamically adding table data based on a relational database according to claim 1, characterized in that: The data import template file is an Excel type data import template file.
6. A method for dynamically adding table data based on a relational database according to claim 5, characterized in that: The process of obtaining the assignment parameters based on the data import template file parsing and using the reflection mechanism to reflectively assign the assignment parameters to the newly added attributes of the relational database object is as follows: Use Excel processing tools to parse the Excel data import template file to obtain the newly added JSON field information; Determine whether the newly added JSON type field information is enabled. If the JSON type field information is enabled, terminate the process. If the JSON type field information is not enabled, use the reflection mechanism to parse the field name and field value of the JSON type field information from the Excel type data import template file, and assemble the field name and field value of the JSON type field information into a string and assign it to the new attribute of the relational database object.
7. The method for dynamically adding table data based on a relational database according to claim 3, characterized in that: After the reflection mechanism is used to reflect the assignment parameters to the newly added attributes of the relational database object, the data is displayed according to the enabled field information.
8. A system for dynamically adding table data based on a relational database, characterized in that: The system comprises: A business field creation unit, the business field creation unit is used to create a business table and add field information to the business table, wherein the newly added field information corresponds to the newly added business information; A database attribute adding unit, the database attribute adding unit is used to add attributes to a relational database object and to make a one-to-one correspondence between the newly added attributes and the newly added field information; A data import template unit, which dynamically generates a data import template file based on the newly added field information in the business table, and uploads the data import template file to the relational database; A parameter reflection assignment unit, wherein the parameter reflection assignment unit obtains assignment parameters based on data import template file parsing, and uses a reflection mechanism to reflectively assign the assignment parameters to newly added attributes of a relational database object.
9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the method for dynamically adding table data based on a relational database as described in any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by the processor, the method for dynamically adding table data based on a relational database as described in any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Universal efficient Excel reading processing method, tool, medium and equipment
CN114357943A
Method and terminal for newly adding fields in database
CN116049205A
Method and electronic equipment for adding additional fields on premise of not changing database
CN116756384A
Configurable database field extension method
CN117331906A
