Database adaptation method and device, equipment, storage medium and product
By rewriting and setting the interface of the Apache ShardingSphere component, the problem that the component does not support some databases is solved, and the adaptation of multiple databases is achieved, which reduces development costs and improves compatibility.
Patent Information
- Application Number
- CN202411786272.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-06
- Publication Date
- 2025-01-03
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The Apache ShardingSphere component does not support some databases, resulting in the difficulty of compatibility and adapting more databases in the library and table components.
By rewriting multiple preset interfaces in the sub-repository sub-table components, the interface implementation class is obtained, and preset database parameters are set in the interface implementation class to achieve support adaptation for multiple databases, including data source metadata , database type, SQL dialect parser and database type checker interface rewrite and parameter settings, and use the service provider interface mechanism to dynamically load the interface implementation class to connect to the database.
Without modifying or modifying the original code in a small amount, the supporting adaptation of the sub-database and table components with more databases is achieved, reducing development and maintenance costs, improving system compatibility, and allowing enterprises to choose more flexibly Database products.
Smart Images

Figure CN119248820A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of database technology, and in particular to a database adaptation method, device, equipment, storage medium and product. Background Art
[0002] Apache ShardingSphere is a distributed database ecosystem that can convert any database into a distributed database and enhance the original database through data sharding, elastic scaling, encryption and other capabilities. Apache ShardingSphere is a middleware that sits between applications and ordinary databases and acts as an intermediate layer, enabling applications to interact with multiple database instances more efficiently.
[0003] At present, with the increasing demand of database enterprise users, the application scenarios are becoming more and more extensive. Because different database management systems have differences in configuration and syntax, it is found in the actual development process of enterprises that the Apache ShardingSphere component does not support some databases. Therefore, how to be compatible and adaptable to more databases in the sharding component ShardingSphere is an urgent problem to be solved. Summary of the invention
[0004] The main purpose of this application is to provide a database adaptation method, device, equipment, storage medium and product, aiming to solve the technical problem of how to adapt the database in the sharding component ShardingSphere.
[0005] To achieve the above objectives, the present application proposes a database adaptation method, which includes: Rewrite multiple preset interfaces in the sub-library and sub-table components to obtain multiple interface implementation classes corresponding to the multiple preset interfaces; Setting preset parameters corresponding to the preset database in the multiple interface implementation classes; The sub-library and sub-table components are connected to the preset database through the preset parameters in the multiple interface implementation classes.
[0006] In one embodiment, the plurality of preset interfaces in the sub-library and sub-table components include a data source metadata interface, a database type interface, an SQL dialect parser facade interface, an SQL statement visitor facade interface, and a database type checker interface; The step of rewriting multiple preset interfaces in the sub-library and sub-table components to obtain multiple interface implementation classes corresponding to the multiple preset interfaces includes: The data source metadata interface, the database type interface, the SQL dialect parser facade interface, the SQL statement visitor facade interface and the database type checker interface are rewritten to obtain a first interface implementation class, a second interface implementation class, a third interface implementation class, a fourth interface implementation class and a fifth interface implementation class respectively.
[0007] In one embodiment, the step of setting preset parameters corresponding to the preset database in the multiple interface implementation classes includes: Setting connection configuration parameters corresponding to a preset database in the first interface implementation class, the connection configuration parameters including a host name, a default port, a database name, a database mode, a maximum number of connections, and a time zone parameter; Modify the return values of the getLexerClass method and the getParserClass method in the third interface implementation class to the identification values corresponding to the preset database; Modify the return values of the various SQL statement parser class methods in the fourth interface implementation class to the identification values corresponding to the preset database; Add the name of the preset database in the static block in the fifth interface implementation class.
[0008] In one embodiment, the step of setting preset parameters corresponding to the preset database in the multiple interface implementation classes includes: Modify the return value of the getType method in the second interface implementation class to the identification value corresponding to the preset database; Modify the value of the database connection parameter of the getJdbcUrlPrefixes method in the second interface implementation class to the identification value corresponding to the preset database; The return value of the getDataSourceMetaData method in the second interface implementation class is modified to the object of the first interface implementation class.
[0009] In one embodiment, the step of connecting the sub-library and sub-table components to the preset database through the preset parameters in the multiple interface implementation classes includes: Add a new service provider interface directory under the resource directory of the current project, and add the multiple interface implementation classes to the service provider interface configuration file under the service provider interface directory; The multiple interface implementation classes are dynamically loaded according to the service provider interface configuration file through the service provider interface mechanism, and the sub-library and sub-table components are connected to the preset database through the preset parameters.
[0010] In one embodiment, after the step of connecting the sub-library and sub-table components to the preset database through the preset parameters in the multiple interface implementation classes, the method further includes: When the preset database is the DAMO database, the interceptor interface in the object-relational mapping framework is rewritten to obtain the interceptor interface implementation class; Get the original SQL statement of the BoundSql object in the interceptor interface implementation class; Modify the parameters of the aggregate function in the original SQL statement to the preset DAMO parameters, and add the modified SQL statement to the BoundSql object; The BoundSql object in the interceptor interface implementation class connects the sub-library and sub-table components to the DAMO database.
[0011] In addition, to achieve the above purpose, the present application also proposes a database adaptation device, the database adaptation device comprising: A preset interface rewriting module is used to rewrite multiple preset interfaces in the sub-library and sub-table components to obtain multiple interface implementation classes corresponding to the multiple preset interfaces; A preset parameter setting module, used to set preset parameters corresponding to the preset database in the plurality of interface implementation classes; The database connection module is used to connect the sub-library and sub-table components with the preset database through the preset parameters in the multiple interface implementation classes.
[0012] In addition, to achieve the above objectives, the present application also proposes a database adaptation device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the database adaptation method described above.
[0013] In addition, to achieve the above-mentioned purpose, the present application also proposes a storage medium, which is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the database adaptation method described above are implemented.
[0014] In addition, to achieve the above-mentioned purpose, the present application also provides a computer program product, wherein the computer program product includes a computer program, and when the computer program is executed by a processor, the steps of the database adaptation method described above are implemented.
[0015] The present application provides a database adaptation method, which rewrites multiple preset interfaces in the sharding component to obtain multiple interface implementation classes corresponding to the multiple preset interfaces; sets preset parameters corresponding to the preset database in the multiple interface implementation classes; and connects the sharding component to the preset database through the preset parameters in the multiple interface implementation classes. The present application rewrites multiple preset interfaces in the sharding component, and sets preset parameters corresponding to the preset database in the multiple interface implementation classes; and extends and implements some interfaces of ShardingSphere, thereby achieving support adaptation between the sharding component and the database without modifying or slightly modifying the original code, reducing the cost of development and maintenance, improving the compatibility of the system, and allowing enterprises to choose database products more flexibly. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0017] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0018] Figure 1 A flowchart of the first embodiment of the database adaptation method of the present application is provided; Figure 2 A flowchart of the second embodiment of the database adaptation method of the present application is provided; Figure 3 A flowchart of the third embodiment of the database adaptation method of the present application is provided; Figure 4 This is a schematic diagram of the overall process of the database adaptation method of this application; Figure 5 This is a schematic diagram of the module structure of the database adaptation device according to an embodiment of the present application; Figure 6 Schematic diagram of the device structure of the hardware operating environment involved in the database adaptation method in the embodiment of the present application.
[0019] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0020] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.
[0021] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.
[0022] The main solution of the embodiment of the present application is: rewrite multiple preset interfaces in the sub-library and sub-table components to obtain multiple interface implementation classes corresponding to the multiple preset interfaces; set preset parameters corresponding to the preset database in the multiple interface implementation classes; connect the sub-library and sub-table components with the preset database through the preset parameters in the multiple interface implementation classes.
[0023] As the demand for database enterprise users increases, the application scenarios are becoming more and more extensive. Because different database management systems have differences in configuration and syntax, it is found in the actual development process of enterprises that the Apache ShardingSphere component does not support some databases. Therefore, how to be compatible and adaptable to more databases in the sharding component ShardingSphere is an urgent problem to be solved.
[0024] The present application provides a solution, which rewrites multiple preset interfaces in the sharding component, obtains multiple interface implementation classes corresponding to the multiple preset interfaces; sets preset parameters corresponding to the preset database in the multiple interface implementation classes; and connects the sharding component to the preset database through the preset parameters in the multiple interface implementation classes. The present application rewrites multiple preset interfaces in the sharding component, sets preset parameters corresponding to the preset database in the multiple interface implementation classes; and extends and implements some interfaces of ShardingSphere, thereby achieving support adaptation between the sharding component and the database without modifying or slightly modifying the original code, reducing the cost of development and maintenance, improving the compatibility of the system, and allowing enterprises to choose database products more flexibly.
[0025] It should be noted that the execution subject of the method of this embodiment can be a computing service device with database adaptation, network communication and program running functions, such as a tablet computer, a personal computer, a mobile phone, etc.; it can also be a database adaptation device with the same or similar functions. This embodiment and the following embodiments will be described by taking the database adaptation device as an example.
[0026] Based on this, the embodiment of the present application provides a database adaptation method, referring to Figure 1 , Figure 1 This is a flowchart of the first embodiment of the database adaptation method of the present application.
[0027] In this embodiment, the database adaptation method includes steps S10 to S30: Step S10, rewrite multiple preset interfaces in the sub-library and sub-table components to obtain multiple interface implementation classes corresponding to the multiple preset interfaces.
[0028] It should be understood that the DAMO database management system (version 8.1.0) is a database with high performance, high availability, cross-platform and high scalability. OceanBase is a distributed relational database with strong data consistency, high availability, high performance, online expansion, high compatibility with SQL standards and mainstream relational databases, and low cost.
[0029] It is understandable that Apache ShardingSphere is a distributed database ecosystem that can convert any database into a distributed database and enhance the original database through data sharding, elastic scaling, encryption and other capabilities. Apache ShardingSphere is a middleware that sits between the application and the ordinary database and acts as an intermediate layer. It enables applications to interact with multiple database instances more efficiently. However, due to differences in configuration and syntax between different database management systems, it was found in the actual development process of enterprises that the Apache ShardingSphere component does not support databases such as DAMO and OceanBase.
[0030] It should be noted that in this embodiment, multiple preset interfaces in the sub-library and sub-table components are rewritten without changing the original code, so as to obtain multiple interface implementation classes corresponding to the multiple preset interfaces.
[0031] Step S20, setting preset parameters corresponding to the preset database in the multiple interface implementation classes.
[0032] It is understandable that after rewriting to obtain multiple interface implementation classes, the preset parameters corresponding to the preset database can be set in each interface implementation class, such as the name of the preset database or iconic fields such as "DM", "OceanBase", etc., so that the rewritten sub-library and sub-table components can recognize whether the currently interacting database is the DM or OceanBase database.
[0033] Step S30, connecting the sub-library and sub-table components to the preset database through the preset parameters in the multiple interface implementation classes.
[0034] It should be understood that by calling the above-mentioned multiple interface implementation classes and adding preset parameters, it is possible to connect the sharding component with the preset database, thereby achieving the goal of supporting databases such as DAMO or OceanBase in the ShardingSphere component.
[0035] This embodiment provides a database adaptation method, which rewrites multiple preset interfaces in the sub-library and sub-table components to obtain multiple interface implementation classes corresponding to the multiple preset interfaces; sets preset parameters corresponding to the preset database in the multiple interface implementation classes; and connects the sub-library and sub-table components to the preset database through the preset parameters in the multiple interface implementation classes. This embodiment rewrites multiple preset interfaces in the sub-library and sub-table components, sets preset parameters corresponding to the preset database in the multiple interface implementation classes; and extends and implements some interfaces of ShardingSphere, thereby achieving support adaptation of the sub-library and sub-table components with more databases without modifying or slightly modifying the original code, reducing the cost of development and maintenance, improving the compatibility of the system, and allowing enterprises to choose database products more flexibly.
[0036] Based on the first embodiment of the present application, in the second embodiment of the present application, the same or similar contents as those in the above-mentioned embodiment 1 can refer to the above introduction, and will not be repeated later. Figure 2 , the multiple preset interfaces in the sub-library and sub-table components include a data source metadata interface, a database type interface, an SQL dialect parser appearance interface, an SQL statement visitor appearance interface and a database type checker interface; step S10, the database adaptation method includes step S101: Step S101: rewrite the data source metadata interface, the database type interface, the SQL dialect parser facade interface, the SQL statement visitor facade interface and the database type checker interface to obtain a first interface implementation class, a second interface implementation class, a third interface implementation class, a fourth interface implementation class and a fifth interface implementation class respectively.
[0037] It should be noted that the Service Provider Interface (SPI) technology can be used to expand some interfaces of ShardingSphere and increase support for databases such as DAMO and OceanBase. Specifically, the first interface implementation class A is customized to implement the rewriting of the data source metadata class (DataSourceMetaData) interface; the second interface implementation class B is customized to implement the rewriting of the database type class (DatabaseType) interface; the third interface implementation class C is customized to implement the rewriting of the SQL dialect parser facade class (SQLDialectParserFacade) interface; the fourth interface implementation class D is customized to implement the rewriting of the SQL statement visitor facade class (SQLStatementVisitorFacade) interface; create a new org.apache.shardingsphere.infra.database.type.checker package in the current project source code (source, src) directory, and customize the fifth interface implementation class to rewrite the database type checker class DatabaseTypeChecker class.
[0038] In a feasible implementation, step S20 may include steps S201 to S204: Step S201, setting connection configuration parameters corresponding to a preset database in the first interface implementation class, wherein the connection configuration parameters include a host name, a default port, a database name, a database mode, a maximum number of connections, and a time zone parameter.
[0039] It is understandable that the connection configuration parameters of databases such as DAMO or OceanBase are defined in the custom first interface implementation class A. Including connection parameter configurations such as host name (hostname), default port (port), database name (catalog), database mode (schema), maximum number of connections, time zone, etc.
[0040] Step S202: modify the return values of the getLexerClass method and the getParserClass method in the third interface implementation class to the identification values corresponding to the preset database.
[0041] It can be understood that the getLexerClass() and getParserClass() methods are rewritten in the custom third interface implementation class C. The return values of the getLexerClass and getParserClass methods are modified to the identification values corresponding to the preset databases. For example, returning "DM" indicates that the target of the interaction is the DM database, and returning "Oceanbase" indicates that the target of the interaction is the Oceanbase database.
[0042] Step S203: modify the return values of the various SQL statement parser class methods in the fourth interface implementation class to identification values corresponding to the preset database.
[0043] It is understandable that multiple SQL statement parser class methods are rewritten in the custom fourth interface implementation class D, and the return value of the method is modified to the identification value corresponding to the preset database. The SQL statement parser class includes methods such as getDMLVisitorClass(), getDDLVisitorClass(), getTCLVisitorClass(), getDCLVisitorClass(), getDALVisitorClass(), and getRLVisitorClass(). These methods are used to obtain different types of SQL statement parser classes. Their function is to return the visitor class of a specific type of SQL statement for use in parsing and processing SQL statements.
[0044] Step S204: adding the name of the preset database to the static block in the fifth interface implementation class.
[0045] It is understandable that the name of the DAMO or Oceanbase database is added to the static block in the custom fifth interface implementation class DatabaseTypeChecker class. For example, the code is as follows: static {Arrays.asList("MySQL", "PostgreSQL", "openGauss", "Oracle", "SQLServer", "H2", "MariaDB","DM","Oceanbase").forEach(each->TypedSPILoader.findService(DatabaseType.class, each).ifPresent(SUPPORTED_STORAGE_TYPES::add));}.
[0046] In a feasible implementation manner, step S20 may further include steps S205 to S207: Step S205: modify the return value of the getType method in the second interface implementation class to an identification value corresponding to the preset database.
[0047] It should be understood that methods such as getType(), getJdbcUrlPrefixes(), getDataSourceMetaData() can be rewritten in the custom second interface implementation class B, and relevant parameters of databases such as DAMO or OceanBase can be added to the methods.
[0048] Specifically, rewrite the getType() method. If it is the DM database, the getType() method returns "DM". If it is the Oceanbase database, it returns "Oceanbase".
[0049] Step S206: modify the value of the database connection parameter of the getJdbcUrlPrefixes method in the second interface implementation class to the identification value corresponding to the preset database.
[0050] It is understandable that if you rewrite the getJdbcUrlPrefixes() method, if it is a DAMO database, add "jdbc:dm:" to the method, and if it is an Oceanbase database, add "jdbc:oceanbase:" to the method. Among them, jdbc is the abbreviation of Java Database Connectivity, which is a standard API for accessing databases.
[0051] Step S207: modify the return value of the getDataSourceMetaData method in the second interface implementation class to the object of the first interface implementation class.
[0052] It is understandable that the getDataSourceMetaData(final String url, final String username) method is rewritten to return an object of the custom first interface implementation class A.
[0053] In a feasible implementation manner, step S30 may further include steps S301-S302: Step S301: Add a new service provider interface directory under the resource directory of the current project, and add the multiple interface implementation classes to the service provider interface configuration file under the service provider interface directory.
[0054] It is worth mentioning that some interfaces of ShardingSphere are extended through SPI technology to increase support for databases such as DAMO and OceanBase. Add the META-INF.services folder (service provider interface directory) under the current project resource directory (resources directory). In Java applications, the META-INF.services folder is a special directory for storing SPI configuration files. Add the SPI configuration files of the custom interface implementation classes A, B, C, and D described in the above steps.
[0055] Step S302: dynamically loading the multiple interface implementation classes according to the service provider interface configuration file through the service provider interface mechanism, and connecting the sub-library and sub-table components with the preset database through the preset parameters.
[0056] It can be understood that by dynamically loading the above custom interface implementation classes A, B, C, and D according to the service provider interface configuration file through the SPI mechanism and obtaining the preset parameters corresponding to the database, the goal of supporting databases such as DAMO or OceanBase in the ShardingSphere component can be achieved.
[0057] In this embodiment, the main interfaces such as data source metadata interface, database type interface, SQL dialect parser appearance interface, SQL statement visitor appearance interface and database type checker interface in ShardingSphere are expanded through the service provider interface technology. Add information such as database name or database identifier, and then dynamically load multiple custom interface implementation classes according to the service provider interface configuration file through the SPI mechanism, and use the preset parameters corresponding to the database. By rewriting the interface, the goal of supporting databases such as DAMO or OceanBase in the ShardingSphere component is achieved without changing the source code.
[0058] Based on the first embodiment of the present application, in the third embodiment of the present application, the same or similar contents as those in the first embodiment can be referred to the above description, and will not be described in detail later. Figure 3 After step S30, the database adaptation method further includes steps S40 to S70: Step S40: When the preset database is the DAMO database, the interceptor interface in the object-relational mapping framework is rewritten to obtain the interceptor interface implementation class.
[0059] It is worth noting that after rewriting the main interface of the shardingSphere component in the above steps, the goal of supporting databases such as DAMO or OceanBase can be achieved. However, when executed through the Object-Relational Mapping (ORM) framework, there is still a problem of not supporting the syntax of the DAMO database. Therefore, in this embodiment, the custom interface implementation class rewrites the interceptor (org.apache.ibatis.plugin.Interceptor) interface in the ORM framework MyBatis to obtain the interceptor interface implementation class E. The intercept method is rewritten in the custom implementation class E to increase the support for the DAMO database syntax.
[0060] Step S50: Obtain the original SQL statement of the BoundSql object in the interceptor interface implementation class.
[0061] First, get the value of the database connection address from the context of the interceptor in the ORM framework MyBatis, and determine whether it is a DAMO database by the prefix. If it is a DAMO database, get the value of the original SQL statement from the BoundSql object in the interceptor interface implementation class.
[0062] Step S60: Modify the parameters of the aggregate function in the original SQL statement to the preset DAMO parameters, and add the modified SQL statement to the BoundSql object.
[0063] Then modify the original SQL statement. Specifically, replace the single apostrophe "`" in the original SQL statement with double quotation marks """ through the replace method; replace the double quotation marks """" with single quotation marks "''" through the replace method; replace "ANY_VALUE" with empty "" through the replace method; replace the aggregate function parameter "GROUP_CONCAT" with the preset DAMO parameter "WM_CONCAT" through the replace method. Finally, set the modified SQL statement to the boundSql.sql parameter.
[0064] Step S70: Connect the sub-library and sub-table components to the DAMO database through the BoundSql object in the interceptor interface implementation class.
[0065] In this embodiment, the interceptor interface in the ORM framework MyBatis is implemented through a custom interface implementation class E, the intercept method is rewritten in the custom implementation class E, the parameters of the aggregate function in the original SQL statement are modified to the preset DAMO parameters, and the modified SQL statement is added to the BoundSql object, thereby enabling support for the DAMO database syntax.
[0066] For example, to help understand the implementation process of the database adaptation method obtained by combining this embodiment with the above-mentioned embodiment 1, please refer to Figure 4 , Figure 4 The following is a schematic diagram of the overall process of the database adaptation method of this application, specifically: When the application needs to access the database, the database connection pool is initialized, the business logic processor processes the logic, and then the steps to access the database are executed. Here, first determine whether the program needs to shard the database when connecting to the database. If not, there is no need to call the sharding component ShardingSphere. Directly execute the interceptor interface in the ORM framework MyBatis, and modify or enhance the BoundSql object through the interceptor, such as adding additional SQL fragments, modifying parameters, and other operations. After processing, the BoundSql object will be passed back to the execution engine of MyBatis, and the actual SQL statement will be generated and executed. Execute the SQL statement to access the corresponding database, you can access databases such as MySQL, DAMO or OceanBase.
[0067] It should be noted that if sharding is required, the adaptation between the shardingSphere component and the databases such as DAMO or OceanBase in this application is implemented. Some interfaces in the ShardingSphere component are rewritten through the ShardingSphere custom SPI extension module, and the sharding is started through the rewritten ShardingSphere component, and the database logic table is sent to the interceptor in MyBatis to complete the interaction and access to the database.
[0068] It should be noted that the above examples are only used to understand the present application and do not constitute a limitation on the database adaptation method of the present application. More simple transformations based on this technical concept are all within the scope of protection of the present application.
[0069] This application also provides a database adapter device, please refer to Figure 5 , the database adaptation device comprises: The preset interface rewriting module 10 is used to rewrite multiple preset interfaces in the sub-library and sub-table components to obtain multiple interface implementation classes corresponding to the multiple preset interfaces; A preset parameter setting module 20, used to set preset parameters corresponding to the preset database in the plurality of interface implementation classes; The database connection module 30 is used to connect the sub-library and sub-table components with the preset database through the preset parameters in the multiple interface implementation classes.
[0070] The database adaptation device provided by the present application adopts the database adaptation method in the above embodiment to solve the technical problem. Compared with the prior art, the beneficial effects of the database adaptation device provided by the present application are the same as the beneficial effects of the database adaptation method provided by the above embodiment, and the other technical features in the database adaptation device are the same as the features disclosed in the above embodiment method, which will not be repeated here.
[0071] The present application provides a database adaptation device, which includes: at least one processor; and a memory that is communicatively connected to the at least one processor; wherein the memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the database adaptation method in the above-mentioned embodiment 1.
[0072] Reference below Figure 6 , which shows a schematic diagram of the structure of a database adaptation device suitable for implementing the embodiment of the present application. The database adaptation device in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 6 The database adaptation device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0073] like Figure 6As shown, the database adapter device may include a processing device 1001 (such as a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the database adapter device are also stored. The processing device 1001, ROM1002 and RAM1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the database adapter device to communicate wirelessly or wired with other devices to exchange data. Although the figure shows a database adapter device with various systems, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be implemented or have alternatively.
[0074] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.
[0075] The database adaptation device provided by the present application adopts the database adaptation method in the above embodiment to solve the technical problem of database adaptation. Compared with the prior art, the beneficial effects of the database adaptation device provided by the present application are the same as the beneficial effects of the database adaptation method provided by the above embodiment, and the other technical features in the database adaptation device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.
[0076] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.
[0077] 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.
[0078] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, and the computer-readable program instructions are used to execute the database adaptation method in the above-mentioned embodiment.
[0079] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM: Random Access Memory), a read-only memory (ROM: Read Only Memory), an erasable programmable read-only memory (EPROM: Erasable Programmable Read Only Memory or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM: CD-Read Only Memory), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution system, system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency: Radio Frequency), etc., or any suitable combination of the above.
[0080] The computer-readable storage medium may be included in the database adapter device; or may exist independently without being assembled into the database adapter device.
[0081] The above-mentioned computer-readable storage medium carries one or more programs. When the above-mentioned one or more programs are executed by the database adapter device, the database adapter device: rewrites multiple preset interfaces in the sub-library and sub-table components to obtain multiple interface implementation classes corresponding to the multiple preset interfaces; sets preset parameters corresponding to the preset database in the multiple interface implementation classes; and connects the sub-library and sub-table components to the preset database through the preset parameters in the multiple interface implementation classes.
[0082] Computer program code for performing the operations of the present application may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0083] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession 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 square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0084] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.
[0085] The readable storage medium provided in the present application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned database adaptation method, and can solve technical problems. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in the present application are the same as the beneficial effects of the database adaptation method provided in the above-mentioned embodiment, and will not be described in detail here.
[0086] The present application also provides a computer program product, including a computer program, which implements the steps of the above-mentioned database adaptation method when executed by a processor.
[0087] The computer program product provided by the present application can solve the technical problem. Compared with the prior art, the beneficial effects of the computer program product provided by the present application are the same as the beneficial effects of the database adaptation method provided by the above embodiment, which will not be described in detail here.
[0088] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present application.
Claims
1. A database adaptation method, characterized in that: The method includes: Rewrite multiple preset interfaces in the sub-library and sub-table components to obtain multiple interface implementation classes corresponding to the multiple preset interfaces; Setting preset parameters corresponding to the preset database in the multiple interface implementation classes; The sub-library and sub-table components are connected to the preset database through the preset parameters in the multiple interface implementation classes.
2. The method according to claim 1, characterized in that The multiple preset interfaces in the sub-library and sub-table components include a data source metadata interface, a database type interface, an SQL dialect parser appearance interface, an SQL statement visitor appearance interface, and a database type checker interface; The step of rewriting multiple preset interfaces in the sub-library and sub-table components to obtain multiple interface implementation classes corresponding to the multiple preset interfaces includes: The data source metadata interface, the database type interface, the SQL dialect parser facade interface, the SQL statement visitor facade interface and the database type checker interface are rewritten to obtain a first interface implementation class, a second interface implementation class, a third interface implementation class, a fourth interface implementation class and a fifth interface implementation class respectively.
3. The method according to claim 2, characterized in that The step of setting preset parameters corresponding to the preset database in the multiple interface implementation classes includes: Setting connection configuration parameters corresponding to a preset database in the first interface implementation class, the connection configuration parameters including a host name, a default port, a database name, a database mode, a maximum number of connections, and a time zone parameter; Modify the return values of the getLexerClass method and the getParserClass method in the third interface implementation class to the identification values corresponding to the preset database; Modify the return values of the various SQL statement parser class methods in the fourth interface implementation class to the identification values corresponding to the preset database; Add the name of the preset database in the static block in the fifth interface implementation class.
4. The method according to claim 2, characterized in that The step of setting preset parameters corresponding to the preset database in the multiple interface implementation classes includes: Modify the return value of the getType method in the second interface implementation class to the identification value corresponding to the preset database; Modify the value of the database connection parameter of the getJdbcUrlPrefixes method in the second interface implementation class to the identification value corresponding to the preset database; The return value of the getDataSourceMetaData method in the second interface implementation class is modified to the object of the first interface implementation class.
5. The method according to claim 1, characterized in that The step of connecting the sub-library and sub-table components to the preset database through the preset parameters in the multiple interface implementation classes includes: Add a new service provider interface directory under the resource directory of the current project, and add the multiple interface implementation classes to the service provider interface configuration file under the service provider interface directory; The multiple interface implementation classes are dynamically loaded according to the service provider interface configuration file through the service provider interface mechanism, and the sub-library and sub-table components are connected to the preset database through the preset parameters.
6. The method according to claim 1, characterized in that After the step of connecting the sub-library and sub-table components to the preset database through the preset parameters in the multiple interface implementation classes, the method further includes: When the preset database is the DAMO database, the interceptor interface in the object-relational mapping framework is rewritten to obtain the interceptor interface implementation class; Get the original SQL statement of the BoundSql object in the interceptor interface implementation class; Modify the parameters of the aggregate function in the original SQL statement to the preset DAMO parameters, and add the modified SQL statement to the BoundSql object; The BoundSql object in the interceptor interface implementation class connects the sub-library and sub-table components to the DAMO database.
7. A database adaptation device, characterized in that: The database adaptation device comprises: A preset interface rewriting module is used to rewrite multiple preset interfaces in the sub-library and sub-table components to obtain multiple interface implementation classes corresponding to the multiple preset interfaces; A preset parameter setting module, used to set preset parameters corresponding to the preset database in the plurality of interface implementation classes; The database connection module is used to connect the sub-library and sub-table components with the preset database through the preset parameters in the multiple interface implementation classes.
8. A database adaptation device, characterized in that: The device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the database adaptation method according to any one of claims 1 to 6.
9. A storage medium, characterized in that: The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the database adaptation method according to any one of claims 1 to 6 are implemented.
10. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the steps of the database adaptation method according to any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Multi-data source adaptation method and system based on mybatis plug-in
CN118332605A
