CN111309785B - Database access method and device based on Spring framework, computer equipment and medium - Google Patents

Database access method and device based on Spring framework, computer equipment and medium Download PDF

Info

Publication number
CN111309785B
CN111309785B CN202010093200.1A CN202010093200A CN111309785B CN 111309785 B CN111309785 B CN 111309785B CN 202010093200 A CN202010093200 A CN 202010093200A CN 111309785 B CN111309785 B CN 111309785B
Authority
CN
China
Prior art keywords
database
data
connection
identifier
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.)
Active
Application number
CN202010093200.1A
Other languages
Chinese (zh)
Other versions
CN111309785A (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 present invention relates to the field of computers, and in particular, to a method, an apparatus, a computer device, and a storage medium for accessing a database based on a Spring framework. The method comprises the following steps: responding to the data query request, and acquiring data information to be queried associated with the data query request; determining a database address identifier corresponding to the data information to be queried 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 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 data source connection is built on the basis of the Spring framework, so that a developer does not need to consider bottom implementation details during programming, namely, does not need to write a large amount of codes to describe the bottom implementation details, and further development efficiency of the developer is improved.

Description

Database access method and device based on Spring framework, computer equipment and medium
Technical Field
The present invention relates to the field of computers, and in particular, to a method, an apparatus, a computer device, and a storage medium for accessing a database based on a Spring framework.
Background
When a user or a server needs to acquire data (such as operation data of the user on an application, log data of the user, etc.), a data query request is sent to a database server, and the database server starts a thread to process the data query request, so that the data to be acquired by the user or the server may be stored in a plurality of databases respectively, and therefore the thread needs to access the databases to acquire related data. When accessing a database, a database connection needs to be taken from the data source of the database, the database can be accessed through the database connection, and if other databases are to be accessed later, the database connection needs to be changed to access the other databases.
In order to improve development efficiency, databases needing to be operated are pooled, then an Object layer (Object/Relational Mapping, object-relation mapping) operation Object is wrapped at the outer layer to realize persistent operation, and when the database connection is changed, the change of the database connection can be realized only by unloading old data sources and adding new data sources and the Object operation Object.
The current Spring framework does not support the way to change the database connection, so when implementing the way, programming development of non-Spring is generally adopted. However, the Spring framework is one of the most popular development frameworks at present, and many persistent frameworks such as Mybatis, mybatis plus, spring Data JPA and the like all make some optimized coding modes on the Spring framework, and if non-Spring programming development is adopted, the characteristics of the frameworks are not utilized. Therefore, the manner in which the database connection change is implemented by adopting the programming without Spring can lead the developer to write a large amount of codes to describe the bottom implementation details of changing the database connection, so that the development efficiency of the developer is low.
Disclosure of Invention
Aiming at the defects of the prior art, the invention provides a database access method, a device, a computer device and a storage medium based on a Spring framework.
The present invention provides, according to a first aspect, a method for accessing a database based on a Spring framework, in one embodiment, the method comprising:
responding to the data query request, and acquiring data information to be queried associated with the data query request;
determining a database address identifier corresponding to the data information to be queried 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 the target database corresponding to the database address identifier through the target database connection.
In one embodiment, determining the database address identification 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 a remote support server in response to a 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 identification 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 refers to 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, by a preset data source management software framework, a target database connection corresponding to a database address identifier includes:
setting a database address identifier into a thread local variable corresponding to the data query request;
receiving database connection sent by a preset data source management software framework, wherein the database connection is one database connection obtained by the preset data source management software framework after acquiring a database address identifier arranged 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 managing the corresponding data source in charge;
and using the database connection as a target database connection corresponding to the database address identification.
In one embodiment, a database connection sent by a preset data source management software framework is received, 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 pre-stored in a memory, and obtaining from a plurality of database connections responsible for management of the corresponding data source, where the database connection includes:
And receiving database connection sent by the preset data source management software framework, wherein the database connection is one obtained from a plurality of database connections responsible for management of the data source corresponding to the database address identification after the preset data source management software framework acquires the database address identification arranged in the thread local variable, judging whether the data source corresponding to the database address identification exists in a plurality of data sources prestored in a memory, or newly creating the data source corresponding to the database address identification in the memory after the data source corresponding to the database address identification is determined to exist in the memory, and obtaining one database connection from a plurality of database connections responsible for management of 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 target database connection, including:
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 the target database corresponding to the database address identifier through the target database connection.
In one embodiment, the sending, through the target database connection, the edited data query command to the target database corresponding to the database address identifier, then includes:
and receiving target query data fed back by the target database, wherein the target query data is data obtained from database storage data corresponding to the database mode identifier stored in the target database after the target database analyzes the edited data query command to obtain the database mode identifier and the data query command.
The present invention provides according to a second aspect a Spring frame based database access device, which in one embodiment comprises:
the data to be queried obtaining module is used for responding to the data query request and obtaining data information to be queried 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 data information to be queried 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 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 target database connection.
According to a third aspect the present invention provides 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 the computer program is executed.
According to a fourth aspect, the present invention provides a computer readable storage medium having stored thereon a computer program which when executed by a processor performs the steps of an embodiment of any of the methods described 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 data information to be queried and query information corresponding to the database address identifier, wherein the query information comprises a data query command; then obtaining a 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 target database connection. 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 a developer does not need to consider bottom implementation details during programming, namely, does not need to write a large amount of codes to describe the bottom implementation details, and further development efficiency of the developer is improved.
Drawings
FIG. 1 is an application environment diagram of a Spring framework-based database access method in one embodiment;
FIG. 2 is a flowchart of a method for accessing a database based on a Spring framework according to an embodiment;
FIG. 3 is a flowchart illustrating steps for obtaining a target database connection in one embodiment;
FIG. 4 is a block diagram of a database access device based on a Spring framework in one embodiment;
fig. 5 is an internal structural diagram of a computer device in one embodiment.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the present application will be further described in detail with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the present application.
FIG. 1 is a diagram illustrating an application environment of a method for accessing a database based on a Spring framework according to an embodiment of the present invention. When other servers 11 (such as servers with data query requirements, such as application servers, service servers, etc.) need to query data in the databases, a data query request may be sent to the database server 20, or when users (such as operators, developers, operation and maintenance personnel, etc.) need to query data in the databases, a data query request may be sent to the database server 20 through the user terminal 12, multiple databases are disposed on the database server 20 and/or multiple databases (such as 31, 32, 3N shown in fig. 1) are connected, after the database server 20 receives the data query request, a corresponding SQL (Structured Query Language ) command is generated based on the data information to be queried associated with the data query request, and sent to the corresponding databases, each database executes the SQL command to query related data and feeds back related data to the database server, and the database server may sort the related data fed back to each database (such as perform data integration, data filtering, etc.), 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, smartphones, tablet computers, desktop computers, etc., and the other servers 11 and the database server 20 may be implemented as separate servers or a server cluster composed of a plurality of servers. The databases in the present solution may be various types of databases, and the types of databases corresponding to the various databases may or may not be identical, for example, the database 31 is a relational database (for example, mySQL database) and the database 32 is a non-relational database (for example, redis database).
Fig. 2 is a schematic diagram of a database access method based on a Spring framework according to an embodiment of the present invention, and the following description will take the application of the method 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 data information to be queried associated with the data query request.
In this embodiment, after receiving a data query request sent by a user terminal or other databases, the 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 a user or other servers, that is, data to be queried, corresponding attribute information, and the database server can query the data to be queried from the databases through the attribute information.
S120: determining a database address identifier corresponding to the data information to be queried 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 each database identifier and a mapping relation (for example, may be a mapping table) between the database identifiers, and the database server may determine, according to the mapping relation, a database address identifier corresponding to the database identifier included in the data information to be queried, for example, in the above example, the database server may determine, according to the unique area service identifier of the first game area service, a database address identifier corresponding to the database responsible for storing the game data of the first game area service. Wherein the database address identification is 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 information used for being provided for the database server, so that the database server can query the data to be queried from the database corresponding to the database address identification 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, since the data to be queried may be more or more in category when accessing the database, the query information may include multiple data query commands.
In one embodiment, before the step of determining the database address identification 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 a remote support server in response to a 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 in some situations, the ip address of the database is often changed, for example, when the importance degree of the data stored in the database is high, the ip address of the database is often required to be changed to ensure the security of the data, or in the game field, one game may have thousands or even tens of thousands of game areas, and in the operation of the game, the ip address of the database is often changed due to frequent combination (i.e. combination of game areas) and opening (i.e. provision of new game areas). Therefore, in this embodiment, the ip address of the database is not preconfigured in the configuration file, and the database server actively initiates a request to the remote support server to obtain the latest database information when the database server is started or when receiving the database information update notification issued by the remote support server. In addition, in a scenario where the frequency of changing the ip address of the 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.
For the database information fed back by the remote support server, the database server stores the database information in a preset storage area.
Further, the step of determining, by the database server, a 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 refers to 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 data information to be queried, wherein the database identifier refers to a unique identifier of a database storing the data information to be queried. And then searching a preset storage area for storing database information, and finding out a database address identifier corresponding to the database identifier.
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 written by a developer through spring programming in advance, and can automatically determine a target 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 a persistence framework such as Mybatis, mybatis plus or Spring data JPA.
S140: and sending a data query command to the target database corresponding to the database address identifier through the target database connection.
In this embodiment, the database to be accessed must be connected through the database of the database, and after the database server obtains the target database connection, the data query command may be sent 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 built on the basis of the Spring framework, so that a developer does not need to consider the bottom layer implementation details when the database connection is changed during programming, does not need to write a large amount of codes to describe the bottom layer implementation details, and can describe the operation of changing the database connection with a small amount of codes, thereby improving the development efficiency of the developer.
In one embodiment, as shown in fig. 3, the step of obtaining, by the database server, a target database connection corresponding to the database address identifier through a preset data source management software framework includes:
S131: and setting the database address identification into the thread local variable corresponding to the data query request.
S132: and receiving database connection sent by the preset data source management software framework, wherein the database connection is one database connection obtained by the preset data source management software framework after acquiring the database address identification arranged in the thread local variable, determining the data source corresponding to the database address identification from a plurality of data sources prestored in a memory and managing the corresponding data source.
S133: and using the database connection as a target database connection corresponding to the database address identification.
When a thread accesses a database, it needs to obtain a database connection, and access to the database is only possible through the database connection. The database Connection is a limited and precious resource, a relatively large performance cost is required for creating the database Connection, in order to save resources, a data source (i.e., a DataSource) is generally established, that is, a plurality of database connections (i.e., connections) are generated in advance when a database server is initialized, the plurality of database connections generated in advance are stored in a memory as objects, when a thread needs to access the database, it is not required to re-create a database Connection, and only one Connection object (i.e., a database Connection) in an idle state needs to be taken out of a plurality of database connections pre-stored in the memory, and then the database can be accessed through the Connection object.
In this embodiment, the database server creates a data source for the database associated with itself and stores the data source in the memory, after receiving a data query request, starts a thread to process the data query request, when the thread needs to access a certain database, needs to first obtain a database connection of the database, and the thread only needs to set a database address identifier corresponding to the database to be accessed in its own thread local variable, where the preset data source management software framework automatically obtains the database address identifier from the thread local variable, then determines a data source corresponding to the database address identifier from a plurality of data sources pre-stored in the memory, and returns a database connection to the thread from a plurality of database connections responsible for management of the data source corresponding to the database address identifier. The thread local variable refers to thread local or thread variable copy, a copy variable can be created in each thread for each variable in the 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 acquiring the database connection only by setting the database address identifier corresponding to the other database in the local variable of the thread, and return the acquired database connection to the thread.
From the perspective of a developer, the code required to be written by the developer only needs to describe which databases the thread needs to access and the access order of each database, and then the database address identifiers of the databases to be accessed at this time are sequentially set into the thread local variables corresponding to the thread according to the access order, so that whether the databases to be accessed at this time by the thread are different from the databases to be accessed at last time is not required to be concerned.
Further, receiving a database connection sent by the preset data source management software framework, where the database connection is one database connection obtained by the preset data source management software framework from a plurality of data sources pre-stored in a memory and corresponding to the database address identifier after obtaining the database address identifier set in the thread local variable, and from a plurality of database connections responsible for management of the corresponding data sources, specifically including:
and receiving database connection sent by the preset data source management software framework, wherein the database connection is one obtained from a plurality of database connections responsible for management of the data source corresponding to the database address identification after the preset data source management software framework acquires the database address identification arranged in the thread local variable, judging whether the data source corresponding to the database address identification exists in a plurality of data sources prestored in a memory, or newly creating the data source corresponding to the database address identification in the memory after the data source corresponding to the database address identification is determined to exist in the memory, and obtaining one database connection from a plurality of database connections responsible for management of the newly created data source.
In one 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 is a collection of database objects that include tables, indexes, views, stored procedures, and the like.
The step of sending the data query command to the target database corresponding to the database address identifier by the database server through the target database connection comprises the following steps:
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 the target database corresponding to the database address identifier through the target database connection.
In this embodiment, considering that in some scenarios, data in the database needs to be divided into data, for example, in the game field, the number of game areas of a game is very large, usually there are hundreds of thousands of game areas, and data of different game areas are isolated from each other, in theory, only one game area can be deployed on one physical server, but this causes a waste of machine resources, for example, the data of some game areas is relatively small, and occupying one physical server alone causes a waste of machine resources. Thus, a plurality of game areas are typically deployed on a physical server, and a database is divided into a plurality of database patterns, each database pattern corresponding to a game area, and the data of the different database patterns are isolated from each other.
Since one database includes a plurality of database patterns, in order to obtain desired data by itself when the database returns data, it is necessary to specify which database pattern data is to be queried when a data query command is sent to the database.
Specifically, the database server uses a preset interceptor, such as an SQL interceptor, to intercept the data query command corresponding to the database address identifier, 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, and then includes:
and receiving target query data fed back by the target database, wherein the target query data is data obtained from database storage data corresponding to the database mode identifier stored in the target database after the target database analyzes the edited data query command to obtain the database mode identifier 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 mode identifier and the data query command before being not edited, and then execute the data query command, so as to obtain related data from the database storage data corresponding to the database mode identifier stored in the target database.
In one embodiment, as shown in fig. 4, there is provided a database access device based on a Spring framework, including the following modules:
the to-be-queried data acquisition module 110 is configured to respond to a data query request and acquire 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;
the database connection obtaining module 130 is configured to obtain, through a preset data source management software framework, a target database connection corresponding to the database address identifier;
the command sending module 140 is configured to send a data query command to a target database corresponding to the database address identifier through the target database connection.
In one embodiment, the database access device based on the Spring framework further performs the functions corresponding to the following modules before performing the functions corresponding to the address identification and query information determination modules:
the acquisition request sending module is used for sending a database information acquisition request to the remote support server;
the database information receiving module is used for 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 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 comprises:
the storage identification determining submodule is used for determining a database identification corresponding to the data information to be queried, wherein the database identification refers to a unique identification of a database storing the data information to be queried;
the address identification determining sub-module is used for inquiring the database information stored in the preset storage area and determining the database address identification corresponding to the database identification from the database information.
In one embodiment, the database connection acquisition module comprises:
the identification setting sub-module is used for setting the database address identification into the thread local variable corresponding to the data query request;
the database connection receiving sub-module is used for receiving the database connection sent by the preset data source management software framework, wherein the database connection is one database connection obtained from a plurality of database connections which are responsible for management of the corresponding data sources and 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 the database connection determination submodule is used for taking the database connection as a target database connection corresponding to the database address identification.
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 a database connection obtained from a plurality of database connections responsible for management of a data source corresponding to a database address identifier after the preset data source management software framework obtains the database address identifier set in a thread local variable, determines whether there is a data source corresponding to the database address identifier in a plurality of data sources pre-stored in a memory, determines that there is a data source corresponding to the database address identifier in the memory, and then obtains a database connection from a plurality of database connections responsible for management of the data source corresponding to the database address identifier, or newly creates a data source corresponding to the database address identifier in the memory after it is determined that there is no data source corresponding to the database address identifier in the memory, and obtains a database connection from a plurality of database connections responsible for management of the newly created data source.
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 sub-module is used for intercepting a data query command corresponding to the database address identifier by using a preset interceptor;
the command editing sub-module is used for adding the database mode identification into the data query command to obtain an edited data query command;
and the command sending sub-module 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 databases.
In one embodiment, the spring framework based database access device further comprises:
the target query data receiving module is used for receiving target query data fed back by the target database, wherein the target query data is data obtained from database storage data corresponding to the database mode identifier stored in the target database after the target database analyzes the edited data query command to obtain the database mode identifier and the data query command.
For specific limitations on the Spring frame-based database access device, reference may be made to the above limitation on the Spring frame-based database access method, which is not described herein. The modules in the database access device based on the Spring framework can be all or partially realized by software, hardware and a combination thereof. The above modules may be embedded in hardware or may be independent of a processor in the computer device, or may be stored in software in a memory in the computer device, so that the processor may call and execute operations corresponding to the above 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 includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage media. The network interface of the computer device is used for communicating with an external terminal through a network connection. The computer program, when executed by a processor, implements a method for accessing a database based on a Spring framework.
It will be appreciated by those skilled in the art that the structure shown in fig. 5 is merely a block diagram of some of the structures associated with the present application and is not limiting of the computer device to which the present application may be applied, and that a particular computer device may include more or fewer components than 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 steps of when executing the computer program:
responding to the data query request, and acquiring data information to be queried associated with the data query request; determining a database address identifier corresponding to the data information to be queried 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 the target database corresponding to the database address identifier through the target database connection.
In one embodiment, the processor executes a computer program to perform 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 a remote support server in response to a 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 a computer program to perform the steps of, when determining a database address identifier corresponding to data information to be queried, further performing the steps of:
determining a database identifier corresponding to the data information to be queried, wherein the database identifier refers to 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 further implemented:
setting a database address identifier into a thread local variable corresponding to the data query request; receiving database connection sent by a preset data source management software framework, wherein the database connection is one database connection obtained by the preset data source management software framework after acquiring a database address identifier arranged 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 managing the corresponding data source in charge; and using the database connection as a target database connection corresponding to the database address identification.
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 a database connection obtained by the preset data source management software framework from a plurality of data sources pre-stored in a memory and corresponding to a database address identifier after acquiring the database address identifier set in a thread local variable, and when the database connection is obtained from a plurality of database connections responsible for management of the corresponding data sources, further implementing the following steps:
and receiving database connection sent by the preset data source management software framework, wherein the database connection is one obtained from a plurality of database connections responsible for management of the data source corresponding to the database address identification after the preset data source management software framework acquires the database address identification arranged in the thread local variable, judging whether the data source corresponding to the database address identification exists in a plurality of data sources prestored in a memory, or newly creating the data source corresponding to the database address identification in the memory after the data source corresponding to the database address identification is determined to exist in the memory, and obtaining one database connection from a plurality of database connections responsible for management of 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 sending the data query command 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 identifier into the data query command to obtain an edited data query command; and sending the edited data query command to the target database corresponding to the database address identifier through the target database connection.
In one embodiment, when the processor executes the computer program, after sending 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 is data obtained from database storage data corresponding to the database mode identifier stored in the target database after the target database analyzes the edited data query command to obtain the database mode identifier 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 data information to be queried associated with the data query request; determining a database address identifier corresponding to the data information to be queried 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 the target database corresponding to the database address identifier through the target database connection.
In one embodiment, the computer program is executed by the processor to perform the further steps of, prior to determining the database address identification 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 a remote support server in response to a 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 the processor to determine a database address identification corresponding to the data information to be queried, further implementing the steps of:
determining a database identifier corresponding to the data information to be queried, wherein the database identifier refers to 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 the 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 a database address identifier into a thread local variable corresponding to the data query request; receiving database connection sent by a preset data source management software framework, wherein the database connection is one database connection obtained by the preset data source management software framework after acquiring a database address identifier arranged 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 managing the corresponding data source in charge; and using the database connection as a target database connection corresponding to the database address identification.
In one embodiment, the computer program is executed by the processor, and the database connection sent by the preset data source management software framework is received, where the database connection is a database connection obtained by the preset data source management software framework from a plurality of data sources pre-stored in the memory and corresponding to the database address identifier after acquiring the database address identifier set in the thread local variable, and the following steps are further implemented when the database connection is obtained from a plurality of database connections responsible for management of the corresponding data source:
and receiving database connection sent by the preset data source management software framework, wherein the database connection is one obtained from a plurality of database connections responsible for management of the data source corresponding to the database address identification after the preset data source management software framework acquires the database address identification arranged in the thread local variable, judging whether the data source corresponding to the database address identification exists in a plurality of data sources prestored in a memory, or newly creating the data source corresponding to the database address identification in the memory after the data source corresponding to the database address identification is determined to exist in the memory, and obtaining one database connection from a plurality of database connections responsible for management of 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 sending a data query command to a target database corresponding to the database address identifier through the target database connection, the following steps are also implemented:
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 the target database corresponding to the database address identifier through the target database connection.
In one embodiment, when the computer program is executed by the processor, after sending 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 is data obtained from database storage data corresponding to the database mode identifier stored in the target database after the target database analyzes the edited data query command to obtain the database mode identifier and the data query command.
Those skilled in the art will appreciate that implementing all or part of the above described methods may be accomplished by way of a computer program stored on a non-transitory computer readable storage medium, which when executed, may comprise the steps of the embodiments of the methods described above. Any reference to memory, storage, database, or other medium used in the various embodiments provided herein may include non-volatile and/or volatile memory. The nonvolatile 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), memory bus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), among others.
The technical features of the above embodiments may be arbitrarily combined, and all possible combinations of the technical features in the above embodiments are not described for brevity of description, however, as long as there is no contradiction between the combinations of the technical features, they should be considered as the scope of the description.
The above examples merely represent a few embodiments of the present application, which are described in more detail and are not to be construed as limiting the scope of the invention. It should be noted that it would be apparent to those skilled in the art that various modifications and improvements could be made without departing from the spirit of the present application, which would be within the scope of the present application. Accordingly, the scope of protection of the present application is to be determined by the claims appended hereto.

