Data updating method and device
Through configuration files and reflection mechanisms, real-time dynamic modification of enumeration constants in business systems is achieved, solving the problem that enumeration constants cannot be modified in real-time in the existing technology, and improving the readability and scalability of the system.
Patent Information
- Application Number
- CN202311437331.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-31
- Publication Date
- 2025-05-02
AI Technical Summary
Enumeration constants in existing business systems cannot be modified in real time, resulting in the inability to effectively improve the readability and scalability of the system.
Through the configuration information in the configuration file, the enumeration class to be updated is obtained from multiple enumeration classes in the business system, and its enumeration constants are stored in the target data source. When an enumeration constant update is detected in the target data source, the reflection mechanism is used to update the enumeration constant information in the business system.
It realizes real-time dynamic modification of enumeration constants without adjusting the code, which improves the readability and scalability of the business system.
Smart Images

Figure CN119917128A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of data processing technology, and in particular to a data updating method and device. Background Art
[0002] With the rapid development of Internet technology, the scale of business systems is becoming larger and larger, and the system architecture is becoming more and more complex. The usability, scalability and security of business systems are extremely important. There are a large number of enumeration constants in business systems, which are usually scattered in multiple places in the business system, resulting in poor readability and scalability of the business system. Therefore, in order to improve the readability and scalability of the business system, it is necessary to manage the enumeration constants.
[0003] At present, most business systems use enumeration types to uniformly manage enumeration constants within a specified range. For example, the interface in the project returns exception information. Different exception information may correspond to different businesses. Generally, an exception information enumeration class is defined to manage the exception information in the project. However, since the enumeration constants are solidified in the code, these enumeration constants cannot be modified in real time, and the enumeration constants cannot be effectively managed, which makes it impossible to effectively improve the readability and scalability of the business system. Summary of the invention
[0004] The present disclosure aims to solve one of the technical problems in the related art at least to some extent.
[0005] To this end, the present disclosure proposes a data updating method and device, so as to obtain at least one to-be-updated enumeration class from multiple enumeration classes of a business system through configuration information in a configuration file, and store the enumeration constants of the to-be-updated enumeration class in a target data source indicated by a configuration parameter. When the enumeration constants of the to-be-updated enumeration class in the target data source are monitored to be updated, the enumeration constant information of the to-be-updated enumeration class in the business system can be updated by using a reflection mechanism, so that the enumeration constants can be modified dynamically in real time without adjusting the code, and the readability and extensibility of the business system can be effectively improved.
[0006] The first aspect of the present disclosure provides a data update method, comprising: in response to the startup of a business system, loading a set configuration file, and reading configuration information from the configuration file, wherein the configuration information includes path information and configuration parameters of a code package; obtaining at least one to-be-updated enumeration class that matches the annotation information in the configuration parameters from a plurality of enumeration classes of the business system stored in the code package corresponding to the path information; obtaining enumeration constant information of the to-be-updated enumeration class, and storing the enumeration constant information in a target data source indicated by the configuration parameters; in response to monitoring that the enumeration constant information of the to-be-updated enumeration class in the target data source is updated, using a reflection mechanism to update the enumeration constant information of the to-be-updated enumeration class in the business system according to the updated enumeration constant of the to-be-updated enumeration class in the target data source.
[0007] The data updating method of the disclosed embodiment loads a set configuration file in response to the startup of the business system, and reads configuration information from the configuration file, wherein the configuration information includes path information and configuration parameters of the code package; obtains at least one to-be-updated enumeration class that matches the annotation information in the configuration parameters from multiple enumeration classes of the business system stored in the code package corresponding to the path information; obtains enumeration constant information of the to-be-updated enumeration class, and stores the enumeration constant information in the target data source indicated by the configuration parameters; in response to monitoring that the enumeration constant information of the to-be-updated enumeration class in the target data source is updated, adopts a reflection mechanism, according to the The enumeration constants of the to-be-updated enumeration class in the target data source are updated, and the enumeration constant information of the to-be-updated enumeration class in the business system is updated. Thus, at least one to-be-updated enumeration class is obtained from multiple enumeration classes in the business system through the configuration information in the configuration file, and the enumeration constants of the to-be-updated enumeration class are stored in the target data source indicated by the configuration parameters. When the enumeration constants of the to-be-updated enumeration class in the target data source are monitored to be updated, the enumeration constant information of the to-be-updated enumeration class in the business system can be updated by using the reflection mechanism, so that the enumeration constants can be modified dynamically in real time without adjusting the code, which can effectively improve the readability and extensibility of the business system.
[0008] The first aspect of the present disclosure provides a data updating device, comprising: a loading module, for loading a set configuration file in response to a business system startup, and reading configuration information from the configuration file, wherein the configuration information includes path information and configuration parameters of a code package; a first acquisition module, for acquiring at least one to-be-updated enumeration class that matches the annotation information in the configuration parameters from a plurality of enumeration classes of the business system stored in the code package corresponding to the path information; a second acquisition module, for acquiring enumeration constant information of the to-be-updated enumeration class, and storing the enumeration constant information in a target data source indicated by the configuration parameters; an updating module, for updating the enumeration constant information of the to-be-updated enumeration class in the business system according to the updated enumeration constant of the to-be-updated enumeration class in the target data source, in response to monitoring that the enumeration constant information of the to-be-updated enumeration class in the target data source is updated, using a reflection mechanism.
[0009] The third aspect embodiment of the present disclosure proposes an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the data updating method described in the first aspect embodiment of the present disclosure is implemented.
[0010] The fourth aspect embodiment of the present disclosure proposes a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the data updating method as described in the first aspect embodiment of the present disclosure is implemented.
[0011] The fifth aspect embodiment of the present disclosure proposes a computer program product. When the instruction processor in the computer program product executes, it implements the data updating method as described in the first aspect embodiment of the present disclosure.
[0012] Additional aspects and advantages of the present disclosure will be given in part in the following description and in part will be obvious from the following description or learned through practice of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] The above and / or additional aspects and advantages of the present disclosure will become apparent and easily understood from the following description of the embodiments in conjunction with the accompanying drawings, in which:
[0014] Figure 1 A flowchart of a data updating method provided by an embodiment of the present disclosure;
[0015] Figure 2 A flowchart of another data updating method provided by an embodiment of the present disclosure;
[0016] Figure 3 A flowchart of another data updating method provided by an embodiment of the present disclosure;
[0017] Figure 4 A flowchart of another data updating method provided by an embodiment of the present disclosure;
[0018] Figure 5 A flowchart of another data updating method provided by an embodiment of the present disclosure;
[0019] Figure 6 A flowchart of another data updating method provided by an embodiment of the present disclosure;
[0020] Figure 7 A software framework diagram for data updating provided by an embodiment of the present disclosure;
[0021] Figure 8 A schematic diagram of the structure of a data updating device provided by an embodiment of the present disclosure;
[0022] Fig. 9 A schematic diagram of the structure of another data updating device provided in the disclosed embodiment;
[0023] Fig.10 A schematic diagram of the function implementation of the service registration module provided in the embodiment of the present disclosure;
[0024] Fig.11 A schematic diagram of the function implementation of the enumeration initialization module provided in the embodiment of the present disclosure;
[0025] Fig.12 A schematic diagram of the function implementation of the enumeration synchronization module provided in an embodiment of the present disclosure;
[0026] Fig.13 It is a block diagram of an electronic device for data updating according to an exemplary embodiment. DETAILED DESCRIPTION
[0027] Embodiments of the present disclosure are described in detail below, examples of which are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are intended to be used to explain the present disclosure, and should not be construed as limiting the present disclosure.
[0028] It should be noted that the collection, collection, updating, analysis, processing, use, transmission, storage and other aspects of user personal information involved in the technical solution of this disclosure are in compliance with the provisions of relevant laws and regulations, are used for legitimate purposes, and do not violate public order and good morals. Necessary measures are taken for user personal information to prevent illegal access to user personal information data and maintain the security of user personal information, network security and national security.
[0029] Most business systems use enumeration types, which list constant values one by one. These constant values are limited to the range of enumerated values, effectively preventing users from providing invalid values and making the code clearer and easier to manage. As systems become increasingly complex, the number of configuration items in the system increases, and configuration management centers are widely used in business systems. The use of enumeration types and configuration management centers has the following disadvantages:
[0030] 1. The related technology cannot dynamically modify enumeration constants. When the online system needs to modify these enumeration constants, it can only be modified at the code level, and then recompiled and put online. The process is cumbersome and time-consuming because the enumeration constants are solidified in the code;
[0031] 2. The existing configuration management center can realize dynamic modification of configuration, but does not support dynamic modification of enumeration constants. When there are a large number of enumeration constants in the system, if you want to dynamically modify the constants in these enumerations, the changes will be very invasive to the original architecture, that is, the enumeration type needs to be modified to a variable or object to realize its dynamic modification.
[0032] In response to the above problems, the present disclosure proposes a data updating method and device. It should be noted that the data updating method of the embodiment of the present disclosure can be applied to a configuration manager (such as a jar package), and the business system can introduce a configuration manager to dynamically modify the enumeration constants in the system.
[0033] The data updating method and device according to the embodiments of the present disclosure are described below with reference to the accompanying drawings.
[0034] Figure 1 A flowchart of a data updating method provided by an embodiment of the present disclosure is provided.
[0035] like Figure 1 As shown, the data updating method may include the following steps:
[0036] Step 101, in response to the business system starting up, load a set configuration file and read configuration information from the configuration file.
[0037] The configuration information includes the path information and configuration parameters of the code package.
[0038] As an example, business personnel can configure the path information and configuration parameters of the code package storing the business system enumeration class in the configuration file. The configuration parameters may include annotation information of at least one enumeration class to be updated and a data source storing at least one enumeration class to be updated. The data source may include a local disk, a database, or a configuration management center of the business system.
[0039] It should be noted that the configuration management center can be a distributed configuration management center, such as DUCC, Apollo, and Disconf, etc. The local disk can be applicable to a single-machine scenario, and the database and configuration management center can be applicable to a distributed scenario.
[0040] In the embodiment of the present disclosure, in response to the business system starting, a set configuration file can be loaded, and configuration information can be read from the configuration file. The configuration information may include path information and configuration parameters of the code package, and the configuration parameters may include annotation information of at least one enumeration class to be updated, and related parameter information indicating a data source storing at least one enumeration class to be updated.
[0041] Step 102: Obtain at least one to-be-updated enumeration class that matches the annotation information in the configuration parameters from the multiple enumeration classes of the business system stored in the code package corresponding to the path information.
[0042] Furthermore, at least one enumeration class to be updated that matches the annotation information in the configuration parameters can be obtained from multiple enumeration classes in the business system, wherein the annotation information is metadata information additionally added to the enumeration class to facilitate business personnel to find the enumeration class in the code, and the annotation information of the enumeration class is usually only contained in the declaration of the enumeration class.
[0043] Step 103: Obtain enumeration constant information of the enumeration class to be updated, and store the enumeration constant information in the target data source indicated by the configuration parameter.
[0044] As an example, the enumeration constant information may be obtained by using the reflection mechanism and the fully qualified name of the enumeration class to be updated, and the enumeration constant information may be stored in the target data source indicated by the configuration parameter.
[0045] Step 104 , in response to monitoring that the enumeration constant information of the enumeration class to be updated in the target data source is updated, a reflection mechanism is used to update the enumeration constant information of the enumeration class to be updated in the business system according to the updated enumeration constant of the enumeration class to be updated in the target data source.
[0046] As an example, a monitoring function may be used to monitor the enumeration constant information of the to-be-updated enumeration class in the target data source.
[0047] As another example, a callback function is defined in at least one to-be-updated enumeration class, the function is called when the value of the enumeration constant changes, and the enumeration constant information is passed to the callback function as a parameter.
[0048] In an embodiment of the present disclosure, in response to monitoring that the enumeration constant information of the enumeration class to be updated in the target data source is updated, a reflection mechanism is adopted to update the enumeration constant information of the enumeration class to be updated in the business system according to the updated enumeration constant of the enumeration class to be updated in the target data source.
[0049] Among them, it should be noted that because the reflection mechanism allows the value of the enumeration constant to be dynamically modified at runtime, the reflection mechanism is adopted to update the enumeration constant information of the enumeration class to be updated in the business system according to the updated enumeration constant of the enumeration class to be updated in the target data source, without the need to recompile the code, and at the same time, it is realized that there is no need to change the enumeration type to a variable or object to realize its dynamic modification.
[0050] In summary, in response to the business system startup, the set configuration file is loaded, and the configuration information is read from the configuration file, wherein the configuration information includes the path information and configuration parameters of the code package; at least one to-be-updated enumeration class that matches the annotation information in the configuration parameters is obtained from multiple enumeration classes of the business system stored in the code package corresponding to the path information; the enumeration constant information of the to-be-updated enumeration class is obtained, and the enumeration constant information is stored in the target data source indicated by the configuration parameters; in response to monitoring that the enumeration constant information of the to-be-updated enumeration class in the target data source is updated, a reflection mechanism is adopted to update the enumeration constant information of the to-be-updated enumeration class in the target data source according to the enumeration constant information of the to-be-updated enumeration class in the target data source. The updated enumeration constants update the enumeration constant information of the enumeration class to be updated in the business system. Thus, at least one enumeration class to be updated is obtained from multiple enumeration classes in the business system through the configuration information in the configuration file, and the enumeration constants of the enumeration class to be updated are stored in the target data source indicated by the configuration parameters. When the enumeration constants of the enumeration class to be updated in the target data source are monitored to be updated, the reflection mechanism can be used to update the enumeration constant information of the enumeration class to be updated in the business system, so that the enumeration constants can be modified dynamically in real time without adjusting the code, which can effectively improve the readability and extensibility of the business system.
[0051] As an example, when the target data source is a local disk of a business system, the enumeration constant information of the enumeration class to be updated in the business system can be updated according to the enumeration constant information of the enumeration class to be updated in the local file of the local disk. Figure 2 The embodiments are described in detail.
[0052] Figure 2 A flowchart of another data updating method provided by an embodiment of the present disclosure.
[0053] like Figure 2 As shown, the data updating method may include the following steps:
[0054] Step 201, in response to the business system starting up, load a set configuration file, and read configuration information from the configuration file.
[0055] The configuration information includes the path information and configuration parameters of the code package.
[0056] Step 202: Obtain at least one to-be-updated enumeration class that matches the annotation information in the configuration parameters from the multiple enumeration classes of the business system stored in the code package corresponding to the path information.
[0057] Step 203: Obtain enumeration constant information of the enumeration class to be updated, and store the enumeration constant information in the target data source indicated by the configuration parameter.
[0058] The target data source is the local disk of the business system.
[0059] As an example, the target data source indicated by the configuration parameter may be a local disk of the business system, and the enumeration constant information may be stored in a local file of the local disk.
[0060] Step 204: Whenever a set period is reached, read the enumeration constant information of the enumeration class to be updated in the local file of the local disk.
[0061] As an example, a timer can be used to read the enumeration constant information of the enumeration class to be updated in the local file of the local disk every time a set period is reached, so as to achieve regular pulling of the enumeration constant information of the enumeration class to be updated in the local file.
[0062] Step 205: in response to monitoring that the enumeration constant information of the to-be-updated enumeration class in the local file is updated, it is determined whether the enumeration switch in the configuration parameter is in an on state.
[0063] In order to improve the security of the business system, as an example, in response to monitoring the update of the enumeration constant information of the enumeration class to be updated in the local file, it can be further determined whether the enumeration switch in the configuration parameter is in the on state. It should be noted that the enumeration switch in the configuration parameter is used to indicate whether the business system uses the enumeration constant in the code or the enumeration constant in the target data source.
[0064] Step 206 , in response to the enumeration switch in the configuration parameter being in the on state, a reflection mechanism is used to update the enumeration constant information of the enumeration class to be updated in the business system according to the updated enumeration constant information of the enumeration class to be updated in the local file.
[0065] As an example, in response to the enumeration switch in the configuration parameter being in the on state, a reflection mechanism can be used to update the enumeration constant information of the enumeration class to be updated in the business system according to the updated enumeration constant information of the enumeration class to be updated in the local file. For example, a reflection mechanism is used to update the enumeration constant information of the enumeration class to be updated in the business system according to the updated enumeration constant information in the enumeration class to be updated.
[0066] As another example, in response to the enumeration switch in the configuration parameter being in an off state, the enumeration constant information of the enumeration class to be updated in the business system is maintained and used.
[0067] In summary, whenever a set period is reached, the enumeration constant information of the enumeration class to be updated in the local file of the local disk is read; in response to monitoring that the enumeration constant information of the enumeration class to be updated in the local file is updated, it is determined whether the enumeration switch in the configuration parameters is in the on state; in response to the enumeration switch in the configuration parameters being in the on state, a reflection mechanism is adopted to update the enumeration constant information of the enumeration class to be updated in the business system according to the updated enumeration constant information of the enumeration class to be updated in the local file. Therefore, by combining the enumeration constants with the local file of this disk, the dynamic configuration of the enumeration constants is realized, and by utilizing the reflection mechanism, the enumeration constant information of the enumeration class to be updated in the business system is updated according to the updated enumeration constant information of the enumeration class to be updated in the local file. Therefore, the enumeration constants can be modified dynamically in real time without adjusting the code, which can effectively improve the readability and extensibility of the business system.
[0068] As another example, the target data source is a database. The enumeration constant information of the enumeration class to be updated in the business system can be updated according to the enumeration constant information of the enumeration class to be updated in the database. Figure 3 The embodiments are described in detail.
[0069] Figure 3 A flowchart of another data updating method provided by an embodiment of the present disclosure.
[0070] like Figure 3 As shown, the data updating method may include the following steps:
[0071] Step 301, in response to the business system starting up, load a set configuration file and read configuration information from the configuration file.
[0072] The configuration information includes the path information and configuration parameters of the code package.
[0073] Step 302: Obtain at least one to-be-updated enumeration class that matches the annotation information in the configuration parameters from the multiple enumeration classes of the business system stored in the code package corresponding to the path information.
[0074] Step 303: Obtain enumeration constant information of the enumeration class to be updated, and store the enumeration constant information in the target data source indicated by the configuration parameter.
[0075] As an example, the target data source indicated by the configuration parameter is a database, which may be a database suitable for distributed scenarios, and the enumeration constant information may be stored in the database indicated by the configuration parameter.
[0076] Step 304: in response to monitoring that the enumeration constant information of the to-be-updated enumeration class in the database is updated, determining whether the enumeration switch in the configuration parameter is in an on state.
[0077] In order to improve the security of the system, in response to monitoring that the enumeration constant information of the to-be-updated enumeration class in the database is updated, it can be further determined whether the enumeration switch in the configuration parameter is in the on state.
[0078] Step 305 , in response to the enumeration switch in the configuration parameter being in the on state, a reflection mechanism is adopted to update the enumeration constant information of the enumeration class to be updated in the business system according to the updated enumeration constant information of the enumeration class to be updated in the database.
[0079] As an example, when the enumeration switch in the configuration parameters is turned on, a reflection mechanism can be used to update the corresponding enumeration constant information of the enumeration class to be updated in the business system according to the updated enumeration constant information sent from the database.
[0080] In summary, in response to monitoring that the enumeration constant information of the enumeration class to be updated in the database is updated, it is determined whether the enumeration switch in the configuration parameter is in the on state; in response to the enumeration switch in the configuration parameter being in the on state, a reflection mechanism is adopted to update the enumeration constant information of the enumeration class to be updated in the business system according to the updated enumeration constant information of the enumeration class to be updated in the database. Therefore, by combining the enumeration constants with the database, the dynamic configuration of the enumeration constants is realized, and by utilizing the reflection mechanism, the enumeration constant information of the enumeration class to be updated in the business system is updated according to the updated enumeration constant information of the enumeration class to be updated in the database, so that the enumeration constants can be modified dynamically in real time without adjusting the code, which can effectively improve the readability and extensibility of the business system.
[0081] As another example, the target data source is the configuration management center. The enumeration constant information of the enumeration class to be updated in the business system can be updated according to the enumeration constant information of the enumeration class to be updated in the configuration management center. Figure 4 The embodiments are described in detail.
[0082] Figure 4 A flowchart of another data updating method provided by an embodiment of the present disclosure.
[0083] like Figure 4 As shown, the data updating method may include the following steps:
[0084] Step 401, in response to the business system starting up, load a set configuration file and read configuration information from the configuration file.
[0085] The configuration information includes the path information and configuration parameters of the code package.
[0086] Step 402: Obtain at least one to-be-updated enumeration class that matches the annotation information in the configuration parameters from the multiple enumeration classes of the business system stored in the code package corresponding to the path information.
[0087] Step 403: Obtain enumeration constant information of the enumeration class to be updated, and store the enumeration constant information in the target data source indicated by the configuration parameter.
[0088] Among them, the target data source is the configuration management center.
[0089] As an example, the target data source indicated by the configuration parameter is a configuration management center, which may be a distributed configuration management center, such as DUCC, Apollo, and Disconf. The configuration management center can centrally manage the configurations of different application environments and different clusters.
[0090] Step 404: in response to monitoring that the enumeration constant information of the to-be-updated enumeration class in the configuration management center is updated, it is determined whether the enumeration switch in the configuration parameter is in an on state.
[0091] As an example, the configuration parameters also include an enumeration switch, which is used to indicate whether the business system uses the enumeration constant in the code or the enumeration constant in the target data source.
[0092] In order to improve the security of the system, in the embodiment of the present disclosure, in response to monitoring that the enumeration constant information of the enumeration class to be updated in the configuration management center is updated, it can be further determined whether the enumeration switch in the configuration parameter is in the on state.
[0093] Step 405 , in response to the enumeration switch in the configuration parameter being in the on state, a reflection mechanism is adopted to update the enumeration constant information of the enumeration class to be updated in the business system according to the updated enumeration constant of the enumeration class to be updated in the configuration management center.
[0094] As an example, in response to the enumeration switch in the configuration parameter being in an on state, a reflection mechanism is used to update the enumeration constant information of the enumeration class to be updated in the business system according to the updated enumeration constants in the enumeration class to be updated in the configuration management center.
[0095] In summary, by obtaining the enumeration constant information of the enumeration class to be updated, and storing the enumeration constant information in the target data source indicated by the configuration parameter; in response to monitoring that the enumeration constant information of the enumeration class to be updated in the configuration management center is updated, it is determined whether the enumeration switch in the configuration parameter is in the on state; in response to the enumeration switch in the configuration parameter being in the on state, a reflection mechanism is adopted to update the enumeration constant information of the enumeration class to be updated in the business system according to the updated enumeration constant of the enumeration class to be updated in the configuration management center. Therefore, by combining the enumeration constant with the configuration management center, the dynamic configuration of the enumeration constant is realized, and by utilizing the reflection mechanism, the enumeration constant information of the enumeration class to be updated in the business system is updated according to the updated enumeration constant information of the enumeration class to be updated in the configuration management center. Therefore, the enumeration constant can be modified dynamically in real time without adjusting the code, which can effectively improve the readability and extensibility of the business system.
[0096] In order to clearly explain how to obtain the enumeration constant information of the enumeration class to be updated in the above embodiment and store the enumeration constant information in the target data source indicated by the configuration parameter, the present disclosure proposes another data updating method.
[0097] Figure 5 A flowchart of another data updating method provided by an embodiment of the present disclosure.
[0098] like Figure 5 As shown, the data updating method may include the following steps:
[0099] Step 501, in response to the business system starting up, load a set configuration file, and read configuration information from the configuration file.
[0100] The configuration information includes the path information and configuration parameters of the code package.
[0101] Step 502: Obtain at least one to-be-updated enumeration class that matches the annotation information in the configuration parameters from the multiple enumeration classes of the business system stored in the code package corresponding to the path information.
[0102] Step 503: parse the enumeration class to be updated to obtain the fully qualified name of the enumeration class to be updated.
[0103] As an example, the fully qualified name of the enumeration class to be updated may be obtained by parsing the enumeration class to be updated. The fully qualified name usually consists of multiple parts such as a package name, a class name, and a method name.
[0104] Step 504: using the reflection mechanism, according to the fully qualified name of the enumeration class to be updated, obtain the enumeration constant information of the enumeration class to be updated.
[0105] As an example, the reflection mechanism can be used to obtain all fields of the enumeration class to be updated according to the fully qualified name of the enumeration class to be updated, and then each declared field is checked. If the field is an enumeration constant, the value of the enumeration constant can be obtained.
[0106] Step 505: determine the target data source indicated by the configuration parameters.
[0107] As an example, the configuration parameters may also include parameter information indicating a target data source, wherein the target data source is: a local disk, a database, or a configuration management center.
[0108] Step 506: Store the enumeration constant information of the enumeration class to be updated in the target data source.
[0109] Furthermore, the enumeration constant information of the enumeration class to be updated is stored in the target data source, so that the data source has the same enumeration constant information as the business system.
[0110] Step 507 , in response to monitoring that the enumeration constant information of the enumeration class to be updated in the target data source is updated, the reflection mechanism is used to update the enumeration constant information of the enumeration class to be updated in the business system according to the updated enumeration constant of the enumeration class to be updated in the target data source.
[0111] In summary, the enumeration class to be updated is parsed to obtain the fully qualified name of the enumeration class to be updated; the reflection mechanism is used to obtain the enumeration constant information of the enumeration class to be updated according to the fully qualified name of the enumeration class to be updated; the target data source indicated by the configuration parameters is determined; the enumeration constant information of the enumeration class to be updated is stored in the target data source, thereby effectively obtaining the enumeration constant information of the enumeration class to be updated in the business system, and storing the enumeration constant information of the enumeration class to be updated in the target data source indicated by the configuration parameters, so that the target data source has the same enumeration constant information as the business system, so that when the enumeration constant information in the target data source changes, the changed enumeration constant information in the data source can be synchronized to the business system, and the enumeration constant can be modified in real time without adjusting the code.
[0112] In order to clearly illustrate how in the above embodiment, at least one enumeration class to be updated that matches the annotation information in the configuration parameters is obtained from multiple enumeration classes of the business system stored in the code package corresponding to the path information, the present disclosure proposes a flowchart of another data updating method.
[0113] Figure 6 A flowchart of another data updating method provided by an embodiment of the present disclosure.
[0114] like Figure 6 As shown, the data updating method may include the following steps:
[0115] Step 601, in response to the business system starting up, loading a set configuration file, and reading configuration information from the configuration file.
[0116] The configuration information includes the path information and configuration parameters of the code package.
[0117] Step 602: Scan the path information through a class initialization analysis scanner to obtain multiple enumeration classes stored in a code package corresponding to the path information.
[0118] As an example, the Spring life cycle mechanism is used to scan the path information through a class initialization analysis scanner to obtain multiple enumeration classes stored in a code package corresponding to the path information.
[0119] Step 603: Obtain annotation information in the configuration parameters.
[0120] As an example, configuration parameters may include annotation information.
[0121] Step 604: Determine at least one to-be-updated enumeration class that matches the annotation information from among the multiple enumeration classes.
[0122] Furthermore, at least one to-be-updated enumeration class matching the annotation information may be obtained from the plurality of enumeration classes.
[0123] Step 605: Obtain enumeration constant information of the enumeration class to be updated, and store the enumeration constant information in the target data source indicated by the configuration parameter.
[0124] Step 606, in response to monitoring that the enumeration constant information of the enumeration class to be updated in the target data source is updated, a reflection mechanism is used to update the enumeration constant information of the enumeration class to be updated in the business system according to the updated enumeration constant of the enumeration class to be updated in the target data source.
[0125] In summary, the path information is scanned by a class initialization analysis scanner to obtain multiple enumeration classes stored in a code package corresponding to the path information; the annotation information in the configuration parameters is obtained; and from the multiple enumeration classes, at least one enumeration class to be updated that matches the annotation information is determined, thereby effectively obtaining at least one enumeration class to be updated.
[0126] In the embodiments of the present disclosure, Figure 7 As shown, Figure 7 The software framework diagram of data update provided by the embodiment of the present disclosure is as follows: when the system starts, the enumeration that needs to be dynamically modified is loaded into the system context through configuration, and then the enumeration constant is modified according to the configuration item selection policy. In the data update method of the embodiment of the present disclosure, the user only needs to perform simple configuration to dynamically modify the enumeration constant in a single machine or distributed scenario.
[0127] Based on any embodiment of the present disclosure, the data updating method of the embodiment of the present disclosure can also be implemented based on the following steps:
[0128] 1. Import the enumeration constant dynamic configuration code package into the business system, add custom annotations to the enumeration that needs to support the dynamic configuration function, add enumeration switches and data sources and other configurations in the configuration file, and inject the configuration information into the enumeration configuration manager.
[0129] 2. When the business system starts, it scans all enumerations with custom annotations, parses the fully qualified class names, and fills them into the corresponding properties of the enumeration configuration manager;
[0130] 3. The enumeration configuration manager uses the reflection mechanism to obtain all enumeration constant information through the fully qualified name of the enumeration class and synchronizes it to the data source.
[0131] 4. The enumeration configuration manager establishes a connection with the data source and views / listens to configuration changes in the data source in real time.
[0132] 5. When the enumeration configuration manager detects changes in the enumeration constants of the data source, if the enumeration switch is turned on, it will use the reflection mechanism to synchronize the change information of the data source to the corresponding enumeration of the business system. At this time, the enumeration constants in the business system are consistent with the enumeration information in the configuration management center, which means that the real-time dynamic modification of the enumeration constants is realized.
[0133] In order to implement the above embodiments, the present disclosure proposes a data updating device.
[0134] Figure 8 A schematic diagram of the structure of a data updating device provided in an embodiment of the present disclosure.
[0135] like Figure 8 As shown, the data updating device 800 includes: a loading module 810 , a first obtaining module 820 , a second obtaining module 830 and an updating module 840 .
[0136] Among them, the loading module 810 is used to load the set configuration file in response to the startup of the business system, and read the configuration information from the configuration file, wherein the configuration information includes the path information and configuration parameters of the code package; the first acquisition module 820 is used to obtain at least one to-be-updated enumeration class that matches the annotation information in the configuration parameters from multiple enumeration classes of the business system stored in the code package corresponding to the path information; the second acquisition module 830 is used to obtain the enumeration constant information of the to-be-updated enumeration class, and store the enumeration constant information in the target data source indicated by the configuration parameters; the update module 840 is used to respond to monitoring that the enumeration constant information of the to-be-updated enumeration class in the target data source is updated, and adopt a reflection mechanism to update the enumeration constant information of the to-be-updated enumeration class in the business system according to the updated enumeration constant of the to-be-updated enumeration class in the target data source.
[0137] As a possible implementation method of the embodiment of the present disclosure, the target data source is the local disk of the business system, and the update module 840 is used to read the enumeration constant information of the enumeration class to be updated in the local file of the local disk whenever a set period is reached; in response to monitoring that the enumeration constant information of the enumeration class to be updated in the local file is updated, determine whether the enumeration switch in the configuration parameter is in the on state; in response to the enumeration switch in the configuration parameter being in the on state, adopt a reflection mechanism to update the enumeration constant information of the enumeration class to be updated in the business system according to the updated enumeration constant information of the enumeration class to be updated in the local file.
[0138] As a possible implementation of the embodiment of the present disclosure, the target data source is a database, and the update module 840 is used to judge whether the enumeration switch in the configuration parameter is in the on state in response to monitoring that the enumeration constant information of the enumeration class to be updated in the database is updated; in response to the enumeration switch in the configuration parameter being in the on state, adopt a reflection mechanism to update the enumeration constant information of the enumeration class to be updated in the business system according to the updated enumeration constant information of the enumeration class to be updated in the database.
[0139] As a possible implementation method of the embodiment of the present disclosure, the target data source is a configuration management center, and the update module 840 is used to judge whether the enumeration switch in the configuration parameter is in the on state in response to monitoring that the enumeration constant information of the enumeration class to be updated in the configuration management center is updated; in response to the enumeration switch in the configuration parameter being in the on state, adopt a reflection mechanism to update the enumeration constant information of the enumeration class to be updated in the business system according to the updated enumeration constant of the enumeration class to be updated in the configuration management center.
[0140] As a possible implementation method of the embodiment of the present disclosure, the second acquisition module 830 is used to parse the enumeration class to be updated to obtain the fully qualified name of the enumeration class to be updated; use the reflection mechanism to obtain the enumeration constant information of the enumeration class to be updated according to the fully qualified name of the enumeration class to be updated; determine the target data source indicated by the setting parameter; and store the enumeration constant information of the enumeration class to be updated in the target data source.
[0141] As a possible implementation method of the embodiment of the present disclosure, the first acquisition module 820 is used to scan the path information through the class initialization analysis scanner to obtain multiple enumeration classes stored in the code package corresponding to the path information; obtain annotation information in the configuration parameters; and determine at least one enumeration class to be updated that matches the annotation information from the multiple enumeration classes.
[0142] As a possible implementation of the embodiment of the present disclosure, the data updating device 800 further includes: a maintaining module.
[0143] The maintaining module is used to maintain and use the enumeration constant information of the enumeration class to be updated in the business system in response to the enumeration switch in the configuration parameter being in an off state.
[0144] The data updating device of the disclosed embodiment loads a set configuration file in response to the startup of the business system, and reads configuration information from the configuration file, wherein the configuration information includes path information and configuration parameters of the code package; obtains at least one to-be-updated enumeration class that matches the annotation information in the configuration parameters from multiple enumeration classes of the business system stored in the code package corresponding to the path information; obtains enumeration constant information of the to-be-updated enumeration class, and stores the enumeration constant information in the target data source indicated by the configuration parameters; in response to monitoring that the enumeration constant information of the to-be-updated enumeration class in the target data source is updated, adopts a reflection mechanism, and updates the enumeration constant information according to the to-be-updated enumeration class in the target data source. Update the updated enumeration constants of the enumeration class, and update the enumeration constant information of the enumeration class to be updated in the business system. Therefore, through the configuration information in the configuration file, at least one enumeration class to be updated is obtained from multiple enumeration classes in the business system, and the enumeration constants of the enumeration class to be updated are stored in the target data source indicated by the configuration parameters. When the enumeration constants of the enumeration class to be updated in the target data source are monitored to be updated, the reflection mechanism can be used to update the enumeration constant information of the enumeration class to be updated in the business system, so that the enumeration constants can be modified dynamically in real time without adjusting the code, which can effectively improve the readability and extensibility of the business system.
[0145] Figure 8 The data updating device of the embodiment is divided based on the execution action. In the embodiment of the present disclosure, it can also be divided based on the implementation function. As an example, Fig. 9As shown, according to the implementation functions, it can be divided into the following three modules: service registration module, enumeration initialization module and enumeration synchronization module.
[0146] Among them, the function of the service registration module can be realized as follows Fig.10 As shown, when the application system starts, the system will load the enumeration configuration file and obtain the package scanning path and related parameters in the configuration file. The package scanning path is the package path where the enumeration class is stored. Then, using the Spring lifecycle mechanism, the class initialization analysis scanner scans the enumeration class containing custom annotations under the package path, obtains the fully qualified name set of all enumeration classes containing the annotation, and loads the fully qualified name set and configuration-related parameters into the enumeration configuration manager; the enumeration configuration manager is essentially a Bean object in the Spring container, which is used to manage the fully qualified name and related configuration information of the enumeration class. Related configuration information includes the enumeration synchronization switch and data source information. The enumeration synchronization switch is used to control whether the system uses the enumeration constants in the local code or the enumeration constants in the data source, thereby improving the security of the system; the data source information is used to establish a connection between the system and the data source. The data source can be a local disk, a distributed configuration center, or a database;
[0147] The function of enumeration initialization module can be realized as follows Fig.11 As shown: In the initialization phase of the enumeration configuration manager, the fully qualified name of the enumeration class and the reflection mechanism are used to obtain the object of the enumeration class, thereby obtaining the enumeration constant information. Then, the enumeration configuration manager establishes a connection between the business system and the data source based on the data source information, and initializes the enumeration constant information into the data source. Among them, the data source mainly supports one of the following three modes: local disk, configuration management center and database, among which local disk is suitable for single-machine scenarios, and configuration management center and database are suitable for distributed scenarios;
[0148] 1. If the local disk is used as the data source, the enumeration configuration management center writes the enumeration information into the local file, and uses the timer to periodically pull the enumeration constants in the local file and synchronize them to the enumeration of the application system;
[0149] 2. If the configuration management center is used as the data source, the enumeration configuration manager will synchronize the enumeration information to the configuration management center in JSON format and establish a monitoring with the configuration management center. If the enumeration information in the configuration management center is changed, the change information will be synchronized to the enumeration of the application system;
[0150] 3. If the database is used as the data source, the enumeration configuration management center will save the enumeration information to the database and monitor the change log of the database (any changes in the data in the database will be recorded in the log file). If the enumeration information in the database is monitored to change, the change information will be synchronized to the enumeration of the application system;
[0151] This module automatically synchronizes the enumeration constants in the business system to the data source, avoiding errors that may be caused by manually adding enumeration constants and improving the security and efficiency of the system.
[0152] The function of enumerating synchronization modules can be realized as follows Fig.12 As shown: After the enumeration configuration manager initializes the enumeration constants to the configuration management center, it will establish a connection with the configuration management center based on the connection information of the data source, and view / listen to the configuration management center information in real time. When the enumeration configuration manager listens to changes in the configuration center, it will determine whether the enumeration switch is turned on. If the enumeration switch is turned on, it will obtain the enumeration constant information that has changed in the data source in real time, and then use the reflection mechanism to inject the information into the corresponding enumeration of the application system. Among them, the enumeration switch controls whether the business system uses the enumeration constants in the code or the enumeration constants in the data source. The switch is turned on by default and can be configured in the data source, which enhances the security of the system.
[0153] It should be noted that the above explanations of the data updating method embodiment are also applicable to the data updating device of this embodiment, and will not be repeated here.
[0154] In order to implement the above embodiments, the present application also proposes an electronic device, such as Fig.13 As shown, Fig.13 It is a block diagram of an electronic device for data updating according to an exemplary embodiment.
[0155] like Fig.13 As shown, the electronic device 1300 includes:
[0156] The memory 1310 and the processor 1320, a bus 1330 connecting different components (including the memory 1310 and the processor 1320), the memory 1310 stores a computer program, and when the processor 1320 executes the program, the data updating method described in the embodiment of the present disclosure is implemented.
[0157] Bus 1330 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor or a local bus using any of a variety of bus architectures. For example, these architectures include but are not limited to Industry Standard Architecture (ISA) bus, Micro Channel Architecture (MAC) bus, Enhanced ISA bus, Video Electronics Standards Association (VESA) local bus and Peripheral Component Interconnect (PCI) bus.
[0158] The electronic device 1300 typically includes a variety of electronic device readable media. These media can be any available media that can be accessed by the electronic device 1300, including volatile and non-volatile media, removable and non-removable media.
[0159] The memory 1310 may also include computer system readable media in the form of volatile memory, such as random access memory (RAM) 1340 and / or cache memory 1350. The electronic device 1300 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, the storage system 1360 may be used to read and write non-removable, non-volatile magnetic media ( Fig.13 not shown, usually called a "hard drive"). Although Fig.13 Not shown, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk"), and an optical disk drive for reading and writing to a removable non-volatile optical disk (e.g., a CD-ROM, a DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to the bus 1330 via one or more data medium interfaces. The memory 1310 may include at least one program product having a set (e.g., at least one) of program modules that are configured to perform the functions of the various embodiments of the present disclosure.
[0160] A program / utility 1380 having a set (at least one) of program modules 1370 may be stored, for example, in the memory 1310, such program modules 1370 including but not limited to an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment. The program modules 1370 generally perform the functions and / or methods of the embodiments described in the present disclosure.
[0161] The electronic device 1300 may also communicate with one or more external devices 1390 (e.g., keyboards, pointing devices, displays, etc.), one or more devices that enable a user to interact with the electronic device 1300, and / or any device that enables the electronic device 1300 to communicate with one or more other computing devices (e.g., network cards, modems, etc.). Such communication may be performed through an input / output (I / O) interface 1392. Furthermore, the electronic device 1300 may also communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) through a network adapter 1393. Fig.13 As shown, the network adapter 1393 communicates with other modules of the electronic device 1300 via the bus 1330. It should be understood that although Fig.13Not shown, other hardware and / or software modules may be used in conjunction with electronic device 1300, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0162] The processor 1320 executes various functional applications and data processing by running the programs stored in the memory 1310 .
[0163] It should be noted that the implementation process and technical principles of the electronic device of this embodiment refer to the aforementioned explanation of the data updating method of the embodiment of the present disclosure, and will not be repeated here.
[0164] In order to implement the above embodiments, the present disclosure further proposes a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the data updating method described in the above embodiments is implemented.
[0165] In order to implement the above embodiments, the present disclosure further provides a computer program product. When an instruction processor in the computer program product is executed, the data updating method described in the above embodiments is executed.
[0166] In the description of this specification, the terms "first" and "second" are used for descriptive purposes only and cannot be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features. In the description of this application, the meaning of "plurality" is at least two, such as two, three, etc., unless otherwise clearly and specifically defined.
[0167] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present application. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art may combine and combine the different embodiments or examples described in this specification and the features of the different embodiments or examples, without contradiction.
[0168] Although the embodiments of the present application have been shown and described above, it can be understood that the above embodiments are exemplary and cannot be understood as limitations on the present application. Ordinary technicians in this field can change, modify, replace and modify the above embodiments within the scope of the present application.
Claims
1. A data updating method, characterized in that: include: In response to the business system starting up, loading a set configuration file, and reading configuration information from the configuration file, wherein the configuration information includes path information and configuration parameters of the code package; Acquire at least one to-be-updated enumeration class that matches the annotation information in the configuration parameter from a plurality of enumeration classes of the business system stored in the code package corresponding to the path information; Obtaining enumeration constant information of the enumeration class to be updated, and storing the enumeration constant information in the target data source indicated by the configuration parameter; In response to monitoring that the enumeration constant information of the to-be-updated enumeration class in the target data source is updated, a reflection mechanism is adopted to update the enumeration constant information of the to-be-updated enumeration class in the business system according to the updated enumeration constant of the to-be-updated enumeration class in the target data source.
2. The method according to claim 1, characterized in that The target data source is a local disk of the business system. In response to monitoring that the enumeration constant information of the to-be-updated enumeration class in the target data source is updated, a reflection mechanism is adopted to update the enumeration constant information of the to-be-updated enumeration class in the business system according to the updated enumeration constant of the to-be-updated enumeration class in the target data source, including: Whenever a set period is reached, the enumeration constant information of the to-be-updated enumeration class in the local file of the local disk is read; In response to monitoring that the enumeration constant information of the to-be-updated enumeration class in the local file is updated, determining whether the enumeration switch in the configuration parameter is in an on state; In response to the enumeration switch in the configuration parameter being in an on state, a reflection mechanism is adopted to update the enumeration constant information of the to-be-updated enumeration class in the business system according to the updated enumeration constant information of the to-be-updated enumeration class in the local file.
3. The method according to claim 1, characterized in that The target data source is a database, and in response to monitoring that the enumeration constant information of the to-be-updated enumeration class in the target data source is updated, a reflection mechanism is adopted to update the enumeration constant information of the to-be-updated enumeration class in the business system according to the updated enumeration constant of the to-be-updated enumeration class in the target data source, including: In response to monitoring that the enumeration constant information of the to-be-updated enumeration class in the database is updated, determining whether the enumeration switch in the configuration parameter is in an on state; In response to the enumeration switch in the configuration parameter being in an on state, a reflection mechanism is adopted to update the enumeration constant information of the to-be-updated enumeration class in the business system according to the updated enumeration constant information of the to-be-updated enumeration class in the database.
4. The method according to claim 1, characterized in that: The target data source is a configuration management center, and in response to monitoring that the enumeration constant information of the to-be-updated enumeration class in the target data source is updated, a reflection mechanism is adopted to update the enumeration constant information of the to-be-updated enumeration class in the business system according to the updated enumeration constant of the to-be-updated enumeration class in the target data source, including: In response to monitoring that the enumeration constant information of the to-be-updated enumeration class in the configuration management center is updated, determining whether the enumeration switch in the configuration parameter is in an on state; In response to the enumeration switch in the configuration parameter being in an on state, a reflection mechanism is adopted to update the enumeration constant information of the enumeration class to be updated in the business system according to the updated enumeration constant of the enumeration class to be updated in the configuration management center.
5. The method according to claim 1, characterized in that The obtaining the enumeration constant information of the to-be-updated enumeration class and storing the enumeration constant information in the target data source indicated by the configuration parameter includes: Parsing the to-be-updated enumeration class to obtain the fully qualified name of the to-be-updated enumeration class; Using the reflection mechanism, according to the fully qualified name of the enumeration class to be updated, the enumeration constant information of the enumeration class to be updated is obtained; Determine the target data source indicated by the setting parameter; The enumeration constant information of the enumeration class to be updated is stored in the target data source.
6. The method according to claim 1, characterized in that The acquiring, from a plurality of enumeration classes of the business system stored in the code package corresponding to the path information, at least one to-be-updated enumeration class matching the annotation information in the configuration parameter comprises: Scanning the path information through a class initialization analysis scanner to obtain a plurality of enumeration classes stored in a code package corresponding to the path information; Obtaining annotation information in the configuration parameters; At least one to-be-updated enumeration class matching the annotation information is determined from the multiple enumeration classes.
7. The method according to any one of claims 2, 3 or 4, characterized in that The method further comprises: In response to the enumeration switch in the configuration parameter being in an off state, the enumeration constant information of the to-be-updated enumeration class in the business system is maintained and used.
8. A data updating device, characterized in that: include: A loading module, used to load a set configuration file in response to the business system starting up, and read configuration information from the configuration file, wherein the configuration information includes path information and configuration parameters of the code package; A first acquisition module, configured to acquire at least one to-be-updated enumeration class that matches the annotation information in the configuration parameter from a plurality of enumeration classes of the business system stored in the code package corresponding to the path information; A second acquisition module, used for acquiring the enumeration constant information of the enumeration class to be updated, and storing the enumeration constant information in the target data source indicated by the configuration parameter; The update module is used to respond to monitoring that the enumeration constant information of the enumeration class to be updated in the target data source is updated, and adopt a reflection mechanism to update the enumeration constant information of the enumeration class to be updated in the business system according to the updated enumeration constant of the enumeration class to be updated in the target data source.
9. An electronic device, characterized in that: The method comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the data updating method according to any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the data updating method according to any one of claims 1 to 7 is implemented.