Database adaptation device and method based on dynamic multiple data sources

By using in-memory database, database keyword library, syntax difference library, syntax adapter and SQL executor in the database adapter device, the problem of high complexity in dynamic docking of multi-source data development is solved, and database adaptation and efficient query of multiple data sources are realized.

CN114281875BActive Publication Date: 2025-02-28INSPUR SOFTWARE CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111476466.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-06
Publication Date
2025-02-28
Estimated Expiration
2041-12-06

AI Technical Summary

Technical Problem

In the case of diversified business systems, dynamic docking multi-source data execution and development is complex, and it is difficult for the existing technology to effectively solve this problem.

Method used

Provides database adaptation devices and methods based on dynamic multi-data sources, encapsulates underlying database differences through in-memory databases, database keyword databases, syntax differences, syntax adapters and SQL executors, realizes syntax parsing and conversion of SQL statements, and adapts to multiple data sources.

Benefits of technology

It realizes database adaptation of multiple data sources, reduces development complexity, improves database query efficiency, and supports dynamic expansion and flexible use.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114281875B_ABST
    Figure CN114281875B_ABST
Patent Text Reader

Abstract

The present invention discloses a database adaptation device and method based on dynamic multi-data sources, which belongs to the field of database technology. The technical problem to be solved is how to solve the high complexity of dynamic docking multi-source data execution development. It includes: an in-memory database for storing data source information; a database keyword library for storing all keywords of the adapted database type; a grammar difference library for storing grammar differences, which are differences in grammar content between relational databases; a grammar adapter for obtaining the database type based on the database information, and performing grammar analysis and conversion on the SQL statement based on the database type to obtain an adapted SQL statement; an SQL executor, which interacts with the grammar adapter and is used to load and drive the corresponding database based on the database type, and output the execution result after the database executes the adapted SQL statement.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of database technology, in particular to a database adaptation device and method based on dynamic multiple data sources. Background Art

[0002] With the diversification of business systems, there are more and more demands and systems for data processing and data application. Connecting to dynamic multiple data sources requires solving problems such as inconsistent database syntax, dynamic driver loading, and dynamic driver expansion. The development process is complex and error-prone.

[0003] The ORM (Object Relational Mapping) framework uses metadata to describe the details of object-relational mapping. The metadata is generally in XML format and stored in a special object-mapping file. It is mainly used to persist the mapping relationship between persistent classes and tables, and persist objects to the database at runtime. This technology can be used to directly operate the database through the operation object without SQL coding, shielding the differences of the underlying database. The greatest effect of this technology is to shield complex SQL, but it cannot solve the problem of running complex SQL with multiple data sources.

[0004] Springboot multi-data source configuration can solve the problem of multiple data sources and dynamic data sources. The multiple data sources of the system application need to be configured in the configuration file, and the corresponding routes can be configured. This technology is suitable for business systems with multiple data sources fixed or read-write separation business scenarios. It cannot support dynamic configuration and dynamic expansion based on multi-source data (data comes from multiple types of databases during data application).

[0005] How to solve the problem of high development complexity in dynamically connecting multi-source data (in the process of data processing applications, data comes from various types of databases) is a technical problem that needs to be solved. Summary of the invention

[0006] The technical task of the present invention is to address the above shortcomings and provide a database adaptation device and method based on dynamic multi-source data to solve the technical problem of how to solve the high complexity of dynamic docking multi-source data execution development.

[0007] In a first aspect, a database adaptation device based on dynamic multiple data sources of the present invention is used to encapsulate differences in underlying databases, and the device includes:

[0008] An in-memory database, the in-memory database is used to store data source information, the data source information includes a data source code and data source specific information, the data source specific information includes a database type and database connection information;

[0009] A database keyword library, which is used to store all keywords that have been adapted to the database type;

[0010] A grammar difference library, which is used to store grammar differences, wherein the grammar differences are differences in grammar content between relational databases;

