CN115374083A - Data source switching method and device, electronic equipment and storage medium - Google Patents

Data source switching method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN115374083A
CN115374083A CN202211006544.XA CN202211006544A CN115374083A CN 115374083 A CN115374083 A CN 115374083A CN 202211006544 A CN202211006544 A CN 202211006544A CN 115374083 A CN115374083 A CN 115374083A
Authority
CN
China
Prior art keywords
data source
target
switching
data
database
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202211006544.XA
Other languages
Chinese (zh)
Inventor
何辉
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ping An E Wallet Electronic Commerce Co Ltd
Original Assignee
Ping An E Wallet Electronic Commerce Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Ping An E Wallet Electronic Commerce Co Ltd filed Critical Ping An E Wallet Electronic Commerce Co Ltd
Priority to CN202211006544.XA priority Critical patent/CN115374083A/en
Publication of CN115374083A publication Critical patent/CN115374083A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/21Design, administration or maintenance of databases
    • G06F16/214Database migration support
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/25Integrating or interfacing systems involving database management systems
    • G06F16/252Integrating or interfacing systems involving database management systems between a Database Management System and a front-end application
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/28Databases characterised by their database models, e.g. relational or object models
    • G06F16/284Relational databases

Landscapes

  • Engineering & Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The application relates to the technical field of database access, and discloses a data source switching method, a data source switching device, electronic equipment and a storage medium, wherein the data source switching method comprises the following steps: responding to a switching instruction of a data source, loading a target plug-in, wherein the switching instruction carries identification information of the target data source; intercepting a target class file corresponding to the service logic of the data persistence layer according to an operation instruction of a target plug-in, wherein the target class file has annotation information of an operationDAO class; and executing the target class file according to the configuration file corresponding to the identification information of the target data source so as to switch access from the original data source to the target data source, wherein the configuration file is used for indicating the method and the attribute of the target data source. The method can avoid modification of a large number of codes during switching, enhances the flexibility of data source switching, and is beneficial to reducing the cost of data source switching.

Description

