CN111309785A - Spring framework-based database access method and device, computer equipment and medium - Google Patents

Spring framework-based database access method and device, computer equipment and medium Download PDF

Info

Publication number
CN111309785A
CN111309785A CN202010093200.1A CN202010093200A CN111309785A CN 111309785 A CN111309785 A CN 111309785A CN 202010093200 A CN202010093200 A CN 202010093200A CN 111309785 A CN111309785 A CN 111309785A
Authority
CN
China
Prior art keywords
database
data
address identifier
connection
information
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202010093200.1A
Other languages
Chinese (zh)
Other versions
CN111309785B (en
Inventor
刘舟
谢林廷
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Guangzhou Jisheng Network Technology Co ltd
Original Assignee
Guangzhou Jisheng Network Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Guangzhou Jisheng Network Technology Co ltd filed Critical Guangzhou Jisheng Network Technology Co ltd
Priority to CN202010093200.1A priority Critical patent/CN111309785B/en
Publication of CN111309785A publication Critical patent/CN111309785A/en
Application granted granted Critical
Publication of CN111309785B publication Critical patent/CN111309785B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2458Special types of queries, e.g. statistical queries, fuzzy queries or distributed queries
    • G06F16/2471Distributed queries
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Databases & Information Systems (AREA)
  • General Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Computing Systems (AREA)
  • Fuzzy Systems (AREA)
  • Mathematical Physics (AREA)
  • Probability & Statistics with Applications (AREA)
  • Software Systems (AREA)
  • Computational Linguistics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The application relates to the field of computers, in particular to a database access method and device based on a Spring framework, computer equipment and a storage medium. The method comprises the following steps: responding to the data query request, and acquiring to-be-queried data information associated with the data query request; determining a database address identifier corresponding to the to-be-queried data information and query information corresponding to the database address identifier, wherein the query information comprises a data query command; obtaining target database connection corresponding to the database address identification through a preset data source management software framework; and sending a data query command to a target database corresponding to the database address identifier through the connection of the target database. According to the embodiment of the invention, the data source management software framework for realizing automatic switching of data source connection is built on the basis of the Spring framework, so that developers do not need to consider bottom layer implementation details during programming, namely, a large number of codes do not need to be written to describe the bottom layer implementation details, and the development efficiency of the developers is further improved.

Description

Spring framework-based database access method and device, computer equipment and medium
Technical Field
The present application relates to the field of computers, and in particular, to a method and an apparatus for accessing a database based on a Spring framework, a computer device, and a storage medium.
Background
When a user or a server needs to obtain data (for example, operation data of the user on a certain application, log data of the user, etc.), a data query request is sent to a database server, the database server starts a thread to be responsible for processing the data query request, and the data to be obtained by the user or the server may be stored on a plurality of databases respectively, so that the thread needs to access the plurality of databases to obtain related data. When accessing the database, a database connection is required to be taken from a data source of the database, the database can be accessed through the database connection, and if other databases are subsequently accessed, the database connection is required to be changed to access the other databases.
In order to improve development efficiency, currently, a database needing to be operated is usually pooled, and then an Object/Relational Mapping (Object/Relational Mapping) operation Object is operated at an outer layer ORM (Object/Relational Mapping) layer to realize a persistence operation.
The current Spring framework does not support the mode of changing database connection, so non-Spring programming development is generally adopted when the mode is realized. However, the Spring framework is one of the most popular development frameworks at present, many persistent frameworks such as Mybatis, Mybatis plus, Spring Data JPA, etc. all make some ways of optimizing coding on the Spring framework, and if non-Spring programming development is adopted, there is no way to utilize the characteristics of these frameworks. Therefore, the way of implementing database connection change by using non-Spring programming may require a developer to write a large amount of code to describe the implementation details of changing the database connection, resulting in low development efficiency of the developer.
Disclosure of Invention
Aiming at the defects of the prior art, the invention provides a database access method, a device, computer equipment and a storage medium based on a Spring frame.
The invention provides a database access method based on a Spring framework according to a first aspect, and in one embodiment, the method comprises the following steps:
responding to the data query request, and acquiring to-be-queried data information associated with the data query request;
determining a database address identifier corresponding to the to-be-queried data information and query information corresponding to the database address identifier, wherein the query information comprises a data query command;
obtaining target database connection corresponding to the database address identification through a preset data source management software framework;
and sending a data query command to a target database corresponding to the database address identifier through the connection of the target database.
In one embodiment, determining the database address identifier corresponding to the data information to be queried previously includes:
sending a database information acquisition request to a remote support server;
receiving database information fed back by the remote support server in response to the database information acquisition request, wherein the database information comprises a plurality of database address identifiers and database identifiers corresponding to the database address identifiers;
and storing the database information into a preset storage area.
In one embodiment, determining the database address identifier corresponding to the data information to be queried includes:
determining a database identifier corresponding to the data information to be queried, wherein the database identifier is a unique identifier of a database storing the data information to be queried;
and inquiring database information stored in a preset storage area, and determining a database address identifier corresponding to the database identifier from the database information.
In one embodiment, obtaining a target database connection corresponding to a database address identifier through a preset data source management software framework includes:
setting the database address identifier into a thread local variable corresponding to the data query request;
receiving a database connection sent by a preset data source management software framework, wherein the database connection is a database connection obtained by determining a data source corresponding to a database address identifier from a plurality of data sources prestored in a memory after the preset data source management software framework acquires the database address identifier arranged in a thread local variable and taking charge of management from the corresponding data source;
and taking the database connection as a target database connection corresponding to the database address identifier.
In one embodiment, receiving a database connection sent by a preset data source management software framework, where the database connection is a database connection obtained by the preset data source management software framework after acquiring a database address identifier set in a thread local variable, determining a data source corresponding to the database address identifier from a plurality of data sources prestored in a memory, and obtaining the database connection from a plurality of database connections for which the corresponding data source is responsible for management, includes:
receiving a database connection sent by a preset data source management software framework, wherein the database connection is that the preset data source management software framework judges whether a data source corresponding to a database address identifier exists in a plurality of data sources prestored in a memory after acquiring the database address identifier arranged in a thread local variable, and after determining that the data source corresponding to the database address identifier exists in the memory, one database connection is obtained from a plurality of database connections managed by the data source corresponding to the database address identifier, or after determining that the data source corresponding to the database address identifier does not exist in the memory, a data source corresponding to the database address identifier is newly created in the memory, and one database connection is obtained from a plurality of database connections managed by the newly created data source.
In one embodiment, the query information corresponding to the database address identifier further includes a database mode identifier;
sending a data query command to a target database corresponding to the database address identifier through the connection of the target database, wherein the data query command comprises the following steps:
intercepting a data query command corresponding to the database address identifier by using a preset interceptor;
adding the database mode identification into the data query command to obtain an edited data query command;
and sending the edited data query command to a target database corresponding to the database address identifier through the connection of the target database.
In one embodiment, sending the edited data query command to the target database corresponding to the database address identifier through the target database connection, then includes:
and receiving target query data fed back by the target database, wherein the target query data are obtained from database storage data which are stored in the target database and correspond to the database mode identification after the target database analyzes and edits the data query command to obtain the database mode identification and the data query command.
The invention provides a Spring framework-based database access device according to a second aspect, and in one embodiment, the device comprises:
the data to be queried acquisition module is used for responding to the data query request and acquiring the data information to be queried related to the data query request;
the system comprises an address identification and query information determining module, a query information processing module and a query information processing module, wherein the address identification and query information determining module is used for determining a database address identification corresponding to data information to be queried and query information corresponding to the database address identification, and the query information comprises a data query command;
the database connection obtaining module is used for obtaining target database connection corresponding to the database address identifier through a preset data source management software framework;
and the command sending module is used for sending a data query command to the target database corresponding to the database address identifier through the connection of the target database.
The present invention provides according to a third aspect a computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the steps of an embodiment of any of the methods described above when executing the computer program.
The present invention provides according to a fourth aspect a computer-readable storage medium having stored thereon a computer program which, when being executed by a processor, carries out the steps of the embodiments of the method of any one of the above.
In the embodiment of the invention, after receiving a data query request, a database server acquires data information to be queried associated with the data query request; determining a database address identifier corresponding to the to-be-queried data information and query information corresponding to the database address identifier, wherein the query information comprises a data query command; then, acquiring target database connection corresponding to the database address identifier through a preset data source management software framework; and finally, sending a data query command to a target database corresponding to the database address identifier through the connection of the target database. According to the embodiment of the invention, the data source management software framework for realizing automatic switching of data source connection is built on the basis of the Spring framework, so that developers do not need to consider bottom layer implementation details during programming, namely, a large number of codes do not need to be written to describe the bottom layer implementation details, and the development efficiency of the developers is further improved.
Drawings
FIG. 1 is a diagram illustrating an application environment of a Spring framework-based database access method according to an embodiment;
FIG. 2 is a schematic flow chart illustrating a method for accessing a database based on a Spring framework according to an embodiment;
FIG. 3 is a flow diagram that illustrates the steps of obtaining a target database connection, in one embodiment;
FIG. 4 is a block diagram of a database access device based on a Spring framework according to an embodiment;
FIG. 5 is a diagram illustrating an internal structure of a computer device according to an embodiment.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the present application is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the present application and are not intended to limit the present application.
Fig. 1 shows an application environment of a Spring framework-based database access method according to an embodiment of the present invention. When other servers 11 (for example, application servers, service servers, and the like, which have data Query requirements) need to Query data in the database, a data Query request may be sent to the database server 20, or when a user (for example, an operator, a developer, an operation and maintenance person, and the like) needs to Query data in the database, a data Query request may be sent to the database server 20 through the user terminal 12, a plurality of databases are deployed on the database server 20 and/or a plurality of databases (such as 31, 32, and 3N shown in fig. 1) are connected, when the database server 20 receives the data Query request, a corresponding SQL (Structured Query Language) command may be generated based on the data information to be queried associated with the data Query request and sent to the corresponding database, each database may perform receiving the SQL command to Query related data, and feeds back the relevant data to the database server, and the database server will perform sorting (for example, perform data integration, data filtering, and the like) on the relevant data fed back by each database, and feed back the sorted data to other servers 11 or the user terminal 12.
The user terminal 12 includes, but is not limited to, various personal computers, notebook computers, smart phones, tablet computers, desktop computers, and the like, and the other server 11 and the database server 20 may be implemented by a separate server or a server cluster composed of a plurality of servers. Each database in the present solution may be various types of databases, and the types of the databases corresponding to each database may be the same or may not be completely the same, for example, the database 31 is a relational database (e.g., MySQL database) and the database 32 is a non-relational database (e.g., Redis database).
Fig. 2 shows a database access method based on a Spring framework according to an embodiment of the present invention, and the following description will take the example that the method is applied to the database server in fig. 1 as an example. The method comprises the following steps:
s110: and responding to the data query request, and acquiring the to-be-queried data information associated with the data query request.
In this embodiment, after receiving a data query request sent by a user terminal or another database, a database server obtains data information to be queried associated with the data query request, where the data information to be queried refers to data to be queried by the user or another server, that is, data to be queried, and corresponding attribute information, and the database server can query the data to be queried from the database through the attribute information.
S120: and determining a database address identifier corresponding to the to-be-queried data information and query information corresponding to the database address identifier, wherein the query information comprises a data query command.
In this embodiment, the data information to be queried may include a database identifier, for example, a unique uniform identifier of the first game uniform, a unique uniform identifier of the second game uniform, and the like. The database server pre-stores mapping relationships (for example, mapping tables) between the database identifiers and the database address identifiers thereof, and the database server may determine, through the mapping relationships, the database address identifiers corresponding to the database identifiers included in the data information to be queried, for example, in the above example, the database server may determine, through the unique identifier of the first game zone server, the database address identifiers corresponding to the database in charge of storing the game data of the first game zone server. The database address identifier refers to an ip address of the database. The database server may obtain the database address identifier from a configuration file configured in advance by the user.
The query information is used for providing the information for the database server, so that the database server can query the data to be queried from the database corresponding to the database address identifier through the query information. In this embodiment, the query information includes a data query command, i.e., an SQL command. It should be noted that, because there may be more data to be queried when accessing the database, or there may be more types of data, there may be more data query commands included in the query information.
In one embodiment, before the step of determining the database address identifier corresponding to the data information to be queried, the database server further includes:
sending a database information acquisition request to a remote support server;
receiving database information fed back by the remote support server in response to the database information acquisition request, wherein the database information comprises a plurality of database address identifiers and database identifiers corresponding to the database address identifiers;
and storing the database information into a preset storage area.
In this embodiment, the database address identifier refers to the ip address of the database.
Considering that the ip address of the database is frequently changed in some scenarios, for example, when the importance of the data stored in the database is high, the ip address of the database is often required to be frequently changed to ensure the security of the data, or in the field of games, a game may have thousands or even tens of thousands of game zones, and the ip address of the database is frequently changed due to frequent compliance (i.e., merging of game zones) and compliance (i.e., opening of new game zones) during the operation of the game. Therefore, in this embodiment, the ip address of the database is not pre-configured in the configuration file, and the database server actively sends a request to the remote support server to obtain the latest database information when the database server is started or receives a database information update notification sent by the remote support server. In a scenario where the change frequency of the ip address of one database is not high but the security level is high, the ip address of the database may not be stored in the remote support server, and the database server may actively send a request to the remote support server to obtain the corresponding ip address of the database.
The database server stores the database information fed back from the remote support server in a predetermined storage area.
Further, the step of determining, by the database server, the database address identifier corresponding to the data information to be queried includes:
determining a database identifier corresponding to the data information to be queried, wherein the database identifier is a unique identifier of a database storing the data information to be queried;
and inquiring database information stored in a preset storage area, and determining a database address identifier corresponding to the database identifier from the database information.
Specifically, the database server determines a database identifier included in the to-be-queried data information, where the database identifier is a unique identifier of a database storing the to-be-queried data information. Then, a preset storage area for storing database information is inquired, and a database address identifier corresponding to the database identifier is found out from the preset storage area.
S130: and obtaining the target database connection corresponding to the database address identifier through a preset data source management software framework.
In this embodiment, the preset data source management software framework is a software framework that is written by a developer in advance through a spring program, and can automatically determine a target database connection corresponding to the database address identifier, and as can be understood, the target database connection refers to a database connection corresponding to the database address identifier.
Specifically, the preset data source management software framework can be adapted and developed on the basis of a Spring framework and persistence frameworks such as Mybatis, Mybatis plus or Spring data JPA.
S140: and sending a data query command to a target database corresponding to the database address identifier through the connection of the target database.
In this embodiment, a database connection of the database is necessary to access the database, and after the database server obtains the target database connection, the database server may send a data query command to the target database corresponding to the database address identifier through the target database connection.
According to the embodiment of the invention, the data source management software framework for realizing automatic switching of the data source connection is established on the basis of the Spring framework, so that developers do not need to consider the bottom layer implementation details when changing the database connection during programming, do not need to write a large amount of codes to describe the bottom layer implementation details, and can finish the operation of changing the database connection by using a small amount of codes, thereby improving the development efficiency of the developers.
In one embodiment, as shown in fig. 3, the step of the database server obtaining the target database connection corresponding to the database address identifier through the preset data source management software framework includes:
s131: and setting the database address identification into a thread local variable corresponding to the data query request.
S132: and receiving a database connection sent by a preset data source management software framework, wherein the database connection is a database connection obtained by determining a data source corresponding to the database address identification from a plurality of data sources prestored in a memory after the preset data source management software framework acquires the database address identification arranged in the thread local variable and taking charge of management from the corresponding data source.
S133: and taking the database connection as a target database connection corresponding to the database address identifier.
It should be noted that, when a thread accesses a database, a database connection needs to be obtained, and the database can only be accessed through the database connection. The database Connection is a limited and precious resource, creating the database Connection requires a relatively large performance overhead, in order to save resources, a data source (i.e., a data source) is usually created, that is, a plurality of database connections (i.e., connections) are generated in advance when a database server is initialized, and the plurality of database connections generated in advance are stored in a memory as objects.
In this embodiment, the database server may create a data source for a database associated with the database server, and store the data source in a memory, after receiving a data query request, start a thread to be responsible for processing the data query request, when the thread needs to access a certain database, first obtain a database connection of the database, the thread only needs to set a database address identifier corresponding to the database to be accessed in a thread local variable of the thread, the preset data source management software framework may automatically obtain the database address identifier from the thread local variable, then determine a data source corresponding to the database address identifier from a plurality of data sources prestored in the memory, and return one database connection from the plurality of database connections managed by the data source corresponding to the database address identifier to the thread. The thread local variable is thread local or called a thread variable copy, a copy variable can be created for each variable in the thread in each thread, and each thread can access the copy variable in the thread without affecting the copy variables of other threads.
Further, if the thread wants to access another database after accessing a certain database, the preset data source management software framework will automatically execute the operation of obtaining the database connection and return the obtained database connection to the thread by only setting the database address identifier corresponding to the other database in the thread local variable.
From the perspective of a developer, the code that the developer needs to write only needs to describe which databases the thread needs to access and the access order of each database, and then the database address identifier of the database to be accessed this time is set in the thread local variable corresponding to the thread according to the access order, and whether the database to be accessed this time by the thread is different from the database accessed last time does not need to be concerned.
Further, receiving a database connection sent by a preset data source management software framework, where the database connection is a database connection obtained by determining, from a plurality of data sources prestored in a memory, a data source corresponding to a database address identifier after the preset data source management software framework obtains the database address identifier set in the thread local variable, and taking charge of management from the corresponding data source, and specifically includes:
receiving a database connection sent by a preset data source management software framework, wherein the database connection is that the preset data source management software framework judges whether a data source corresponding to a database address identifier exists in a plurality of data sources prestored in a memory after acquiring the database address identifier arranged in a thread local variable, and after determining that the data source corresponding to the database address identifier exists in the memory, one database connection is obtained from a plurality of database connections managed by the data source corresponding to the database address identifier, or after determining that the data source corresponding to the database address identifier does not exist in the memory, a data source corresponding to the database address identifier is newly created in the memory, and one database connection is obtained from a plurality of database connections managed by the newly created data source.
In an embodiment, the query information corresponding to the database address identifier further includes a database schema identifier, where the database schema refers to schema in an SQL environment. In the SQL environment, schema refers to a collection of database objects including tables, indexes, views, stored procedures, and the like.
The database server sends a data query command to a target database corresponding to the database address identifier through the connection of the target database, and the data query command comprises the following steps:
intercepting a data query command corresponding to the database address identifier by using a preset interceptor;
adding the database mode identification into the data query command to obtain an edited data query command;
and sending the edited data query command to a target database corresponding to the database address identifier through the connection of the target database.
In this embodiment, it is considered that in some scenarios, data in the database needs to be divided, for example, in the field of games, the number of game zone suits of a game is very large, usually, hundreds of game zone suits are provided, and data of different game zone suits are usually isolated from each other, theoretically, only one game zone suit may be deployed on one physical server, but this may cause a great waste of machine resources, for example, the amount of data of some game zone suits is small, and a great waste of machine resources may be caused by occupying one physical server alone. Therefore, a plurality of game zones are usually deployed on one physical server, one database is divided into a plurality of database modes, each database mode corresponds to one game zone, and data of different database modes are isolated from each other.
Since one database includes a plurality of database schemas, it is necessary to specify which database schema data is to be queried when a data query command is sent to the database in order to obtain desired data by itself when data returned by the database is returned.
Specifically, the database server intercepts a data query command corresponding to the database address identifier by using a preset interceptor, such as an SQL interceptor, dynamically adds the database mode identifier to the data query command to obtain an edited data query command, and finally sends the edited data query command to the target database through the target database connection.
In one embodiment, sending the edited data query command to the target database corresponding to the database address identifier through the target database connection, then includes:
and receiving target query data fed back by the target database, wherein the target query data are obtained from database storage data which are stored in the target database and correspond to the database mode identification after the target database analyzes and edits the data query command to obtain the database mode identification and the data query command.
In this embodiment, after receiving the edited data query command, the target database needs to parse the edited data query command to obtain the database schema identifier and the data query command before editing, and then execute the data query command, so as to obtain the relevant data from the database storage data corresponding to the database schema identifier stored in the target database.
In one embodiment, as shown in fig. 4, there is provided a Spring framework based database access device, including the following modules:
a to-be-queried data obtaining module 110, configured to respond to a data query request, and obtain to-be-queried data information associated with the data query request;
an address identifier and query information determining module 120, configured to determine a database address identifier corresponding to the data information to be queried and query information corresponding to the database address identifier, where the query information includes a data query command;
a database connection obtaining module 130, configured to obtain, through a preset data source management software framework, a target database connection corresponding to the database address identifier;
and the command sending module 140 is configured to send a data query command to the target database corresponding to the database address identifier through the target database connection.
In one embodiment, before the Spring framework-based database access device performs the functions corresponding to the address identification and query information determination module, the Spring framework-based database access device further performs the functions corresponding to the following modules:
an acquisition request sending module for sending a database information acquisition request to a remote support server;
a database information receiving module for receiving database information fed back by the remote support server in response to the database information acquisition request, wherein the database information includes a plurality of database address identifiers and database identifiers corresponding to the database address identifiers;
and the storage module is used for storing the database information into a preset storage area.
In one embodiment, the address identification and query information determination module includes:
the storage identification determining submodule is used for determining a database identification corresponding to the data information to be queried, and the database identification refers to the unique identification of the database for storing the data information to be queried;
and the address identifier determining submodule is used for inquiring the database information stored in the preset storage area and determining the database address identifier corresponding to the database identifier from the database information.
In one embodiment, the database connection obtaining module includes:
the identification setting submodule is used for setting the database address identification into a thread local variable corresponding to the data query request;
the database connection receiving submodule is used for receiving database connection sent by a preset data source management software framework, the database connection is that after the preset data source management software framework obtains a database address identifier arranged in a thread local variable, a data source corresponding to the database address identifier is determined from a plurality of data sources prestored in a memory, and one database connection is obtained from a plurality of database connections for which the corresponding data source is responsible for management;
and the database connection determining submodule is used for connecting the database as a target database corresponding to the database address identifier.
In one embodiment, the database connection receiving submodule is further configured to receive a database connection sent by the preset data source management software framework, where the database connection is that after the preset data source management software framework acquires the database address identifier set in the thread local variable, judging whether a data source corresponding to the database address identifier exists in a plurality of data sources prestored in the memory, after determining that there is a data source corresponding to the database address identifier in the memory, obtaining a database connection from a plurality of database connections for which the data source corresponding to the database address identifier is responsible for management, or, after determining that the memory has no data source corresponding to the database address identifier, newly creating a data source corresponding to the database address identifier in the memory, and one database connection obtained from among the plurality of database connections that the newly created data source is responsible for managing.
In one embodiment, the query information corresponding to the database address identifier further includes a database mode identifier;
a command sending module comprising:
the command interception submodule is used for intercepting a data query command corresponding to the database address identifier by using a preset interceptor;
the command editing submodule is used for adding the database mode identification into the data query command to obtain an edited data query command;
and the command sending submodule is used for sending the edited data query command to the target database corresponding to the database address identifier through the connection of the target database.
In one embodiment, the spring framework based database access device further comprises:
and the target query data receiving module is used for receiving target query data fed back by the target database, and the target query data is obtained from database storage data which is stored in the target database and corresponds to the database mode identification after the target database analyzes and edits the data query command to obtain the database mode identification and the data query command.
For specific limitations of the Spring framework based database access device, reference may be made to the above limitations of the Spring framework based database access method, and details are not repeated here. The modules in the Spring framework-based database access device can be wholly or partially implemented by software, hardware and 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, the internal structure of which may be as shown in FIG. 5. The computer device includes a processor, a memory, a network interface, and a database 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, a computer program, and a database. 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 Spring framework based database access method.
Those skilled in the art will appreciate that the architecture shown in fig. 5 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 one embodiment, a computer device is provided, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, the processor implementing the following steps when executing the computer program:
responding to the data query request, and acquiring to-be-queried data information associated with the data query request; determining a database address identifier corresponding to the to-be-queried data information and query information corresponding to the database address identifier, wherein the query information comprises a data query command; obtaining target database connection corresponding to the database address identification through a preset data source management software framework; and sending a data query command to a target database corresponding to the database address identifier through the connection of the target database.
In one embodiment, the processor executes the computer program to realize the following steps before determining the database address identifier corresponding to the data information to be queried:
sending a database information acquisition request to a remote support server; receiving database information fed back by the remote support server in response to the database information acquisition request, wherein the database information comprises a plurality of database address identifiers and database identifiers corresponding to the database address identifiers; and storing the database information into a preset storage area.
In one embodiment, the processor executes the computer program to realize the following steps when determining the database address identifier corresponding to the data information to be queried:
determining a database identifier corresponding to the data information to be queried, wherein the database identifier is a unique identifier of a database storing the data information to be queried; and inquiring database information stored in a preset storage area, and determining a database address identifier corresponding to the database identifier from the database information.
In one embodiment, when the processor executes the computer program to obtain the target database connection corresponding to the database address identifier through the preset data source management software framework, the following steps are also implemented:
setting the database address identifier into a thread local variable corresponding to the data query request; receiving a database connection sent by a preset data source management software framework, wherein the database connection is a database connection obtained by determining a data source corresponding to a database address identifier from a plurality of data sources prestored in a memory after the preset data source management software framework acquires the database address identifier arranged in a thread local variable and taking charge of management from the corresponding data source; and taking the database connection as a target database connection corresponding to the database address identifier.
In one embodiment, the processor executes a computer program to implement receiving a database connection sent by a preset data source management software framework, where the database connection is when the preset data source management software framework determines, after acquiring a database address identifier set in a thread local variable, a data source corresponding to the database address identifier from a plurality of data sources prestored in a memory, and obtains one database connection from the plurality of database connections for which the corresponding data source is responsible for management, the following further steps are implemented:
receiving a database connection sent by a preset data source management software framework, wherein the database connection is that the preset data source management software framework judges whether a data source corresponding to a database address identifier exists in a plurality of data sources prestored in a memory after acquiring the database address identifier arranged in a thread local variable, and after determining that the data source corresponding to the database address identifier exists in the memory, one database connection is obtained from a plurality of database connections managed by the data source corresponding to the database address identifier, or after determining that the data source corresponding to the database address identifier does not exist in the memory, a data source corresponding to the database address identifier is newly created in the memory, and one database connection is obtained from a plurality of database connections managed by the newly created data source.
In one embodiment, the query information corresponding to the database address identifier further includes a database mode identifier; the processor executes the computer program to realize the following steps when the data query command is sent to the target database corresponding to the database address identifier through the target database connection:
intercepting a data query command corresponding to the database address identifier by using a preset interceptor; adding the database mode identification into the data query command to obtain an edited data query command; and sending the edited data query command to a target database corresponding to the database address identifier through the connection of the target database.
In one embodiment, when the processor executes the computer program, after the edited data query command is sent to the target database corresponding to the database address identifier through the target database connection, the following steps are further implemented:
and receiving target query data fed back by the target database, wherein the target query data are obtained from database storage data which are stored in the target database and correspond to the database mode identification after the target database analyzes and edits the data query command to obtain the database mode identification and the data query command.
In one embodiment, a computer-readable storage medium is provided, having a computer program stored thereon, which when executed by a processor, performs the steps of:
responding to the data query request, and acquiring to-be-queried data information associated with the data query request; determining a database address identifier corresponding to the to-be-queried data information and query information corresponding to the database address identifier, wherein the query information comprises a data query command; obtaining target database connection corresponding to the database address identification through a preset data source management software framework; and sending a data query command to a target database corresponding to the database address identifier through the connection of the target database.
In one embodiment, the computer program is executed by a processor, and before determining the database address identifier corresponding to the data information to be queried, further implements the following steps:
sending a database information acquisition request to a remote support server; receiving database information fed back by the remote support server in response to the database information acquisition request, wherein the database information comprises a plurality of database address identifiers and database identifiers corresponding to the database address identifiers; and storing the database information into a preset storage area.
In one embodiment, the computer program is executed by a processor, and when determining the database address identifier corresponding to the data information to be queried, further implements the following steps:
determining a database identifier corresponding to the data information to be queried, wherein the database identifier is a unique identifier of a database storing the data information to be queried; and inquiring database information stored in a preset storage area, and determining a database address identifier corresponding to the database identifier from the database information.
In one embodiment, when the computer program is executed by the processor and a target database connection corresponding to the database address identifier is obtained through the preset data source management software framework, the following steps are further implemented:
setting the database address identifier into a thread local variable corresponding to the data query request; receiving a database connection sent by a preset data source management software framework, wherein the database connection is a database connection obtained by determining a data source corresponding to a database address identifier from a plurality of data sources prestored in a memory after the preset data source management software framework acquires the database address identifier arranged in a thread local variable and taking charge of management from the corresponding data source; and taking the database connection as a target database connection corresponding to the database address identifier.
In one embodiment, when the computer program is executed by the processor, and receives a database connection sent by a preset data source management software framework, where the database connection is obtained by the preset data source management software framework after a database address identifier set in a thread local variable is obtained, determining a data source corresponding to the database address identifier from a plurality of data sources prestored in the memory, and obtaining one database connection from the plurality of database connections for which the corresponding data source is responsible for management, the following steps are further implemented:
receiving a database connection sent by a preset data source management software framework, wherein the database connection is that the preset data source management software framework judges whether a data source corresponding to a database address identifier exists in a plurality of data sources prestored in a memory after acquiring the database address identifier arranged in a thread local variable, and after determining that the data source corresponding to the database address identifier exists in the memory, one database connection is obtained from a plurality of database connections managed by the data source corresponding to the database address identifier, or after determining that the data source corresponding to the database address identifier does not exist in the memory, a data source corresponding to the database address identifier is newly created in the memory, and one database connection is obtained from a plurality of database connections managed by the newly created data source.
In one embodiment, the query information corresponding to the database address identifier further includes a database mode identifier; the computer program is executed by the processor, and when the data query command is sent to the target database corresponding to the database address identifier through the target database connection, the following steps are also realized:
intercepting a data query command corresponding to the database address identifier by using a preset interceptor; adding the database mode identification into the data query command to obtain an edited data query command; and sending the edited data query command to a target database corresponding to the database address identifier through the connection of the target database.
In one embodiment, after the computer program is executed by the processor and sends the edited data query command to the target database corresponding to the database address identifier through the target database connection, the following steps are further implemented:
and receiving target query data fed back by the target database, wherein the target query data are obtained from database storage data which are stored in the target database and correspond to the database mode identification after the target database analyzes and edits the data query command to obtain the database mode identification and the data query command.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by hardware instructions of a computer program, which can be stored in a non-volatile computer-readable storage medium, and when executed, can include the processes of the embodiments of the methods described above. Any reference to memory, storage, database, or other medium used in the embodiments provided herein may include non-volatile and/or volatile memory, among others. Non-volatile memory can include read-only memory (ROM), Programmable ROM (PROM), Electrically Programmable ROM (EPROM), Electrically Erasable Programmable ROM (EEPROM), or flash memory. Volatile memory can include Random Access Memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms such as Static RAM (SRAM), Dynamic RAM (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDRSDRAM), Enhanced SDRAM (ESDRAM), Synchronous Link DRAM (SLDRAM), Rambus Direct RAM (RDRAM), direct bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
The technical features of the above embodiments can be arbitrarily combined, and for the sake of brevity, all possible combinations of the technical features in the above embodiments are not described, but should be considered as the scope of the present specification as long as there is no contradiction between the combinations of the technical features.
The above-mentioned embodiments only express several embodiments of the present application, and the description thereof is more specific and detailed, but not construed as limiting the scope of the invention. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the concept of the present application, which falls within the scope of protection of the present application. Therefore, the protection scope of the present patent shall be subject to the appended claims.

Claims (10)

1. A database access method based on a Spring framework is characterized by comprising the following steps:
responding to a data query request, and acquiring to-be-queried data information associated with the data query request;
determining a database address identifier corresponding to the to-be-queried data information and query information corresponding to the database address identifier, wherein the query information comprises a data query command;
obtaining target database connection corresponding to the database address identification through a preset data source management software framework;
and sending the data query command to a target database corresponding to the database address identifier through the target database connection.
2. The Spring framework-based database access method according to claim 1, wherein the determining of the database address identifier corresponding to the data information to be queried previously comprises:
sending a database information acquisition request to a remote support server;
receiving database information fed back by the remote support server in response to the database information acquisition request, wherein the database information comprises a plurality of database address identifiers and database identifiers corresponding to the database address identifiers;
and storing the database information into a preset storage area.
3. The Spring framework-based database access method according to claim 2, wherein the determining the database address identifier corresponding to the data information to be queried includes:
determining a database identifier corresponding to the information of the data to be queried, wherein the database identifier is a unique identifier of a database storing the data to be queried;
and inquiring database information stored in the preset storage area, and determining a database address identifier corresponding to the database identifier from the database information.
4. The method for accessing a database based on a Spring framework according to claim 1, wherein the obtaining of the target database connection corresponding to the database address identifier through a preset data source management software framework includes:
setting the database address identifier into a thread local variable corresponding to the data query request;
receiving a database connection sent by a preset data source management software framework, wherein the database connection is a database connection obtained by determining a data source corresponding to a database address identifier from a plurality of data sources prestored in a memory after the preset data source management software framework acquires the database address identifier arranged in the thread local variable, and taking charge of management from the corresponding data source;
and taking the database connection as a target database connection corresponding to the database address identifier.
5. A database access method according to claim 4, wherein the receiving a database connection sent by a preset data source management software framework, the database connection being a database connection obtained by the preset data source management software framework after acquiring a database address identifier set in the thread local variable, determining a data source corresponding to the database address identifier from a plurality of data sources pre-stored in a memory, and obtaining the data source from a plurality of database connections for which the corresponding data source is responsible for management, comprises:
receiving a database connection sent by a preset data source management software framework, wherein the database connection is that the preset data source management software framework judges whether a data source corresponding to a database address identifier exists in a plurality of data sources prestored in a memory after acquiring the database address identifier arranged in the thread local variable, and after determining that the data source corresponding to the database address identifier exists in the memory, one database connection is obtained from a plurality of database connections managed by the data source corresponding to the database address identifier in charge of, or after determining that the data source corresponding to the database address identifier does not exist in the memory, a data source corresponding to the database address identifier is newly created in the memory, and one database connection is obtained from a plurality of database connections managed by the newly created data source in charge of.
6. The Spring framework-based database access method according to claim 1, wherein the query information corresponding to the database address identifier further includes a database schema identifier;
the sending the data query command to the target database corresponding to the database address identifier through the target database connection includes:
intercepting a data query command corresponding to the database address identifier by using a preset interceptor;
adding the database mode identifier into the data query command to obtain an edited data query command;
and sending the edited data query command to a target database corresponding to the database address identifier through the connection of the target database.
7. The Spring framework-based database access method according to claim 6, wherein the sending the edited data query command to the target database corresponding to the database address identifier through the target database connection, thereafter includes:
and receiving target query data fed back by the target database, wherein the target query data is obtained from database storage data which is stored in the target database and corresponds to the database mode identification after the target database analyzes the edited data query command to obtain the database mode identification and the data query command.
8. A Spring framework-based database access device, comprising:
the query data acquisition module is used for responding to a data query request and acquiring the information of the query data associated with the data query request;
the address identification and query information determining module is used for determining a database address identification corresponding to the to-be-queried data information and query information corresponding to the database address identification, wherein the query information comprises a data query command;
the database connection obtaining module is used for obtaining the target database connection corresponding to the database address identifier through a preset data source management software framework;
and the command sending module is used for sending the data query command to a target database corresponding to the database address identifier through the connection of the target database.
9. A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, characterized in that the steps of the method of any of claims 1 to 7 are implemented when the computer program is executed by the processor.
10. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the steps of the method of any one of claims 1 to 7.
CN202010093200.1A 2020-02-14 2020-02-14 Database access method and device based on Spring framework, computer equipment and medium Active CN111309785B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010093200.1A CN111309785B (en) 2020-02-14 2020-02-14 Database access method and device based on Spring framework, computer equipment and medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010093200.1A CN111309785B (en) 2020-02-14 2020-02-14 Database access method and device based on Spring framework, computer equipment and medium

Publications (2)

Publication Number Publication Date
CN111309785A true CN111309785A (en) 2020-06-19
CN111309785B CN111309785B (en) 2023-05-16

Family

ID=71145009

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010093200.1A Active CN111309785B (en) 2020-02-14 2020-02-14 Database access method and device based on Spring framework, computer equipment and medium

Country Status (1)

Country Link
CN (1) CN111309785B (en)

Cited By (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112434069A (en) * 2020-12-01 2021-03-02 天津市鑫联兴科技有限公司 Multi-source heterogeneous database access adaptation method and adapter
CN112650773A (en) * 2020-12-24 2021-04-13 北京奇艺世纪科技有限公司 Data query method and device, electronic equipment and storage medium
CN112667716A (en) * 2020-12-30 2021-04-16 京东数字科技控股股份有限公司 Data processing method and device, electronic equipment and storage medium
CN112817799A (en) * 2021-01-13 2021-05-18 中国建设银行股份有限公司 Method and device for accessing multiple data sources based on Spring framework
CN113253691A (en) * 2021-06-18 2021-08-13 武汉科迪智能环境股份有限公司 Equipment management method and device
CN113923256A (en) * 2020-06-22 2022-01-11 北京金山云网络技术有限公司 Data source management method, device, server and system
CN114077619A (en) * 2020-08-20 2022-02-22 北京字节跳动网络技术有限公司 Data query method and device, electronic equipment and storage medium
CN116244361A (en) * 2022-12-23 2023-06-09 北京柏睿数据技术股份有限公司 Method and system for dynamic persistence processing of database connection
CN117539949A (en) * 2024-01-10 2024-02-09 腾讯科技(深圳)有限公司 Processing method and device of database access request, electronic equipment and storage medium

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20110213778A1 (en) * 2010-02-26 2011-09-01 Robert Brian Hess Processor Implemented Systems and Methods for Using the Catalog Part of an SQL Identifier to Expose/Access Heterogeneous Data
CN108804644A (en) * 2018-06-05 2018-11-13 中国平安人寿保险股份有限公司 Interface log storing method, device, computer equipment and storage medium
CN110597782A (en) * 2019-08-13 2019-12-20 上海陆家嘴国际金融资产交易市场股份有限公司 Database dynamic switching method and device, computer equipment and storage medium

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20110213778A1 (en) * 2010-02-26 2011-09-01 Robert Brian Hess Processor Implemented Systems and Methods for Using the Catalog Part of an SQL Identifier to Expose/Access Heterogeneous Data
CN108804644A (en) * 2018-06-05 2018-11-13 中国平安人寿保险股份有限公司 Interface log storing method, device, computer equipment and storage medium
CN110597782A (en) * 2019-08-13 2019-12-20 上海陆家嘴国际金融资产交易市场股份有限公司 Database dynamic switching method and device, computer equipment and storage medium

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
伍文彬;: "Spring环境下的敏捷ORM框架设计与实现" *
张少应;陈庆荣;: "基于Spring的数据库访问技术研究" *

Cited By (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113923256A (en) * 2020-06-22 2022-01-11 北京金山云网络技术有限公司 Data source management method, device, server and system
CN113923256B (en) * 2020-06-22 2024-05-03 北京金山云网络技术有限公司 Data source management method, device, server and system
CN114077619A (en) * 2020-08-20 2022-02-22 北京字节跳动网络技术有限公司 Data query method and device, electronic equipment and storage medium
CN112434069A (en) * 2020-12-01 2021-03-02 天津市鑫联兴科技有限公司 Multi-source heterogeneous database access adaptation method and adapter
CN112650773A (en) * 2020-12-24 2021-04-13 北京奇艺世纪科技有限公司 Data query method and device, electronic equipment and storage medium
CN112667716A (en) * 2020-12-30 2021-04-16 京东数字科技控股股份有限公司 Data processing method and device, electronic equipment and storage medium
CN112817799A (en) * 2021-01-13 2021-05-18 中国建设银行股份有限公司 Method and device for accessing multiple data sources based on Spring framework
CN113253691B (en) * 2021-06-18 2021-09-14 武汉科迪智能环境股份有限公司 Equipment management method and device
CN113253691A (en) * 2021-06-18 2021-08-13 武汉科迪智能环境股份有限公司 Equipment management method and device
CN116244361A (en) * 2022-12-23 2023-06-09 北京柏睿数据技术股份有限公司 Method and system for dynamic persistence processing of database connection
CN116244361B (en) * 2022-12-23 2023-10-10 北京柏睿数据技术股份有限公司 Method and system for dynamic persistence processing of database connection
CN117539949A (en) * 2024-01-10 2024-02-09 腾讯科技(深圳)有限公司 Processing method and device of database access request, electronic equipment and storage medium
CN117539949B (en) * 2024-01-10 2024-04-12 腾讯科技(深圳)有限公司 Processing method and device of database access request, electronic equipment and storage medium

Also Published As

Publication number Publication date
CN111309785B (en) 2023-05-16

Similar Documents

Publication Publication Date Title
CN111309785B (en) Database access method and device based on Spring framework, computer equipment and medium
CN110069572B (en) HIVE task scheduling method, device, equipment and storage medium based on big data platform
CN107562513B (en) Intelligent contract life cycle management method based on JAVA
CN109992354B (en) Container processing method, device, main body server, system and storage medium
CN110290112B (en) Authority control method and device, computer equipment and storage medium
CN109379398B (en) Data synchronization method and device
CN110008665B (en) Authority control method and device for blockchain
CN110555041A (en) Data processing method, data processing device, computer equipment and storage medium
CN111831191A (en) Workflow configuration method and device, computer equipment and storage medium
CN113220669B (en) Service data processing method and device and electronic equipment
CN114531477B (en) Method and device for configuring functional components, computer equipment and storage medium
CN112100152A (en) Service data processing method, system, server and readable storage medium
CN111582824B (en) Cloud resource synchronization method, device, equipment and storage medium
CN108874837B (en) Database partitioning method and device, middleware, storage medium and electronic equipment
CN112148699A (en) Log management method, device, equipment and medium
CN110543465B (en) Directory operation method and device, computer equipment and storage medium
CN111966704A (en) ORM framework implementation method, system, computer equipment and storage medium
CN112069223A (en) Data acquisition demand processing method and device, computer equipment and storage medium
CN115374083A (en) Data source switching method and device, electronic equipment and storage medium
CN111414242B (en) Method, device, server, system and storage medium for operating state machine
CN112783866A (en) Data reading method and device, computer equipment and storage medium
CN112463836A (en) Data query method and device based on Django framework, computer equipment and medium
CN113343275B (en) Data access method and data management service system
CN111611447B (en) Computer and server
CN114385597A (en) Data processing method, device, equipment and storage medium

Legal Events

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