[0011] A grammar adapter, which interacts with the memory database, the database keyword library, and the grammar difference library, and is used to receive parameters consisting of SQL statements and database information, wherein the database information is a database code or specific information of a data source, and is used to obtain a database type based on the database information, and to perform grammar analysis and conversion on the SQL statement based on the database type to obtain an adapted SQL statement;

[0012] SQL executor, which interacts with the grammar adapter and is used to load and drive the corresponding database based on the database type, and output the execution result after the database executes the adapted SQL statement.

[0013] Preferably, the content of the grammatical difference includes:

[0014] Paging differences, where the paging differences are paging syntaxes between different databases;

[0015] Field mapping, which is the mapping of different field types in different databases. Field mapping is used for DDL statement execution and supports database table creation;

[0016] Function differences, which are built-in function mapping information of various databases. Function information is used to query SQL execution;

[0017] The contents of the grammatical differences are respectively stored in a grammatical difference library in the form of library tables.

[0018] Preferably, the grammar adapter is used to obtain the adapted SQL statement through the following steps:

[0019] Based on all the keywords that have been adapted to the database type in the database keyword library, the SQL statement is parsed by keyword to obtain the parsed SQL statement;

[0020] If the database information is the data source code, the corresponding database type is queried from the memory database. If the database information is the specific information of the data source, the database type is read.

[0021] Query the corresponding SQL statement template from the syntax difference library based on the database type;

[0022] Based on the parsed SQL statement, the variables of the SQL statement template are replaced to obtain an adapted SQL statement.

[0023] Preferably, the SQL executor is used to load the database corresponding to the driver based on the database type through the following steps:

[0024] If the received database information is a data source code, the corresponding database connection information is queried from the memory database; if the received database information is specific information of the data source, the database connection information is read;

[0025] Based on the database connection information, determine whether there is a connection in the connection pool;

[0026] If it exists, load the adapted SQL statement into the corresponding database so that the corresponding database can output the execution result after executing the adapted SQL statement;

[0027] If it does not exist, a database driver is dynamically created based on the database connection information, and a connection is created based on the database driver. After the connection is established, the adapted SQL statement is loaded into the corresponding database so that the corresponding database can execute the adapted SQL statement and output the execution result.

[0028] Preferably, the device is adapted to be equipped with a data service interface, which is stored in a database configuration table and is used to configure the output parameters, input parameters, request method and request URL information of the query interface based on the multi-source database table, and is used to generate corresponding SQL statements based on the output parameters and input parameters;

[0029] When the device is started, the corresponding data service interface is called based on the data source information, and the data service interface information is loaded into the memory database. In the memory database, the key is the request URL, and the value is the corresponding data source information or the corresponding data source information and SQL statement. The device queries the corresponding SQL statement and data source information based on the incoming URL, and takes the SQL statement and data source information as received parameters.

[0030] In a second aspect, a database adaptation method based on dynamic multiple data sources of the present invention is applied to a database adaptation device based on dynamic multiple data sources as described in any one of the first aspect, and the method comprises the following steps:

[0031] Pre-store data source information in the memory database, the data source information including data source code and data source specific information, the data source specific information including database type and database connection information;

[0032] Pre-store all keywords that have been adapted to the database type in the database keyword library;

[0033] Pre-storing grammatical differences in a grammatical difference library, wherein the grammatical differences are differences in grammatical content between relational databases;

[0034] Receive parameters consisting of an SQL statement and database information, wherein the database information is a database code or specific information of a data source, obtain a database type based on the database information, and perform syntax parsing and conversion on the SQL statement based on the database type to obtain an adapted SQL statement;

[0035] The database corresponding to the driver is loaded based on the database type, and the database executes the adapted SQL statement and outputs the execution result.

[0036] Preferably, the content of the grammatical difference includes:

[0037] Paging differences, where the paging differences are paging syntaxes between different databases;

[0038] Field mapping, which is the mapping of different field types in different databases. Field mapping is used for DDL statement execution and supports database table creation;