Data source switching method and device, electronic equipment and storage medium
Technical Field
The present application relates to the field of database access technologies, and in particular, to a method and an apparatus for switching data sources, an electronic device, and a storage medium.
Background
At the present stage, internet application products are used more frequently, more and more organizations rely on internet products to solve daily work or product popularization, and the product demand of similar industries and similar services is continuously increased. More and more internet products tend to mature, and the degree of productization has been able to cover a wider customer base. And the data source is the description of the connection parameters of the physical database. The Oracle database is a mainstream database nowadays, and although the Oracle database is powerful, the Oracle database is poor in compatibility and high in cost.
At present, the trend of reducing the operation cost is overwhelmingly inevitable by a 'go O' mode, namely, migrating data in the Oracle database to other simpler open source databases. However, in practical applications, most data migration schemes are implemented by the codes of project developers, which results in a new increase of code modification work for developers, and is easy to introduce unnecessary errors.
Disclosure of Invention
In view of this, the present application provides a method and an apparatus for switching a data source, an electronic device, and a storage medium, so as to solve the problems that a developer has high programming workload and inflexible configuration and affects function operation in a system engineering code during a data source switching process.
In a first aspect, a method for switching data sources is provided, including:
responding to a switching instruction of a data source, loading a target plug-in, wherein the switching instruction carries identification information of the target data source;
intercepting a target class file corresponding to the business logic of the data persistence layer according to an operation instruction of a target plug-in, wherein the target class file has annotation information of an operationDAO class;
and executing the target class file according to the configuration file corresponding to the identification information of the target data source so as to switch access from the original data source to the target data source, wherein the configuration file is used for indicating the method and the attribute of the target data source.
Further, intercepting a target class file corresponding to the service logic of the data persistence layer according to an operation instruction of the target plug-in, including:
determining operation information of service logic of a data persistence layer;
if the running information is in a to-be-executed state, intercepting a target class file corresponding to the service logic of the to-be-executed data persistence layer;
and if the operation information is in an execution state, delaying to intercept the target class file corresponding to the service logic of the data persistence layer.
Further, intercepting a target class file corresponding to the service logic of the data persistence layer in the original data source according to an operation instruction of the target plug-in, including:
acquiring system flow data;
and if the system flow data is less than or equal to the preset flow data, intercepting a target class file corresponding to the service logic of the data persistence layer according to an operation instruction of the target plug-in.
Further, after executing the target class file according to the configuration file corresponding to the identification information of the target data source, the method for switching the data source includes:
calling a detection service interface to execute a switching detection task;
and if the target data source does not have data update corresponding to the detection task in the execution process of the switching detection task, outputting switching failure information.
Further, the method for switching the data source further comprises the following steps:
and responding to the input operation, and generating a switching instruction according to the identification information of the target data source indicated by the input operation.
Further, the method for switching the data source further comprises the following steps:
and if the original data source is detected to be invalid, generating a switching instruction according to the identification information of any data source in the preset data source list.
Further, the method for switching the data source further comprises the following steps:
if the configuration file corresponding to the identification information of the target data source is not configured, sending a configuration request;
and creating a configuration file according to the configuration information fed back by the configuration request.
Further, the target data source comprises a relational database or a non-relational database; the relational database includes at least one of: a Mysql database, an SQLServer database and a DB2 database; the non-relational database includes at least one of: mongodb database, cassandra database, redis database, hbase database, neo4j database.
In a second aspect, there is provided a switching apparatus of data sources, including:
the loading module is used for responding to a switching instruction of the data source and loading the target plug-in, wherein the switching instruction carries the identification information of the target data source;
the intercepting module is used for intercepting a target class file corresponding to the service logic of the data persistence layer according to an operation instruction of the target plug-in, wherein the target class file has annotation information of an operationDAO class;
and the switching module is used for executing the target class file according to the configuration file corresponding to the identification information of the target data source so as to switch the access from the original data source to the target data source, wherein the configuration file is used for indicating the method and the attribute of the target data source.
Further, the switching device of the data source further comprises:
the determining module is used for determining the operation information of the service logic of the data persistence layer;
the intercepting module is specifically used for intercepting a target class file corresponding to the service logic of the data persistence layer to be executed if the operation information is in a state to be executed; and if the operation information is in an execution state, delaying to intercept the target class file corresponding to the service logic of the data persistence layer.
Further, the switching device of the data source further comprises:
the acquisition module is used for acquiring system flow data;
and the intercepting module is specifically used for intercepting a target class file corresponding to the service logic of the data persistence layer in the original data source according to an operation instruction of the target plug-in if the system flow data is less than or equal to the preset flow data.
Further, the switching device of the data source further comprises:
the detection module is used for calling a detection service interface to execute a switching detection task; and if the target data source does not have data update corresponding to the detection task in the execution process of the switching detection task, outputting switching failure information.
Further, the switching device of the data source further comprises:
the instruction generation module is used for responding to the input operation and generating a switching instruction according to the identification information of the target data source indicated by the input operation; or if the original data source is detected to be invalid, generating a switching instruction according to the identification information of any data source in the preset data source list.
Further, the switching device of data source further includes:
the communication module is used for sending a configuration request if the configuration file corresponding to the identification information of the target data source is not configured;
and the calling module is used for creating a configuration file according to the configuration information fed back by the configuration request.
Further, the target data source comprises a relational database or a non-relational database; the relational database includes at least one of: a Mysql database, an SQLServer database and a DB2 database; the non-relational database includes at least one of: mongodb database, cassandra database, redis database, hbase database, neo4j database.
In a third aspect, an electronic device is provided, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, and when the computer program is executed by the processor, the steps of the method for switching data sources are implemented.
In a fourth aspect, a computer-readable storage medium is provided, in which a computer program is stored, which, when being executed by a processor, carries out the steps of the above-mentioned data source switching method.
According to the scheme, the target plug-in required by switching is written in advance before the data migration of the database. When the system detects a switch instruction of the data source, the system engineering code refers to the target plug-in. And after the system loads the target plug-in, starting the target plug-in and analyzing the operation instruction of the target plug-in. And scanning all Java files, searching a target class file with operation DAO class annotation information in the service logic of the DAO layer, and intercepting the target class file through an operation instruction, so as to intercept all interface keywords written in Java codes to operate the proxy class file of the SQL. And then, calling a configuration file corresponding to the identification information of the target data source. Because the proxy class contains the data source, when the method of the proxy class is executed, the proxy class file is executed according to the method and the attribute in the configuration file, and the access of the system can be switched from the original data source to the target data source, so that the corresponding function can be operated in the target data source. Therefore, a large amount of code modification is avoided during switching, the flexibility of data source switching is enhanced, and the cost of data source switching is reduced.
The foregoing description is only an overview of the technical solutions of the present application, and the present application can be implemented according to the content of the description in order to make the technical means of the present application more clearly understood, and the following detailed description of the present application is given in order to make the above and other objects, features, and advantages of the present application more clearly understandable.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings needed to be used in the description of the embodiments of the present application will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and it is obvious for those skilled in the art that other drawings can be obtained according to these drawings without inventive exercise.
Fig. 1 is a schematic flow chart of a data source switching method in the present application;
FIG. 2 is a second flowchart illustrating a data source switching method according to the present application;
fig. 3 is a third schematic flowchart of a data source switching method in the present application;
FIG. 4 is a fourth flowchart illustrating a data source switching method according to the present application;
FIG. 5 is one of the schematic diagrams of switching of data sources in the present application;
FIG. 6 is a schematic diagram of a switching device of data sources in the present application;
fig. 7 is a schematic structural diagram of an electronic device in the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are some, but not all, embodiments of the present application. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
Referring to fig. 1, fig. 1 is a schematic flow chart of a data source switching method according to an embodiment of the present application, including the following steps:
s10: loading a target plug-in response to a switching instruction of a data source;
the switching instruction carries identification information of the target data source, and the identification information is used for distinguishing different databases. The target plug-in is used to migrate data in the Oracle database to the target data source in a less intrusive and with very little change. The target plug-in may be a plug-in package, such as a jar package, and the plug-in may be named iswitch-proxy.
In this embodiment, the target plug-ins needed for the switchover are pre-written prior to the migration of the database data. When the system detects a switching instruction of a data source, the system engineering code refers to the target plug-in and places the target plug-in a plug-in directory of a system main frame. The data sources are managed uniformly through the target plug-in, and the whole operation of managing and switching in an organized discipline mode is achieved. The method can support continuous expansion of different types, enhances the flexibility of data source switching, saves a large amount of manpower development cost, and is favorable for large-scale system data source switching.
In a specific application scenario, the target data source comprises a relational database or a non-relational database; the relational database can be a Mysql database, an SQLServer database or a DB2 database and the like; the non-relational database may be a mongodb database, a cassandra database, a redis database, a hbase database, a neo4j database, or the like.
Further, in some embodiments of the present application, obtaining the switching instruction of the data source includes the following steps:
in a first mode, in response to an input operation, a switching instruction is generated according to the identification information of the target data source indicated by the input operation.
In this embodiment, the system administrator may actively trigger the switching of data sources as needed. Specifically, a target data source to be switched is set by an input operation. And the system generates a switching instruction according to the identification information of the target data source.
And if the original data source is detected to be invalid, generating a switching instruction according to the identification information of any data source in the preset data source list.
In this embodiment, a preset data source list capable of being converted, which is pre-stored in the system, is obtained in advance. When detecting that the currently accessed original data source is invalid, the original data source is unavailable, and if the data source needs to be automatically switched, one data source is randomly selected from a preset data source list to serve as a target data source, and a switching instruction is generated by using identification information of the data source. Therefore, when the main data source has a problem, the standby data source can be automatically switched, the data of multiple data sources are synchronized in real time, the reliability of the system is improved, and high availability is really achieved.
It can be understood that the failure of the original data source means that the number of times of errors occurring when the operations of adding, deleting, checking and changing the original data source are performed in unit time exceeds a threshold value. In addition, in the preferred embodiment, the size of the threshold value can be automatically adjusted according to the service data request quantity corresponding to the current service logic. For example, at peak access times, the likelihood of a data source problem increases due to traffic surges, matching a larger threshold.
S20: intercepting a target class file corresponding to the service logic of the data persistence layer according to an operation instruction of the target plug-in;
wherein the target class file has annotation information of the operationDAO class.
Specifically, the MVC framework-based system includes a traffic model layer (model), a control layer (controller), and a view layer (view). The Service model layer is used for finishing Service processing and comprises a Service logic layer (Service) and a Data Access Object (DAO), the Service layer can call the DAO layer to finish Service realization, the DAO layer is an intermediate layer between the Service layer and the database layer, and the Service logic code realizes interaction with the database by calling the DAO file.
In this embodiment, considering that there must be many unknown codes in the system code engineering operating using the data source, for this purpose, after the system loads the target plug-in, the target plug-in is started, and the operation instruction of the target plug-in is parsed out. Scanning all Java files, searching a target class file with operation DAO class annotation information in the service logic of the DAO layer, and intercepting the target class file through an operation instruction, thereby intercepting all interface (interface) keyword operation Structured Query Language (SQL) proxy class files written in Java codes to intercept all codes using an original data source. Therefore, the agent file can be executed according to the method and the attribute execution file in the configuration file, and the access of the system can be switched from the original data source to the target data source. Therefore, developers do not need to modify codes used for switching sentence by sentence, the possibility of artificial errors is reduced, the data source switching efficiency is improved, and the effect of flexibly switching a plurality of data sources is realized.
In some embodiments of the present application, as shown in fig. 2, a specific entity alignment scheme is provided, in S20, that is, a target class file corresponding to a service logic of a data persistence layer is intercepted according to an operation instruction of a target plug-in, which specifically includes the following steps:
s21: acquiring system flow data;
specifically, the system is interfaced with a Cat (Central Application Tracking) monitoring platform, which is a real-time distributed Application monitoring platform developed based on Java. When the interface of the system is called, the system asynchronously sends the called operation to the Cat monitoring platform, and then obtains the system flow data from the Cat monitoring platform.
S22: and if the system flow data is less than or equal to the preset flow data, intercepting a target class file corresponding to the service logic of the data persistence layer according to an operation instruction of the target plug-in.
In this embodiment, after receiving a switching instruction of a data source, the flow data of the system is detected in real time. And under the condition that the system flow data is less than or equal to the preset flow data, the user access amount is lower at the moment, even if the data source is switched, the use of a large number of users cannot be influenced, the agent class file with the comment information of the operationDAO class in the service logic is intercepted, and the subsequent switching operation is executed. Therefore, data source switching is carried out in a relatively low peak period of the system flow, the influence caused by switching the data source is further reduced, and the use experience of a user is improved.
In some embodiments of the present application, as shown in fig. 3, a specific entity alignment scheme is provided, in S20 or S22, that is, a target class file corresponding to a service logic of a data persistence layer is intercepted according to an operation instruction of a target plug-in, which specifically includes the following steps:
s221: determining operation information of service logic of a data persistence layer;
s222: whether the running information is in a state to be executed or not is judged, if yes, the step is S223, and if not, the step is S224;
s223: intercepting a target class file corresponding to the service logic of the data persistence layer to be executed;
s224: and delaying to intercept the target class file corresponding to the service logic of the data persistence layer.
The duration of the delay may be a specified duration, for example, a possible duration in the service logic operation process; or, the time length is corresponding to the time when the service logic operation is finished, that is, the target class file corresponding to the service logic of the data persistence layer is delayed and intercepted after the service logic is released.
In this embodiment, all data access objects in the system are scanned and operational information of the business logic of the data access object is detected. If the operation information is in a to-be-executed state, namely the system does not use the method and the attribute under the service logic currently, the target class file corresponding to the service logic of the to-be-executed data persistence layer is directly intercepted. If the operation information is in an execution state, the system is indicated to execute the function of the service logic, and in order to avoid service interruption, the target class file in the service logic is intercepted after the service logic is completely operated. Therefore, the running function is reserved in the switching process, so that the service cannot be stopped during data migration, the consistency of the operation data source is ensured, and the influence on a service system is effectively reduced.
S30: and executing the target class file according to the configuration file corresponding to the identification information of the target data source.
Wherein the configuration file is used to indicate the method and attributes of the target data source.
In this embodiment, a configuration file corresponding to the identification information of the target data source in the system is called to determine that the method and attribute of the target data source replace the method and attribute of the original data source. And then, executing the target class file according to the method and the attribute in the configuration file so as to operate the target database according to the method and the attribute of the proxy class and the target data source, thereby achieving the purpose of switching the access of the system from the original data source to the target data source, operating the corresponding function on the target data source and realizing smooth data source switching. Therefore, developers are saved from rewriting code files to perform the operation of if … else, the agent classes are directly and dynamically generated, different databases are operated through the agent classes, the problem that the data sources can be read and written when being switched is not needed to be considered, the modification of a large number of codes is avoided, the flexibility of data source switching is enhanced, and the cost of data source switching is reduced.
For example, as shown in fig. 5, when switching from the Oracle database to the Mysql database, the iswitch-proxy. Jar plug-in is referred to in the pom file of the code project of system a, and the specific introduction manner is as follows:
<dependency>
<groupId>com.iswitch</groupId>
<artifactId>iswitch-proxy</artifactId>
<version>1.0.0</version>
</dependency>
after the pom file of system A references the plug-in, system A is started, and the file of the plug-in is loaded naturally by system A. When the iswitch-proxy jar plug-in senses that the Dao layer interface is called, namely the JDK proxies the class, whether the class file where the executed method is located has the @ OperationDAO annotation is identified. If the @ OperationDAO annotation exists, the @ OperationDAO annotation is intercepted, and Oracle is kept readable and writable in the migration process. And then, checking the identification information of the Mysql database indicated in the switching instruction, taking the configuration file of the corresponding Mysql database in the system through the identification information, and binding the Mysql database to complete the switching of the data source, wherein once the migration is completed, oracle becomes read only. And after the Mysql database is bound, triggering a method for executing the lowest layer of Dao file, and keeping the Mysql to be readable and writable.
It should be noted that, when switching data sources, configuration files corresponding to the identification information of the target data source are pre-stored in the system, so as to ensure that the system can be used in a new data source environment. For example, two folders of mappers and mappers Mysql are stored in the system, where the mappers folder is the location of the Oracle-type SQL file, and where the mappers Mysql folder is the location of the Mysql-type SQL file. At this point, the system may allow a switch from Oracle to Mysql to occur.
The method provided by the embodiment of the application is applicable to electronic devices, which may include various handheld devices, vehicle-mounted devices, wearable devices, computing devices or other processing devices connected to a wireless modem with wireless communication functions, as well as various forms of User Equipment (UE), mobile Station (MS), terminal equipment (terminal), and the like. For convenience of description, the above-mentioned devices are collectively referred to as electronic devices.
In some embodiments of the present application, as shown in fig. 4, a specific entity alignment scheme is provided, S30, that is, after executing the target class file according to the configuration file corresponding to the identification information of the target data source, the following steps are further included:
s40: calling a detection service interface to execute a switching detection task;
s50: and if the target data source does not have data update corresponding to the detection task in the execution process of the switching detection task, outputting switching failure information.
In this embodiment, the traffic interface is detected in operation to perform at least one new function (handover detection task). And in the process of executing the switching detection task, inquiring whether the target data source has corresponding newly added data or not. If yes, the target database is successfully accessed, and the target database is successfully switched and the detection service is successfully executed. If not, the switching failure is indicated, and at this time, switching failure information is output to prompt that the data source fails to be switched, and the switching step needs to be carried out again. Therefore, whether the switching of the detection data source is completed or not can be timely realized by calling the detection service interface, the influence caused by various unknown abnormity during switching is effectively prevented, and the stable and smooth switching of the service is ensured.
In some embodiments of the present application, a specific entity alignment scheme is provided, and before S30, the method for switching the data source further includes the following steps: if the configuration file corresponding to the identification information of the target data source is not configured, sending a configuration request; and creating a configuration file according to the configuration information fed back by the configuration request.
In this embodiment, when data source switching is considered, it needs to be ensured that the system can support the SQL-type file corresponding to the target data source. And when the system does not configure the configuration file corresponding to the identification information of the target data source, which indicates that the data source environment of the current system does not support the target data source, sending a configuration request of the target data source to the external equipment. When the system receives the configuration information fed back based on the configuration request, a configuration file of the target data source is created according to the configuration information. Therefore, switching error caused by the configuration file is avoided, and the success rate of data source switching is improved.
The external device may be a server or a terminal.
Specifically, for example, if the system needs to support the Redis non-relational database, a new Mapperredis folder is added in the system through an external device, and then the syntactic content of the corresponding operation Redis is realized in the Mapperredis folder.
It should be understood that, the sequence numbers of the steps in the foregoing embodiments do not imply an execution sequence, and the execution sequence of each process should be determined by its function and inherent logic, and should not constitute any limitation to the implementation process of the embodiments of the present application.
In an embodiment, a data source switching device is provided, where the data source switching device corresponds to the data source switching method in the foregoing embodiment one to one. As shown in fig. 6, the switching device of the data source includes a loading module 601, an intercepting module 602, and a switching module 603. The functional modules are explained in detail as follows:
a loading module 601, configured to load a target plug-in response to a switching instruction of a data source, where the switching instruction carries identification information of the target data source;
an interception module 602, configured to intercept, according to an operation instruction of a target plug-in, a target class file corresponding to a service logic of a data persistence layer, where the target class file has annotation information of an OperationDAO class;
the switching module 603 is configured to execute the target class file according to the configuration file corresponding to the identification information of the target data source, so as to switch access from the original data source to the target data source, where the configuration file is used to indicate a method and an attribute of the target data source.
In an embodiment, the apparatus for switching data sources further includes: a determining module (not shown in the figure) for determining the operation information of the business logic of the data persistence layer; the intercepting module 602 is specifically configured to intercept a target class file corresponding to a service logic of a data persistence layer to be executed if the operation information is in a state to be executed; and if the operation information is in an execution state, delaying to intercept the target class file corresponding to the service logic of the data persistence layer.
In an embodiment, the apparatus for switching data sources further includes: an obtaining module (not shown in the figure) for obtaining system flow data; the intercepting module 602 is specifically configured to intercept, according to an operation instruction of the target plug-in, a target class file corresponding to a service logic of a data persistence layer in the original data source if the system traffic data is less than or equal to the preset traffic data.
In an embodiment, the apparatus for switching data sources further includes: a detection module (not shown in the figure), configured to invoke a detection service interface to execute a switching detection task; and if the target data source does not have data update corresponding to the detection task in the execution process of the switching detection task, outputting switching failure information.
In an embodiment, the apparatus for switching data sources further includes: an instruction generating module (not shown in the figure), configured to generate, in response to an input operation, a switching instruction according to identification information of a target data source indicated by the input operation; or if the original data source is detected to be invalid, generating a switching instruction according to the identification information of any data source in the preset data source list.
In an embodiment, the apparatus for switching data sources further includes: a communication module (not shown in the figure), configured to send a configuration request if the configuration file corresponding to the identification information of the target data source is not configured; and the calling module (not shown in the figure) is used for creating the configuration file according to the configuration information fed back by the configuration request.
In one embodiment, the target data source comprises a relational or non-relational database; the relational database includes at least one of: a Mysql database, an SQLServer database and a DB2 database; the non-relational database includes at least one of: mongodb database, cassandra database, redis database, hbase database, neo4j database.
The application provides a data source switching device, which is used for pre-compiling a target plug-in required by switching before database data migration. When the system detects a switch instruction of the data source, the system engineering code refers to the target plug-in. And after the system loads the target plug-in, starting the target plug-in and analyzing the operation instruction of the target plug-in. And scanning all Java files, searching a target class file with operation DAO class annotation information in the service logic of the DAO layer, and intercepting the target class file through an operation instruction, so as to intercept all interface keywords written in Java codes to operate the proxy class file of the SQL. And then, calling a configuration file corresponding to the identification information of the target data source. Because the proxy class contains the data source, when the method of the proxy class is executed, the proxy class file is executed according to the method and the attribute in the configuration file, namely, the access of the system can be switched from the original data source to the target data source, so that the corresponding function can be operated in the target data source. Therefore, a large amount of code modification is avoided during switching, the flexibility of data source switching is enhanced, and the cost of data source switching is reduced.
For the specific definition of the switching device of the data source, reference may be made to the above definition of the switching method of the data source, which is not described herein again. The modules in the switching device of the data source can be wholly or partially realized by software, hardware and a combination thereof. The modules can be embedded in a hardware form or independent of a processor in the electronic device, or can be stored in a memory in the electronic device in a software form, so that the processor can call and execute operations corresponding to the modules.
In one embodiment, an electronic device is provided, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, the processor implementing the following steps when executing the computer program: responding to a switching instruction of a data source, and loading a target plug-in, wherein the switching instruction carries identification information of the target data source; intercepting a target class file corresponding to the service logic of the data persistence layer according to an operation instruction of a target plug-in, wherein the target class file has annotation information of an operationDAO class; and executing the target class file according to the configuration file corresponding to the identification information of the target data source so as to switch access from the original data source to the target data source, wherein the configuration file is used for indicating the method and the attribute of the target data source.
In one embodiment, a computer-readable storage medium is provided, having a computer program stored thereon, which when executed by a processor, performs the steps of: responding to a switching instruction of a data source, and loading a target plug-in, wherein the switching instruction carries identification information of the target data source; intercepting a target class file corresponding to the service logic of the data persistence layer according to an operation instruction of a target plug-in, wherein the target class file has annotation information of an operationDAO class; and executing the target class file according to the configuration file corresponding to the identification information of the target data source so as to switch access from the original data source to the target data source, wherein the configuration file is used for indicating the method and the attribute of the target data source.
In one embodiment, an electronic device is provided, which may be a client, and the internal structure thereof is shown in fig. 7. The electronic device comprises a processor, a memory, a network interface, a display screen and an input device which are connected through a system bus. Wherein the processor of the electronic device is configured to provide computing and control capabilities. The memory of the electronic equipment comprises a nonvolatile 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 an operating system and computer programs in the non-volatile storage medium. The network interface of the electronic device is used for communicating with an external server through network connection. The computer program is executed by a processor to implement the functions or steps of a method of switching data sources.
It should be noted that, the functions or steps that can be implemented by the computer-readable storage medium or the electronic device may be correspondingly described in the foregoing method embodiments, and in order to avoid repetition, the description is not repeated here.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by hardware instructions of a computer program, which can be stored in a non-volatile computer-readable storage medium, and when executed, can include the processes of the embodiments of the methods described above. Any reference to memory, storage, data source, or other medium used in the embodiments provided herein can include non-volatile and/or volatile memory, among others. 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. By way of illustration and not limitation, RAM is available in a variety of forms such as Static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double Data Rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous Link DRAM (SLDRAM), rambus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
It will be apparent to those skilled in the art that, for convenience and brevity of description, only the above-mentioned division of the functional units and modules is illustrated, and in practical applications, the above-mentioned function distribution may be performed by different functional units and modules according to needs, that is, the internal structure of the apparatus is divided into different functional units or modules to perform all or part of the above-mentioned functions.
Although the present invention has been described in detail with reference to the foregoing embodiments, it should be understood by those skilled in the art that various changes and modifications may be made, and equivalents may be substituted for elements thereof without departing from the scope of the present invention; such modifications and substitutions do not substantially depart from the spirit and scope of the embodiments of the present invention, and are intended to be included within the scope of the present invention.

