Adaptation device and device of database, computer equipment and storage medium
1. An apparatus for adapting a database, comprising:
the Sharding-JDBC framework rewriting module is used for rewriting SQL sentences supported by different databases;
and the execution module is used for judging different databases by using the mybatis built-in parameter _ database Id so as to execute SQL with different writing methods.
2. The database adaptation device according to claim 1, wherein the method further comprises:
and the dynamic SQL using module is used for using the dynamic SQL aiming at the SQL with different databases.
3. The database adaptation device according to claim 1, wherein the method further comprises:
and the SQL analysis module is used for analyzing the SQL statement.
4. The database adaptation device according to claim 1, wherein the method further comprises:
and the query optimization module is used for optimizing the query of the SQL statement.
5. The database adaptation device according to claim 1, wherein the method further comprises:
and the SQL routing module is used for routing the SQL statement.
6. Computer device comprising a memory and a processor, the memory storing a computer program, characterized in that the processor realizes the corresponding steps of the adaptation means of the database of any of claims 1 to 5 when executing the computer program.
7. A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out corresponding steps of an adaptation means of a database according to any one of claims 1 to 5.
Background
As the data volume of the system increases, the data of some tables of the database will increase, and when the data is up to the level of millions or even tens of millions, the performance will be lower, and the data processing efficiency will be further improved.
Disclosure of Invention
In view of the above, embodiments of the present invention are proposed in order to provide an adaptation apparatus of a database, a computer device and a storage medium that overcome or at least partially solve the above-mentioned problems.
In order to solve the above problem, an embodiment of the present invention discloses an adaptation apparatus for a database, including:
the Sharding-JDBC framework rewriting module is used for rewriting SQL sentences supported by different databases;
and the execution module is used for judging different databases by using the mybatis built-in parameter _ database Id so as to execute SQL with different writing methods.
Preferably, the method further comprises:
and the dynamic SQL using module is used for using the dynamic SQL aiming at the SQL with different databases.
Preferably, the method further comprises:
and the SQL analysis module is used for analyzing the SQL statement.
Preferably, the method further comprises:
and the query optimization module is used for optimizing the query of the SQL statement.
Preferably, the method further comprises:
and the SQL routing module is used for routing the SQL statement.
The embodiment of the invention discloses computer equipment, which comprises a memory and a processor, wherein the memory stores a computer program, and the processor executes the corresponding steps of an adaptive device of a database when executing the computer program.
The embodiment of the invention discloses a computer readable storage medium, wherein a computer program is stored on the computer readable storage medium, and when the computer program is executed by a processor, the computer program realizes the corresponding steps of the database adaptation device.
The embodiment of the invention has the following advantages:
in the embodiment of the invention, the adaptation device of the database can enable shardingjdbc to completely support a system, adapt to different databases and web application database operation, SQL reaches the database through java jdbc to be executed, mybatis built-in parameter _ database id is used for judging different databases, and then corresponding SQL is executed, and in a big data scene, a scheme is required to be adopted for separately storing data. The purpose of database partitioning and table partitioning can be achieved by using the Sharding-JDBC plug-in, the SQL writing method is improved to support the Sharding-JDBC plug-in, a program can judge and execute the SQL corresponding to the database according to different databases, and the phenomenon that the SQL is incompatible in the using process of the Sharding-JDBC is avoided.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings needed to be used in the description of the embodiments are briefly introduced below, it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on the drawings without creative efforts
FIG. 1 is a block diagram of an embodiment of an adaptation apparatus for a database according to an embodiment of the present invention;
FIG. 2 is an internal block diagram of a computer device of an embodiment.
Detailed Description
In order to make the technical problems, technical solutions and advantageous effects solved by the embodiments of the present invention more clearly apparent, the embodiments of the present invention are described in further detail below with reference to the accompanying drawings and the embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
Referring to fig. 1, a block diagram of a structure of an embodiment of an adaptation apparatus for a database according to an embodiment of the present invention is shown, which may specifically include the following modules:
the Sharding-JDBC framework rewriting module 301 is used for rewriting SQL statements supported by different databases;
the execution module 302 is configured to determine different databases by using the mybatis built-in parameter _ database id, and then execute SQL with different writing methods.
Preferably, the method further comprises:
and the dynamic SQL using module is used for using the dynamic SQL aiming at the SQL with different databases.
Preferably, the method further comprises:
and the SQL analysis module is used for analyzing the SQL statement.
Preferably, the method further comprises:
and the query optimization module is used for optimizing the query of the SQL statement.
Preferably, the method further comprises:
and the SQL routing module is used for routing the SQL statement.
In the embodiment of the invention, SQL writing rewriting is carried out on SQL which is not supported by part of the database and table splitting plug-ins, and SQL is reconstructed by using an SQL writing method supported by Sharding-JDBC to achieve a consistent execution effect. The mybatis built-in parameter _ databaseId is used to determine different databases, and then SQL with different writing methods is executed. And rewriting SQL which is not supported by Sharding-JDBC, wherein different databases have different SQL, and using dynamic SQL.
For example, when Sharding-JDBC receives an SQL statement, SQL parsing, query optimization, SQL routing, SQL rewriting, SQL execution, and result merging are performed successively, and finally an execution result is returned
In the embodiment of the invention, the adaptation device of the database can enable shardingjdbc to completely support a system, adapt to different databases and web application database operation, SQL reaches the database through java jdbc to be executed, mybatis built-in parameter _ database id is used for judging different databases, and then corresponding SQL is executed, and in a big data scene, a scheme is required to be adopted for separately storing data. The purpose of database partitioning and table partitioning can be achieved by using the Sharding-JDBC plug-in, the SQL writing method is improved to support the Sharding-JDBC plug-in, a program can judge and execute the SQL corresponding to the database according to different databases, and the phenomenon that the SQL is incompatible in the using process of the Sharding-JDBC is avoided.
The modules in the adaptation means of the database described above may be implemented wholly or partly in software, hardware or a combination thereof. The modules can be embedded in a hardware form or independent from a processor in the computer device, and can also be stored in a memory in the computer device in a software form, so that the processor can call and execute operations corresponding to the modules.
In one embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be as shown in fig. 2. The computer device includes a processor, a memory, a network interface, a display screen, and an input device connected by a system bus. Wherein the processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device comprises a nonvolatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of an operating system and computer programs in the non-volatile storage medium. The network interface of the computer device is used for communicating with an external terminal through a network connection. The computer program is executed by a processor to implement a method of adapting a database. The display screen of the computer equipment can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer equipment can be a touch layer covered on the display screen, a key, a track ball or a touch pad arranged on the shell of the computer equipment, an external keyboard, a touch pad or a mouse and the like.
Those skilled in the art will appreciate that the architecture shown in fig. 2 is merely a block diagram of some of the structures associated with the disclosed aspects and is not intended to limit the computing devices to which the disclosed aspects apply, as particular computing devices may include more or less components than those shown, or may combine certain components, or have a different arrangement of components.
In an embodiment, a computer device is provided, comprising a memory and a processor, the memory having stored therein a computer program, the processor implementing the corresponding steps of the adaptation means of the database described above when executing the computer program.
In an embodiment, a computer-readable storage medium is provided, on which a computer program is stored, which computer program, when being executed by a processor, carries out the corresponding steps of the adaptation means of the database as described above.
The embodiments in the present specification are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments are referred to each other.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, apparatus, or computer program product. Accordingly, embodiments of the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, embodiments of the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
Embodiments of the present invention are described with reference to flowchart illustrations and/or block diagrams of methods, terminal devices (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing terminal to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing terminal, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing terminal to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing terminal to cause a series of operational steps to be performed on the computer or other programmable terminal to produce a computer implemented process such that the instructions which execute on the computer or other programmable terminal provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
While preferred embodiments of the present invention have been described, additional variations and modifications of these embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including preferred embodiments and all such alterations and modifications as fall within the scope of the embodiments of the invention.
Finally, it should also be noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or terminal that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or terminal. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or terminal that comprises the element.
The foregoing describes in detail a database adaptation method, a database adaptation device, a computer device, and a storage medium, which are provided by the present invention, and specific examples are applied herein to explain the principles and embodiments of the present invention, and the descriptions of the foregoing examples are only used to help understand the method and the core ideas of the present invention; meanwhile, for a person skilled in the art, according to the idea of the present invention, there may be variations in the specific embodiments and the application scope, and in summary, the content of the present specification should not be construed as a limitation to the present invention.