[0039] Function differences, which are built-in function mapping information of various databases. Function information is used to query SQL execution;

[0040] The contents of the grammatical differences are stored in the grammatical difference library in the form of a library table.

[0041] Preferably, the adapted SQL statement is obtained through the following steps:

[0042] Based on all the keywords that have been adapted to the database type in the database keyword library, the SQL statement is parsed by keyword to obtain the parsed SQL statement;

[0043] If the database information is the data source code, the corresponding database type is queried from the memory database. If the database information is the specific information of the data source, the database type is read.

[0044] Query the corresponding SQL statement template from the syntax difference library based on the database type;

[0045] Based on the parsed SQL statement, the variables of the SQL statement template are replaced to obtain an adapted SQL statement.

[0046] As a preferred method, the following steps are used to load the corresponding database of the driver based on the data source encoding:

[0047] If the received database information is a data source code, the corresponding database connection information is queried from the memory database; if the received database information is specific information of the data source, the database connection information is read;

[0048] Based on the database connection information, determine whether there is a connection in the connection pool;

[0049] If it exists, load the adapted SQL statement into the corresponding database so that the corresponding database can output the execution result after executing the adapted SQL statement;

[0050] If it does not exist, a database driver is dynamically created based on the database connection information, and a connection is created based on the database driver. After the connection is established, the adapted SQL statement is loaded into the corresponding database so that the corresponding database can execute the adapted SQL statement and output the execution result.

[0051] Preferably, when the device is started, the corresponding data service interface is called based on the data source information, and the data service interface information is loaded into the memory database, in which the key is the request URL, and the value is the corresponding data source information or the corresponding data source information and SQL statement. The device queries the corresponding SQL statement and data source information based on the incoming URL, and takes the SQL statement and data source information as receiving parameters;

[0052] The data service interface is stored in the database configuration table, and is used to configure the output parameters, input parameters, request method and request URL information of the query interface based on the multi-source database table, and to generate corresponding SQL statements based on the output parameters and input parameters.

[0053] The database adaptation device and method based on dynamic multiple data sources of the present invention have the following advantages:

[0054] 1. Sort out the database syntax content and store the syntax differences in the syntax difference library. Based on the input SQL statement and data source code or data source specific information, find the corresponding database type. With the help of the syntax difference library, parse the SQL statement through the SQL adapter and convert it into an adaptive SQL statement. Then load the corresponding database through the SQL executor, so that the database can execute the adaptive SQL statement. This device can realize database adaptation of multiple data sources;

[0055] 2. When the SQL executor loads the corresponding database, it first determines whether there is a connection in the connection pool based on the database connection information. If so, it directly loads the database corresponding to the driver. If not, it loads the driver based on the database connection information and loads the corresponding database through the driver. It uses the database connection pool technology to improve the efficiency of database queries.

[0056] 3. The syntax adapter and SQL execution engine are loosely coupled and assembled as plug-ins. The syntax adapter can be loaded separately to realize the syntax conversion function, and the SQL execution engine can be loaded separately as a database query engine or database persistence layer. In the actual application process, it can be used as a third-party jar for reference, or it can be run separately as a microservice. The usage and operation modes are flexible and the application scenarios are diverse. BRIEF DESCRIPTION OF THE DRAWINGS

[0057] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0058] The present invention is further described below in conjunction with the accompanying drawings.

[0059] Figure 1 is a structural block diagram of a database adaptation device based on dynamic multiple data sources in Example 1;

[0060] Figure 2 A flowchart of generating an adaptation SQL statement by a database adaptation device based on dynamic multiple data sources in Example 1;

[0061] Figure 3 This is a flowchart of database connection performed by a database adapter device based on dynamic multiple data sources in Example 1. DETAILED DESCRIPTION

[0062] The present invention is further described below in conjunction with the accompanying drawings and specific embodiments so that those skilled in the art can better understand the present invention and implement it. However, the embodiments are not intended to limit the present invention. In the absence of conflict, the embodiments of the present invention and the technical features in the embodiments may be combined with each other.