Claims (9)

1. A database access method based on Spring framework is characterized by comprising the following steps:
responding to a data query request, and acquiring data information to be queried associated with the data query request;
determining a database address identifier corresponding to the data information to be queried 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;
transmitting the data query command to a target database corresponding to the database address identifier through the target database connection;
the obtaining, by the preset data source management software framework, the target database connection corresponding to the database address identifier includes:
setting the database address identifier into a thread local variable corresponding to the data query request;
receiving database connection sent by a preset data source management software framework, wherein the database connection is one database connection obtained by the preset data source management software framework from a plurality of data sources pre-stored in a memory and corresponding to the database address identification after acquiring the database address identification arranged in the thread local variable;
and using the database connection as a target database connection corresponding to the database address identifier.
2. The Spring framework-based database access method as claimed in claim 1, wherein said determining a 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 of claim 2, wherein the determining the database address identifier corresponding to the data information to be queried comprises:
determining a database identifier corresponding to the data information to be queried, wherein the database identifier refers to 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 Spring frame-based database access method as claimed in claim 1, wherein said receiving a database connection sent by a preset data source management software frame, said database connection being a database connection obtained by said preset data source management software frame after acquiring a database address identifier set in said thread local variable, determining a data source corresponding to said database address identifier from a plurality of data sources pre-stored in a memory, and from a plurality of database connections responsible for management of said corresponding data source, comprises:
And receiving a database connection sent by a preset data source management software framework, wherein the database connection is one obtained from a plurality of database connections responsible for management of the data source corresponding to the database address identification after the preset data source management software framework acquires the database address identification arranged in the thread local variable, judging whether the data source corresponding to the database address identification exists in a plurality of data sources prestored in a memory, or newly creating the data source corresponding to the database address identification in the memory and obtaining one database connection from a plurality of database connections responsible for management of the newly created data source after determining that the data source corresponding to the database address identification does not exist in the memory.
5. The Spring frame-based database access method of claim 1, wherein the query information corresponding to the database address identifier further comprises a database mode 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 target database connection.
6. The Spring framework-based database access method as claimed in claim 5, wherein said sending the edited data query command to the target database corresponding to the database address identifier through the target database connection, and then comprises:
and receiving target query data fed back by the target database, wherein the target query data is data obtained from database storage data corresponding to the database mode identifier stored in the target database after the target database analyzes the edited data query command to obtain the database mode identifier and the data query command, and executing the data query command.
7. A Spring framework-based database access device, comprising:
the data query module is used for responding to the data query request and acquiring data information to be queried 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 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;
the command sending module is used for sending the data query command to a target database corresponding to the database address identifier through the target database connection;
a database connection acquisition module comprising:
the identification setting sub-module is used for setting the database address identification into the thread local variable corresponding to the data query request;
the database connection receiving sub-module is used for receiving the database connection sent by the preset data source management software framework, wherein the database connection is one database connection obtained from a plurality of database connections which are responsible for management of the corresponding data sources and 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 the database connection determination submodule is used for taking the database connection as a target database connection corresponding to the database address identification.
8. 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 processor implements the steps of the method according to any one of claims 1 to 6 when the computer program is executed by the processor.
9. A computer readable storage medium, on which a computer program is stored, characterized in that the computer program, when being executed by a processor, implements the steps of the method of any of claims 1 to 6.
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 CN111309785A (en) 2020-06-19
CN111309785B true 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)

Families Citing this family (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
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
CN116244361B (en) * 2022-12-23 2023-10-10 北京柏睿数据技术股份有限公司 Method and system for dynamic persistence processing of database connection
CN117539949B (en) * 2024-01-10 2024-04-12 腾讯科技(深圳)有限公司 Processing method and device of database access request, electronic equipment and storage medium

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
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

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20110214165A1 (en) * 2010-02-26 2011-09-01 David Kerr Jeffreys Processor Implemented Systems And Methods For Using Identity Maps And Authentication To Provide Restricted Access To Backend Server Processor or Data

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
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框架设计与实现.软件导刊.2019,(05),全文. *
张少应 ; 陈庆荣 ; .基于Spring的数据库访问技术研究.信息技术.2016,(10),全文. *

Also Published As

Publication number Publication date
CN111309785A (en) 2020-06-19

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
CN108197200B (en) Log tracking method and device, computer equipment and storage medium
CN111930780B (en) Data query method and system
CN111464615B (en) Request processing method, device, server and storage medium
CN109032824A (en) Database method of calibration, device, computer equipment and storage medium
CN109379398B (en) Data synchronization method and device
CN110555041A (en) Data processing method, data processing device, computer equipment and storage medium
CN105100051A (en) Method and system for realizing data resource access right control
CN111708586B (en) Application starting configuration item loading method and device, computer equipment and storage medium
CN109460252B (en) Configuration file processing method and device based on git and computer equipment
CN109358874B (en) Business rule updating method, business rule updating device, computer equipment and storage medium
CN112100152A (en) Service data processing method, system, server and readable storage medium
CN112148699B (en) Log management method, device, equipment and medium
CN112866339B (en) Data transmission method and device, computer equipment and storage medium
CN112434037A (en) Data processing method, processing device, data processing apparatus, and storage medium
CN110543465B (en) Directory operation method and device, 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
CN110389966B (en) Information processing method and device
CN113779326A (en) Data processing method, device, system and storage medium
CN112783866A (en) Data reading method and device, computer equipment and storage medium
CN113127549B (en) Incremental data synchronization method, device, computer equipment and storage medium
CN116302206B (en) Presto data source hot loading method based on MQ
CN111488545B (en) Method, device, computer equipment and storage medium for managing network request cookie

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