Data transaction processing method and device, computer device and storage medium
Patent Information
- Application Number
- CN202310629101.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-30
- Publication Date
- 2026-09-18
- Estimated Expiration
- 2043-05-30
AI Technical Summary
[0005]然而,发明人发现,这种方式将会导致每次处理一个业务数据时,均需开启所有的数据库,导致无效占用过多的数据库连接的情况发生,造成降低多数据库的性能的情况发生
[0053]This application provides a data transaction processing method, apparatus, computer equipment, and storage medium that intercepts business data through a Spring JDBC component, so that proxy transaction information can be obtained subsequently based on the business data, thereby avoiding the Spring JDBC component from directly starting all databases in the data cluster based on the business data.
Smart Images

Figure CN116644122B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of big data technology, and in particular to a data transaction processing method, apparatus, computer equipment, and storage medium. Background Technology
[0002] Relational databases are inherently prone to becoming system bottlenecks due to limitations in single-machine storage capacity, connection count, and processing power. When the data volume in a single table reaches a certain order of magnitude, even database optimization alone cannot meet performance requirements. Therefore, current solutions utilize database sharding and table partitioning to divide business data and distribute it across multiple databases. This reduces the burden on individual databases, thereby improving performance. Database sharding and table partitioning is a horizontal partitioning solution that effectively alleviates performance bottlenecks and pressures caused by single machines and single databases, overcoming bottlenecks in network I / O, hardware resources, and connection count. It involves partitioning data based on a specific field using strategies such as hashing or range analysis, splitting a single set of data into multiple parts and storing them across multiple databases or tables. This addresses performance bottlenecks caused by excessively large single-database volumes and high concurrency, improving system stability and load capacity.
[0003] For database access layer transaction processing, Spring JDBC's declarative transactions have become the de facto standard. However, in Spring Boot's autowiring mode, Spring JDBC's declarative transaction management only supports single-database transactions; that is, the database connection is obtained and the transaction is started before the business logic begins. In scenarios with multiple databases created based on sharding and table partitioning, Spring JDBC cannot locate the database the business logic will access and therefore cannot start the corresponding transaction.
[0004] To achieve multi-database transaction processing based on Spring JDBC, existing technologies use Spring JDBC to provide a transaction manager to open all databases, ensuring that business data processed by Spring JDBC can be processed in the target database, which is one of the multiple databases.
[0005] However, the inventors discovered that this approach would require opening all databases each time business data is processed, resulting in excessive unnecessary database connections being used and degrading the performance of multiple databases. Summary of the Invention
[0006] This application provides a data transaction processing method, apparatus, computer device, and storage medium to solve the problem that the current method of using Spring JDBC to provide a transaction manager to open all databases, in order to ensure that business data processed based on Spring JDBC can be processed in the target database, requires opening all databases every time business data is processed, resulting in excessive invalid database connections and reduced performance of multiple databases.
[0007] Firstly, this application provides a data transaction processing method based on Spring JDBC, applied to a data cluster having at least one database, the method comprising:
[0008] Invoke a Spring JDBC component to intercept business data;
[0009] The transaction manager in the Spring JDBC component is invoked to perform business processing on the business data according to the pre-set proxy database to obtain proxy transaction information, and the proxy transaction information is loaded into the pre-set proxy connection. The proxy transaction information defines the transaction context for processing business data in the database. The data processing includes: adding, deleting, modifying, and querying.
[0010] The pre-built Mybatis component is invoked to obtain the database name based on the business data, and the database in the data cluster corresponding to the database name is set as the real database, and the proxy connection with the proxy transaction information is associated with the database name;
[0011] The Mybatis component is invoked to create a real connection with the real database;
[0012] The proxy transaction information in the proxy connection is output to the real connection, and the real connection with the proxy transaction information is executed to process the data in the real database according to the proxy transaction information.
[0013] In the above solution, the step of calling the Spring JDBC component to intercept business data includes:
[0014] The Spring JDBC component is invoked to create annotations and interceptors associated with the annotations, wherein the annotations are the entry points for the Spring JDBC component to receive business data;
[0015] If the transaction manager is invoked, it will intercept a piece of business data received by the annotation through the interceptor.
[0016] In the above scheme, the step of calling the transaction manager in the Spring JDBC component to perform business processing on the business data based on the preset proxy database to obtain proxy transaction information includes:
[0017] The transaction manager is invoked to construct a proxy connection based on the proxy database, and the proxy connection is a communication connection with the proxy database;
[0018] The transaction manager is invoked to process the business data according to the preset business operation rules, thereby obtaining proxy transaction information.
[0019] In the above scheme, the step of calling the pre-built Mybatis component to obtain the database name based on the business data includes:
[0020] Call the mapping interface in the Mybatis component to extract business elements from the business data;
[0021] The database name of the business data is obtained by calculating the business elements according to the preset database sharding and table partitioning rules; or
[0022] A hash digest is obtained by performing a hash operation on the business elements, and the database name of the business data is obtained by calculating the hash digest according to a preset calculation rule.
[0023] In the above scheme, the step of calling the Mybatis component to create a real connection between the real database includes:
[0024] If it is determined that the Spring JDBC component generates proxy transaction information, then the transaction factory in the Mybatis component is called to generate a real transaction. The real transaction is used to commit, close, or roll back the transaction to the real database.
[0025] The transaction factory in the Mybatis component is invoked to create a real connection based on the real transaction. The real connection is a communication connection with the real database.
[0026] In the above scheme, the step of calling the transaction factory in the Mybatis component to generate a real transaction includes:
[0027] If the transaction factory determines that the type of the proxy transaction information is a commit type, it generates a real transaction for transaction commit based on the commit type.
[0028] If the transaction factory determines that the type of the proxy transaction information is a close type, it generates a real transaction for transaction closure based on the commit type.
[0029] If the transaction factory determines that the type of the proxy transaction information is a rollback type, it generates a real transaction for transaction rollback based on the commit type.
[0030] In the above scheme, the step of calling the transaction factory in the Mybatis component to create a real connection based on the real transaction includes:
[0031] The transaction factory extracts the database name from the real transaction and establishes a connection between the real database corresponding to the database name, or switches the connection to the real database.
[0032] The real transaction is loaded into the connection line to obtain a real connection, which is used to execute the real transaction on the real database.
[0033] In the above scheme, outputting the proxy transaction information in the proxy connection to the real connection includes:
[0034] Obtain the database name of the real database corresponding to the real connection, and obtain the proxy connection associated with the database name;
[0035] Extract proxy transaction information from the proxy connection and load the extracted proxy transaction information into the real connection.
[0036] In the above scheme, executing a real connection with the proxy transaction information includes:
[0037] The Spring JDBC component is invoked to access the real database through the real connection.
[0038] The Spring JDBC component is invoked to process the data in the real database corresponding to the proxy transaction information based on the proxy transaction information.
[0039] In the above solution, before calling the Spring JDBC component to intercept business data, the method further includes:
[0040] Start the Spring container for the Spring JDBC component and input the proxy database into the configuration file of the Spring container;
[0041] Configure the bean tag on the proxy database in the configuration file to define the bean in the transaction manager of the Spring JDBC component.
[0042] Secondly, this application provides a data transaction processing apparatus based on Spring JDBC, which connects to a data cluster having at least one database, the apparatus comprising:
[0043] The input interception module is used to call Spring JDBC components to intercept business data;
[0044] The transaction generation module is used to call the transaction manager in the Spring JDBC component to perform business processing on the business data according to the preset proxy database to obtain proxy transaction information, and load the proxy transaction information into the preset proxy connection. The proxy transaction information defines the transaction context for processing business data in the database. The data processing includes: adding, deleting, modifying, and querying.
[0045] The real identification module is used to call the pre-set Mybatis component to obtain the database name based on the business data, set the database in the data cluster corresponding to the database name as the real database, and associate the proxy connection with the proxy transaction information with the database name.
[0046] The connection building module is used to call the Mybatis component to create a real connection between the real database;
[0047] The transaction processing module is used to output the proxy transaction information in the proxy connection to the real connection, and execute the real connection with the proxy transaction information to process the data in the real database according to the proxy transaction information.
[0048] Thirdly, this application provides a computer device, including: a processor, and a memory communicatively connected to the processor;
[0049] The memory stores computer-executed instructions;
[0050] The processor executes computer execution instructions stored in the memory to implement the above method.
[0051] Fourthly, this application provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, are used to implement the above-described method.
[0052] Fifthly, this application provides a computer program product, including a computer program that, when executed by a processor, implements the above-described method.
[0053] This application provides a data transaction processing method, apparatus, computer equipment, and storage medium that intercepts business data through a Spring JDBC component, so that proxy transaction information can be obtained subsequently based on the business data, thereby avoiding the Spring JDBC component from directly starting all databases in the data cluster based on the business data.
[0054] By using the transaction manager in the Spring JDBC component to establish a proxy connection with the proxy database, the step of building a real connection with the database in the data cluster is skipped. Business data is processed, and proxy transaction information is obtained, avoiding the need to connect to all databases during business processing and thus preventing the unnecessary occupation of excessive database connections. The proxy transaction information is loaded into a pre-built proxy connection, which is used to virtualize the proxy connection as a real connection, so that the information in the proxy connection can be synchronized to the real connection later.
[0055] The Mybatis component performs logical processing on the business data according to the preset database sharding and table partitioning rules to obtain the database name, and sets the database corresponding to the database name in the data cluster as the real database, so as to achieve the technical effect of knowing the real database corresponding to the business data.
[0056] By establishing a real connection with a real database, a foundation is laid for subsequent data processing within the real database.
[0057] By using Spring JDBC components to output the proxy transaction information from the proxy connection to the real connection, the real connection is equipped with the foundation for performing data processing. By executing the real connection with the proxy transaction information, the effect of processing data in the real database based on business data can be achieved. Attached Figure Description
[0058] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0059] Figure 1 This is a structural diagram illustrating the application scenario of this application;
[0060] Figure 2 This is a flowchart of Embodiment 1 of a data transaction processing method according to this application;
[0061] Figure 3 This is a flowchart of Embodiment 2 of a data transaction processing method according to this application;
[0062] Figure 4 This is a block diagram of Embodiment 3 of a data transaction processing apparatus according to this application;
[0063] Figure 5 This is a schematic diagram of the hardware structure of the computer device in the computer device of the present invention.
[0064] The accompanying drawings illustrate specific embodiments of this application, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concept of this application to those skilled in the art through reference to particular embodiments. Detailed Implementation
[0065] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.
[0066] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use and processing of the relevant data must comply with relevant laws, regulations and standards, and corresponding operation entry points are provided for users to choose to authorize or refuse.
[0067] It should be noted that the data transaction processing method, apparatus, computer equipment, and storage medium of this application can be used in the field of big data technology, or in any field other than the field of big data technology. The application field of the data transaction processing method, apparatus, computer equipment, and storage medium of this application is not limited.
[0068] The specific application scenario for this application is as follows: Please refer to... Figure 1 A server 11 running a data transaction processing method based on Spring JDBC is connected to a data cluster 12 with at least one database 121. The server 11 is also connected to at least one client 13, which is used to send business data to the server 11.
[0069] Server 11 calls a Spring JDBC component to intercept business data.
[0070] Server 11 calls the transaction manager in the Spring JDBC component to perform business processing on the business data according to the pre-configured proxy database to obtain proxy transaction information, and loads the proxy transaction information into the pre-configured proxy connection. The proxy transaction information defines the transaction context for processing business data in the database. The data processing includes: add processing, and / or delete processing, and / or modify processing, and / or query processing.
[0071] Server 11 calls the pre-built Mybatis component to obtain the database name based on the business data, sets the database corresponding to the database name in the data cluster 12 as the real database 122, and associates the proxy connection with the proxy transaction information with the database name.
[0072] Server 11 calls the Mybatis component to create a real connection between the server and the real database 122.
[0073] Server 11 outputs the proxy transaction information in the proxy connection to the real connection and executes the real connection with the proxy transaction information to process the data in the real database 122 according to the proxy transaction information.
[0074] The data transaction processing method provided in this application allows for the sharing of a client's risk assessment information across the entire consortium blockchain once the client completes a single risk assessment. Furthermore, the application of big data technology ensures the immutability of the client's risk assessment, guaranteeing information accuracy and improving risk control efficiency. Due to the use of encryption technology, client information is difficult to leak or crack. This method aims to solve the aforementioned technical problems of existing technologies.
[0075] The technical solution of this application and how the technical solution of this application solves the above-mentioned technical problems are described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will now be described with reference to the accompanying drawings.
[0076] Example 1:
[0077] Please see Figure 2 This application provides a data transaction processing method based on Spring JDBC, applied to a data cluster with at least one database, the method comprising:
[0078] S201: Call a Spring JDBC component to intercept business data.
[0079] In this step, Spring's JDBC module provides a declarative transaction framework standard and implementation, and is responsible for database resource management and error handling. This greatly simplifies the database operations for developers, freeing them from tedious database operations and allowing them to devote more energy to writing business logic.
[0080] By intercepting business data through Spring JDBC components, it is possible to obtain proxy transaction information based on the business data later, thus avoiding the Spring JDBC components from directly starting all databases in the data cluster based on the business data.
[0081] In this embodiment, the business data is a declarative transaction. A declarative transaction declares the scope of the transaction through annotations, and all operations within that scope will be atomic.
[0082] In a preferred embodiment, invoking a Spring JDBC component to intercept business data includes:
[0083] The Spring JDBC component is invoked to create annotations and interceptors associated with the annotations. The annotations are the entry points for the Spring JDBC component to receive business data.
[0084] If the transaction manager is invoked, it can intercept business data received through the annotation via an interceptor.
[0085] For example, by setting the @Transactional annotation in the data cluster and associating an interceptor with the annotation, when the data cluster receives business data and runs the annotation, it directly calls the interceptor to intercept the business data, thus reducing code intrusion into the data cluster.
[0086] S202: The transaction manager in the Spring JDBC component is invoked to perform business processing on the business data according to the pre-configured proxy database to obtain proxy transaction information, and the proxy transaction information is loaded into the pre-configured proxy connection. The proxy transaction information defines the transaction context for processing business data in the database. The data processing includes: insert processing, and / or delete processing, and / or modify processing, and / or query processing.
[0087] In this step, because the transaction manager in the existing Spring JDBC component establishes connections with all databases in the data cluster before processing business data and obtaining proxy transaction information, the transaction manager ineffectively occupies too many database connections, resulting in reduced performance of multiple databases.
[0088] To address this, this step provides a proxy database, which is an abstract database object used to create proxy connections. The transaction manager in the Spring JDBC component establishes a proxy connection with this database, bypassing the step of building a real connection with the databases in the data cluster. Business data is processed, and proxy transaction information is obtained, avoiding the need to connect to all databases during business processing and thus preventing the unnecessary consumption of excessive database connections. By loading the proxy transaction information into a pre-built proxy connection, the proxy connection is virtualized as a real connection, facilitating the subsequent synchronization of information from the proxy connection to the real connection.
[0089] In this embodiment, Spring provides declarative transaction management based on AOP. No transaction management code needs to be written; it's ready to use after configuration, streamlining the traditional transaction management process and reducing the workload for developers to some extent. The transaction manager controls secure access to business data; for data modifications, either all modifications are executed, or none are executed. Proxy transaction information can be SQL statements used to process data in the database based on business data.
[0090] In a preferred embodiment, the transaction manager in the Spring JDBC component is invoked to perform business processing on the business data based on a pre-configured proxy database to obtain proxy transaction information, including:
[0091] The transaction manager is invoked to construct a proxy connection based on the proxy database. The proxy connection is a communication connection between the transaction manager and the proxy database.
[0092] The transaction manager is invoked to process the business data according to the preset business operation rules, and the proxy transaction information is obtained.
[0093] For example, business operation rules are computer rules for processing business data. For instance, if the business data is: ABCC transfers 1,000 yuan to BBAA, then the resulting proxy transaction information is: Operation Transaction 1 - ABCC's account decreases by 1,000 yuan, Operation Transaction 2 - BBAA's account increases by 1,000 yuan.
[0094] It should be noted that at least one transaction manager in the Spring JDBC components serves as a facade for the transaction implementation of a specific platform. Transaction managers include:
[0095] `DataSourceTransactionManager`: Located in the `org.springframework.jdbc.datasource` package, this is a database transaction manager that provides transaction management for individual `javax.sql.DataSource` instances, used for transaction management within the Spring JDBC abstraction framework, iBATIS, or MyBatis framework. `JdoTransactionManager`: Located in the `org.springframework.orm.jdo` package, this provides transaction management for individual `javax.jdo.PersistenceManagerFactory` instances, used for transaction management when integrating with the JDO framework. `JpaTransactionManager`: Located in the `org.springframework.orm.jpa` package, this provides transaction support for individual `javax.persistence.EntityManagerFactory` instances, used for transaction management when integrating with JPA implementation frameworks. `HibernateTransactionManager`: Located in the `org.springframework.orm.hibernate3` package, this provides transaction support for individual `org.hibernate.SessionFactory` instances, used for transaction management when integrating with the Hibernate framework. `JtaTransactionManager`: Located in the `org.springframework.transaction.jta` package, this provides support for distributed transaction management and delegates transaction management to Java. EE Application Server Transaction Manager; OC4JjtaTransactionManager: Located in the org.springframework.transaction.jta package, Spring provides an adapter for the OC4J 10.1.3+ application server transaction manager, which is used for support of advanced transactions provided by the application server; WebSphereUowTransactionManager: Located in the org.springframework.transaction.jta package, Spring provides an adapter for the WebSphere 6.0+ application server transaction manager, which is used for support of advanced transactions provided by the application server; WebLogicJtaTransactionManager: Located in the org.springframework.transaction.jta package, Spring provides an adapter for the WebLogic 8.0+ application server transaction manager.1. An adapter for the Application Server Transaction Manager, used to support advanced transactions provided by the application server.
[0096] S203: Call the pre-built Mybatis component to obtain the database name based on the business data, set the database corresponding to the database name in the data cluster as the real database, and associate the proxy connection with the proxy transaction information with the database name.
[0097] In this step, the Mybatis component performs logical processing on the business data according to pre-defined database sharding rules to obtain the database name, and sets the database corresponding to the database name in the data cluster as the real database, thus achieving the technical effect of knowing the real database corresponding to the business data. The Mybatis component is a component used to provide an ORM framework implementation for the database access layer, simplifying the mapping of database data to objects. ORM (Object Relational Mapping) is a technology designed to solve the mismatch between object-oriented programming and relational databases. The ORM framework acts as a bridge connecting the database; as long as the mapping relationship between persistent classes and tables is provided, the ORM framework can refer to the information in the mapping file at runtime to persist objects to the database.
[0098] In a preferred embodiment, a pre-built Mybatis component is invoked to obtain the database name based on business data, including:
[0099] Call the mapping interface in the Mybatis component to extract business elements from the business data;
[0100] The database name of the business data is obtained by calculating the business elements according to the preset database sharding and table partitioning rules; or
[0101] The business elements are hashed to obtain a hash digest, and the hash digest is calculated according to the preset calculation rules to obtain the database name of the business data.
[0102] For example, business elements are metadata that describes information in business data. Suppose the business elements are username and account. Based on the business elements, the following can be obtained from the business data: username: ABCC and username: BBAA, account of ABCC: M line N branch, and account of BBAA: P line Q branch.
[0103] By applying the database sharding and table partitioning rules to ABCC and M-line N-branch, database T1 is obtained, which stores the account data of ABCC in M-line N-branch. Similarly, by applying the database sharding and table partitioning rules to BBAA and P-line Q-branch, database T2 is obtained, which stores the account data of BBAA in P-line Q-branch.
[0104] Hash operations are computer algorithms that use hash algorithms to calculate hash digests from business elements. A hash algorithm maps a binary string of arbitrary length to a binary string of fixed length; the resulting binary string after mapping the original data is the hash value. In this embodiment, hash digest 1 is obtained by performing a hash operation on ABCC and line M, branch N; hash digest 2 is obtained by performing a hash operation on BBAA and line P, branch Q.
[0105] The database name corresponding to hash digest 1 is obtained by calculating the rules (e.g., a mapping table defining the mapping relationship between hash digests and database names): database T1; and the database name corresponding to hash digest 2 is obtained: database T2.
[0106] S204: Call the Mybatis component to create a real connection between the database and the actual database.
[0107] In this step, a real connection is established with the real database, laying the foundation for subsequent data processing in the real database.
[0108] In a preferred embodiment, invoking the Mybatis component to create a real connection between the real database includes:
[0109] If it is determined that the Spring JDBC component generates proxy transaction information, then the transaction factory in the Mybatis component is called to generate a real transaction. The real transaction is used to commit, close, or roll back the transaction to the real database.
[0110] The transaction factory in the Mybatis component is invoked to create a real connection based on the real transaction. The real connection is the communication connection between the real database and the real database.
[0111] For example, the proxy transaction information is: Operation Transaction 1 - ABCC account decreases by 1000 yuan, Operation Transaction 2 - BBAA account increases by 1000 yuan; the database storing ABCC's account data at M branch N is database T1, and the database storing BBAA's account data at P branch Q is database T2; the transaction factory generates real transactions that are committed in database T1 and in database T2 based on the proxy transaction information.
[0112] If ABCC requests a refund from BBAA, the generated proxy transaction information is: Operation Transaction 1 - ABCC account increases by 1000 yuan, Operation Transaction 2 - BBAA account decreases by 1000 yuan. Based on the above example, the transaction factory will generate a real transaction that rolls back the transaction "ABCC account decreases by 1000 yuan" in database T1. The transaction factory generates a real transaction that rolls back the transaction in database T1 and a real transaction that rolls back the transaction in database T2 based on the proxy transaction information.
[0113] If the transaction between ABCC and BBAA ends, based on the example above, the transaction factory will generate a real transaction that closes the transaction in database T1 and another real transaction that closes the transaction in database T2.
[0114] It should be noted that the transaction factory is either TransactionFactory, which is used to create transactions based on the database connection Connection through the provided main interface newTransaction(); or JdbcTransactionFactory, which is used to create JdbcTransaction transactions; or ManagedTransactionFactory, which is used to create ManagedTransaction transactions; or SpringManagedTransactionFactory, which is used to create SpringManagedTransaction transactions.
[0115] Furthermore, the transaction factory in the Mybatis component is invoked to generate a real transaction, including:
[0116] If the transaction factory determines that the type of the proxy transaction information is a commit type, it generates a real transaction that commits the transaction based on the commit type.
[0117] If the transaction factory determines that the type of the proxy transaction information is a close type, it generates a real transaction for transaction closure based on the commit type.
[0118] If the transaction factory determines that the type of the proxy transaction information is a rollback type, it generates a real transaction for transaction rollback based on the commit type.
[0119] For example, the types of proxy transaction information include commit type, close type, and rollback type. The type field in the proxy transaction information records the type of proxy transaction information. Based on the above example, if the proxy transaction information is: Operation Transaction 1 - ABCC account decreases by 1000 yuan, Operation Transaction 2 - BBAA account increases by 1000 yuan; the database storing ABCC's account data at branch N of bank M is database T1, and the database storing BBAA's account data at branch Q of bank P is database T2; the type field is commit type; the real transaction generated will represent the real transaction that commits the transaction "ABCC account decreases by 1000 yuan" in database T1, and the transaction factory will generate the transaction that commits the transaction "BBAA account increases by 1000 yuan" in database T2.
[0120] If the proxy transaction information is: Operation Transaction 1 - ABCC account decreases by 1000 yuan, Operation Transaction 2 - BBAA account increases by 1000 yuan; the database storing ABCC's account data at branch N of bank M is database T1, and the database storing BBAA's account data at branch Q of bank P is database T2; the field type is rollback type; the generated real transaction will represent the transaction rollback of "ABCC account increases by 1000 yuan" to "BBAA account decreases by 1000 yuan" in database T2.
[0121] If the proxy transaction information is: if the transaction between ABCC and BBAA ends, and the field type is closed, the generated real transaction will represent the real transaction of closing the ABCC account in database T1 and the BBAA account in database T2.
[0122] Furthermore, the transaction factory in the Mybatis component is invoked to create a real connection based on the actual transaction, including:
[0123] The transaction factory extracts the database name from the real transaction and establishes a connection between the database name and the real database, or switches the connection to the real database.
[0124] The real transaction is loaded into the connection line to obtain the real connection, which is used to execute the real transaction on the real database.
[0125] For example, since the JDBC driver's connection to the database is represented as an object, creating a database connection is also called creating a database connection object. To connect to the database, the transaction factory in the Mybatis component uses static methods in the DriverManager class of the driver to create a connection to the actual database. Commonly used methods include: `public static Connection getConnection(String url, String user, String password);` which creates a connection from the driver to the specified database URL. Here, `url` provides a way to identify the database, `user` is the username, and `password` is the password. `public static Driver getDriver(String url)` returns the driver for the database connection specified by `url`.
[0126] Based on the above example, the databases recorded in the real transaction include database T1 and database T2. Then, a connection is established with database T1 and database T2. The real transaction that commits "ABCC account decreases by 1000 yuan" in database T1 will be committed. The transaction factory will generate a transaction that adds "BBAA account increases by 1000 yuan" in database T2, and load the connection lines between database T1 and database T2 respectively.
[0127] S205: Output the proxy transaction information in the proxy connection to the real connection, and execute the real connection with the proxy transaction information to process the data in the real database according to the proxy transaction information.
[0128] In this step, the proxy transaction information in the proxy connection is output to the real connection through the Spring JDBC component, so that the real connection has the basis to perform data processing. By executing the real connection with proxy transaction information, the effect of processing the data in the real database according to the business data can be achieved.
[0129] For example, the proxy transaction information in the proxy connection is extracted, and a Statement interface object is created. The Statement interface object is called to load the proxy transaction information into the real connection. The proxy transaction information in the real connection is used to process the data in the real database (i.e., database T1 and database T2) (the ABCC account in database T1 is reduced by 1000 yuan, and the BBAA account in database T2 is increased by 1000 yuan).
[0130] In a preferred embodiment, outputting proxy transaction information from the proxy connection to the real connection includes:
[0131] Get the database name of the real database corresponding to the real connection, and get the proxy connection associated with the database name;
[0132] Extract proxy transaction information from the proxy connection and load the extracted proxy transaction information into the real connection.
[0133] For example, the database name is extracted, and the proxy connection associated with the database name is obtained to ensure that the proxy transaction information in the proxy connection can be accurately loaded into the corresponding real connection, thus ensuring the reliability and accuracy of the real connection.
[0134] In a preferred embodiment, executing a real connection with proxy transaction information includes:
[0135] Invoke Spring JDBC components to access the real database through a real connection;
[0136] The Spring JDBC component is invoked to process the data in the real database that corresponds to the proxy transaction information, based on the proxy transaction information.
[0137] For example, the Spring JDBC component outputs proxy transaction information to the real database through the Statement interface object, and runs the proxy transaction information in the real database to perform data processing on business data in the real database.
[0138] Example 2:
[0139] Please see Figure 3 This application provides a data transaction processing method based on Spring JDBC, applied to a data cluster with at least one database, the method comprising:
[0140] S301: Start the Spring container for the Spring JDBC component and input the proxy database into the Spring container's configuration file;
[0141] Configure the bean tag on the proxy database in the configuration file to define the bean in the transaction manager of the Spring JDBC component.
[0142] In this step, the Spring JDBC component is used to handle declarative transactions. Declarative transactions mean that you tell Spring which methods need Spring to manage transactions through configuration, such as through configuration files (XML) or annotations. Developers then only need to focus on the business logic, while Spring automatically handles the transaction management. For example, with annotations, simply adding the `@Transaction` annotation to a method will cause Spring to automatically start a transaction before the method executes and automatically commit or roll back the transaction after the method completes. There is no transaction-related code inside the method itself, making it very convenient to use.
[0143] The Spring container is the core of the Spring framework and is used to manage objects. The container creates objects, connects them, configures them, and manages their entire lifecycle from creation to destruction.
[0144] For example, beans can be defined in Spring JDBC components by configuring bean tags on the proxy database in the configuration file. The way beans are defined is declarative. Declarative can be understood as using a tag to identify relevant information, and the underlying code then performs a parsing process on these identifiers.
[0145] If the Spring container is started using an XML configuration file, then a bean can be defined in the XML configuration file using the `@Bean` annotation. For example, in the configuration class, the `@Bean` annotation can be used as the bean tag to define the bean in the transaction manager.
[0146] If you configure a bean tag on a configuration class in the configuration file, then use @Component and its similar annotations (@Controller, @Service, @Repository) to annotate the configuration class so that the configuration class can be injected into the Spring container as a bean.
[0147] S302: Call a Spring JDBC component to intercept business data.
[0148] This step is the same as S201 in Example 1, so it will not be described again here.
[0149] S303: The transaction manager in the Spring JDBC component is invoked to perform business processing on the business data according to the pre-configured proxy database to obtain proxy transaction information, and the proxy transaction information is loaded into the pre-configured proxy connection. The proxy transaction information defines the transaction context for processing business data in the database. The data processing includes: insert processing, and / or delete processing, and / or modify processing, and / or query processing.
[0150] This step is the same as S202 in Example 1, so it will not be described again here.
[0151] S304: Call the pre-built Mybatis component to obtain the database name based on the business data, set the database corresponding to the database name in the data cluster as the real database, and associate the proxy connection with the proxy transaction information with the database name.
[0152] This step is the same as S203 in Example 1, so it will not be described again here.
[0153] S305: Call the Mybatis component to create a real connection between the database and the actual database.
[0154] This step is the same as S204 in Example 1, so it will not be described again here.
[0155] S306: Output the proxy transaction information in the proxy connection to the real connection, and execute the real connection with the proxy transaction information to process the data in the real database according to the proxy transaction information.
[0156] This step is the same as S205 in Example 1, so it will not be described again here.
[0157] Example 3:
[0158] Please see Figure 4 This application provides a data transaction processing device 1 based on Spring JDBC, which connects to a data cluster having at least one database. The device includes:
[0159] Input interception module 42 is used to call a Spring JDBC component to intercept business data;
[0160] The transaction generation module 43 is used to call the transaction manager in the Spring JDBC component to perform business processing on business data according to the pre-set proxy database to obtain proxy transaction information, and load the proxy transaction information into the pre-set proxy connection. The proxy transaction information defines the transaction context for processing business data in the database. The data processing includes: adding, deleting, modifying, and querying.
[0161] The real identification module 44 is used to call the pre-built Mybatis component to obtain the database name based on the business data, set the database corresponding to the database name in the data cluster as the real database, and associate the proxy connection with the proxy transaction information with the database name.
[0162] The connection building module 45 is used to call the Mybatis component to create a real connection between the real database;
[0163] The transaction processing module 46 is used to output the proxy transaction information in the proxy connection to the real connection and execute the real connection with the proxy transaction information to process the data in the real database according to the proxy transaction information.
[0164] Optionally, the Spring JDBC-based data transaction processing appliance 1 also includes:
[0165] Configuration definition module 11 is used to start the Spring container of the Spring JDBC component, input the proxy database into the configuration file of the Spring container, and configure bean tags on the proxy database in the configuration file to define beans in the transaction manager of the Spring JDBC component.
[0166] Example 4:
[0167] Figure 5 This is a block diagram of a computer device according to an exemplary embodiment. The computer device 5 may be a control circuit in an information management system 1. The control circuit is implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field-programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components in the information management system, and is used to execute data transaction processing methods.
[0168] Specifically, computer device 5 includes: a processor 52 and a memory 51 communicatively connected to the processor 52; the memory stores computer-executed instructions;
[0169] The processor executes computer execution instructions stored in memory 51 to implement the aforementioned data transaction processing method. The components of the data transaction processing device can be distributed across different computer devices. Computer device 5 can be a smartphone, tablet, laptop, desktop computer, rack server, blade server, tower server, or cabinet server (including standalone servers or server clusters composed of multiple application servers), etc. The computer devices in this embodiment include, but are not limited to, memory 51 and processor 52, which can be interconnected via a system bus. Figure 5 As shown. It should be noted that, Figure 5 Only computer devices with components are shown; however, it should be understood that it is not required to implement all the components shown, and more or fewer components may be implemented instead. In this embodiment, memory 51 (i.e., readable storage medium) includes flash memory, hard disk, multimedia card, card-type memory (e.g., SD or DX memory), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, memory 51 may be an internal storage unit of the computer device, such as the hard disk or memory of the computer device. In other embodiments, memory 51 may also be an external storage device of the computer device, such as a plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, etc., provided on the computer device. Of course, memory 51 may also include both internal storage units and external storage devices of the computer device. In this embodiment, memory 51 is typically used to store the operating system and various application software installed on the computer device, such as the program code of the data transaction processing apparatus of Embodiment 3. In addition, the memory 51 can also be used to temporarily store various types of data that have been output or will be output. In some embodiments, the processor 52 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chip. The processor 52 is typically used to control the overall operation of the computer device. In this embodiment, the processor 52 is used to run program code stored in the memory 51 or process data, for example, to run a data transaction processing device to implement the data transaction processing method of the above embodiments.
[0170] The integrated modules implemented as software functional modules described above can be stored in a computer-readable storage medium. These software functional modules, stored in a storage medium, include several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) or processor to execute some steps of the methods of the various embodiments of this application. It should be understood that the processor may be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), etc. A general-purpose processor may be a microprocessor or any conventional processor. The steps of the methods disclosed in this application can be directly implemented by a hardware processor, or implemented by a combination of hardware and software modules in the processor. The memory may include high-speed RAM, and may also include non-volatile memory (NVM), such as at least one disk storage device, and may also be a USB flash drive, external hard drive, read-only memory, disk, or optical disk, etc.
[0171] To achieve the above objectives, this application also provides a computer-readable storage medium, such as flash memory, hard disk, multimedia card, card-type memory (e.g., SD or DX memory), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, disk, optical disk, server, App application store, etc., which stores computer-executable instructions, and the program implements the corresponding function when executed by processor 52. The computer-readable storage medium of this embodiment is used to store computer-executable instructions for implementing the data transaction processing method, and when executed by processor 52, it implements the data transaction processing method of the above embodiment.
[0172] The aforementioned storage medium can be implemented from any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk. The storage medium can be any available medium accessible to general-purpose or special-purpose computers.
[0173] An exemplary storage medium is coupled to a processor, enabling the processor to read information from and write information to the storage medium. Alternatively, the storage medium can be an integral part of the processor. Both the processor and the storage medium can reside in an Application Specific Integrated Circuit (ASIC). Alternatively, the processor and storage medium can exist as discrete components within a computer device or host device.
[0174] This application provides a computer program product, including a computer program that, when executed by a processor, implements the above-described data transaction processing method.
[0175] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0176] Other embodiments of this application will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of this application that follow the general principles of this application and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this application are indicated by the following claims.
[0177] It should be understood that this application is not limited to the precise structure described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this application is limited only by the appended claims.
Claims
1. A data transaction processing method based on Spring JDBC, characterized in that, Applied to a data cluster having at least one database, the method includes: Invoke a Spring JDBC component to intercept business data; The transaction manager in the Spring JDBC component is invoked to perform business processing on the business data based on a pre-defined proxy database to obtain proxy transaction information. This proxy transaction information is then loaded into a pre-defined proxy connection. The proxy transaction information defines the transaction context for processing business data in the database. This data processing includes: add processing, and / or delete processing, and / or modify processing, and / or query processing. The proxy database is an abstract database object used to create proxy connections. The proxy connection is the communication connection between the transaction manager and the proxy database, constructed based on the proxy database. The pre-built Mybatis component is invoked to obtain the database name based on the business data, and the database in the data cluster corresponding to the database name is set as the real database, and the proxy connection with the proxy transaction information is associated with the database name; The Mybatis component is invoked to create a real connection with the real database; The proxy transaction information in the proxy connection is output to the real connection, and the real connection with the proxy transaction information is executed to process the data in the real database according to the proxy transaction information.
2. The data transaction processing method according to claim 1, characterized in that, The process of intercepting business data using a Spring JDBC component includes: The Spring JDBC component is invoked to create annotations and interceptors associated with the annotations, wherein the annotations are the entry points for the Spring JDBC component to receive business data; If the transaction manager is invoked, it will intercept a piece of business data received by the annotation through the interceptor.
3. The data transaction processing method according to claim 1, characterized in that, The step of calling the transaction manager in the Spring JDBC component to perform business processing on the business data based on the pre-configured proxy database to obtain proxy transaction information includes: The transaction manager is invoked to process the business data according to the preset business operation rules, thereby obtaining proxy transaction information.
4. The data transaction processing method according to claim 1, characterized in that, The process of calling a pre-built Mybatis component to obtain the database name based on the business data includes: Call the mapping interface in the Mybatis component to extract business elements from the business data; The database name of the business data is obtained by calculating the business elements according to the preset database sharding and table partitioning rules; or The business elements are hashed to obtain a hash digest, and the hash digest is calculated according to a preset calculation rule to obtain the database name of the business data.
5. The data transaction processing method according to claim 1, characterized in that, The step of calling the Mybatis component to create a real connection between the real database includes: If it is determined that the Spring JDBC component generates proxy transaction information, then the transaction factory in the Mybatis component is invoked to generate a real transaction. The real transaction is used to commit, close, or roll back the transaction to the real database. The transaction factory in the Mybatis component is then invoked to create a real connection based on the real transaction. The real connection is the communication connection between the real database and the real database.
6. The data transaction processing method according to claim 5, characterized in that, Calling the transaction factory in the Mybatis component to generate a real transaction includes: If the transaction factory determines that the type of the proxy transaction information is a commit type, it generates a real transaction for transaction commit based on the commit type. If the transaction factory determines that the type of the proxy transaction information is a close type, it generates a real transaction for transaction closure based on the commit type. If the transaction factory determines that the type of the proxy transaction information is a rollback type, it generates a real transaction for transaction rollback based on the commit type.
7. The data transaction processing method according to claim 5, characterized in that, The step of calling the transaction factory in the Mybatis component to create a real connection based on the real transaction includes: The transaction factory extracts the database name from the real transaction and establishes a connection between the real database corresponding to the database name, or switches the connection to the real database. The real transaction is loaded into the connection line to obtain a real connection, which is used to execute the real transaction on the real database.
8. The data transaction processing method according to any one of claims 1-7, characterized in that, Outputting the proxy transaction information from the proxy connection to the real connection includes: Obtain the database name of the real database corresponding to the real connection, and obtain the proxy connection associated with the database name; Extract proxy transaction information from the proxy connection and load the extracted proxy transaction information into the real connection.
9. The data transaction processing method according to any one of claims 1-7, characterized in that, The execution of the real connection with the proxy transaction information includes: The Spring JDBC component is invoked to access the real database through the real connection. The Spring JDBC component is invoked to process the data in the real database corresponding to the proxy transaction information based on the proxy transaction information.
10. The data transaction processing method according to any one of claims 1-7, characterized in that, Before invoking the Spring JDBC component to intercept business data, the method further includes: Start the Spring container for the Spring JDBC component and input the proxy database into the configuration file of the Spring container; Configure the bean tag on the proxy database in the configuration file to define the bean in the transaction manager of the Spring JDBC component.
11. A data transaction processing device based on Spring JDBC, characterized in that, The apparatus, which connects to a data cluster having at least one database, includes: The input interception module is used to call Spring JDBC components to intercept business data; The transaction generation module is used to call the transaction manager in the Spring JDBC component to perform business processing on the business data according to the pre-set proxy database to obtain proxy transaction information, and load the proxy transaction information into the pre-set proxy connection. The proxy transaction information defines the transaction context for processing business data in the database, including: add processing, and / or delete processing, and / or modify processing, and / or query processing. The proxy database is an abstract database object used to create proxy connections. The proxy connection is the communication connection between the transaction manager and the proxy database, constructed based on the proxy database. The real identification module is used to call the pre-built Mybatis component to obtain the database name based on the business data, set the database in the data cluster corresponding to the database name as the real database, and associate the proxy connection with the proxy transaction information with the database name. The connection building module is used to call the Mybatis component to create a real connection between the real database; The transaction processing module is used to output the proxy transaction information in the proxy connection to the real connection, and execute the real connection with the proxy transaction information to process the data in the real database according to the proxy transaction information.
12. A computer device, characterized in that, include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory to implement the method as claimed in any one of claims 1 to 10.
13. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, are used to implement the method as described in any one of claims 1 to 10.
Citation Information
Patent Citations
Database access method, system and device and storage medium
CN111367983A