Self-adaption method, system and equipment for multi-database drive and storage medium

By isolating multiple database drivers into class libraries and registering them in driver management services, the adaptation of multiple database drivers is realized, and the compatibility problems in the existing technology are solved, and the efficiency and adaptability of data collection are improved.

CN119088836APending Publication Date: 2024-12-06DIGITAL CERTIFICATION (WUHAN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411132793.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-19
Publication Date
2024-12-06

AI Technical Summary

Technical Problem

The existing technology has compatibility problems in a multi-database environment, which leads to application systems that need to frequently reconfigure database drivers to adapt to different types and versions of databases, increasing workload and complexity.

Method used

By isolating multiple optional database drivers into different class libraries and registering them on driver management services, the client can adaptively select and adapt the most suitable database driver based on business information, realizing the coexistence and dynamic adaptation of multiple database drivers. .

Benefits of technology

It supports multiple database drivers coexisting in a multi-database environment, reduces the configuration workload of the application system, and improves the efficiency and adaptability of data collection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119088836A_ABST
    Figure CN119088836A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a self-adaption method, system and device for multi-database drive and a storage medium, and relates to the technical field of database management. The multi-database driver-oriented self-adaption method is applied to a client and comprises the following steps: searching at least one pre-selected database driver matched with business information from a plurality of selectable database drivers registered on a driver management service to obtain a driver list; wherein the plurality of selectable database drivers are isolated into a plurality of different class libraries; and traversing each pre-selected database driver in the driver list, and performing an adaptability test on the pre-selected database driver until the pre-selected database driver passing the adaptability test is determined as a first target database driver, or traversing of the driver list is completed. According to the embodiment of the invention, the technical effects of supporting coexistence of multiple database drivers and dynamically adapting to the database drivers can be realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of database management, and in particular to a self-adaptive method, system, device and storage medium for multi-database drivers. Background Art

[0002] With the rapid growth of enterprise business data, a large amount of business data is widely stored in multiple databases, and application systems for managing large amounts of business data are deployed on the client. In data collection scenarios such as big data ETL (Extract-Transform-Load, which is used to describe the process of extracting, transforming and loading data from the source to the destination), the application system needs to support the same deployment package to access multiple different types of databases, multiple databases of the same type but different versions, or multiple databases of the same type but different derivatives according to the configuration.

[0003] Due to the type and version differences between multiple databases, there are many compatibility issues in the database drivers adapted to multiple databases. For example, a certain database is only adapted to a certain type and specific version of the database driver. Therefore, the application system usually directly configures a certain type and specific version of the database driver to connect to a certain database. When it is necessary to connect to another database but the database driver adapted to the other database conflicts with the dependency of this database driver, the application system can only reconfigure another database driver, which increases the workload of the application system.

[0004] In order to adapt to multiple databases for data collection, it is urgent to study a technology that enables the application system to support the coexistence of multiple database drivers and dynamically adapt to the database drivers. Summary of the invention

[0005] The purpose of the embodiments of the present application is to provide a self-adaptive method, system, device and storage medium for multiple database drivers, so as to achieve the technical effect of supporting the coexistence of multiple database drivers and dynamically adapting the database drivers.

[0006] In a first aspect, an embodiment of the present application provides a self-adaptation method for multiple database drivers, which is applied to a client, and the method includes:

[0007] Searching for at least one pre-selected database driver matching the business information from a plurality of optional database drivers registered on the driver management service to obtain a driver list; wherein the plurality of optional database drivers are isolated into a plurality of different class libraries;

[0008] Each pre-selected database driver in the driver list is traversed, and a compatibility test is performed on the pre-selected database driver until the pre-selected database driver that passes the compatibility test is determined as the first target database driver, or the traversal of the driver list is completed.

[0009] In the above implementation process, by pre-registering multiple optional database drivers that are isolated into multiple different class libraries on the driver management service, the client can adaptively obtain the first target database driver for business adaptation from multiple optional database drivers according to business information, thereby achieving the technical effect of supporting the coexistence of multiple database drivers and dynamically adapting database drivers.

[0010] Furthermore, before searching for at least one pre-selected database driver matching the business information from a plurality of optional database drivers registered on the driver management service to obtain a driver list, the method further includes:

[0011] For each original database driver among the multiple original database drivers, rewrite the class configuration information of the original database driver according to the type and version of the original database driver to obtain an optional database driver;

[0012] The optional database driver is encapsulated and registered on the driver management service.

[0013] In the above implementation process, the client rewrites the class configuration information of the original database driver according to the type and version of the original database driver to obtain the optional database driver corresponding to the original database driver, so that multiple optional database drivers isolated into multiple different class libraries can be quickly and accurately obtained.

[0014] Furthermore, the rewriting of the class configuration information of the original database driver according to the type and version of the original database driver to obtain the optional database driver includes:

[0015] Determine a target class loader according to the type of the original database driver;

[0016] Determine the target class path and the target connection address according to the version of the original database driver;

[0017] The class loader of the original database driver is modified to the target class loader, the class path of the original database driver is modified to the target class path, and the connection address of the original database driver is modified to the target connection address to obtain the optional database driver.

[0018] In the above implementation process, the client determines the target class loader according to the type of the original database driver, determines the target class path and the target connection address according to the version of the original database driver, and modifies the class loader, class path and connection address of the original database driver to the target class loader, target class path and target connection address accordingly, so as to obtain the optional database driver corresponding to the original database driver, thereby ensuring that multiple optional database drivers isolated into multiple different class libraries can be quickly and accurately obtained.

[0019] Furthermore, before searching for at least one pre-selected database driver matching the business information from a plurality of optional database drivers registered on the driver management service to obtain a driver list, the method further includes:

[0020] In the case that the type of the optional database driver belongs to the target driver type, a common package corresponding to the target driver type is extracted from the dependent package of the optional database driver, and the common package is stored in a public class library corresponding to the target driver type.

[0021] In the above implementation process, when the type of any optional database driver belongs to the target driver type, the client stores the common package corresponding to the target driver type in the dependency package of the optional database driver in the public class library corresponding to the target driver type, which can effectively reduce the number of classes and reduce the expansion rate of classes.

[0022] Furthermore, before traversing each pre-selected database driver in the driver list, the method further includes:

[0023] According to the type and version of at least one pre-selected database driver in the driver list, a priority order of the at least one pre-selected database driver is determined, so as to traverse each pre-selected database driver in the driver list according to the priority order of the at least one pre-selected database driver.

[0024] In the above implementation process, the client determines the priority order of each pre-selected database driver according to the type and version of each pre-selected database driver in the driver list, and traverses each pre-selected database driver in the driver list according to the priority order of each pre-selected database driver, thereby ensuring that the first target database driver with business adaptation and best performance is quickly obtained.

[0025] Further, the adaptability test of the pre-selected database driver includes:

[0026] Verifying whether the pre-selected database driver successfully connects to the target database, and checking whether the version of the pre-selected database driver matches the version of the target database server; wherein the business information includes the target database;

[0027] If the preselected database driver successfully connects to the target database, and the version of the preselected database driver matches the version of the target database server, it is determined that the preselected database driver passes the compatibility test.

[0028] In the above implementation process, the client performs connectivity test and version matching test on the pre-selected database driver to determine whether the pre-selected database driver can successfully connect to the target database and operate the target database normally, thereby ensuring that the first target database driver adapted to the business is obtained.

[0029] Furthermore, the adaptability test of the pre-selected database driver includes:

[0030] Testing whether the pre-selected database driver successfully executes the business test statement;

[0031] If the preselected database driver successfully connects to the target database, the version of the preselected database driver matches the version of the target database server, and the preselected database driver successfully executes the business test statement, it is determined that the preselected database driver passes the adaptability test.

[0032] In the above implementation process, the client performs connectivity test, version matching test and business execution test on the pre-selected database driver to determine whether the pre-selected database driver can successfully collect business data from the target database, which can further ensure the acquisition of the first target database driver that is business-adaptive.

[0033] Furthermore, the method further comprises:

[0034] A second target database driver whose class configuration information is the same as the target class configuration information is searched from the multiple selectable database drivers.

[0035] In the above implementation process, the client searches for a second target database driver whose class configuration information is the same as the target class configuration information from multiple optional database drivers, so that the user can directly select the second target database driver that is suitable for the service.

[0036] In a second aspect, an embodiment of the present application provides an adaptive system for multi-database drivers, which is applied to a client, and the system includes:

[0037] A driver pre-selection module, used to search for at least one pre-selected database driver matching the business information from a plurality of optional database drivers registered on the driver management service, and obtain a driver list; wherein the plurality of optional database drivers are isolated into a plurality of different class libraries;

[0038] A driver adaptation module is used to traverse each pre-selected database driver in the driver list and perform a compatibility test on the pre-selected database driver until the pre-selected database driver that passes the compatibility test is determined as the first target database driver, or the traversal of the driver list is completed. In a third aspect, an embodiment of the present application provides an electronic device, including a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor; the memory is coupled to the processor, and the processor implements the method as described above when executing the computer program.

[0039] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium includes a stored computer program; wherein, when the computer program is running, the device where the computer-readable storage medium is located is controlled to execute the method described above.

[0040] In a fifth aspect, an embodiment of the present application provides a computer program product, which includes instructions, and when the instructions are executed by a computer, the computer implements the method as described above. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments of the present application will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.

[0042] Figure 1 A flowchart of a multi-database driven self-adaptation method provided in the first embodiment of the present application;

[0043] Figure 2 A schematic diagram of a driver management service exemplified in the first embodiment of the present application;

[0044] Figure 3 A schematic diagram of another example of a driver management service in the first embodiment of the present application;

[0045] Figure 4 A data flow diagram of the self-adaptive method for multiple database drivers illustrated in the first embodiment of the present application;

[0046] Figure 5 A schematic diagram of the structure of a multi-database driven self-adaptive system provided in the second embodiment of the present application;

[0047] Figure 6 A schematic diagram of the structure of an electronic device provided in the third embodiment of the present application. DETAILED DESCRIPTION

[0048] The technical solutions in the embodiments of the present application will be described below in conjunction with the drawings in the embodiments of the present application.

[0049] It should be noted that in the description of this application, the terms "first", "second", etc. are only used to distinguish descriptions and cannot be understood as indicating or implying relative importance. At the same time, the step numbers in the text are only for the convenience of explaining the embodiments of this application and do not serve to limit the order of execution of the steps.

[0050] With the rapid growth of enterprise business data, a large amount of business data is widely stored in multiple databases, and application systems for managing large amounts of business data are deployed on the client. In data collection scenarios such as big data ETL (Extract-Transform-Load, which is used to describe the process of extracting, transforming and loading data from the source to the destination) scenarios, the application system needs to support the same deployment package to access multiple different types of databases (such as relational databases and non-relational databases), multiple databases of the same type but different versions (such as relational database MySQL 5.7 and relational database MySQL 5.8) or multiple databases of the same type but different derivatives (such as relational database PostgreSQL and relational database OpenGuass) according to the configuration.

[0051] In the related art, due to the type and version differences between multiple databases, there are many compatibility issues in the database drivers adapted to multiple databases. For example, a certain database is only adapted to a certain type and specific version of the database driver, etc. Therefore, the application system usually directly configures a certain type and specific version of the database driver to connect to a certain database. When it is necessary to connect to another database but the database driver adapted to the other database conflicts with the dependency of this database driver, the application system can only reconfigure another database driver, which increases the workload of the application system.

[0052] In order to adapt to multiple databases for data collection, it is urgent to study a technology that enables the application system to support the coexistence of multiple database drivers and dynamically adapt to the database drivers.

[0053] To this end, the present application proposes a self-adaptation method for multiple database drivers. By pre-registering multiple optional database drivers that are isolated into multiple different class libraries on the driver management service, the client can adaptively obtain the first target database driver for business adaptation from multiple optional database drivers based on business information, thereby achieving the technical effect of supporting the coexistence of multiple database drivers and dynamically adapting database drivers.

[0054] The method provided in the embodiment of the present application can be executed by a relevant terminal device, and the following description will be given using the client as an example of the execution subject.

[0055] It should be understood that the client described in the embodiments of the present application may be a user terminal or an application server, and the embodiments of the present application are not limited to this.

[0056] Please see Figure 1 , Figure 1 A flowchart of a self-adaptation method for multiple database drivers provided in the first embodiment of the present application. The first embodiment of the present application provides a self-adaptation method for multiple database drivers, which is applied to a client, and the method includes steps S101 to S103:

[0057] S101, searching for at least one pre-selected database driver matching the business information from a plurality of optional database drivers registered on the driver management service, and obtaining a driver list; wherein the plurality of optional database drivers are isolated into a plurality of different class libraries;

[0058] S102, traversing each pre-selected database driver in the driver list, and performing a compatibility test on the pre-selected database driver, until a pre-selected database driver that passes the compatibility test is determined as the first target database driver, or the traversal of the driver list is completed.

[0059] As an example, according to actual application requirements, multiple original database drivers are selected in advance for multiple databases, the multiple original database drivers are isolated into multiple different class libraries, multiple optional database drivers are obtained, and the multiple optional database drivers are registered on the driver management service.

[0060] For example, for multiple databases such as relational database MySQL 5.7, relational database MySQL 5.8, relational database Hive 2.10.0, and relational database Hive 2.8.0, multiple original database drivers are selected including MySQL Driver, MySQL Driver, Hive 2.10.0, and HiveDriver. Multiple original database drivers are isolated into multiple different class libraries. Multiple optional database drivers include MySQL 5.7Driver, MySQL 5.8Driver, MySQL 5.8Driver, Hive 2.10.0Driver, and Hive 2.8.0Driver. Multiple optional database drivers are registered on the driver management service DriverManager. The driver management service DriverManager is as follows: Figure 2 shown.

[0061] When a user needs to collect business data from any database among multiple databases, namely, a target database, the user can input business information into the client, wherein the business information includes the host of the target database server, the port of the target database server, the schema of the target database, the account information for accessing the target database, the type of the optional database driver compatible with the target database, the version of the optional database driver compatible with the target database, and at least one of the digital certificates for connecting to the optional database driver compatible with the target database.

[0062] In actual applications, business information does not necessarily include the version of the optional database driver that is compatible with the target database. If the target database server has enabled the digital certificate authentication function, such as SSL (Secure Sockets Layer) authentication (referring to the authentication from the client to the server), then the business information must include the digital certificate used to connect to the optional database driver that is compatible with the target database.

[0063] After obtaining the business information input by the user, the client calls the driver management service to search for at least one optional database driver that matches the business information from multiple optional database drivers registered on the driver management service. The at least one optional database driver found is the at least one pre-selected database driver, and a driver list is obtained based on the at least one pre-selected database driver.

[0064] It can be understood that the driver list is used to store at least one pre-selected database driver.

[0065] After obtaining the driver list, the client traverses each pre-selected database driver in the driver list and performs a compatibility test on the pre-selected database driver currently traversed. If the pre-selected database driver currently traversed passes the compatibility test, it is considered that the pre-selected database driver currently traversed can meet the demand for collecting business data from the target database, and the pre-selected database driver currently traversed is directly determined as the first target database driver, and the driver list is no longer traversed. If the pre-selected database driver currently traversed does not pass the compatibility test, it is considered that the pre-selected database driver currently traversed cannot meet the demand for collecting business data from the target database, and the next pre-selected database driver is traversed for compatibility testing. This operation is repeated until a pre-selected database driver that passes the compatibility test is determined as the first target database driver, or the traversal of the driver list is completed.

[0066] It can be understood that completing the traversal of the driver list means traversing each pre-selected database driver in the driver list.

[0067] In actual applications, after the client has completed traversing the driver list and each pre-selected database driver in the driver list has failed the adaptability test, the client can return a notification message of failure to obtain the first target database driver to the user so that the user can take timely countermeasures.

[0068] Since multiple optional database drivers are isolated as multiple different class libraries, there will be no incompatibility issues between multiple optional database drivers even if multiple optional database drivers are registered on the driver management service. And since multiple optional database drivers are registered on the driver management service, the client can adaptively obtain the first target database driver for business adaptation according to the business information input by the user by calling the driver management service.

[0069] The embodiment of the present application pre-registers multiple optional database drivers that are isolated into multiple different class libraries on the driver management service, so that the client can adaptively obtain the first target database driver for business adaptation from the multiple optional database drivers according to business information, thereby achieving the technical effect of supporting the coexistence of multiple database drivers and dynamically adapting the database drivers.

[0070] In an optional embodiment, before searching for at least one pre-selected database driver that matches the business information from a plurality of optional database drivers registered on the driver management service to obtain a driver list, the method further includes: for each of the plurality of original database drivers, rewriting the class configuration information of the original database driver according to the type and version of the original database driver to obtain the optional database driver; encapsulating the optional database driver, and registering the optional database driver on the driver management service.

[0071] As an exemplary example, according to actual application requirements, multiple original database drivers are selected in advance for multiple databases.

[0072] For example, for multiple databases including relational database MySQL 5.7, relational database MySQL 5.8, relational database Hive 2.10.0, and relational database Hive 2.8.0, the selected multiple original database drivers include MySQL Driver, a driver for relational database MySQL 5.7, MySQL Driver, a driver for relational database MySQL 5.8, Hive Driver, a driver for relational database Hive 2.10.0, and HiveDriver, a driver for relational database Hive 2.8.0.

[0073] After obtaining multiple original database drivers, the client rewrites the class configuration information of each original database driver according to the type and version of the original database driver, wherein the class configuration information includes a class loader Classloader, a class path, and a connection address URL (Uniform Resource Locator) to isolate the original database driver as a new class library, obtain an optional database driver corresponding to the original database driver, encapsulate the optional database driver, and register the optional database driver on the driver management service, thereby registering multiple optional database drivers on the driver management service.

[0074] For multiple databases of the same type but different versions, the class configuration information of the drivers of these databases is the same. For example, the class configuration information of the driver of the relational database MySQL 5.7 is the class loader MySQL Classloader, the class path "com.mysql.jdbc" and the connection address "jdbc:mysql:", and the class configuration information of the driver of the relational database MySQL 5.8 is also the class loader MySQL Classloader, the class path "com.mysql.jdbc" and the connection address "jdbc:mysql:". Similarly, for multiple databases of the same type but different derivatives, the class configuration information of the drivers of these databases is also the same. By rewriting the class configuration information, class isolation can be achieved quickly and accurately.

[0075] In the embodiment of the present application, the client rewrites the class configuration information of the original database driver according to the type and version of the original database driver to obtain the optional database driver corresponding to the original database driver, so that multiple optional database drivers isolated into multiple different class libraries can be quickly and accurately obtained.

[0076] In an optional embodiment, the method of rewriting the class configuration information of the original database driver according to the type and version of the original database driver to obtain the optional database driver includes: determining the target class loader according to the type of the original database driver; determining the target class path and the target connection address according to the version of the original database driver; modifying the class loader of the original database driver to the target class loader, modifying the class path of the original database driver to the target class path, and modifying the connection address of the original database driver to the target connection address to obtain the optional database driver.

[0077] As an example, considering that in the Java language, classes are distinguished by unique identifiers consisting of class loaders and class paths, two methods can be used to achieve class isolation: one is to set different types of class loaders for different types of database drivers; the other is to set different class paths and connection addresses for different versions of database drivers.

[0078] After obtaining multiple original database drivers, the client determines the type and version of each original database driver in the multiple original database drivers.

[0079] According to the type of the original database driver, the target class loader is determined. For example, assuming that the type of the original database driver is MySQL, the target class loader is determined to be MySQL Classloader.

[0080] It is understandable that, since the target class loader has been previously determined for each of the multiple original database drivers according to the type of the original database driver, the target class loader corresponding to each of the multiple original database drivers can be determined at this time.

[0081] In actual applications, if at least some of the original database drivers in multiple original database drivers correspond to the same target class loader, then the class path can specifically use the class loading path package. If the class loaders corresponding to the multiple original database drivers are different, then the class path can specifically use the class storage path classpath.

[0082] According to the version of the original database driver, determine the target class path and the target connection address. For example, assuming that the version of the original database driver is MySQL 5.7, determine the target class path to be "com.mysql.v57.jdbc" and the target connection address to be "jdbc:mysql:v57".

[0083] The class loader of the original database driver is modified to a target class configurator, and a package management tool is used to modify the class path of the original database driver to a target class path, and the connection address of the original database driver is modified to a target connection address to obtain an optional database driver. For example, the class loader of the original database driver is modified to a target class loader MySQL Classloader, and a package management tool is used to modify the class path of the original database driver from "com.mysql.jdbc" to a target class path "com.mysql.v57.jdbc", and the connection address of the original database driver from "jdbc:mysql:" to a target connection address "jdbc:mysql:v57", wherein the original class path "com.mysql.jdbc" and the target class path "com.mysql.v57.jdbc" are class loading paths.

[0084] In actual applications, since the maven-shade-plugin plug-in of the project management tool software Maven can rewrite the class path and class variables, the package management tool can be selected from Maven tools. The package management tool can also be selected from tools such as Java decompilation tools that have the function of rewriting class paths and class variables.

[0085] In the embodiment of the present application, the client determines the target class loader according to the type of the original database driver, determines the target class path and the target connection address according to the version of the original database driver, and modifies the class loader, class path and connection address of the original database driver to the target class loader, target class path and target connection address, thereby obtaining an optional database driver corresponding to the original database driver, thereby ensuring that multiple optional database drivers isolated into multiple different class libraries can be quickly and accurately obtained.

[0086] In an optional embodiment, before searching for at least one pre-selected database driver that matches the business information from a plurality of optional database drivers registered on the driver management service to obtain a driver list, the method further includes: when the type of the optional database driver belongs to the target driver type, extracting a common package corresponding to the target driver type from the dependent package of the optional database driver, and storing the common package in a public class library corresponding to the target driver type.

[0087] As an example, when there are many types and versions of multiple original database drivers, the number of classes is large and the expansion speed of the classes is also fast. In order to reduce the number of classes and reduce the expansion speed of the classes, the target driver type is determined in advance for some database drivers with more complex dependencies, and the common package corresponding to the target driver type is determined.

[0088] For example, the relational database Hive and the column storage database Kudu are two mainstream large databases based on the distributed system infrastructure Hadoop. The driver Hive Driver of the relational database Hive and the driver Kudu Driver of the column storage database Kudu are based on Hadoop. Hadoop relies on the common packages such as the Common library, Guava library, Jackson library, Netty framework and Thrift framework of the web server software Apache. These common packages have little difference under different versions of Hive Driver and Kudu Driver and can basically be shared. For the dependent packages that conflict under different versions of Hive Driver and KuduDriver, if the dependent functions of the dependent packages under different versions of Hive Driver and Kudu Driver are slightly different, the maven-shade-plugin plug-in of the Maven tool can be used to modify the dependent packages to supplement the missing functions and process the dependent packages into common packages; if the dependent functions of the dependent packages under different versions of Hive Driver and Kudu Driver are significantly different, the dependent packages are directly treated as private packages and are not stored in the public class library. For database drivers such as HiveDriver and Kudu Driver, which have more complex dependencies, the target driver types are sorted out, including HiveDriver and Kudu Driver. The common packages corresponding to the determined target driver types include Common library, Guava library, Jackson library, Netty framework, Thrift framework and other common packages.

[0089] The client determines whether the type of each optional database driver among the multiple optional database drivers belongs to the target driver type. If the optional database driver belongs to the target driver type, the client extracts the common package corresponding to the target driver type from the dependent package of the optional database driver, and stores the extracted common package in the public class library corresponding to the target driver type. Figure 3 shown.

[0090] In the embodiment of the present application, when the type of any optional database driver belongs to the target driver type, the client stores the common package corresponding to the target driver type in the dependency package of the optional database driver in the public class library corresponding to the target driver type, thereby effectively reducing the number of classes and lowering the expansion rate of classes.

[0091] In practical applications, in order to meet the needs of collecting business data from traditional databases, such as FTP (File Transfer Protocol) databases and non-relational databases NoSQL databases, such as Redis databases, and other databases that are not compatible with SQL (Structured Query Language) drivers, for traditional database drivers and non-relational database drivers, service addressing abstraction methods and business operation abstraction methods can be used to abstract traditional database drivers and non-relational database drivers into a driver framework similar to JDBC (Java Database Connectivity, which is oriented to relational databases), so that traditional database drivers and non-relational database drivers can also be registered on the driver management service.

[0092] In an optional embodiment, before traversing each pre-selected database driver in the driver list, it also includes: determining the priority order of at least one pre-selected database driver based on the type and version of at least one pre-selected database driver in the driver list, so as to traverse each pre-selected database driver in the driver list according to the priority order of at least one pre-selected database driver.

[0093] As an example, in order to quickly obtain the first target database driver that is business-adaptive and has the best performance, after obtaining the driver list, the client determines the priority order of each pre-selected database driver according to the type and version of each pre-selected database driver in the driver list, and traverses each pre-selected database driver in the driver list according to the priority order of each pre-selected database driver.

[0094] In actual applications, the priority of each pre-selected database driver can be determined according to the usage frequency of each pre-selected database driver type and the release time of each pre-selected database driver version. If the usage frequency of a pre-selected database driver type is high and the release time of the pre-selected database driver version is later, the priority of the pre-selected database driver is determined to be high. For example, assuming that the driver list includes the driver MySQL5.7Driver of the relational database MySQL 5.7, the driver MySQL 5.8Driver of the relational database MySQL 5.8, and the driver Hive 2.10.0Driver of the relational database Hive 2.10.0, the usage frequency of MySQL Driver is higher than that of Hive Driver, and the release time of MySQL5.8Driver is later than that of MySQL 5.7Driver, then in the driver list, the priority of MySQL5.8Driver is high, the priority of MySQL 5.7Driver is medium, and the priority of Hive 2.10.0Driver is low. Each pre-selected database driver in the driver list is traversed in descending order of the priority of each pre-selected database driver.

[0095] In the embodiment of the present application, the client determines the priority order of each pre-selected database driver according to the type and version of each pre-selected database driver in the driver list, and traverses each pre-selected database driver in the driver list according to the priority order of each pre-selected database driver, thereby ensuring that the first target database driver with business adaptation and the best performance is quickly obtained.

[0096] In an optional embodiment, the adaptability test of the preselected database driver includes: verifying whether the preselected database driver successfully connects to the target database, and checking whether the version of the preselected database driver matches the version of the target database server; if the preselected database driver successfully connects to the target database, and the version of the preselected database driver matches the version of the target database server, it is determined that the preselected database driver passes the adaptability test.

[0097] As an exemplary embodiment, after obtaining the driver list, the client traverses each pre-selected database driver in the driver list and performs a compatibility test on the currently traversed pre-selected database driver, wherein the compatibility test includes a connectivity test and a version matching test.

[0098] The connectivity test verifies whether the currently traversed pre-selected database driver successfully connects to the target database. The client can use the getConnection() method to establish a connection with the target database for the currently traversed pre-selected database driver. If the currently traversed pre-selected database driver successfully connects to the target database, it is determined that the currently traversed pre-selected database driver successfully connects to the target database; if the currently traversed pre-selected database driver fails to connect to the target database, it is determined that the currently traversed pre-selected database driver fails to connect to the target database.

[0099] The version matching test is to check whether the version of the currently traversed pre-selected database driver matches the version of the target database server. The client obtains the version of the target database server and compares the version of the currently traversed pre-selected database driver with the version of the target database server. If the version of the currently traversed pre-selected database driver is consistent with the version of the target database server, it is determined that the version of the currently traversed pre-selected database driver matches the version of the target database server; if the version of the currently traversed pre-selected database driver is inconsistent with the version of the target database server, it is determined that the version of the currently traversed pre-selected database driver does not match the version of the target database server.

[0100] In actual applications, the client can first perform a connectivity test on the currently traversed pre-selected database driver. If the currently traversed pre-selected database driver fails the connectivity test, it is directly determined that the currently traversed pre-selected database driver fails the adaptability test; if the currently traversed pre-selected database driver passes the connectivity test, a version matching test is then performed on the currently traversed pre-selected database driver, and only when the currently traversed pre-selected database driver passes the version matching test, it is determined that the currently traversed pre-selected database driver passes the adaptability test. The client can also perform a connectivity test and a version matching test on the currently traversed pre-selected database driver respectively, and only when the currently traversed pre-selected database driver passes both the connectivity test and the version matching test, it is determined that the currently traversed pre-selected database driver passes the adaptability test.

[0101] In the embodiment of the present application, the client performs a connectivity test and a version matching test on the pre-selected database driver to determine whether the pre-selected database driver can successfully connect to the target database and operate the target database normally, thereby ensuring that the first target database driver adapted to the business is obtained.

[0102] In an optional embodiment, the adaptability test of the preselected database driver includes: testing whether the preselected database driver successfully executes the business test statement; if the preselected database driver successfully connects to the target database, the version of the preselected database driver matches the version of the target database server, and the preselected database driver successfully executes the business test statement, it is determined that the preselected database driver passes the adaptability test.

[0103] As an exemplary example, after obtaining the driver list, the client traverses each pre-selected database driver in the driver list and performs a compatibility test on the currently traversed pre-selected database driver, wherein the compatibility test also includes a service execution test.

[0104] The business execution test is to test whether the currently traversed pre-selected database driver successfully executes the business test statement. The client obtains the business test statement input by the user, loads the currently traversed pre-selected database driver, and operates the target database according to the business test statement. If it is confirmed that the operation authority corresponding to the business test statement is available, such as the read and write authority to a table in the target database, and the operation result meets the expected operation result, it is determined that the currently traversed pre-selected database driver successfully executes the business test statement; if it is confirmed that there is no operation authority corresponding to the business test statement, or the operation result does not meet the expected operation result, it is determined that the currently traversed pre-selected database driver fails to execute the business test statement.

[0105] In actual applications, the client can perform connectivity tests, version matching tests, and business execution tests on the currently traversed pre-selected database driver in sequence. If the currently traversed pre-selected database driver fails the connectivity test or fails the version matching test, it is directly determined that the currently traversed pre-selected database driver fails the adaptability test; if the currently traversed pre-selected database driver passes both the connectivity test and the version matching test, the currently traversed pre-selected database driver is then subjected to a business execution test, and only if the currently traversed pre-selected database driver passes the business execution test, is it determined that the currently traversed pre-selected database driver passes the adaptability test. For example, the data flow diagram of the self-adaptive method for multiple database drivers is as follows: Figure 4 The client can also perform connectivity test, version matching test and business feasibility test on the currently traversed pre-selected database driver respectively, and only when the currently traversed pre-selected database driver passes the connectivity test, version matching test and business execution test, it is determined that the currently traversed pre-selected database driver passes the adaptability test.

[0106] In actual applications, other adaptability tests such as permission tests can also be added according to actual application requirements.

[0107] In the embodiment of the present application, the client performs connectivity test, version matching test and service execution test on the pre-selected database driver to determine whether the pre-selected database driver can successfully collect service data from the target database, which can further ensure the acquisition of the first target database driver that is service-adaptive.

[0108] In an optional embodiment, the method further includes step S103:

[0109] S103: Searching for a second target database driver whose class configuration information is the same as the target class configuration information from a plurality of optional database drivers.

[0110] As an example, when a user needs to collect business data from any database among multiple databases, namely, a target database, the user can also directly input target class configuration information into the client, wherein the target class configuration information includes class configuration information of a database driver adapted to the target database, and the class configuration information includes a class path or a connection address.

[0111] After obtaining the target class configuration information input by the user, the client calls the driver management service to search for an optional database driver whose class configuration information is the same as the target class configuration information from multiple optional database drivers registered on the driver management service, and determines the found optional database driver as the second target database driver.

[0112] In the embodiment of the present application, the client searches for a second target database driver whose class configuration information is the same as the target class configuration information from multiple optional database drivers, so that the user can directly select the second target database driver that is adapted to the service.

[0113] Please see Figure 5 , Figure 5 A structural diagram of a self-adaptive system for multiple database drivers provided for the second embodiment of the present application. The second embodiment of the present application provides a self-adaptive system for multiple database drivers, which is applied to a client, and the system includes: a driver pre-selection module 201, which is used to search for at least one pre-selected database driver that matches the business information from multiple optional database drivers registered on the driver management service to obtain a driver list; wherein the multiple optional database drivers are isolated into multiple different class libraries; a driver adaptation module 202, which is used to traverse each pre-selected database driver in the driver list and perform adaptability tests on the pre-selected database drivers until the pre-selected database driver that passes the adaptability test is determined as the first target database driver, or the traversal of the driver list is completed.

[0114] In an optional embodiment, the system further includes: a driver registration module, which is used to search for at least one pre-selected database driver that matches the business information from the multiple optional database drivers registered on the driver management service, and before obtaining the driver list, for each of the multiple original database drivers, rewrite the class configuration information of the original database driver according to the type and version of the original database driver to obtain the optional database driver; encapsulate the optional database driver, and register the optional database driver on the driver management service.

[0115] In an optional embodiment, the method of rewriting the class configuration information of the original database driver according to the type and version of the original database driver to obtain the optional database driver includes: determining the target class loader according to the type of the original database driver; determining the target class path and the target connection address according to the version of the original database driver; modifying the class loader of the original database driver to the target class loader, modifying the class path of the original database driver to the target class path, and modifying the connection address of the original database driver to the target connection address to obtain the optional database driver.

[0116] In an optional embodiment, the driver registration module is further used to search for at least one pre-selected database driver that matches the business information from the multiple optional database drivers registered on the driver management service, and before obtaining the driver list, when the type of the optional database driver belongs to the target driver type, extract the common package corresponding to the target driver type from the dependent package of the optional database driver, and store the common package in the public class library corresponding to the target driver type.

[0117] In an optional embodiment, the driver adaptation module 202 is further used to determine the priority order of at least one pre-selected database driver according to the type and version of at least one pre-selected database driver in the driver list before traversing each pre-selected database driver in the driver list, so as to traverse each pre-selected database driver in the driver list according to the priority order of at least one pre-selected database driver.

[0118] In an optional embodiment, the adaptability test of the preselected database driver includes: verifying whether the preselected database driver successfully connects to the target database, and checking whether the version of the preselected database driver matches the version of the target database server; if the preselected database driver successfully connects to the target database, and the version of the preselected database driver matches the version of the target database server, it is determined that the preselected database driver passes the adaptability test.

[0119] In an optional embodiment, the adaptability test of the preselected database driver includes: testing whether the preselected database driver successfully executes the business test statement; if the preselected database driver successfully connects to the target database, the version of the preselected database driver matches the version of the target database server, and the preselected database driver successfully executes the business test statement, it is determined that the preselected database driver passes the adaptability test.

[0120] In an optional embodiment, the driver adaptation module 202 is further configured to search for a second target database driver whose class configuration information is the same as the target class configuration information from a plurality of optional database drivers.

[0121] The implementation process of the functions and effects of the drive pre-selection module 201 and the drive adaptation module 202 in the above system is specifically described in the implementation process of the corresponding steps in the above method, which will not be repeated here.

[0122] Please see Figure 6 , Figure 6 The third embodiment of the present application provides an electronic device 30, comprising a processor 301, a memory 302, and a computer program stored in the memory 302 and configured to be executed by the processor 301; the memory 302 is coupled to the processor 301, and when the processor 301 executes the computer program, the method described in the first embodiment of the present application is implemented and the same beneficial effects can be achieved.

[0123] When the processor 301 reads the computer program from the memory 302 through the bus 303 and executes the computer program, the method of any embodiment included in the method described in the first embodiment of the present application can be implemented.

[0124] Processor 301 can process digital signals and can include various computing structures, such as complex instruction set computer structure, reduced instruction set computer structure, or a structure that implements a combination of multiple instruction sets. In some examples, processor 301 can be a microprocessor.

[0125] The memory 302 may be used to store instructions executed by the processor 301 or data related to the execution of instructions. These instructions and / or data may include codes for implementing some or all functions of one or more modules described in the embodiments of the present application. The processor 301 of the disclosed embodiment may be used to execute instructions in the memory 302 to implement the method described in the first embodiment of the present application. The memory 302 includes a dynamic random access memory, a static random access memory, a flash memory, an optical memory, or other memory known to those skilled in the art.

[0126] The fourth embodiment of the present application provides a computer-readable storage medium, which includes a stored computer program; wherein, when the computer program is running, the device where the computer-readable storage medium is located is controlled to execute the method described in the first embodiment of the present application, and can achieve the same beneficial effects as the method.

[0127] The fifth embodiment of the present application provides a computer program product, which includes instructions. When the instructions are executed by a computer, the computer implements the method described in the first embodiment of the present application and can achieve the same beneficial effects.

[0128] The method described in the first embodiment of the present application can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer programs or instructions. When the computer program or instruction is loaded and executed on a computer, the process or function described in each embodiment of the present application is executed in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, a network device, a user device, a core network device, an OAM (Open Application Model) or other programmable device.

[0129] The computer program or instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer program or instructions may be transmitted from one website, computer, server or data center to another website, computer, server or data center by wired or wireless means. The computer-readable storage medium may be any available medium that can be accessed by a computer or a data storage device such as a server or data center that integrates one or more available media. The available medium may be a magnetic medium, such as a floppy disk, a hard disk, or a magnetic tape; it may also be an optical medium, such as a digital video disk; it may also be a semiconductor medium, such as a solid-state drive. The computer-readable storage medium may be a volatile or non-volatile storage medium, or may include both volatile and non-volatile types of storage media.

[0130] In summary, the embodiments of the present application provide a self-adaptation method, system, device and storage medium for multiple database drivers. The self-adaptation method for multiple database drivers is applied to the client, and the method includes: searching for at least one pre-selected database driver that matches the business information from multiple optional database drivers registered on the driver management service to obtain a driver list; wherein the multiple optional database drivers are isolated into multiple different class libraries; traversing each pre-selected database driver in the driver list, and performing an adaptability test on the pre-selected database driver until the pre-selected database driver that passes the adaptability test is determined as the first target database driver, or the traversal of the driver list is completed. The embodiments of the present application pre-register multiple optional database drivers that are isolated into multiple different class libraries on the driver management service, so that the client can adaptively obtain the first target database driver that is business-adapted from multiple optional database drivers according to the business information, thereby achieving the technical effect of supporting the coexistence of multiple database drivers and dynamically adapting the database driver.

[0131] In several embodiments provided in the present application, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are merely schematic. For example, the flowcharts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the devices, methods and computer program products according to multiple embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the module, a program segment or a part of a code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of boxes in the block diagram and / or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.

[0132] In addition, the functional modules in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.

[0133] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

[0134] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

Claims

1. A self-adaptive method for multi-database drivers, characterized in that: Applied to a client, the method comprises: Searching for at least one pre-selected database driver matching the business information from a plurality of optional database drivers registered on the driver management service to obtain a driver list; wherein the plurality of optional database drivers are isolated into a plurality of different class libraries; Each pre-selected database driver in the driver list is traversed, and a compatibility test is performed on the pre-selected database driver until the pre-selected database driver that passes the compatibility test is determined as the first target database driver, or the traversal of the driver list is completed.

2. The method according to claim 1, characterized in that Before searching for at least one pre-selected database driver matching the business information from a plurality of optional database drivers registered on the driver management service to obtain a driver list, the method further includes: For each original database driver among the multiple original database drivers, rewrite the class configuration information of the original database driver according to the type and version of the original database driver to obtain an optional database driver; The optional database driver is encapsulated and registered on the driver management service.

3. The method according to claim 2, characterized in that The step of rewriting the class configuration information of the original database driver according to the type and version of the original database driver to obtain an optional database driver includes: Determine a target class loader according to the type of the original database driver; Determine the target class path and the target connection address according to the version of the original database driver; The class loader of the original database driver is modified to the target class loader, the class path of the original database driver is modified to the target class path, and the connection address of the original database driver is modified to the target connection address to obtain the optional database driver.

4. The method according to claim 2, characterized in that Before searching for at least one pre-selected database driver matching the business information from a plurality of optional database drivers registered on the driver management service to obtain a driver list, the method further includes: In the case that the type of the optional database driver belongs to the target driver type, a common package corresponding to the target driver type is extracted from the dependent package of the optional database driver, and the common package is stored in a public class library corresponding to the target driver type.

5. The method according to claim 1, characterized in that Before traversing each pre-selected database driver in the driver list, the method further includes: According to the type and version of at least one pre-selected database driver in the driver list, a priority order of the at least one pre-selected database driver is determined, so as to traverse each pre-selected database driver in the driver list according to the priority order of the at least one pre-selected database driver.

6. The method according to claim 1, characterized in that The adaptability test of the pre-selected database driver includes: Verifying whether the pre-selected database driver successfully connects to the target database, and checking whether the version of the pre-selected database driver matches the version of the target database server; wherein the business information includes the target database; If the preselected database driver successfully connects to the target database, and the version of the preselected database driver matches the version of the target database server, it is determined that the preselected database driver passes the compatibility test.

7. The method according to claim 6, characterized in that The adaptability test of the pre-selected database driver includes: Testing whether the pre-selected database driver successfully executes the business test statement; If the preselected database driver successfully connects to the target database, the version of the preselected database driver matches the version of the target database server, and the preselected database driver successfully executes the business test statement, it is determined that the preselected database driver passes the adaptability test.

8. The method according to any one of claims 1 to 7, characterized in that: The method further comprises: A second target database driver whose class configuration information is the same as the target class configuration information is searched from the multiple selectable database drivers.

9. A self-adaptive system for multi-database drivers, characterized in that: Applied to a client, the system comprises: A driver pre-selection module, used to search for at least one pre-selected database driver matching the business information from a plurality of optional database drivers registered on the driver management service, and obtain a driver list; wherein the plurality of optional database drivers are isolated into a plurality of different class libraries; The driver adaptation module is used to traverse each pre-selected database driver in the driver list and perform adaptability tests on the pre-selected database drivers until the pre-selected database driver that passes the adaptability test is determined as the first target database driver, or the traversal of the driver list is completed.

10. An electronic device, characterized in that: The method comprises a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor; the memory is coupled to the processor, and the processor implements the method according to any one of claims 1 to 8 when executing the computer program.

11. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored computer program; wherein, when the computer program is running, the device where the computer-readable storage medium is located is controlled to execute the method according to any one of claims 1 to 8.