[0063] The embodiments of the present invention provide a database adaptation device and method based on dynamic multi-source data, which are used to solve the technical problem of how to solve the technical problem of high development complexity of dynamically connecting multi-source data.

[0064] Embodiment 1:

[0065] The present invention is based on a database adaptation device of dynamic multiple data sources, including a memory database, a database keyword library, a grammar difference library, a grammar adapter and an SQL executor, wherein the memory database is used to store data source information, the data source information includes a data source code and data source specific information, and the data source specific information includes a database type and database connection information; the database keyword library is used to store all keywords of the adapted database type; the grammar difference library is used to store grammar differences, and the grammar differences are differences in grammar content between relational databases; the grammar adapter interacts with the memory database, the database keyword library and the grammar difference library, and is used to receive parameters consisting of SQL statements and database information, the database information is a database code or data source specific information, and is used to obtain a database type based on the database information, and perform grammar parsing and conversion on the SQL statement based on the database type to obtain an adapted SQL statement; the SQL executor interacts with the grammar adapter, and is used to load and drive a corresponding database based on the database type, and output an execution result after the database executes the adapted SQL statement.

[0066] In this embodiment, the syntax adapter can accept parameters such as SQL statements and database information, and the database information is the data source code or specific information of the data source.

[0067] The data source information in the memory database is pre-loaded to reduce the internal operation time. The data source includes database type, database connection information, database user name, database password, and database deployment server information, etc. That is, the parameters accepted in this application are SQL statements and data source information.

[0068] The syntax differences in the syntax difference library are pre-loaded to provide syntax support for the syntax adapter. The syntax difference library contains the syntax content differences between databases, which are stored in database tables to facilitate data source expansion. The syntax difference content includes paging, field type mapping, and functions. The paging information table stores the paging syntax of different databases, such as MySql syntax:

[0069] select#BODY limit#OFFSET,#PAGESIZE

[0070] Among them, #BODY, #OFFSET, and #PAGESIZE are different positional parameters. The field mapping table stores the mapping of different field types in different databases. Field mapping is mainly used for DDL statement execution and support table creation. The function table stores the mapping information of built-in functions of various databases. Function information is used for query SQL execution.

[0071] After the syntax adapter receives the SQL statement and database information, it first performs SQL syntax conversion based on the content of the syntax difference library. Specifically, the syntax adapter receives the SQL statement and performs statement keyword parsing. The database keyword library of this device needs to include all keywords that have been adapted to the database type. SQL syntax analysis is performed based on the keywords to extract the statement's #BODY, #OFFSET, #PAGESIZE and other parameter information. Then, based on the database type, the corresponding SQL template is queried from the syntax difference library. If the received database information is the database code, it is necessary to query the corresponding database type from the memory database based on the database code. If the received database information is the specific information of the data source, the database type is directly obtained. Finally, the SQL template is replaced with variables according to the parsed SQL statement parameters to generate an adapted SQL statement.

[0072] The SQL executor obtains the corresponding loading driver according to the incoming data source code or database type, dynamically loads the driver, executes the adapted SQL statement, and outputs the execution result. The specific process in the SQL executor is as follows:

[0073] If the database information is a data source code, the corresponding database connection information is queried from the memory database according to the data source code; if it is specific data source information, the data source connection information is directly obtained;

[0074] Based on the data source connection information, determine whether there is a connection in the connection pool. If not, load the driver and dynamically create a connection based on the driver;

[0075] After the connection is established, the adapted SQL statement is passed to the database. After the database executes the adapted SQL statement, the execution result is returned.

[0076] Among them, the device is adapted with a data service interface, which is stored in the database configuration table. The data service interface configures the output parameters, input parameters, request method, request URL and other information of the query interface based on the multi-source database table, and generates the corresponding database query SQL according to the input and output parameters. After the data service interface is released, the user applies for use, the user calls the released data service interface URL, requests to the gateway, and the gateway forwards the request to the device of the present invention.