Claims (10)

1. A method for switching data sources, comprising:
responding to a switching instruction of a data source, and loading a target plug-in, wherein the switching instruction carries identification information of the target data source;
intercepting a target class file corresponding to the business logic of the data persistence layer according to the operation instruction of the target plug-in, wherein the target class file has annotation information of an operationDAO class;
and executing the target class file according to a configuration file corresponding to the identification information of the target data source so as to switch access from an original data source to the target data source, wherein the configuration file is used for indicating the method and the attribute of the target data source.
2. The method for switching data sources according to claim 1, wherein intercepting a target class file corresponding to a service logic of a data persistence layer according to an operation instruction of the target plug-in comprises:
determining the operation information of the business logic of the data persistence layer;
if the running information is in a state to be executed, intercepting a target class file corresponding to the service logic of the data persistence layer to be executed;
and if the running information is in an execution state, delaying and intercepting the target class file corresponding to the service logic of the data persistence layer.
3. The method according to claim 1, wherein intercepting a target class file corresponding to a service logic of a data persistence layer in an original data source according to an operation instruction of the target plug-in includes:
acquiring system flow data;
and if the system flow data is less than or equal to the preset flow data, intercepting a target class file corresponding to the service logic of the data persistence layer in the original data source according to the operation instruction of the target plug-in.
4. The method for switching data sources according to claim 1, wherein after the target class file is executed according to the configuration file corresponding to the identification information of the target data source, the method includes:
calling a detection service interface to execute a switching detection task;
and if the target data source does not have data updating corresponding to the detection task in the execution process of the switching detection task, outputting switching failure information.
5. The method for switching data sources according to any one of claims 1 to 4, wherein the method further comprises:
responding to an input operation, and generating the switching instruction according to the identification information of the target data source indicated by the input operation; or the like, or a combination thereof,
and if the original data source is detected to be invalid, generating the switching instruction according to the identification information of any data source in a preset data source list.
6. The method for switching data sources according to any one of claims 1 to 4, wherein the method further comprises:
if the configuration file corresponding to the identification information of the target data source is not configured, sending a configuration request;
and creating the configuration file according to the configuration information fed back by the configuration request.
7. The method of switching data sources according to any one of claims 1 to 4,
the target data source comprises a relational database or a non-relational database;
the relational database includes at least one of: a Mysql database, an SQLServer database and a DB2 database;
the non-relational database comprises at least one of: mongodb database, cassandra database, redis database, hbase database, neo4j database.
8. A data source switching apparatus, comprising:
the loading module is used for responding to a switching instruction of a data source and loading a target plug-in, wherein the switching instruction carries identification information of the target data source;
the intercepting module is used for intercepting a target class file corresponding to the service logic of the data persistence layer according to the operation instruction of the target plug-in, wherein the target class file has annotation information of an operationDAO class;
and the switching module is used for executing the target class file according to the configuration file corresponding to the identification information of the target data source so as to switch access from an original data source to the target data source, wherein the configuration file is used for indicating the method and the attribute of the target data source.
9. An electronic device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that the processor implements the steps of the method for switching data sources according to any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, in which a computer program is stored which, when being executed by a processor, carries out the steps of the method for switching data sources according to any one of claims 1 to 7.
CN202211006544.XA 2022-08-22 2022-08-22 Data source switching method and device, electronic equipment and storage medium Pending CN115374083A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211006544.XA CN115374083A (en) 2022-08-22 2022-08-22 Data source switching method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211006544.XA CN115374083A (en) 2022-08-22 2022-08-22 Data source switching method and device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN115374083A true CN115374083A (en) 2022-11-22

