Business system database switching method and device, equipment and medium
By adding annotations to the database of the business system and configuring the dual-write mode, the complexity and maintenance difficulties caused by code confusion during the database switching process are solved, and simplified database switching and efficient data source management are achieved.
Patent Information
- Application Number
- CN202411538518.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-30
- Publication Date
- 2025-02-18
AI Technical Summary
In the prior art, during the switching of the business system database, the double-written code is mixed with the business-related code, resulting in increased system complexity and coupling, difficulty in maintaining, and the workload of double-written logic is large.
By adding annotations to the original database of the business system, configuring the database connection information and data table correspondence relationship, realizing the database's double-write mode and data source switching, and packaging the relevant code into a jar package to realize the data source switching of the business system.
It reduces the workload of developers to manually develop public logic, supports the ID of the two databases to be consistent when adding new data, simplifies the database switching process, and reduces system complexity and maintenance difficulty.
Smart Images

Figure CN119474054A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of underlying database switching, and specifically relates to a business system database switching method, device, equipment and medium. Background Art
[0002] As for the databases used by general business systems, some systems are still using foreign databases such as Oracle and MySQL. Among them, Oracle database is not only expensive, but also easily restricted and affected. Therefore, it is very necessary to switch the underlying database of the used business system.
[0003] In order not to affect the user experience and reduce the probability of errors in the production environment, the current mainstream solution for business systems is to use database dual-write to perform gradual switching. The specific process is as follows: Step 1: Use the ETL synchronization tool to synchronize the data in the Oracle database to the trusted database; Step 2: The application system turns on dual-write mode and still uses the Oracle database to process user read and write requests, but executes user write requests asynchronously in the trusted database; Step 3: The application system is still in dual-write mode, but uses the trusted database to process user read and write requests, and executes user write requests asynchronously in the Oracle database; Step 4: Stop asynchronous write operations to Oracle, and go offline with the Oracle database to complete the switching of the system's underlying database.
[0004] The above solution requires four steps. If each step is developed by the developer himself, the development workload will be huge. In addition, the developers' levels are different, which may lead to many hidden problems. In addition, mixing the double-written code with the business-related code will increase the complexity and coupling of the system, which is not conducive to later maintenance. Including the completion of the database switch, the double-write logic offline will also require a relatively large workload. Summary of the invention
[0005] In order to solve the above technical problems, the present invention provides a business system database switching method, system, device and storage medium to solve the technical problem that mixing double-written code with business-related code will increase the complexity and coupling of the system, which is not conducive to subsequent maintenance, and the double-written logic offline will also require a relatively large workload.
[0006] In a first aspect, the invention provides the following technical solution, a method for switching a business system database, the method comprising:
[0007] Obtain the original database of the business system and create a new trusted database, and configure the connection information and data table correspondence between the original database and the trusted database;
[0008] Performing a first annotation on the class of the original database, and identifying the original database and the trusted database based on the first annotation;
[0009] Perform a second annotation on the execution class method of the original database, determine the dual-write mode of the original database and the trusted database based on the second annotation, and add a section to the second annotation to implement dual-write in the section;
[0010] Performing a third annotation on the persistence layer of the original database, and determining a data source switch of the database based on the third annotation;
[0011] The codes generated in the configuration process and the annotation process are packaged and compiled to obtain a jar package, and the data source switching of the business system is implemented based on the jar package.
[0012] In a second aspect, the invention provides the following technical solution: a business system database switching device, the device comprising:
[0013] A configuration module is used to obtain the original database of the business system and create a new trust-creating database, and configure the connection information between the original database and the trust-creating database and the corresponding relationship between the data tables;
[0014] A first annotation module, used for performing a first annotation on a class of the original database, and identifying the original database and the trusted database based on the first annotation;
[0015] A second annotation module is used to perform a second annotation on the execution class method of the original database, determine the dual writing mode of the original database and the trusted database based on the second annotation, and add a section to the second annotation to realize dual writing in the section;
[0016] A third annotation module, used for performing a third annotation on the persistence layer of the original database, and determining the data source switching of the database based on the third annotation;
[0017] The packaging module is used to package and compile the codes generated in the configuration process and the annotation process to obtain a jar package, and implement the data source switching of the business system based on the jar package.
[0018] In a third aspect, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above-mentioned business system database switching method when executing the computer program.
[0019] In a fourth aspect, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the above-mentioned business system database switching method are implemented.
[0020] In the above-mentioned scheme implemented based on the business system database switching method, system, device and storage medium, the original database of the business system can be obtained and a new trusted database can be created, and the connection information and data table correspondence between the original database and the trusted database can be configured; a first annotation is made on the class of the original database, and the original database and the trusted database are identified based on the first annotation; a second annotation is made on the execution class method of the original database, and the dual-write mode of the original database and the trusted database is determined based on the second annotation, and a section is added to the second annotation to realize dual writing in the section; a third annotation is made on the persistence layer of the original database, and the database is determined based on the third annotation. Data source switching; the codes generated in the configuration process and the annotation process are packaged and compiled to obtain a jar package, and the data source switching of the business system is realized based on the jar package. In the present invention, for the insurance business system, the developer only needs to add a simple annotation to realize the entire database switching operation, without the need to develop a common logic, and supports keeping the IDs of the two databases consistent when adding new data. All of this logic does not need to be developed by the developer himself. The jar package formed by packaging provides these capabilities, reducing the occurrence of many hidden problems in the development process, and will not affect the use of the business system, facilitate subsequent maintenance, and reduce workload. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0022] Figure 1 A schematic diagram of an application environment of a business system database switching method in an embodiment of the present invention;
[0023] Figure 2 A schematic diagram of a process of switching a business system database in an embodiment of the present invention;
[0024] Figure 3 A schematic diagram of the structure of a business system database switching device in an embodiment of the present invention;
[0025] Figure 4 A schematic diagram of the structure of a computer device in one embodiment of the present invention;
[0026] Figure 5 FIG. 4 is another schematic diagram of the structure of a computer device in one embodiment of the present invention.
[0027] The embodiments of the present invention will be further described below with reference to the accompanying drawings. DETAILED DESCRIPTION
[0028] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0029] The business system database switching method provided by the embodiment of the present invention can be applied in Figure 1 In an application environment, a client communicates with a server through a network. The server can obtain the original database of the business system through the client and create a new trusted database, configure the connection information and data table correspondence between the original database and the trusted database; make a first annotation on the class of the original database, and identify the original database and the trusted database based on the first annotation; make a second annotation on the execution class method of the original database, determine the dual-write mode of the original database and the trusted database based on the second annotation, and add a section to the second annotation to realize dual writing in the section; make a third annotation on the persistence layer of the original database, and determine the data source switching of the database based on the third annotation; package and compile the code generated in the configuration process and the annotation process to obtain a jar package, and implement the data source switching of the business system based on the jar package. In the present invention, in the present invention, for the insurance business system, developers only need to add simple annotations to implement the entire database switching operation, without the need to develop common logic, and support keeping the IDs of the two databases consistent when adding new data, and all of this logic does not need to be developed by the developer himself. The jar package formed by packaging provides these capabilities, reduces the emergence of many hidden problems in the development process, and at the same time will not affect the use of the business system, facilitates subsequent maintenance, and can reduce workload. The client is specifically a business system, which can be installed on various personal computers, laptops, smart phones, tablet computers and portable wearable devices. The server can be implemented by an independent server or a server cluster composed of multiple servers. The present invention is described in detail below through specific embodiments.
[0030] like Figure 2 As shown, Figure 2 A flowchart of a method for switching a database of a business system provided by an embodiment of the present invention includes the following steps:
[0031] Step S1, obtain the original database of the business system and create a new trust-creating database, configure the connection information and data table correspondence between the original database and the trust-creating database;
[0032] The business system database switching method provided by the present invention can be applied to business systems in various application scenarios. The business system is usually installed on a client, and the client can obtain the original database of the business system. For example, in the insurance application field, there is often an insurance business system that performs some storage, update, distribution, generation, etc. of insurance policies. By switching the database of the business system, it is convenient for later maintenance.
[0033] For example, during the actual switching process of the insurance business system, the business system will identify its original database and generate a new database on the cloud or other computer devices, and configure the connection information and data table correspondence between the two databases to facilitate the subsequent actual switching process.
[0034] In this step S1, that is, obtaining the original database of the business system and creating a new trust-creating database, configuring the connection information between the original database and the trust-creating database and the corresponding relationship between the data tables, the following steps are included:
[0035] S11. Determine the database connection string, user name, password and other configuration information of the original database and the trusted database.
[0036] S12. Determine corresponding definition identifiers for the original database and the trusted database respectively, and determine connection information based on the definition identifier, the database connection string, the user name, the password and the other configuration information.
[0037] S13. Identify the data tables in the business system, and determine the asynchronous write correspondence and the synchronous write correspondence between the data tables in the business system and the original database and the trusted database, respectively, to obtain the data table correspondence.
[0038] Specifically, in the above steps S11-S13, the connection information between the two databases is first determined, and the specific connection information includes the database connection string of the database, the user name in the database, the password corresponding to the user name, and some other necessary configuration information. At the same time, for the definition identifier, it can be pre-defined or defined when switching, and the definition identifier of the original database is different from the definition identifier of the newly created trusted database, and the two different definition identifiers can be used to distinguish specific databases. After obtaining the connection information, the two databases can be connected according to the connection information to facilitate synchronous or asynchronous writing of data. Later, in order to facilitate the processing of data in the business system, it is hoped that the read and write data will be switched according to the dimension of the table in this step. Therefore, the configuration is performed in units of data tables, that is, there are a large number of data tables in the original database and the trusted database. Each data table needs to be configured here, and the correspondence between each data table and each database is determined. The data tables can be corresponded here according to the definition identifier;
[0039] For example, for a data table, it can be expressed as change-db.table name.async, and async can be replaced with the definition identifier of the corresponding database, that is, async = the definition identifier of the original database or the trusted database, so that the corresponding connection information and data table correspondence can be obtained.
[0040] Step S2, performing a first annotation on the class of the original database, and identifying the original database and the trusted database based on the first annotation;
[0041] After determining the correspondence between the connection information and the data table, the original database and the trusted database are now associated, and the first annotation can be made on the class in the original underlying data. The first annotation here is specifically expressed as @NeedCreateAsyncWriterService. @NeedCreateAsyncWriterService is a custom word, which can be interpreted as "need to create an asynchronous write service". The location of the first annotation is specifically on the class in the original database, which is specifically a Spring Bean class. The Spring Bean class provides a double write method that needs to be executed in the database, and the first annotation is only used to identify the class and has no attributes.
[0042] In this step S2, that is, performing a first annotation on the class of the original database and identifying the original database and the trusted database based on the first annotation, the following steps are included:
[0043] S21, marking the class identifier on the original Spring Bean class where the double writing method is executed in the original database;
[0044] S22, scanning the class identifier through the credentialed database and generating a generated Spring Bean class similar to the original Spring Bean class in the credentialed database through the ASM dynamic agent;
[0045] S23, setting the first annotation interpretation to be identifiable at runtime as the class identifier and setting the first Target attribute to be able to be placed on the original Spring Bean class.
[0046] For the above steps S21-S23, first, a class identifier is added to the original Spring Bean class in the original database. The class identifier is used to identify the class that executes the double write method. Then, the newly created trusted database will scan and identify the class identifier, and generate a generated Spring Bean class similar to the original Spring Bean class in the trusted database through the ASM dynamic proxy method. The generated Spring Bean class specifically executes the logic of the original Spring Bean class in the original database in the business system. Both the generated Spring Bean class and the original Spring Bean class can perform synchronous writing or asynchronous writing, but the databases where the two classes are located are different. Then, the first annotation is interpreted as the class identifier that can be identified at runtime and the first Target attribute is set to be able to be placed in the original Spring On the Bean class, the first annotation is interpreted as Retention1, and the class identifier that can be identified at runtime can be expressed as RetentionPolicy.RUNTIME. Therefore, it can be seen that Retention1 is set to RetentionPolicy.RUNTIME on the first annotation, and the actual meaning of RetentionPolicy.RUNTIME is that it can be identified at runtime. However, in step S23, the specific class identifier identified is attached, and the first Target attribute is specifically the target attribute, which specifically indicates that the class identifier can be specifically placed on the original Spring Bean class;
[0047] Among them, ASM dynamic proxy is one of the Java dynamic proxy mechanisms and will not be described in detail here.
[0048] Step S3, making a second annotation on the execution class method of the original database, determining the dual-write mode of the original database and the trusted database based on the second annotation, and adding a section to the second annotation to realize dual-write in the section;
[0049] Specifically, after class identification of the original Spring Bean class is performed, a corresponding method identification needs to be performed on the method executing the original Spring Bean class, so as to execute the corresponding method according to the method identification, and then perform the double writing process according to the corresponding double writing mode.
[0050] In this step S3, that is, making a second annotation on the execution class method of the original database, determining the dual-write mode of the original database and the trusted database based on the second annotation, adding a section to the second annotation to implement dual-write in the section, the steps include the following steps:
[0051] S311, marking a method identifier on the method of the original Spring Bean class executed in the original database;
[0052] S312, scanning the method identifier through the credentialed database and executing the method of generating a Spring Bean class based on the method identifier, and executing the method of generating a Spring Bean class to implement the logic of the original database;
[0053] S313, setting the second annotation interpretation to be able to identify the method identifier at runtime and setting the second Target attribute to be able to be placed on the method of executing the original Spring Bean class, and setting the mode attribute to synchronous writing or asynchronous writing.
[0054] For the above steps S311-S313, the process is similar to that of steps S21-S23, until the position of the mark is different, from the class to the method. The difference is that in the above steps, there is no need to generate a new class. Since the Spring Bean class has been dynamically generated in steps S21-S23, the method for executing the generated Spring Bean class will also exist accordingly. This method indicates that the method for executing the generated Spring Bean class is similar to the method for executing the original Spring Bean class, that is, the execution is the same as the logic of the original database. At the same time, the second annotation is interpreted as Retention 2, and the class identifier that can be identified at runtime can be expressed as RetentionPolicy.RUNTIME. Therefore, it can be seen that Retention2 is set to RetentionPolicy.RUNTIME on the second annotation. The actual meaning of RetentionPolicy.RUNTIME is that it can be identified during operation. It is just that in step S313, the specific method identifier is attached. The second Target attribute is specifically the target attribute, which specifically indicates that the class identifier can be specifically placed in the execution of the original Spring Bean class method, and the mode attribute specifically indicates the dual write mode, which can be synchronous write or asynchronous write, and the default is asynchronous write.
[0055] The dual writing mode includes mode 1 and mode 2; mode 1 is that synchronous writing and asynchronous writing do not interfere with each other; in mode 2, asynchronous writing must be added to the asynchronous thread pool after the synchronous writing is completed, and the input parameters of the asynchronous writing are adjusted according to the input parameters and execution results of the synchronous writing.
[0056] For example, when a user adds a new piece of data, the original database will often automatically generate a primary key ID for the data. Before executing the asynchronous write method, you can execute a specified method to assign the ID to the input parameter of the asynchronous write method, so that the trusted database does not automatically generate an ID but uses the ID of the original database to maintain data consistency.
[0057] For step S3, it also includes the following steps:
[0058] S321, adding a section to the method of executing the original Spring Bean class based on the method tag;
[0059] S322. Based on the aspect direction of the aspect, a customized double writing logic is added before / after executing the code of the method of the original Spring Bean class to implement double writing in the aspect.
[0060] Specifically, aspect is the concept of domain in Java, which can be applied to code. By adding aspects to the code corresponding to the execution of the original Spring Bean class method, you can then add custom double-write logic before or after the code according to the corresponding aspect direction, so that when the original Spring Bean class method is executed, the corresponding double-write process can be performed according to the custom double-write logic.
[0061] Step S4, performing a third annotation on the persistence layer of the original database, and determining the data source switching of the database based on the third annotation;
[0062] Specifically, after the second annotation, that is, the corresponding annotations have been made on the class and method, the corresponding data source needs to be identified accordingly, that is, the framework identification. For the dual-write process, for the database currently being read and written, it can be used as the main database, and for the database being read and written, it can be used as the slave database. The third annotation is used to distinguish the databases of specific operations, and switch the data source of the main database or the slave database through the framework identification.
[0063] In this step S4, that is, performing a third annotation on the persistence layer of the original database and determining the data source switching of the database based on the third annotation, the following steps are included:
[0064] S41, adding a framework identifier to the persistence layer framework in the original database, wherein the framework identifier is used to distinguish the database currently being operated;
[0065] S42, switching the data source of the original database or the trusted database based on the framework identifier;
[0066] S43, setting the third annotation interpretation to be identifiable as the framework identifier at runtime and setting the third Target attribute to be able to be placed on the method that executes the original Spring Bean class and on the original Spring Bean class, and setting the value of the name attribute to correspond to the definition identifier.
[0067] For the above steps S41-S43, first, a corresponding framework identifier is added to the persistence layer framework in the original database, where the persistence layer framework is Mapper. According to the framework identifier, the process of switching the data source corresponding to the database can be specifically executed to distinguish which database is currently being read and written, so as to facilitate the execution of asynchronous write and synchronous write objects. Then, the third annotation is set to be interpreted as the framework identifier that can be identified at runtime and the third Target attribute is set to be able to be placed in the method of executing the original Spring Bean class and can be placed on the original Spring Bean class. The value of the name attribute is set to correspond to the definition identifier. The third annotation is interpreted as Retention3. The framework identifier that can be identified at runtime can be expressed as RetentionPolicy.RUNTIME. Therefore, it can be seen that Retention3 is set to RetentionPolicy.RUNTIME on the third annotation. The actual meaning of RetentionPolicy.RUNTIME is that it can be identified at runtime. It is just that in step S43, the specific framework identifier is attached. The third Target attribute is specifically the target attribute, which specifically indicates that the class identifier can be specifically placed in the method of executing the original Spring Bean class and can be placed on the original Spring On the Bean class, the name attribute is specifically a name attribute, which indicates that when the master library and the slave library are switched, it can identify which library is currently being read and written according to the defined identifier, so as to switch the database and data source.
[0068] Step S5: Pack and compile the codes generated in the configuration process and the annotation process to obtain a jar package, and implement data source switching of the business system based on the jar package;
[0069] Specifically, the configuration process and annotation process here are the above-mentioned steps S1 to S4. The code files generated in the steps S1 to S4 are packaged and compiled to form an independent jar package. Through the jar package, the dual-write logic can be executed according to the above steps to perform the business system switching process, and the packaging and compilation process can be completed through the packaging software.
[0070] The non-Company software tools or components appearing in the embodiments of this application are merely examples and do not represent actual use.
[0071] It can be seen that in the above scheme, the original database of the business system can be obtained and a new trusted database can be created, and the connection information and data table correspondence between the original database and the trusted database can be configured; the first annotation is made on the class of the original database, and the original database and the trusted database are identified based on the first annotation; the second annotation is made on the execution class method of the original database, and the dual-write mode of the original database and the trusted database is determined based on the second annotation, and a section is added to the second annotation to realize dual writing in the section; the third annotation is made on the persistence layer of the original database, and the data source switching of the database is determined based on the third annotation; the code generated in the configuration process and the annotation process is packaged and compiled to obtain a jar package, and the data source switching of the business system is realized based on the jar package. In the present invention, for the insurance business system, the developer only needs to add simple annotations to realize the entire database switching operation, without the need to develop common logic, and supports keeping the IDs of the two databases consistent when adding new data, and all this logic does not need to be developed by the developer himself. The jar package formed by packaging provides these capabilities, reduces the emergence of many hidden problems in the development process, and at the same time will not affect the use of the business system, facilitates subsequent maintenance, and can reduce workload.
[0072] It should be understood that the order of execution of the steps in the above embodiment does not necessarily mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present invention.
[0073] In one embodiment, a business system database switching device is provided, and the business system database switching device corresponds one-to-one to the business system database switching method in the above embodiment. Figure 3 As shown, the business system database switching device includes a configuration module 101, a first annotation module 102, a second annotation module 103, a third annotation module 104 and a packaging module 105. The functional modules are described in detail as follows:
[0074] Configuration module 101, used to obtain the original database of the business system and create a new trust-creating database, and configure the connection information and data table correspondence between the original database and the trust-creating database;
[0075] A first annotation module 102, configured to perform a first annotation on a class of the original database, and identify the original database and the trusted database based on the first annotation;
[0076] A second annotation module 103 is used to perform a second annotation on the execution class method of the original database, determine the dual writing mode of the original database and the trusted database based on the second annotation, and add a section to the second annotation to realize dual writing in the section;
[0077] A third annotation module 104, configured to perform a third annotation on the persistence layer of the original database, and determine a data source switch of the database based on the third annotation;
[0078] The packaging module 105 is used to package and compile the codes generated in the configuration process and the annotation process to obtain a jar package, and implement the data source switching of the business system based on the jar package.
[0079] In one embodiment, the configuration module 101 is specifically configured to:
[0080] Determine the database connection string, user name, password and other configuration information of the original database and the trusted database;
[0081] Determine corresponding definition identifiers for the original database and the trusted database, respectively, and determine connection information based on the definition identifier, the database connection string, the user name, the password, and the other configuration information;
[0082] Identify the data tables in the business system, determine the asynchronous write correspondence and the synchronous write correspondence between the data tables in the business system and the original database and the trusted database, respectively, to obtain the data table correspondence.
[0083] In one embodiment, the first annotation module 102 is specifically used for:
[0084] Put a class identifier on the original Spring Bean class where the double writing method is executed in the original database;
[0085] Scan the class identifier through the credentialed database and generate a Spring Bean class similar to the original Spring Bean class in the credentialed database through the ASM dynamic agent;
[0086] The first annotation interpretation is set to be identifiable at runtime as the class identifier and the first Target attribute is set to be able to be placed on the original Spring Bean class.
[0087] In one embodiment, the second annotation module 103 is specifically used for:
[0088] Marking a method identifier on the method of the original Spring Bean class executed in the original database;
[0089] Scan the method identifier through the Xinchuang database and execute the method of generating the Spring Bean class based on the method identifier, and execute the method of generating the Spring Bean class to implement the logic of the original database;
[0090] The second annotation interpretation is set to allow the method identifier to be recognized at runtime, and the second Target attribute is set to be able to be placed on the method of the original Spring Bean class, and the mode attribute is set to synchronous writing or asynchronous writing.
[0091] In one embodiment, the second annotation module 103 is further used for:
[0092] Add aspects to the methods of the original Spring Bean class based on the method tags;
[0093] Based on the aspect direction of the aspect, a customized double writing logic is added before / after executing the code of the method of the original Spring Bean class to implement double writing in the aspect.
[0094] In one embodiment, the third annotation module 104 is specifically used for:
[0095] Adding a framework identifier to the persistence layer framework in the original database, wherein the framework identifier is used to distinguish the database currently being operated;
[0096] Switching the data source of the original database or the trusted database based on the framework identifier;
[0097] The third annotation interpretation is set to be identifiable as the framework identifier at runtime, and the third Target attribute is set to be placed on the method that executes the original Spring Bean class and on the original Spring Bean class, and the value of the name attribute is set to correspond to the definition identifier.
[0098] The present invention provides a business system database switching device. For the insurance business system, developers only need to add simple annotations to implement the entire database switching operation without developing common logic, and support keeping the IDs of the two databases consistent when adding new data. All of this logic does not need to be developed by the developer himself. The jar package formed by packaging provides these capabilities, reducing the occurrence of many hidden problems in the development process. At the same time, it will not affect the use of the business system, facilitates subsequent maintenance, and can reduce workload.
[0099] For the specific definition of the business system database switching device, please refer to the definition of the business system database switching method above, which will not be repeated here. Each module in the above-mentioned business system database switching can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0100] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 4 As shown. The computer device includes a processor, a memory, a network interface and a database connected via a system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile and / or volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external client via a network connection. When the computer program is executed by the processor, it implements the functions or steps of a service-side method for switching a database of a business system.
[0101] In one embodiment, a computer device is provided. The computer device may be a client, and its internal structure diagram may be as follows: Figure 5 As shown. The computer device includes a processor, a memory, a network interface, a display screen and an input device connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external server through a network connection. When the computer program is executed by the processor, it realizes the functions or steps of the client side of a business system database switching method.
[0102] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the following steps when executing the computer program:
[0103] Obtain the original database of the business system and create a new trusted database, and configure the connection information and data table correspondence between the original database and the trusted database;
[0104] Performing a first annotation on the class of the original database, and identifying the original database and the trusted database based on the first annotation;
[0105] Perform a second annotation on the execution class method of the original database, determine the dual-write mode of the original database and the trusted database based on the second annotation, and add a section to the second annotation to implement dual-write in the section;
[0106] Performing a third annotation on the persistence layer of the original database, and determining a data source switch of the database based on the third annotation;
[0107] The codes generated in the configuration process and the annotation process are packaged and compiled to obtain a jar package, and the data source switching of the business system is implemented based on the jar package.
[0108] In one embodiment, a computer readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:
[0109] Obtain the original database of the business system and create a new trusted database, and configure the connection information and data table correspondence between the original database and the trusted database;
[0110] Performing a first annotation on the class of the original database, and identifying the original database and the trusted database based on the first annotation;
[0111] Perform a second annotation on the execution class method of the original database, determine the dual-write mode of the original database and the trusted database based on the second annotation, and add a section to the second annotation to implement dual-write in the section;
[0112] Performing a third annotation on the persistence layer of the original database, and determining a data source switch of the database based on the third annotation;
[0113] The codes generated in the configuration process and the annotation process are packaged and compiled to obtain a jar package, and the data source switching of the business system is implemented based on the jar package.
[0114] It should be noted that the above functions or steps that can be implemented by the computer-readable storage medium or computer device can refer to the relevant descriptions on the server side and the client side in the aforementioned method embodiment. To avoid repetition, they will not be described one by one here.
[0115] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0116] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.
[0117] The embodiments described above are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included in the protection scope of the present invention.
Claims
1. A method for switching a business system database, characterized in that: The method comprises: Obtain the original database of the business system and create a new trusted database, and configure the connection information and data table correspondence between the original database and the trusted database; Performing a first annotation on the class of the original database, and identifying the original database and the trusted database based on the first annotation; Perform a second annotation on the execution class method of the original database, determine the dual-write mode of the original database and the trusted database based on the second annotation, and add a section to the second annotation to implement dual-write in the section; Performing a third annotation on the persistence layer of the original database, and determining a data source switch of the database based on the third annotation; The codes generated in the configuration process and the annotation process are packaged and compiled to obtain a jar package, and the data source switching of the business system is implemented based on the jar package.
2. The method for switching a business system database according to claim 1, characterized in that: The step of configuring the connection information and data table between the original database and the credentialed database includes: Determine the database connection string, user name, password and other configuration information of the original database and the trusted database; Determine corresponding definition identifiers for the original database and the trusted database, respectively, and determine connection information based on the definition identifier, the database connection string, the user name, the password, and the other configuration information; Identify the data tables in the business system, determine the asynchronous write correspondence and the synchronous write correspondence between the data tables in the business system and the original database and the trusted database, respectively, to obtain the data table correspondence.
3. The method for switching a business system database according to claim 1, characterized in that: The step of performing a first annotation on the class of the original database and identifying the original database and the trusted database based on the first annotation comprises: Put a class identifier on the original Spring Bean class where the double writing method is executed in the original database; Scan the class identifier through the credentialed database and generate a Spring Bean class similar to the original Spring Bean class in the credentialed database through the ASM dynamic agent; The first annotation interpretation is set to be identifiable at runtime as the class identifier and the first Target attribute is set to be able to be placed on the original Spring Bean class.
4. The method for switching a business system database according to claim 3, characterized in that: The step of performing a second annotation on the execution class method of the original database and determining the dual-write mode of the original database and the trusted database based on the second annotation includes: Marking a method identifier on the method of the original Spring Bean class executed in the original database; Scan the method identifier through the Xinchuang database and execute the method of generating the SpringBean class based on the method identifier, and execute the method of generating the Spring Bean class to implement the logic of the original database; The second annotation interpretation is set to allow the method identifier to be recognized at runtime, and the second Target attribute is set to be able to be placed on the method of the original Spring Bean class, and the mode attribute is set to synchronous writing or asynchronous writing.
5. The method for switching a business system database according to claim 4, characterized in that: The dual writing mode includes mode 1 and mode 2; mode 1 is that synchronous writing and asynchronous writing do not interfere with each other; in mode 2, asynchronous writing must be added to the asynchronous thread pool after the synchronous writing is completed, and the input parameters of the asynchronous writing are adjusted according to the input parameters and execution results of the synchronous writing.
6. The method for switching a business system database according to claim 4, characterized in that: The step of adding a section for the second annotation to implement double writing in the section includes: Add aspects to the methods of the original Spring Bean class based on the method tags; Based on the aspect direction of the aspect, a customized double writing logic is added before / after executing the code of the method of the original Spring Bean class to implement double writing in the aspect.
7. The method for switching a business system database according to claim 2, characterized in that: The step of performing a third annotation on the persistence layer of the original database and determining the data source switching of the database based on the third annotation comprises: Adding a framework identifier to the persistence layer framework in the original database, wherein the framework identifier is used to distinguish the database currently being operated; Switching the data source of the original database or the trusted database based on the framework identifier; The third annotation interpretation is set to be identifiable as the framework identifier at runtime, and the third Target attribute is set to be placed on the method that executes the original Spring Bean class and on the original Spring Bean class, and the value of the name attribute is set to correspond to the definition identifier.
8. A business system database switching device, characterized in that: The device comprises: A configuration module is used to obtain the original database of the business system and create a new trust-creating database, and configure the connection information between the original database and the trust-creating database and the corresponding relationship between the data tables; A first annotation module, used for performing a first annotation on a class of the original database, and identifying the original database and the trusted database based on the first annotation; A second annotation module is used to perform a second annotation on the execution class method of the original database, determine the dual writing mode of the original database and the trusted database based on the second annotation, and add a section to the second annotation to realize dual writing in the section; A third annotation module, used for performing a third annotation on the persistence layer of the original database, and determining the data source switching of the database based on the third annotation; The packaging module is used to package and compile the codes generated in the configuration process and the annotation process to obtain a jar package, and implement the data source switching of the business system based on the jar package.
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 steps of the business system database switching method according to any one of claims 1 to 7 are 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 a processor, the steps of the business system database switching method according to any one of claims 1 to 7 are implemented.