[0077] When the device starts, it loads the data service interface information into the memory database (REDIS database). The key in REDIS is the request URL, and the value is the corresponding data source information and SQL statement. The device obtains the query SQL and database information according to the incoming URL, performs SQL conversion according to the SQL and database information, generates SQL adapted to the database type, loads the corresponding database driver, executes the adapted SQL, and returns the query result information.

[0078] The device is deployed as a microservice during use, runs independently, and can deploy load clusters and proxy to NGINX to improve query efficiency.

[0079] The grammar adapter and SQL execution engine in the device are loosely coupled and assembled as plug-ins. The grammar adapter can be loaded separately to realize the grammar conversion function, and the SQL execution engine can also be loaded separately as a database query engine or database persistence layer. In actual application, it can be used as a third-party jar for reference, or it can be run separately as a microservice. The usage and operation modes are flexible and the application scenarios are diverse.

[0080] Embodiment 2:

[0081] The database adaptation method based on dynamic multiple data sources of the present invention is applied to the database adaptation device based on dynamic multiple data sources disclosed in Example 1. The method comprises the following steps:

[0082] S100, pre-store data source information in a memory database, where the data source information includes a data source code and specific data source information, where the specific data source information includes a database type and database connection information;

[0083] Pre-store all keywords that have been adapted to the database type in the database keyword library;

[0084] Pre-storing grammatical differences in a grammatical difference library, where the grammatical differences are differences in grammatical content between relational databases;

[0085] S200, receiving parameters consisting of an SQL statement and database information, where the database information is a database code or specific information of a data source, obtaining a database type based on the database information, and performing syntax parsing and conversion on the SQL statement based on the database type to obtain an adapted SQL statement;

[0086] S200, loading the database corresponding to the driver based on the database type, and outputting the execution result after the database executes the adapted SQL statement.

[0087] The syntax adapter can accept parameters such as SQL statements and database information, where the database information is the data source code or data source specific information.

[0088] The data source information in the memory database is pre-loaded to reduce the internal operation time. The data source includes database type, database connection information, database user name, database password, and database deployment server information, etc. That is, the parameters accepted in this application are SQL statements and data source information.

[0089] The syntax differences in the syntax difference library are pre-loaded to provide syntax support for the syntax adapter. The syntax difference library contains the syntax content differences between databases, which are stored in database tables to facilitate data source expansion. The syntax difference content includes paging, field type mapping, and functions. The paging information table stores the paging syntax of different databases, such as MySql syntax:

[0090] select#BODY limit#OFFSET,#PAGESIZE

[0091] Among them, #BODY, #OFFSET, and #PAGESIZE are different positional parameters. The field mapping table stores the mapping of different field types in different databases. Field mapping is mainly used for DDL statement execution and support table creation. The function table stores the mapping information of built-in functions of various databases. Function information is used for query SQL execution.

[0092] After the syntax adapter receives the SQL statement and database information, it first performs SQL syntax conversion based on the content of the syntax difference library. Specifically, the syntax adapter receives the SQL statement and performs statement keyword parsing. The database keyword library of this device needs to include all keywords that have been adapted to the database type. SQL syntax analysis is performed based on the keywords to extract the statement's #BODY, #OFFSET, #PAGESIZE and other parameter information. Then, based on the database type, the corresponding SQL template is queried from the syntax difference library. If the received database information is the database code, it is necessary to query the corresponding database type from the memory database based on the database code. If the received database information is the specific information of the data source, the database type is directly obtained. Finally, the SQL template is replaced with variables according to the parsed SQL statement parameters to generate an adapted SQL statement.

[0093] The SQL executor obtains the corresponding loading driver according to the incoming data source code or database type, dynamically loads the driver, and the database executes the adapted SQL statement and outputs the execution result. The specific process in the SQL executor is as follows:

[0094] If the database information is a data source code, the corresponding database connection information is queried from the memory database according to the data source code; if it is specific data source information, the data source connection information is directly obtained;

[0095] Based on the data source connection information, determine whether there is a connection in the connection pool. If not, load the driver and dynamically create a connection based on the driver;

[0096] After the connection is established, the adapted SQL statement is passed to the database. After the database executes the adapted SQL statement, the execution result is output.

[0097] In this embodiment, the data service interface is published based on the multi-source database table and is used as a database execution engine microservice to run separately. The data service interface configures the query interface's output parameters, input parameters, request method, request URL and other information based on the multi-source database table, and generates the corresponding database query SQL based on the input and output parameters, and saves it in the database configuration table. After the interface is published, the user applies for use. The user calls the published data service interface URL and requests to the gateway, and the gateway forwards the request to the device of the present invention.

[0098] During use, the data service interface information is loaded into the memory database (REDIS database), the key in REDIS is the request URL, and the value is the corresponding data source information and the execution SQL. The adapter disclosed in Example 1 obtains the query SQL and database information according to the incoming URL, performs SQL conversion according to the SQL and database information, generates SQL adapted to the database type, loads the corresponding database driver, executes the adapted SQL, and returns the query result information.

[0099] The present invention is shown and described in detail above through the accompanying drawings and preferred embodiments. However, the present invention is not limited to these disclosed embodiments. Based on the above multiple embodiments, those skilled in the art can know that the code review methods in the above different embodiments can be combined to obtain more embodiments of the present invention, and these embodiments are also within the protection scope of the present invention.

Claims

1. A database adapter device based on dynamic multiple data sources, characterized in that For encapsulating underlying database differences, the device comprises: An in-memory database, the in-memory database is used to store data source information, the data source information includes a data source code and data source specific information, the data source specific information includes a database type and database connection information; A database keyword library, which is used to store all keywords that have been adapted to the database type; A grammar difference library, which is used to store grammar differences, wherein the grammar differences are differences in grammar content between relational databases; A grammar adapter, which interacts with the memory database, the database keyword library, and the grammar difference library, and is used to receive parameters consisting of SQL statements and database information, wherein the database information is a database code or specific information of a data source, and is used to obtain a database type based on the database information, and to perform grammar analysis and conversion on the SQL statement based on the database type to obtain an adapted SQL statement; SQL executor, which interacts with the grammar adapter and is used to load the corresponding database based on the database type, and output the execution result after the database executes the adapted SQL statement; The syntax adapter is used to obtain the adapted SQL statement through the following steps: Based on all the keywords that have been adapted to the database type in the database keyword library, the SQL statement is parsed by keyword to obtain the parsed SQL statement; If the database information is the data source code, the corresponding database type is queried from the memory database. If the database information is the specific information of the data source, the database type is read. Query the corresponding SQL statement template from the syntax difference library based on the database type; Based on the parsed SQL statement, the variables in the SQL statement template are replaced to obtain an adapted SQL statement; The SQL executor is used to load the database corresponding to the driver based on the database type through the following steps: If the received database information is a data source code, the corresponding database connection information is queried from the memory database; if the received database information is specific information of the data source, the database connection information is read; Based on the database connection information, determine whether there is a connection in the connection pool; If it exists, load the adapted SQL statement into the corresponding database so that the corresponding database can execute the adapted SQL statement and return the execution result; If it does not exist, a database driver is dynamically created based on the database connection information, and a connection is created based on the database driver. After the connection is established, the adapted SQL statement is loaded into the corresponding database so that the corresponding database can execute the adapted SQL statement and output the execution result.

2. The database adapter device based on dynamic multiple data sources according to claim 1 is characterized in that The syntax differences include: Paging differences, where the paging differences are paging syntaxes between different databases; Field mapping, which is the mapping of different field types in different databases. Field mapping is used for DDL statement execution and supports database table creation; Function differences, which are built-in function mapping information of various databases. Function information is used to query SQL execution; The contents of the grammatical differences are respectively stored in a grammatical difference library in the form of library tables.

3. The database adaptation device based on dynamic multiple data sources according to claim 1 or 2, characterized in that The device is adapted to be equipped with a data service interface, which is stored in a database configuration table and is used to configure the output parameters, input parameters, request method and request URL information of the query interface based on the multi-source database table, and is used to generate corresponding SQL statements based on the output parameters and input parameters; When the device is started, the corresponding data service interface is called based on the data source information, and the data service interface information is loaded into the memory database. In the memory database, the key is the request URL, and the value is the corresponding data source information or the corresponding data source information and SQL statement. The device queries the corresponding SQL statement and data source information based on the incoming URL, and takes the SQL statement and data source information as received parameters.

4. A database adaptation method based on dynamic multiple data sources, characterized in that Applied to the database adaptation device based on dynamic multiple data sources as claimed in any one of claims 1 to 3, the method comprises the following steps: Pre-store data source information in the memory database, the data source information including data source code and data source specific information, the data source specific information including database type and database connection information; Pre-store all keywords that have been adapted to the database type in the database keyword library; Pre-storing grammatical differences in a grammatical difference library, wherein the grammatical differences are differences in grammatical content between relational databases; Receive parameters consisting of an SQL statement and database information, wherein the database information is a database code or specific information of a data source, obtain a database type based on the database information, and perform syntax parsing and conversion on the SQL statement based on the database type to obtain an adapted SQL statement; Load the database corresponding to the driver based on the database type, and the database executes the adapted SQL statement and outputs the execution result; The adapted SQL statement is obtained through the following steps: Based on all the keywords that have been adapted to the database type in the database keyword library, the SQL statement is parsed by keyword to obtain the parsed SQL statement; If the database information is the data source code, the corresponding database type is queried from the memory database. If the database information is the specific information of the data source, the database type is read. Query the corresponding SQL statement template from the syntax difference library based on the database type; Based on the parsed SQL statement, the variables in the SQL statement template are replaced to obtain an adapted SQL statement; Use the following steps to load the driver's corresponding database based on the data source code: If the received database information is a data source code, the corresponding database connection information is queried from the memory database; if the received database information is specific information of the data source, the database connection information is read; Based on the database connection information, determine whether there is a connection in the connection pool; If it exists, load the adapted SQL statement into the corresponding database so that the corresponding database can output the execution result after executing the adapted SQL statement; If it does not exist, a database driver is dynamically created based on the database connection information, and a connection is created based on the database driver. After the connection is established, the adapted SQL statement is loaded into the corresponding database so that the corresponding database can execute the adapted SQL statement and output the execution result.

5. The database adaptation method based on dynamic multiple data sources according to claim 4 is characterized in that The syntax differences include: Paging differences, where the paging differences are paging syntaxes between different databases; Field mapping, which is the mapping of different field types in different databases. Field mapping is used for DDL statement execution and supports database table creation; Function differences, which are built-in function mapping information of various databases. Function information is used to query SQL execution; The contents of the grammatical differences are stored in the grammatical difference library in the form of a library table.

6. The database adaptation method based on dynamic multiple data sources according to claim 4 or 5, characterized in that When the device is started, the corresponding data service interface is called based on the data source information, and the data service interface information is loaded into the memory database, in which the key is the request URL, and the value is the corresponding data source information or the corresponding data source information and SQL statement. The device queries the corresponding SQL statement and data source information based on the incoming URL, and takes the SQL statement and data source information as receiving parameters; The data service interface is stored in the database configuration table, and is used to configure the output parameters, input parameters, request method and request URL information of the query interface based on the multi-source database table, and to generate corresponding SQL statements based on the output parameters and input parameters.

Citation Information

Patent Citations

  • Method for accessing relational databases of different types

    CN101645074A

  • Database access method and system

    CN103838781A