Database access management method and device, electronic equipment and storage medium
By obtaining and parsing database configuration information and persistent object interfaces, the service data is automatically routed to the target database, solving the problems of intrusiveness and coupling of database storage codes in the existing technology, and achieving lightweight service data storage processing.
Patent Information
- Application Number
- CN202311753447.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-19
- Publication Date
- 2025-06-20
AI Technical Summary
In the prior art, when using annotations to implement database storage, the code is highly invasive and complex in coupling, and business data adjustment requires adjustment of the data query statement and data source binding relationship, resulting in complex configuration.
By obtaining the pre-configured database configuration information, analyzing the persistent object interface to obtain SQL execution statements, querying the corresponding business data source from the database configuration information based on the sub-table information, and routing it to the target database to realize the sub-stock storage of business data.
It reduces the coupling complexity and intrusion of the code, realizes lightweight operations of business data partition processing, and reduces the configuration complexity during business data adjustment.
Smart Images

Figure CN120179726A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technologies, and in particular, to a database access management method, an apparatus thereof, an electronic device, and a storage medium. Background Art
[0002] With the popularization of the mobile Internet, a large amount of business data is generated during the process of applying mobile Internet services. This business data needs to be stored in a database for processing. However, due to the increase in business data, a single database is difficult to store all business data.
[0003] Therefore, in related technologies, mycat (a distributed database system), sharding-jbdc (a database sharding and table sharding framework), or mybatis-plus (a persistence layer framework) is used to store different business data in different databases, that is, to store business data in different databases. Among them, since the native mybatis-plus does not support the automatic database sharding function, it is usually necessary to rely on annotations to bind the data query statement and the corresponding data source. When executing the data query statement, the corresponding data source is determined according to the bound corresponding relationship, and then the business data is sent to the corresponding database according to the address information in the data source to achieve the storage of business data in different databases. However, when using annotations to achieve storage in different databases, due to the existence of annotations, the invasiveness of the code is relatively large. In addition, if the business data needs to be adjusted, the binding relationship between the data query statement and the corresponding data source needs to be adjusted, resulting in a very complex coupling of the code. Summary of the Invention
[0004] In view of this, embodiments of the present application provide a database access management method, an apparatus thereof, an electronic device, and a storage medium to solve or alleviate the problems existing in the prior art.
[0005] According to a first aspect of an embodiment of the present application, there is provided a database access management method, including: obtaining database configuration information, where the database configuration information includes a mapping relationship between each business data source and each sub-table information of the database; obtaining a persistent object interface, and parsing the persistent object interface to obtain an SQL execution statement for an access operation, where the persistent object interface is pre-configured to perform an access operation on the database based on a request of a business object, and the access operation includes one of data addition, data deletion, data modification, and data query in the database; querying, from the database configuration information, a business data source corresponding to the sub-table information based on the sub-table information in the SQL execution statement; and routing the business data source to a target database.
[0006] In some embodiments of the present application, before obtaining the database configuration information, the database access management method further includes: obtaining a data source list of a configuration file; obtaining sub-table information corresponding to each business data source from the data source list based on a preset view table command; creating a mapping relationship between each business data source and each sub-table information of the database.
[0007] In some embodiments of the present application, the database access management method further includes: parsing a persistent object interface to obtain an SQL execution statement for an access operation; modifying the SQL execution statement based on sub-table attribute information of a target sub-table; writing the modified SQL execution statement back to the persistent object interface.
[0008] In some embodiments of the present application, the persistent object interface is configured to: after generating access operation parameters for the database, stop the access operation based on the access operation parameters, and after writing the modified SQL execution statement back to the persistent object interface, execute the access operation based on the SQL execution statement.
[0009] In some embodiments of the present application, routing the access operation to a target sub-table having a mapping relationship with a business object includes: determining, based on the mapping relationship, a target sub-table corresponding to the business object from multiple sub-tables of the database; determining connection parameters of the target sub-table from the connection parameters of the database; and routing the access operation parameters to an access interface of the database based on the connection parameters of the target sub-table.
[0010] In some embodiments of the present application, parsing the persistent object interface to obtain a business object for the access operation includes: receiving, by a callback function pre-configured in the persistent object interface, a business object returned by the persistent object interface call, and when the callback function is called, the persistent object interface stops the access operation based on the access operation parameters.
[0011] According to a second aspect of the embodiments of the present application, there is provided a database access configuration method, the method including: configuring a management component of a persistent object interface, the management component being used to execute the database access management method of any one of the above embodiments, the persistent object interface being pre-configured to perform an access operation on a database, the access operation including one of data addition, data deletion, data modification, and data query in the database; associating database configuration information with the management component, the database configuration information indicating a mapping relationship between each business data source and each sub-table information of the database.
[0012] According to a third aspect of the embodiments of the present application, a database access management device is provided. The device includes: a first acquisition module that acquires database configuration information, where the database configuration information includes the mapping relationship between each business data source and each sub-table information of the database; a second acquisition module that acquires a persistent object interface and parses the persistent object interface to obtain an SQL execution statement for an access operation, where the persistent object interface is pre-configured to perform an access operation on the database based on a request of a business object, and the access operation includes one of data addition, data deletion, data modification, and data query in the database; a query module that queries, based on the sub-table information in the SQL execution statement, the business data source corresponding to the sub-table information from the database configuration information; and a routing module that routes the business data source to a target database.
[0013] According to a fourth aspect of the embodiments of the present application, a database access configuration device is provided. The device includes: a first configuration module that configures a management component of the persistent object interface, where the management component is used to execute the database access management method of any one of the above embodiments, and the persistent object interface is pre-configured to perform an access operation on the database, and the access operation includes one of data addition, data deletion, data modification, and data query in the database; and a second configuration module that associates the database configuration information with the management component, where the database configuration information indicates the mapping relationship between each business data source and each sub-table information of the database.
[0014] According to a fifth aspect of the embodiments of the present application, an electronic device is provided, including: a processor, a memory, a communication interface, and a communication bus. The processor, the memory, and the communication interface complete communication with each other through the communication bus; the memory is used to store at least one executable instruction, and the executable instruction causes the processor to execute operations corresponding to the database access management method and the database access configuration method of any one of the above embodiments.
[0015] According to a sixth aspect of the embodiments of the present application, a computer storage medium is provided, on which a computer program is stored. When the program is executed by a processor, it implements the database access management method and the database access configuration method of any one of the above embodiments.
[0016] According to the database access management method, its device, electronic device, and storage medium provided by the embodiments of the present application, by acquiring pre-configured database configuration information and parsing the acquired persistent object interface to obtain an SQL execution statement for an access operation, and then querying, based on the sub-table information in the SQL execution statement, the business data source corresponding to the sub-table information from the database configuration information, and thus routing the business data to the target database according to the address information of the business data source, realizes the split storage of business data, reduces the coupling complexity and invasiveness of the code, and realizes the lightweight operation of the split database processing of business data. Brief Description of the Drawings
[0017] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings required for the description of the embodiments or the prior art. Obviously, the drawings in the following description are only some embodiments recorded in the embodiments of the present application. For those of ordinary skill in the art, other drawings can also be obtained based on these drawings.
[0018] Figure 1 It is a schematic flowchart of a database access management method according to an embodiment of the present application;
[0019] Figure 2 It is a schematic flowchart of a database access configuration method according to an embodiment of the present application;
[0020] Figure 3 It is a structural block diagram of a database access management device according to an embodiment of the present application;
[0021] Figure 4 It is a structural block diagram of a database access configuration device according to an embodiment of the present application;
[0022] Figure 5 It is a schematic structural diagram of an electronic device according to an embodiment of the present application. Detailed Description of the Embodiments
[0023] In order to enable those skilled in the art to better understand the technical solutions in the embodiments of the present application, the following will clearly and completely describe the technical solutions in the embodiments of the present application in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the embodiments of the present application, all other embodiments obtained by those of ordinary skill in the art shall fall within the scope protected by the embodiments of the present application.
[0024] The following further illustrates the specific implementation of the embodiments of the present application in conjunction with the drawings of the embodiments of the present application.
[0025] Figure 1 It is a schematic flowchart of a database access management method according to an embodiment of the present application. As Figure 1 shown, the method includes:
[0026] S11: Obtain database configuration information, where the database configuration information includes the mapping relationship between each business data source and each sub-table information of the database.
[0027] The business data source defines the path to connect to the database and how to connect to the database. One database can correspond to multiple data sources. Each sub-table information includes specific content in the table, table name, and other information.
[0028] It can be understood that as the number of business scenarios increases, the complexity of business data also gradually grows. It is difficult for a single database to store all business data. Therefore, through database sharding and table partitioning operations, the business data written by write operations is sliced to store different business data in different databases. For example, the native mybatis-plus relies on annotations to bind the data query statement (SQL statement) and the corresponding data source, so that when the SQL statement is executed, the corresponding data source can be determined according to the bound correspondence, and then the business data can be sent to the corresponding database according to the address information in the data source to achieve the sharded storage of business data. If the business data needs to be adjusted during the application process, then the annotations in the code also need to be rewritten according to the adjustment of the business data. Using this method will make the coupling of the code very complex.
[0029] In addition, if mybatis-plus is used in the project, then the annotations provided by mybatis-plus or the base class must be used. Otherwise, it will be difficult to ensure the functions of mybatis-plus, making the native mybatis-plus have strong invasiveness and complex coupling, resulting in a high configuration complexity when using this mybatis-plus framework.
[0030] Therefore, by pre-setting the database configuration information composed of the mapping relationships between each business data source and each sub-table information of the database, it is possible to automatically match the business data source corresponding to each sub-table through this mapping relationship in the future, and then route the business data to the corresponding database according to this business data source.
[0031] S12: Obtain the persistent object interface and parse the persistent object interface to obtain the SQL execution statement for the access operation. Among them, the persistent object interface is pre-configured to perform access operations on the database, and the access operation includes one of data addition, data deletion, data modification, and data query in the database.
[0032] Specifically, the persistent object interface can be the Mapper interface. The Mapper interface is the interface for database operations. Its methods correspond to SQL statements. By calling the methods in the Mapper interface, the SQL statements can be indirectly executed to achieve access operations on the database. That is to say, the Mapper interface decouples the program from database operations. When writing code, there is no need to directly write SQL statements. Just calling the methods in the Mapper interface can perform access operations on the database.
[0033] The Mapper interface performs database access operations, including data addition, deletion, modification, and query in the database. Among them, for data addition, deletion, modification, and query operations, corresponding tags are usually added to the SQL mapping file of the Mapper interface to write SQL statements. The SQL mapping file contains the SQL statements for performing database operations and the mapping relationship between the SQL statements and business objects.
[0034] It can be understood that the persistent object interface is the interface for database operations. When the persistent object interface performs access operations on the database, corresponding SQL execution statements are written according to each access operation performed on the business data. Therefore, by parsing the persistent object interface, the SQL execution statements for performing access operations on the database can be obtained.
[0035] S13: Based on the sharding table information in the SQL execution statement, query the business data source corresponding to the sharding table information from the database configuration information.
[0036] It can be understood that each SQL execution statement includes table name information (sharding table information). Therefore, after obtaining the SQL execution statement, parsing it can obtain the table name information. Furthermore, the corresponding business data source can be queried from the mapping relationship between the business data sources and sharding table information in the database configuration information, so as to automatically route the business data to the corresponding target database.
[0037] Compared with the native mybatis-plus that relies on annotations to bind the SQL execution statement and the corresponding data source to force the routing of business data to the database specified by the pre-set data source, this application does not need to rely on annotations. It can query the business data source corresponding to the sharding table information from the database configuration information according to the sharding table information in the SQL execution statement, so as to automatically match the database corresponding to the business data, reducing the coupling of the code.
[0038] S14: Route the business data source to the target database.
[0039] It can be understood that the database configuration information includes the mapping relationship between each business data source and each sharding table information of the database, that is, there is a corresponding mapping relationship between the business data source and the sharding table. For example, business data source A corresponds to sharding table a, and business data source B corresponds to sharding table b. Sharding table a and sharding table b may be stored in the same database or in different databases. After parsing the SQL execution statement, the sharding table information corresponding to this SQL statement can be obtained. Further, according to the database configuration information, the business data source corresponding to the sharding table information can be determined, and then the address information of the business data source is used to route the business data to the target database. In this way, the sharding storage of business data can be realized.
[0040] In addition, this application does not need to rely on annotations to determine the target database corresponding to each business object. Compared with specifying the target database corresponding to the business data source in the business data in the annotation when writing code, it can reduce the coupling complexity and invasiveness of the code and achieve lightweight operation of business data sub-database processing.
[0041] According to the database access management method of the embodiments of this application, by obtaining the pre-configured database configuration information and parsing the obtained persistent object interface, the SQL execution statement for the access operation is obtained. Then, based on the sub-table information in the SQL execution statement, the business data source corresponding to the sub-table information is queried from the database configuration information. Thus, according to the address information of the business data source, the business data is routed to the target database, realizing the sub-database storage of business data, reducing the coupling complexity and invasiveness of the code, and achieving lightweight operation of business data sub-database processing.
[0042] In some embodiments, before obtaining the database configuration information, the database access management method further includes: obtaining the data source list of the configuration file; obtaining the sub-table information corresponding to each business data source from the data source list based on a preset table viewing command; creating a mapping relationship between each business data source and the sub-table information of the database.
[0043] Specifically, to reduce the strong invasiveness and complex coupling of the native mybatis-plus framework, this application is based on the mybatis-plus framework. When the project starts, it loads the data source list in the configuration file to obtain multiple business data sources. Further, through the table viewing command show table, the table names corresponding to each business data source are obtained from the data source list. Then, through threads, a mapping relationship between each business data source and the table name is established and stored in memory as the database configuration information for subsequent determination of the corresponding business data source according to the sub-table information in the SQL execution statement. Thus, according to the business data source, the business data is automatically routed to the target database without much concern about the positions of each sub-table in the database.
[0044] In some embodiments, the database access management method further includes: parsing the persistent object interface to obtain the SQL execution statement for the access operation; modifying the SQL execution statement based on the sub-table attribute information of the target sub-table; writing the modified SQL execution statement back to the persistent object interface.
[0045] Specifically, as a structured query language, SQL statements are mainly used to access and process databases. Common execution operations of SQL execution statements include: data addition, data deletion, data modification, and data query. Among them, the SQL statement for executing data query operations is the SELECT statement, which is used to query data from a table, and the query results are stored in the result table; the SQL statement for executing data addition operations is the INSERT INTO statement, which is used to insert new data rows into a table; the SQL statement for executing data modification operations is the UPDATE statement, which is used to modify data in a table; the SQL statement for executing data deletion operations is the DELETE statement, which is used to delete data rows in a table.
[0046] The basic stages for the server process to handle the execution of SQL statements are parsing, execution, and returning results. By parsing the persistent object interface, the SQL execution statement for the access operation is obtained, and the syntax and semantics of the SQL execution statement are parsed to generate an execution plan for the SQL execution statement. Then, the server process executes the SQL execution statement according to the execution plan of the SQL execution statement and returns the execution results to the server process during the execution stage.
[0047] It can be understood that each SQL execution statement includes table name information (sub-table information). Therefore, after obtaining the SQL execution statement, parsing it can obtain the table name information. When the sub-table attribute information of the target sub-table needs to be adjusted, it can be considered that the business data source corresponding to the sub-table information has also changed. At this time, modify the SQL execution statement to ensure the accuracy of the table name information in each SQL execution statement, and write the modified SQL execution statement back to the persistent object interface for subsequent parsing of the persistent object interface to obtain the SQL execution statement for the access operation.
[0048] In this way, when the business data changes, the updated table name information can be determined by parsing the SQL execution statement formed by the business data, and then the database corresponding to the business data can be updated according to the mapping relationship between the business data source and the sub-table in the business data, reducing the coupling of the code.
[0049] In some embodiments, the persistent object interface is configured to: after generating the access operation parameters for the database, stop the access operation based on the access operation parameters, and after writing the modified SQL execution statement back to the persistent object interface, execute the access operation based on the SQL execution statement.
[0050] It can be understood that when processing business data through the data addition, data deletion, data modification, and data query operation methods in the persistent object interface, it still needs to rely on annotations, and the business data is forced to be routed to a preset database through the annotations.
[0051] The solution of this application is to establish a mapping relationship between the business data source in the business data and each sub-table through the pre-set database configuration information, so that when parsing the SQL execution statement of the access operation from the persistent object interface, the business data source corresponding to the sub-table information can be queried from the database configuration information based on the sub-table information in the SQL execution statement, and then according to the address information of the business data source, the business data is routed to the target database to realize the sub-library storage of the business data. Therefore, after generating the access operation parameters for the database, this application stops the access operation based on the access operation parameters, removes the dependence on annotations, and after writing the modified SQL execution statement back to the persistent object interface, performs the corresponding access operation based on the modified SQL execution statement.
[0052] It should be noted that stopping the access operation based on the access operation parameters can intercept the access operation performed by the persistent object interface on the database through an interceptor. The interceptor provided in Java (a programming language) provides non-system-level interception, and this interceptor is implemented based on the Java reflection mechanism.
[0053] In this way, by intercepting the access operation of the persistent object interface, the dependence on annotations is removed, and the logical complexity of the staff's operation of dividing the business data into databases is reduced.
[0054] In some embodiments, parsing the persistent object interface to obtain the SQL execution statement of the access operation includes: receiving the SQL execution statement returned by the callback function called by the persistent object interface. The callback function is pre-configured in the persistent object interface. When the callback function is called, the persistent object interface stops the access operation based on the access operation parameters.
[0055] Specifically, the callback function is a common programming technique. It can call a predefined function to process the result after the asynchronous operation is completed, and is usually used in scenarios such as processing events, performing asynchronous operations, or responding to user input, etc. It can decouple the relationship between different modules and make the code easier to maintain and expand. Therefore, this application calls the callback function through the persistent object interface to stop its access operation based on the access operation parameters. In this way, by using the callback function to intercept the access operation of the persistent object interface, the function of automatically dividing the business data into databases according to the sub-table information is realized, and the performance loss of the application program is reduced.
[0056] It can be understood that when obtaining the sub-table information in the SQL execution statement in the present application, it can be obtained through the entity (entity layer). There is a mapping relationship between the entity and the sub-table information, and the SQL execution statement is also generated based on the entity. Moreover, the present application can obtain the dynamic business data source corresponding to the sub-table information from the database configuration information through the sharding plug-in, and thus route the business data to the target database according to the address information of the business data source. In this way, different sub-table information can be obtained according to different SQL execution statements, and then different business data sources can be obtained, so as to automatically route different business data, and the learning cost of the code is relatively low, without the need to introduce a third-party jar package (a software package).
[0057] In addition, the present application uses a callback function to intercept the access operation of the persistent object interface, and the function of automatically dividing the database for business data according to the sub-table information can be configured to be closed according to actual needs, and there will be no impact on the project after closing, and it has a plug-in function.
[0058] Figure 2 It is a schematic flowchart of a database access configuration method according to an embodiment of the present application. As Figure 1 shown, the method includes:
[0059] S21: Configure the management component of the persistent object interface. The management component is used to execute the database access management method of any of the above embodiments. The persistent object interface is pre-configured to perform access operations on the database, and the access operations include one of data addition, data deletion, data modification, and data query in the database;
[0060] S22: Associate the database configuration information with the management component. The database configuration information indicates the mapping relationship between each business data source and each sub-table information of the database.
[0061] It can be understood that the management component can be the central component Service. The Service component can call the Mapper interface to perform operations such as data addition, data deletion, data modification, and data query on the database. By associating the database configuration information with the management component, the function of automatically dividing the database for business data according to the sub-table information can be executed according to the management component.
[0062] Figure 3 It is a structural block diagram of a database access management device according to an embodiment of the present application.
[0063] As Figure 3 shown, the database access management device 300 can execute Figure 1Database access management method, the database access management device 300 includes: a first acquisition module 301 that acquires database configuration information, where the database configuration information includes the mapping relationship between each business data source and each sub-table information of the database; a second acquisition module 302 that acquires a persistent object interface and parses the persistent object interface to obtain an SQL execution statement for an access operation, where the persistent object interface is pre-configured to perform an access operation on the database based on a request of a business object, and the access operation includes one of data addition, data deletion, data modification, and data query in the database; a query module 303 that queries, based on the sub-table information in the SQL execution statement, the business data source corresponding to the sub-table information from the database configuration information; and a routing module 304 that routes the business data source to the target database.
[0064] In some embodiments of the present application, before acquiring the database configuration information, the database access management method further includes: acquiring a data source list of a configuration file; obtaining, based on a preset view table command, the sub-table information corresponding to each business data source from the data source list; and creating a mapping relationship between each business data source and each sub-table information of the database.
[0065] In some embodiments of the present application, the database access management method further includes: parsing the persistent object interface to obtain an SQL execution statement for an access operation; modifying the SQL execution statement based on the sub-table attribute information of the target sub-table; and writing the modified SQL execution statement back to the persistent object interface.
[0066] In some embodiments of the present application, the persistent object interface is configured to: after generating access operation parameters for the database, stop the access operation based on the access operation parameters, and after writing the modified SQL execution statement back to the persistent object interface, perform the access operation based on the SQL execution statement.
[0067] In some embodiments of the present application, routing the access operation to a target sub-table having a mapping relationship with the business object includes: determining, based on the mapping relationship, the target sub-table corresponding to the business object from multiple sub-tables of the database; determining the connection parameters of the target sub-table from the connection parameters of the database; and routing the access operation parameters to the access interface of the database based on the connection parameters of the target sub-table.
[0068] In some embodiments of the present application, parsing the persistent object interface to obtain the business object of the access operation includes: receiving the business object returned by the callback function called by the persistent object interface, where the callback function is pre-configured in the persistent object interface, and when the callback function is called, the persistent object interface stops the access operation based on the access operation parameters.
[0069] The database access management device according to the embodiment of the present application obtains the pre-configured database configuration information, parses the obtained persistent object interface to obtain the SQL execution statement for the access operation, and then queries the business data source corresponding to the sub-table information from the database configuration information based on the sub-table information in the SQL execution statement. Thus, according to the address information of the business data source, the business data is routed to the target database, realizing the sub-library storage of the business data, reducing the coupling complexity and invasiveness of the code, and realizing the lightweight operation of the sub-database processing of the business data.
[0070] The database access management device of this embodiment is used to implement the corresponding database access management method in the foregoing multiple method embodiments, and has the beneficial effects of the corresponding method embodiments, which will not be elaborated here. In addition, the function implementation of each module in the database access management device of this embodiment can refer to the description of the corresponding part in the foregoing method embodiments, which will not be elaborated here either.
[0071] Figure 4 It is a structural block diagram of a database access configuration device according to an embodiment of the present application.
[0072] As Figure 4 shown, the database access configuration device 400 can execute Figure 2 the database access configuration method. The database access configuration device 400 includes: a first configuration module 401 that configures a management component for the persistent object interface, and the management component is used to execute the database access management method of any of the foregoing embodiments. The persistent object interface is pre-configured to perform an access operation on the database, and the access operation includes one of data addition, data deletion, data modification, and data query in the database; a second configuration module 402 that associates the database configuration information with the management component, and the database configuration information indicates the mapping relationship between each business data source and each sub-table information of the database.
[0073] The database access configuration device according to the embodiment of the present application obtains the pre-configured database configuration information, parses the obtained persistent object interface to obtain the SQL execution statement for the access operation, and then queries the business data source corresponding to the sub-table information from the database configuration information based on the sub-table information in the SQL execution statement. Thus, according to the address information of the business data source, the business data is routed to the target database, realizing the sub-library storage of the business data, reducing the coupling complexity and invasiveness of the code, and realizing the lightweight operation of the sub-database processing of the business data.
[0074] The database access configuration device of this embodiment is used to implement the corresponding database access configuration methods in the foregoing multiple method embodiments, and has the beneficial effects of the corresponding method embodiments, which will not be elaborated here. In addition, the implementation of the functions of each module in the database access configuration device of this embodiment can be referred to the description of the corresponding parts in the foregoing method embodiments, which will not be elaborated here either.
[0075] Figure 5 FIG. 4 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
[0076] As Figure 5 shown, the electronic device 500 may include: a processor 502, a memory 503, a communication interface 504, and a communication bus 505. The processor 502, the memory 503, and the communication interface 504 complete mutual communication through the communication bus 505. The memory 503 is used to store at least one executable instruction, and the executable instruction causes the processor 502 to perform the operations corresponding to the database access management method and the database access configuration method in any of the foregoing embodiments.
[0077] The processor 502 may be a central processing unit CPU, or a specific integrated circuit ASIC (Application Specific Integrated Circuit), or one or more integrated circuits configured to implement the embodiments of the present application. One or more processors included in the intelligent device may be of the same type of processor, such as one or more CPUs; or may be of different types of processors, such as one or more CPUs and one or more ASICs.
[0078] The memory 503, used to store programs, may include a high-speed RAM memory, and may also include a non-volatile memory, such as at least one disk memory.
[0079] Through the electronic device of this embodiment, by obtaining the pre-configured database configuration information and parsing the obtained persistent object interface, the SQL execution statement for the access operation is obtained. Then, based on the sub-table information in the SQL execution statement, the business data source corresponding to the sub-table information is queried from the database configuration information. Thus, according to the address information of the business data source, the business data is routed to the target database, realizing the split storage of business data, reducing the coupling complexity and invasiveness of the code, and realizing the lightweight operation of the split database processing of business data.
[0080] The embodiment of the present application also provides a computer storage medium, on which a computer program is stored, and when the program is executed by a processor, it implements the database access management method and the database access configuration method in any of the foregoing embodiments.
[0081] According to the storage medium provided by the embodiments of the present application, by obtaining pre-configured database configuration information and parsing the obtained persistent object interface, the SQL execution statement for the access operation is obtained. Then, based on the table sharding information in the SQL execution statement, the business data source corresponding to the table sharding information is queried from the database configuration information. Thus, according to the address information of the business data source, the business data is routed to the target database, realizing the split storage of business data, reducing the coupling complexity and invasiveness of the code, and realizing the lightweight operation of the split database processing of business data.
[0082] It should be noted that according to the needs of implementation, each component / step described in the embodiments of the present application can be split into more components / steps, or two or more components / steps or partial operations of the components / steps can be combined into new components / steps to achieve the purpose of the embodiments of the present application.
[0083] The above method according to the embodiments of the present application can be implemented in hardware, firmware, or be implemented as software or computer code that can be stored in a recording medium (such as a CD ROM, RAM, floppy disk, hard disk, or magneto-optical disk), or be implemented as computer code that is originally stored in a remote recording medium or a non-transitory machine-readable medium and downloaded through a network and will be stored in a local recording medium. Thus, the method described herein can be stored in such software processing on a recording medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware (such as an ASIC or FPGA). It can be understood that a computer, a processor, a microprocessor controller, or programmable hardware includes a storage component (such as RAM, ROM, flash memory, etc.) that can store or receive software or computer code. When the software or computer code is accessed and executed by the computer, the processor, or the hardware, the database access management method and the database access configuration method described herein are implemented. In addition, when a general-purpose computer accesses the code for implementing the database access management method and the database access configuration method shown herein, the execution of the code converts the general-purpose computer into a dedicated computer for executing the database access management method and the database access configuration method shown herein.
[0084] Those of ordinary skill in the art can realize that the units and method steps of each example described in combination with the embodiments disclosed herein can be implemented by electronic hardware, or by a combination of computer software and electronic hardware. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Professional technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the embodiments of the present application.
[0085] The above embodiments are only used to illustrate the embodiments of the present application, rather than limiting the embodiments of the present application. Those of ordinary skill in the relevant technical field can also make various changes and modifications without departing from the spirit and scope of the embodiments of the present application. Therefore, all equivalent technical solutions also belong to the scope of the embodiments of the present application. The patent protection scope of the embodiments of the present application shall be defined by the claims. The systems, devices or modules illustrated in the above embodiments can be specifically implemented by computer chips or entities, or by products with certain functions.
Claims
1. A database access management method, characterized in that, Including: Obtain database configuration information, where the database configuration information includes the mapping relationship between each business data source and each sub-table information of the database; Obtain a persistent object interface, and parse the persistent object interface to obtain an SQL execution statement for an access operation. Among them, the persistent object interface is pre-configured to perform an access operation on the database based on a request of a business object, and the access operation includes one of data addition, data deletion, data modification, and data query in the database; Based on the sub-table information in the SQL execution statement, query the business data source corresponding to the sub-table information from the database configuration information; Route the business data source to the target database.
2. The database access management method according to claim 1, characterized in that, Before obtaining the database configuration information, the method further includes: Obtain the data source list of the configuration file; Based on a preset table viewing command, obtain the sub-table information corresponding to each business data source from the data source list; Create a mapping relationship between each business data source and each sub-table information of the database.
3. The database access management method according to claim 1, characterized in that, The method further includes: Parse the persistent object interface to obtain the SQL execution statement for the access operation; Modify the SQL execution statement based on the sub-table attribute information of the target sub-table; Write the modified SQL execution statement back to the persistent object interface.
4. The database access management method according to claim 3, characterized in that, The persistent object interface is configured to: after generating access operation parameters for the database, stop the access operation based on the access operation parameters, and after writing the modified SQL execution statement back to the persistent object interface, execute the access operation based on the SQL execution statement.
5. The database access management method according to claim 4, characterized in that, Parsing the persistent object interface to obtain the SQL execution statement for the access operation includes: Receive the SQL execution statement returned by the persistent object interface calling a callback function. The callback function is pre-configured in the persistent object interface. When the callback function is called, the persistent object interface stops the access operation based on the access operation parameters.
6. A database access configuration method, characterized in that, Including: Configure a management component of the persistent object interface. The management component is used to execute the database access management method according to any one of claims 1-5. The persistent object interface is pre-configured to perform an access operation on the database, and the access operation includes one of data addition, data deletion, data modification, and data query in the database; Associate the database configuration information with the management component. The database configuration information indicates the mapping relationship between each business data source and each sub-table information of the database.
7. A database access management device, characterized in that, Including: A first acquisition module that acquires database configuration information, where the database configuration information includes the mapping relationship between each business data source and each sub-table information of the database; A second acquisition module acquires a persistence object interface and parses the persistence object interface to obtain an SQL execution statement for an access operation, where the persistence object interface is pre-configured to perform an access operation on the database based on a request of a business object, and the access operation includes one of data addition, data deletion, data modification, and data query in the database; A query module queries, based on the sharding information in the SQL execution statement, a business data source corresponding to the sharding information from the database configuration information; A routing module routes the business data source to a target database.
8. A database access configuration device, characterized in that, Comprising: A first configuration module configures a management component of the persistence object interface, and the management component is used to execute the database access management method according to any one of claims 1-5. The persistence object interface is pre-configured to perform an access operation on the database, and the access operation includes one of data addition, data deletion, data modification, and data query in the database; A second configuration module associates database configuration information into the management component, and the database configuration information indicates a mapping relationship between each business data source and each sharding information of the database; 9. An electronic device, comprising: A processor, a memory, a communication interface, and a communication bus, and the processor, the memory, and the communication interface complete communication with each other through the communication bus; The memory is used to store at least one executable instruction, and the executable instruction causes the processor to execute an operation corresponding to the method according to any one of claims 1-6.
10. A computer storage medium having a computer program stored thereon, and when the program is executed by a processor, it implements the method according to any one of claims 1-6.
Citation Information
Cited By
Target space-time position information persistence method
CN121561206A