Family

ID=84068022

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211006544.XA Pending CN115374083A (en) 2022-08-22 2022-08-22 Data source switching method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN115374083A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117493378A (en) * 2024-01-03 2024-02-02 成都数之联科技股份有限公司 Method and system for switching multiple data sources

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117493378A (en) * 2024-01-03 2024-02-02 成都数之联科技股份有限公司 Method and system for switching multiple data sources
CN117493378B (en) * 2024-01-03 2024-03-08 成都数之联科技股份有限公司 Method and system for switching multiple data sources

Similar Documents

Publication Publication Date Title
EP3128421B1 (en) Method, device, and system for achieving java application installation by cloud compilation
CN109766330B (en) Data slicing method and device, electronic equipment and storage medium
CN109032631A (en) Application program service packs acquisition methods, device, computer equipment and storage medium
CN114661580A (en) Flow recording playback method and device, computer equipment and storage medium
CN111309303B (en) Code generation method and device, computer equipment and storage medium
CN113986402A (en) Function calling method and device, electronic equipment and storage medium
CN113434230A (en) Jump control method and device for H5 page, storage medium and electronic device
CN115374083A (en) Data source switching method and device, electronic equipment and storage medium
CN113608742A (en) Detection method, code packet processing method, operation control method and computing device
CN113791809B (en) Application exception handling method and device and computer readable storage medium
CN111090442A (en) Application updating method and device and storage medium
CN112947956B (en) Application software upgrading method
CN112988132B (en) Automatic generation method and device of data interface, computer equipment and storage medium
CN115129348A (en) Resource updating method, device and equipment of application program and readable storage medium
CN117441157A (en) Software updater
CN111949301B (en) Application program hot update method, device and computer readable storage medium
CN114860204A (en) Program processing method, program operating device, terminal, smart card and storage medium
CN114860202A (en) Project operation method, device, server and storage medium
CN109857380B (en) Workflow file compiling method and device
CN113495723A (en) Method and device for calling functional component and storage medium
CN114579167A (en) Method, device and storage medium for downloading application upgrade file
US11017032B1 (en) Document recovery utilizing serialized data
CN115242874B (en) Network request agent optimization method, system, equipment and storage medium in application development stage
CN111897534B (en) Method, device, electronic equipment and storage medium for accessing SSLVPN
CN116302710A (en) Application version rollback method, device, computer equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination