CN118210778A - Database operation method, apparatus, device, storage medium, and program product - Google Patents
Database operation method, apparatus, device, storage medium, and program product Download PDFInfo
- Publication number
- CN118210778A CN118210778A CN202410312708.4A CN202410312708A CN118210778A CN 118210778 A CN118210778 A CN 118210778A CN 202410312708 A CN202410312708 A CN 202410312708A CN 118210778 A CN118210778 A CN 118210778A
- Authority
- CN
- China
- Prior art keywords
- target
- database
- structured query
- storage process
- query statement
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000000034 method Methods 0.000 title claims abstract description 295
- 230000008569 process Effects 0.000 claims abstract description 100
- 230000004044 response Effects 0.000 claims abstract description 6
- 238000004590 computer program Methods 0.000 claims description 23
- 230000005856 abnormality Effects 0.000 claims description 12
- 230000015654 memory Effects 0.000 claims description 11
- 238000006243 chemical reaction Methods 0.000 claims description 9
- 230000002085 persistent effect Effects 0.000 claims description 9
- 230000005540 biological transmission Effects 0.000 claims description 8
- 238000001028 reflection method Methods 0.000 claims description 4
- 230000002452 interceptive effect Effects 0.000 claims description 2
- 238000011017 operating method Methods 0.000 abstract description 11
- 230000005012 migration Effects 0.000 description 29
- 238000013508 migration Methods 0.000 description 29
- 238000010586 diagram Methods 0.000 description 12
- 230000006870 function Effects 0.000 description 9
- 238000004891 communication Methods 0.000 description 8
- 230000003993 interaction Effects 0.000 description 7
- 238000012545 processing Methods 0.000 description 5
- 238000012986 modification Methods 0.000 description 4
- 230000004048 modification Effects 0.000 description 4
- 230000003287 optical effect Effects 0.000 description 3
- 235000010627 Phaseolus vulgaris Nutrition 0.000 description 2
- 244000046052 Phaseolus vulgaris Species 0.000 description 2
- 230000002159 abnormal effect Effects 0.000 description 2
- 238000005516 engineering process Methods 0.000 description 2
- 230000002688 persistence Effects 0.000 description 2
- 238000001514 detection method Methods 0.000 description 1
- 238000011161 development Methods 0.000 description 1
- 239000000835 fiber Substances 0.000 description 1
- 239000004973 liquid crystal related substance Substances 0.000 description 1
- 238000013507 mapping Methods 0.000 description 1
- 238000004806 packaging method and process Methods 0.000 description 1
- 230000002441 reversible effect Effects 0.000 description 1
- 239000004065 semiconductor Substances 0.000 description 1
- 239000000758 substrate Substances 0.000 description 1
- 230000009466 transformation Effects 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/21—Design, administration or maintenance of databases
- G06F16/214—Database migration support
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/24—Querying
- G06F16/242—Query formulation
- G06F16/2433—Query languages
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/24—Querying
- G06F16/245—Query processing
- G06F16/2455—Query execution
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Databases & Information Systems (AREA)
- Physics & Mathematics (AREA)
- Data Mining & Analysis (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Computational Linguistics (AREA)
- Mathematical Physics (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The present disclosure provides a database operating method, which may be applied to the technical field of computers and the technical field of financial science. The database operation method comprises the following steps: in response to receiving an instruction for operating the database, obtaining target stored procedure information according to the instruction, wherein the target stored procedure information comprises information of a target stored procedure for operating the database; determining a target execution method according to the target storage process information; generating a structured query statement according to the target execution method; and sending the structured query statement to the database. The present disclosure also provides a database operating apparatus, device, storage medium, and program product.
Description
Technical Field
The present disclosure relates to the field of computer technology and financial technology, and more particularly, to a database operating method, apparatus, device, medium, and program product.
Background
In the database migration process, data such as a data table in a source database and a storage process need to be migrated to a target database. In general, since the syntax and the function of different database systems are different, in the process of database migration, the data table and the storage process in the source database need to be modified according to the syntax and the function of the target database.
However, the above method has high migration cost, large workload and low efficiency for realizing data migration due to large data volume of the data table and the storage process.
Disclosure of Invention
In view of the foregoing, the present disclosure provides a database operating method, apparatus, device, medium, and program product.
According to a first aspect of the present disclosure, there is provided a database operating method comprising: in response to receiving an instruction for operating a database, obtaining target stored procedure information according to the instruction, wherein the target stored procedure information comprises information of a target stored procedure for operating the database; determining a target execution method according to the target storage process information; generating a structured query statement according to the target execution method; and sending the structured query statement to the database.
According to an embodiment of the present disclosure, the target stored procedure information includes a stored procedure package name, a stored procedure name, and an input parameter of the target stored procedure; the method for determining the target execution method to be executed by the database according to the target storage process information comprises the following steps: acquiring a storage object associated with the target storage process according to the storage process package name; and determining a target execution method for calling the database to execute target operation according to the storage object, the storage process name and the input parameter, wherein the target operation comprises adding, deleting, modifying or inquiring a target database table, and the target database table is a database table to be processed in the target storage process.
According to an embodiment of the present disclosure, the obtaining, according to the storage procedure package name, a storage object associated with the target storage procedure includes: and determining a storage object consistent with the target object name from the container of the application side execution framework by taking the storage process package name as the target object name.
According to an embodiment of the present disclosure, the determining a target execution method for calling the database to execute a target operation according to the storage object, the storage procedure name, and the input parameter includes: determining at least one execution method based on the storage object; and determining a target execution method from the at least one execution method according to the stored procedure name and the input parameter based on the reflection method.
According to an embodiment of the present disclosure, the generating a structured query statement according to the above target execution method includes: and converting the target execution method based on the storage object into a structured query statement corresponding to the target operation based on a persistent layer framework of the object conversion layer.
According to an embodiment of the present disclosure, the above method further includes: starting a target transaction before generating a structured query statement according to the target execution method; detecting an abnormality occurring in an application-side execution framework from the generation of the structured query sentence to the transmission of the structured query sentence to the database based on the target transaction; and performing rollback operation when abnormality of the application side execution frame is detected.
According to an embodiment of the present disclosure, the foregoing opening a target transaction before generating a structured query statement according to the foregoing target operation includes: starting a target transaction based on annotation information of the application side execution framework; or opening the target transaction through the interaction operation of the user and the application side execution framework.
A second aspect of the present disclosure provides a database operating apparatus, comprising: the acquisition module is used for responding to the received instruction for operating the database and acquiring target storage process information according to the instruction, wherein the target storage process information comprises information of a target storage process for operating the database; the determining module is used for determining a target execution method according to the target storage process information, wherein the target execution method is used for calling the database to execute target operation; the generation module is used for generating a structured query statement according to the target execution method; and the sending module is used for sending the structured query statement to the database.
A third aspect of the present disclosure provides an electronic device, comprising: one or more processors; and a memory for storing one or more programs, wherein the one or more programs, when executed by the one or more processors, cause the one or more processors to perform the database operating method.
A fourth aspect of the present disclosure also provides a computer-readable storage medium having stored thereon executable instructions that, when executed by a processor, cause the processor to perform the database operating method described above.
A fifth aspect of the present disclosure also provides a computer program product comprising a computer program which, when executed by a processor, implements the above database operating method.
According to the embodiment of the disclosure, the target operation which is the same as the stored process logic is obtained at the application side by extracting the stored process logic which needs to be realized in the database, and is converted into the structured query statement and then sent to the database, so that the direct interaction of the database is realized without depending on the stored process. Therefore, when the database migration is performed, a large number of storage processes are not required to be modified, the database migration cost is reduced, and the database migration efficiency is improved.
Drawings
The foregoing and other objects, features and advantages of the disclosure will be more apparent from the following description of embodiments of the disclosure with reference to the accompanying drawings, in which:
FIG. 1 schematically illustrates an application scenario diagram of a database operating method, apparatus, device, medium and program product according to an embodiment of the present disclosure;
FIG. 2 schematically illustrates a flow chart of a database operation method according to an embodiment of the present disclosure;
FIG. 3 schematically illustrates generating a structured query statement schematic in accordance with an embodiment of the disclosure;
FIG. 4 schematically illustrates a flow chart of a transaction control method according to an embodiment of the disclosure;
FIG. 5 schematically illustrates a database operating architecture diagram in accordance with a specific embodiment of the present disclosure;
FIG. 6 schematically illustrates a block diagram of a database operating apparatus according to an embodiment of the present disclosure; and
Fig. 7 schematically illustrates a block diagram of an electronic device adapted to implement a database operating method according to an embodiment of the disclosure.
Detailed Description
Hereinafter, embodiments of the present disclosure will be described with reference to the accompanying drawings. It should be understood that the description is only exemplary and is not intended to limit the scope of the present disclosure. In the following detailed description, for purposes of explanation, numerous specific details are set forth in order to provide a thorough understanding of the embodiments of the present disclosure. It may be evident, however, that one or more embodiments may be practiced without these specific details. In addition, in the following description, descriptions of well-known structures and techniques are omitted so as not to unnecessarily obscure the concepts of the present disclosure.
The terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the disclosure. The terms "comprises," "comprising," and/or the like, as used herein, specify the presence of stated features, steps, operations, and/or components, but do not preclude the presence or addition of one or more other features, steps, operations, or components.
All terms (including technical and scientific terms) used herein have the same meaning as commonly understood by one of ordinary skill in the art unless otherwise defined. It should be noted that the terms used herein should be construed to have meanings consistent with the context of the present specification and should not be construed in an idealized or overly formal manner.
Where a convention analogous to "at least one of A, B and C, etc." is used, in general such a convention should be interpreted in accordance with the meaning of one of skill in the art having generally understood the convention (e.g., "a system having at least one of A, B and C" would include, but not be limited to, systems having a alone, B alone, C alone, a and B together, a and C together, B and C together, and/or A, B, C together, etc.).
When data in a source database is migrated to a target database, the migration failure of the storage process can be caused because the storage process is not implemented in the target database in a peer-to-peer manner with the source database, and further the migration failure of the database is caused. And because the data volume of the storage process is large, the storage process is migrated in a mode of modifying the storage process, and the migration cost is high, the workload is large and the efficiency is low. Therefore, the application provides a storage process migration mode without modifying the storage process, and the database operation logic realized in the storage process is transferred to the application side framework realization, so that the modification of the storage process is avoided.
The embodiment of the disclosure provides a database operation method, which comprises the following steps: in response to receiving an instruction for operating the database, obtaining target stored procedure information according to the instruction, wherein the target stored procedure information comprises information of a target stored procedure for operating the database; determining a target execution method according to the target storage process information, wherein the target execution method is used for calling a database to execute target operation; generating a structured query statement according to the target execution method; and sending the structured query statement to the database.
Fig. 1 schematically illustrates an application scenario diagram of a database operation method according to an embodiment of the present disclosure.
As shown in fig. 1, an application scenario 100 according to this embodiment may include a first terminal device 101, a second terminal device 102, a third terminal device 103, a network 104, and a server 105. The network 104 is a medium used to provide a communication link between the first terminal device 101, the second terminal device 102, the third terminal device 103, and the server 105. The network 104 may include various connection types, such as wired, wireless communication links, or fiber optic cables, among others.
The user may interact with the server 105 via the network 104 using the first terminal device 101, the second terminal device 102, the third terminal device 103, to receive or send messages etc. Various communication client applications, such as a shopping class application, a web browser application, a search class application, an instant messaging tool, a mailbox client, social platform software, etc. (by way of example only) may be installed on the first terminal device 101, the second terminal device 102, and the third terminal device 103.
The first terminal device 101, the second terminal device 102, the third terminal device 103 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smartphones, tablets, laptop and desktop computers, and the like.
The server 105 may be a server providing various services, such as a background management server (by way of example only) providing support for websites browsed by the user using the first terminal device 101, the second terminal device 102, and the third terminal device 103. The background management server may analyze and process the received data such as the user request, and feed back the processing result (e.g., the web page, information, or data obtained or generated according to the user request) to the terminal device.
It should be noted that the database operation method provided in the embodiments of the present disclosure may be generally executed by the server 105. Accordingly, the database operating apparatus provided by the embodiments of the present disclosure may be generally provided in the server 105. The database operating method provided by the embodiments of the present disclosure may also be performed by a server or a server cluster that is different from the server 105 and is capable of communicating with the first terminal device 101, the second terminal device 102, the third terminal device 103, and/or the server 105. Accordingly, the database operating apparatus provided by the embodiments of the present disclosure may also be provided in a server or a server cluster that is different from the server 105 and is capable of communicating with the first terminal device 101, the second terminal device 102, the third terminal device 103, and/or the server 105.
It should be understood that the number of terminal devices, networks and servers in fig. 1 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
The database operation method of the disclosed embodiment will be described in detail below with reference to fig. 2 to 5 based on the scenario described in fig. 1.
Fig. 2 schematically illustrates a flowchart of a database operation method according to an embodiment of the present disclosure.
As shown in fig. 2, the database operations of this embodiment include operations S210 to S240.
In response to receiving an instruction for operating the database, target stored procedure information is acquired according to the instruction in operation S210.
According to embodiments of the present disclosure, instructions for operating a database may be generated based on flow execution instructions, for example, when the flow execution instructions are used to execute a transaction flow, the process of executing the transaction flow includes operating the database, and thus, instructions for operating the database need to be generated.
According to embodiments of the present disclosure, the operated database may be a target database after the database migration.
According to an embodiment of the present disclosure, the target stored procedure information includes information of a target stored procedure operating on the database. The target stored procedure information may include a package name, a stored procedure name, internal parameter information of the target stored procedure, and the like.
According to embodiments of the present disclosure, the target storage process may be a storage process that matches the source database prior to database migration. The target storage process can be used for acquiring data in a database, and can also be used for storing the data in the database.
In operation S220, a target execution method is determined according to the target storage procedure information.
According to the embodiments of the present disclosure, since the target storage procedure information can uniquely determine the target storage procedure for operating the database, the target execution method matched with the target storage procedure can be determined by the target storage procedure information.
According to the embodiment of the disclosure, since the target storage process is not implemented in the database in a peer-to-peer manner after the database is migrated, the same logic as that of the target storage process can be implemented by converting the target storage process into the target execution method having the same operation meaning as that of the target storage process and operating the database through the target execution method. Specifically, processing of the target storage procedure information can be added in the application side, the target storage procedure is converted into a target execution method, and the target storage procedure is replaced by the target execution method.
In operation S230, a structured query statement is generated according to the target execution method.
According to embodiments of the present disclosure, the structured query statement may be a statement written in the structured query language (Structured Query Language, SQL) that may be used to interact directly with the database.
According to the embodiment of the disclosure, the target execution method is converted into the structured query statement which can be directly identified by the database, and the database is operated through the structured query statement, so that interaction with the database does not need to depend on a target storage process, modification of the target storage process is not needed, database migration cost is reduced, and migration efficiency is improved.
In operation S240, the structured query statement is transmitted to the database.
According to embodiments of the present disclosure, a structured query statement may be sent to a database through an interface so that the database performs a target operation based on an operation instruction.
According to the embodiment of the disclosure, the target operation which is the same as the stored process logic is obtained at the application side by extracting the stored process logic which needs to be realized in the database, and is converted into the structured query statement and then sent to the database, so that the direct interaction of the database is realized without depending on the stored process. Therefore, when the database migration is performed, a large number of storage processes are not required to be modified, the database migration cost is reduced, and the database migration efficiency is improved.
Typically, the method of database operation prior to database migration includes: defining a target storage process; receiving an instruction for operating a database; compiling the stored procedure into a structured query statement through an application program interface (Java Database Connectivity, JDBC) according to the instruction; and calling the database to execute the structured query statement.
The target storage process may be defined using extensible markup language (Extensible Markup Language, XML) modeling, specifically defining the target storage process includes defining a storage process name, input parameters, and output parameters.
In general, the method for operating the database before the database migration is implemented through JDBC, specifically, the structured query statement needs to be spliced through placeholders according to the definition of the stored procedure, then the structured query statement is precompiled through a stored procedure calling method (CallableStatement), finally the value of the input parameter is set to the designated position of the precompiled structured query statement according to the definition of the stored procedure to obtain the structured query statement, and the structured query statement is executed.
According to the embodiment of the disclosure, the database operation architecture after the database migration can be modified on the basis of the original architecture, and the target storage process is defined before the database migration, so that the database operation architecture after the migration only needs to convert the target storage process into the target execution method, the difficulty of the database migration is reduced, and the database migration efficiency is improved.
According to an embodiment of the present disclosure, the target stored procedure information includes a stored procedure package name, a stored procedure name, and an input parameter of the target stored procedure.
According to an embodiment of the present disclosure, a method for determining target execution to be performed by a database according to target storage procedure information includes: acquiring a storage object associated with a target storage process according to the storage process package name; and determining a target execution method for calling the database to execute the target operation according to the stored object, the stored process name and the input parameter.
According to embodiments of the present disclosure, the stored procedure package name may be the package name of the package in which the target stored procedure is located.
According to an embodiment of the present disclosure, when creating a storage object, a storage object name (Bean Id) may be configured to be identical to a storage process package name, whereby a storage object associated with a target storage process may be determined by the storage process package name.
According to embodiments of the present disclosure, a storage object may be an object associated with a target storage process.
According to an embodiment of the present disclosure, the target operation includes an add, delete, modify, or query operation on a target database table, where the target database table is a database table to be processed by a target storage process, and the target database table is stored in the database.
According to embodiments of the present disclosure, the input parameter may be an input parameter of a target stored procedure. The target operation can operate the target storage process through the input parameters, obtain the output parameters and return.
According to the embodiment of the disclosure, the dependence on the storage process during interaction of the database is avoided by converting the target storage process information into the target operation, and the database migration efficiency is improved.
According to an embodiment of the present disclosure, according to a stored procedure package name, acquiring a stored object associated with a target stored procedure includes: and determining the storage object consistent with the target object name from the container of the application side execution framework by taking the storage process package name as the target object name.
According to embodiments of the present disclosure, a storage object is created by a container, and the container may be used to store the storage object, possibly including multiple storage objects therein.
According to the embodiment of the present disclosure, since the storage process package name is the same as the storage object name, it is possible to determine that a storage object consistent with the target object name among the plurality of storage objects is a storage object associated with the target storage process by performing a traversal query in the container with the storage process package name as the target object name. Specifically, the application side execution framework may be SpringBoot framework, the container may be Spring IoC container of SpringBoot framework, the storage object may be a Service Bean object, and the Service Bean object is created by Spring IoC container at the time of initialization.
According to the embodiment of the disclosure, the database operation efficiency is improved by determining the storage object for the storage process package name.
According to an embodiment of the present disclosure, determining a target execution method for calling a database to execute a target operation according to a stored object, a stored procedure name, and an input parameter, includes: determining at least one execution method based on the storage object; and a reflection-based method of determining a target execution method from the at least one execution method based on the stored procedure name and the input parameter.
According to the embodiment of the present disclosure, each storage object corresponds to at least one execution method, and thus, it is necessary to determine a target execution method from among a plurality of execution methods by storing a process name and an input parameter.
According to an embodiment of the present disclosure, the determining of the at least one execution method based on the storage object may be determined by storing the object name. Specifically, the method of reflection may be Java reflection, and the target execution method is determined by the method of Java reflection. Specifically, by Java reflection, a class of the storage object can be obtained based on the storage process name and the input parameter, and thus the target execution method can be obtained through the class.
According to the embodiment of the disclosure, the migration efficiency of the database is improved by determining the target execution method corresponding to the target storage process by using the reflection method.
According to an embodiment of the present disclosure, generating a structured query statement according to a target execution method includes: and converting the target execution method based on the storage object into a structured query statement corresponding to the target operation based on the persistent layer framework of the object conversion layer.
According to embodiments of the present disclosure, the object transformation layer is a layer of the application-side execution framework that can be used to directly operate on the database. The persistent layer framework is a framework of an object conversion layer, and can be used for realizing the operation of the object conversion layer on a database, in particular, the object conversion layer can be a DAO layer of SpringBoot frameworks, and the persistent layer framework can be a Mybatis framework.
According to embodiments of the present disclosure, the target storage process is not implemented peer-to-peer in the database and therefore cannot be operated using conventional Java language connection database (JDBC). And the data can be persisted by the persistence layer framework, and the structured query language can be separated from the service codes of the application side, so that the maintainability is improved, and the operation on the database is realized by using the persistence layer framework.
According to an embodiment of the disclosure, the target execution method may include at least one target operation, where the number of target operations relates to the business requirement, and specifically, the target operation may be implemented by the Mapper methods in the Mybaits framework mapping file, where each Mapper method generates one structured query statement.
According to an embodiment of the present disclosure, a Mapper may be created by the Spring IoC container at the time of initialization, where the Bean Id of the Mapper may be determined according to the traffic demand, which is not limited in any way. Each Mapper method corresponds to an add, delete, modify or query operation to the database table during the target storage process.
According to the embodiment of the disclosure, the target execution method is converted into the structured query statement through the persistent layer framework, so that database migration is simplified and development efficiency is improved.
FIG. 3 schematically illustrates generating a structured query statement, according to an embodiment of the disclosure.
As shown in fig. 3, the target execution method includes an add operation 301, a delete operation 302, a modify operation 303, and a query operation 304. Converting the target execution method into a structured query statement corresponding to the target operation includes adding statement 305, deleting statement 306, modifying statement 307, and query statement 308.
Fig. 4 schematically illustrates a flow chart of a transaction control method according to an embodiment of the present disclosure.
In operation S410, the target transaction is started before the structured query statement is generated according to the target execution method.
In operation S420, an abnormality occurring in the application-side execution framework from the generation of the structured query statement to the transmission of the structured query statement to the database is detected based on the target transaction.
In operation S430, in the case where an abnormality of the application-side execution frame is detected, a rollback operation is performed.
According to embodiments of the present disclosure, transaction control is configured in the target storage process prior to database migration. However, after the database is migrated, a persistent layer framework and an application side execution framework are introduced to interact with the database through a structured query statement, so that in this case, transaction control needs to be configured to be completed at the application side.
According to the embodiment of the disclosure, since the transaction control is performed on the target storage process in the target storage process, but after the application side execution framework and the persistent layer framework are introduced, the transaction control is performed on the target operation, so that the transaction control needs to be performed manually, and the target transaction is started before the structured query statement is generated so as to perform the transaction control on the target execution method equivalent to the target storage process. For example, before manual control, target operation 1, target operation 2, and target operation 3 each correspond to one transaction, i.e., three transactions. After the manual control is performed, the target operation 1, the target operation 2, and the target operation 3 collectively correspond to one target transaction.
According to an embodiment of the present disclosure, a target transaction is used to detect an exception that occurs to an application-side execution framework. Specifically, the application side execution framework includes operations such as generating a structured query statement by a target execution method, and sending the structured query statement to a database. The anomalies may include anomalies caused by the structured query statement itself, mapper method anomalies, and so on.
According to the embodiment of the present disclosure, the rollback operation may be to restore the database table to a state before the operation in the case that an abnormality occurs in the application side execution framework, and specifically, the rollback operation may be performed using a method such as rollback ().
According to the embodiment of the disclosure, the rollback operation under the abnormal state is realized through the manual transaction control, and the rollback operation is consistent with the transaction control logic of the target storage process, so that the data abnormality in the database caused by the abnormal execution frame of the application side is avoided.
According to an embodiment of the present disclosure, before generating a structured query statement according to a target operation, starting a target transaction includes: opening a target transaction based on annotation information of an application side execution framework; or the target transaction is started through the interaction operation of the user and the application side execution framework.
According to an embodiment of the present disclosure, the target transaction may be opened by annotation information of the application side execution framework, in particular, by adding an annotation such as @ Transactional annotation on the target execution method, the SpringBoot framework may automatically open the transaction for the target execution method. If the target execution method calls the database to execute the target operation, a rollback operation is performed, and if the target execution method is successfully executed, the transaction is submitted.
According to the embodiment of the disclosure, the transaction opening can also be performed manually, and the target transaction is performed manually by performing the interactive operation of the framework on the application side.
According to the embodiment of the disclosure, the target transaction is started by the execution frame at the application side, so that database data abnormality caused by abnormality of the execution frame at the application side in the process of operating the database is avoided.
Fig. 5 schematically illustrates a database operation architecture diagram according to a specific embodiment of the present disclosure.
As shown in fig. 5, the database operation architecture includes a definition layer, a common class, a service layer, a data layer, and a database.
In operation S510, an instruction for operating a database is generated.
In operation S520, a storage object is determined according to the target storage process package name.
In operation S530, a target execution method is acquired through Java reflection according to the stored procedure name and the input parameters.
In operation S540, the target execution method is executed.
In operation S550, a structured query statement is generated according to the target execution method.
In operation S560, the structured query statement is executed and the result is returned.
In operation S570, the process returns a result.
In operation S580, the subsequent operations are performed.
According to embodiments of the present disclosure, a definition layer may be used to define business logic, e.g., may define a complete transaction process. The definition layer may implement business logic by defining and organizing common classes using XML language.
According to embodiments of the present disclosure, the common classes may be implemented by common components, providing a variety of common functions, such as the execution of stored procedures and the invocation of service interfaces.
According to embodiments of the present disclosure, the service layer and the data layer may be implemented by SpringBoot frameworks. Specifically, the Service layer may be a Service layer, the data layer may be a DAO layer, and the Service layer is configured to encapsulate operations of the DAO layer on data, where the DAO layer is configured to perform operations of adding, deleting, and checking a database table in the database.
Based on the database operation method, the disclosure also provides a database operation device. The device will be described in detail below in connection with fig. 6.
Fig. 6 schematically shows a block diagram of a database operating apparatus according to an embodiment of the present disclosure.
As shown in fig. 6, the database operating apparatus 600 of this embodiment includes an acquisition module 610, a determination module 620, a generation module 630, and a transmission module 640.
The obtaining module 610 is configured to obtain, in response to receiving an instruction to operate the database, target stored procedure information according to the instruction, where the target stored procedure information includes information of a target stored procedure that operates on the database. In an embodiment, the obtaining module 610 may be configured to perform the operation S210 described above, which is not described herein.
The determining module 620 is configured to determine a target execution method according to the target storage procedure information. In an embodiment, the determining module 620 may be configured to perform the operation S220 described above, which is not described herein.
The generating module 630 is configured to generate a structured query statement according to the target execution method. In an embodiment, the generating module 630 may be configured to perform the operation S230 described above, which is not described herein.
The sending module 640 is configured to send the structured query statement to the database. In an embodiment, the sending module 640 may be configured to perform the operation S240 described above, which is not described herein.
According to an embodiment of the present disclosure, the target stored procedure information includes a stored procedure package name, a stored procedure name, and an input parameter of the target stored procedure.
According to an embodiment of the present disclosure, the determination module 620 includes an object acquisition sub-module and an operation determination sub-module.
And the object acquisition sub-module is used for acquiring the storage object associated with the target storage process according to the storage process package name.
And the operation determination submodule is used for determining a target execution method for calling the database to execute target operation according to the storage object, the storage process name and the input parameter, wherein the target operation comprises adding, deleting, modifying or inquiring the target database table, and the target database table is a database table to be processed in the target storage process.
According to an embodiment of the present disclosure, the object acquisition submodule includes an object determination unit.
The object determination unit is configured to determine a storage object that matches a target object name from a container of the application-side execution framework, using the storage process package name as the target object name.
According to an embodiment of the present disclosure, the operation determination sub-module includes a first determination unit and a second determination unit.
The first determination unit is used for determining at least one execution method based on the storage object.
The second determining unit is used for determining a target execution method from at least one execution method according to the stored procedure name and the input parameter based on the reflection method.
According to an embodiment of the present disclosure, the generation module 630 includes a conversion sub-module.
The conversion submodule is used for converting the target execution method based on the storage object into a structured query statement corresponding to the target operation based on the persistent layer framework of the object conversion layer.
According to an embodiment of the present disclosure, the database operating apparatus 600 further includes an opening module, a detecting module, and a rollback module.
The opening module is used for opening the target transaction before the structured query statement is generated according to the target execution method.
The detection module is used for detecting the abnormality of the application side execution framework in the process from the generation of the structured query statement to the transmission of the structured query statement to the database based on the target transaction.
The operation module is used for performing rollback operation under the condition that abnormality of the application side execution frame is detected.
According to an embodiment of the present disclosure, the opening module includes a first opening sub-module and a second opening sub-module.
The first opening submodule is used for opening the target transaction based on annotation information of the application side execution framework.
The second opening submodule is used for opening the target transaction through the interaction operation of the user and the application side execution framework.
Any of the acquisition module 610, the determination module 620, the generation module 630, and the transmission module 640 may be combined in one module to be implemented, or any of the modules may be split into a plurality of modules, according to embodiments of the present disclosure. Or at least some of the functionality of one or more of the modules may be combined with, and implemented in, at least some of the functionality of other modules. At least one of the acquisition module 610, the determination module 620, the generation module 630, and the transmission module 640 may be implemented at least in part as hardware circuitry, such as a Field Programmable Gate Array (FPGA), a Programmable Logic Array (PLA), a system on a chip, a system on a substrate, a system on a package, an Application Specific Integrated Circuit (ASIC), or may be implemented in hardware or firmware, such as any other reasonable way of integrating or packaging circuitry, or in any one of or a suitable combination of three of software, hardware, and firmware. Or at least one of the acquisition module 610, the determination module 620, the generation module 630 and the transmission module 640 may be at least partially implemented as computer program modules which, when executed, may perform the respective functions.
Fig. 7 schematically illustrates a block diagram of an electronic device adapted to implement a database operating method according to an embodiment of the disclosure.
As shown in fig. 7, an electronic device 700 according to an embodiment of the present disclosure includes a processor 701 that can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM) 702 or a program loaded from a storage section 708 into a Random Access Memory (RAM) 703. The processor 701 may include, for example, a general purpose microprocessor (e.g., a CPU), an instruction set processor and/or an associated chipset and/or a special purpose microprocessor (e.g., an Application Specific Integrated Circuit (ASIC)), or the like. The processor 701 may also include on-board memory for caching purposes. The processor 701 may comprise a single processing unit or a plurality of processing units for performing different actions of the method flows according to embodiments of the disclosure.
In the RAM 703, various programs and data necessary for the operation of the electronic apparatus 700 are stored. The processor 701, the ROM 702, and the RAM 703 are connected to each other through a bus 704. The processor 701 performs various operations of the method flow according to the embodiments of the present disclosure by executing programs in the ROM 702 and/or the RAM 703. Note that the program may be stored in one or more memories other than the ROM 702 and the RAM 703. The processor 701 may also perform various operations of the method flow according to embodiments of the present disclosure by executing programs stored in the one or more memories.
According to an embodiment of the present disclosure, the electronic device 700 may further include an input/output (I/O) interface 705, the input/output (I/O) interface 705 also being connected to the bus 704. The electronic device 700 may also include one or more of the following components connected to the I/O interface 705: an input section 706 including a keyboard, a mouse, and the like; an output portion 707 including a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, a speaker, and the like; a storage section 708 including a hard disk or the like; and a communication section 709 including a network interface card such as a LAN card, a modem, or the like. The communication section 709 performs communication processing via a network such as the internet. The drive 710 is also connected to the I/O interface 705 as needed. A removable medium 711 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 710 as necessary, so that a computer program read therefrom is mounted into the storage section 708 as necessary.
The present disclosure also provides a computer-readable storage medium that may be embodied in the apparatus/device/system described in the above embodiments; or may exist alone without being assembled into the apparatus/device/system. The computer-readable storage medium carries one or more programs which, when executed, implement methods in accordance with embodiments of the present disclosure.
According to embodiments of the present disclosure, the computer-readable storage medium may be a non-volatile computer-readable storage medium, which may include, for example, but is not limited to: a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this disclosure, a computer-readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. For example, according to embodiments of the present disclosure, the computer-readable storage medium may include ROM 702 and/or RAM 703 and/or one or more memories other than ROM 702 and RAM 703 described above.
Embodiments of the present disclosure also include a computer program product comprising a computer program containing program code for performing the methods shown in the flowcharts. The program code, when executed in a computer system, causes the computer system to implement the item recommendation method provided by embodiments of the present disclosure.
The above-described functions defined in the system/apparatus of the embodiments of the present disclosure are performed when the computer program is executed by the processor 701. The systems, apparatus, modules, units, etc. described above may be implemented by computer program modules according to embodiments of the disclosure.
In one embodiment, the computer program may be based on a tangible storage medium such as an optical storage device, a magnetic storage device, or the like. In another embodiment, the computer program may also be transmitted, distributed over a network medium in the form of signals, downloaded and installed via the communication section 709, and/or installed from the removable medium 711. The computer program may include program code that may be transmitted using any appropriate network medium, including but not limited to: wireless, wired, etc., or any suitable combination of the foregoing.
In such an embodiment, the computer program may be downloaded and installed from a network via the communication portion 709, and/or installed from the removable medium 711. The above-described functions defined in the system of the embodiments of the present disclosure are performed when the computer program is executed by the processor 701. The systems, devices, apparatus, modules, units, etc. described above may be implemented by computer program modules according to embodiments of the disclosure.
According to embodiments of the present disclosure, program code for performing computer programs provided by embodiments of the present disclosure may be written in any combination of one or more programming languages, and in particular, such computer programs may be implemented in high-level procedural and/or object-oriented programming languages, and/or assembly/machine languages. Programming languages include, but are not limited to, such as Java, c++, python, "C" or similar programming languages. The program code may execute entirely on the user's computing device, partly on the user's device, partly on a remote computing device, or entirely on the remote computing device or server. In the case of remote computing devices, the remote computing device may be connected to the user computing device through any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computing device (e.g., connected via the Internet using an Internet service provider).
The flowcharts and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
Those skilled in the art will appreciate that the features recited in the various embodiments of the disclosure and/or in the claims may be provided in a variety of combinations and/or combinations, even if such combinations or combinations are not explicitly recited in the disclosure. In particular, the features recited in the various embodiments of the present disclosure and/or the claims may be variously combined and/or combined without departing from the spirit and teachings of the present disclosure. All such combinations and/or combinations fall within the scope of the present disclosure.
The embodiments of the present disclosure are described above. These examples are for illustrative purposes only and are not intended to limit the scope of the present disclosure. Although the embodiments are described above separately, this does not mean that the measures in the embodiments cannot be used advantageously in combination. The scope of the disclosure is defined by the appended claims and equivalents thereof. Various alternatives and modifications can be made by those skilled in the art without departing from the scope of the disclosure, and such alternatives and modifications are intended to fall within the scope of the disclosure.
Claims (11)
1. A method of database operation, the method comprising:
In response to receiving an instruction for operating a database, obtaining target stored procedure information according to the instruction, wherein the target stored procedure information comprises information of a target stored procedure for operating the database;
determining a target execution method according to the target storage process information;
generating a structured query statement according to the target execution method; and
And sending the structured query statement to the database.
2. The method of claim 1, wherein the target stored procedure information includes a stored procedure package name, a stored procedure name, and an input parameter of the target stored procedure; the method for determining the target execution method according to the target storage process information comprises the following steps:
acquiring a storage object associated with the target storage process according to the storage process package name; and
And determining a target execution method for calling the database to execute target operation according to the storage object, the storage process name and the input parameter, wherein the target operation comprises adding, deleting, modifying or inquiring a target database table, and the target database table is a database table to be processed in the target storage process.
3. The method of claim 2, wherein the retrieving a storage object associated with the target stored procedure based on the stored procedure package name comprises:
And taking the storage process package name as a target object name, and determining a storage object consistent with the target object name from a container of an application side execution framework.
4. The method of claim 2, wherein the determining a target execution method for invoking the database to execute a target operation based on the stored object, the stored procedure name, and the input parameter comprises:
determining at least one execution method based on the storage object; and
And determining a target execution method from the at least one execution method according to the stored procedure name and the input parameters based on the reflection method.
5. The method of claim 4, wherein generating a structured query statement according to the target execution method comprises:
And converting a target execution method based on the storage object into a structured query statement corresponding to the target operation based on a persistent layer framework of an object conversion layer.
6. The method according to claim 1, wherein the method further comprises:
starting a target transaction before generating a structured query statement according to the target execution method;
detecting an abnormality occurring in an application side execution framework from the generation of the structured query statement to the transmission of the structured query statement to the database based on the target transaction; and
And performing rollback operation under the condition that the abnormality of the application side execution frame is detected.
7. The method of claim 6, wherein the opening the target transaction prior to generating the structured query statement according to the target operation comprises:
Opening a target transaction based on annotation information of the application side execution framework; or alternatively
And starting the target transaction through the interactive operation of the user and the application side execution framework.
8. A database operating apparatus, the apparatus comprising:
the acquisition module is used for responding to the received instruction for operating the database and acquiring target storage process information according to the instruction, wherein the target storage process information comprises information of a target storage process for operating the database;
The determining module is used for determining a target execution method according to the target storage process information, wherein the target execution method is used for calling the database to execute target operation;
The generation module is used for generating a structured query statement according to the target execution method; and
And the sending module is used for sending the structured query statement to the database.
9. An electronic device, comprising:
one or more processors;
a memory for storing one or more computer programs,
Characterized in that the one or more processors execute the one or more computer programs to implement the steps of the method according to any one of claims 1 to 7.
10. A computer-readable storage medium, on which a computer program or instructions is stored, characterized in that the computer program or instructions, when executed by a processor, implement the steps of the method according to any one of claims 1-7.
11. A computer program product comprising a computer program or instructions which, when executed by a processor, implement the steps of the method according to any one of claims 1 to 7.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202410312708.4A CN118210778A (en) | 2024-03-19 | 2024-03-19 | Database operation method, apparatus, device, storage medium, and program product |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202410312708.4A CN118210778A (en) | 2024-03-19 | 2024-03-19 | Database operation method, apparatus, device, storage medium, and program product |
Publications (1)
Publication Number | Publication Date |
---|---|
CN118210778A true CN118210778A (en) | 2024-06-18 |
Family
ID=91453749
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202410312708.4A Pending CN118210778A (en) | 2024-03-19 | 2024-03-19 | Database operation method, apparatus, device, storage medium, and program product |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN118210778A (en) |
-
2024
- 2024-03-19 CN CN202410312708.4A patent/CN118210778A/en active Pending
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN113419740B (en) | Program data stream analysis method and device, electronic equipment and readable storage medium | |
CN110109983B (en) | Method and device for operating Redis database | |
CN110764769B (en) | Method and device for processing user request | |
CN114237651A (en) | Installation method and device of cloud native application, electronic equipment and medium | |
CN115982491A (en) | Page updating method and device, electronic equipment and computer readable storage medium | |
CN115599386A (en) | Code generation method, device, equipment and storage medium | |
CN116594683A (en) | Code annotation information generation method, device, equipment and storage medium | |
US20240187501A1 (en) | Techniques for distributed interface component generation | |
CN114116678A (en) | Data migration method, device, equipment, medium and program product | |
CN116700745A (en) | Application deployment method and device based on container cloud platform, electronic equipment and medium | |
CN110825622A (en) | Software testing method, device, equipment and computer readable medium | |
CN116303620A (en) | Accounting method, system, equipment, medium and product based on light database | |
CN114237765B (en) | Functional component processing method, device, electronic equipment and medium | |
CN115760013A (en) | Operation and maintenance model construction method and device, electronic equipment and storage medium | |
CN115033634A (en) | Data acquisition method, data acquisition device, electronic equipment and medium | |
CN114677114A (en) | Approval process generation method and device based on graph dragging | |
CN114780361A (en) | Log generation method, device, computer system and readable storage medium | |
CN118210778A (en) | Database operation method, apparatus, device, storage medium, and program product | |
CN113448578A (en) | Page data processing method, processing system, electronic device and readable storage medium | |
CN113064987A (en) | Data processing method, apparatus, electronic device, medium, and program product | |
CN113760262A (en) | Task processing method, device, computer system and computer readable storage medium | |
CN114911858A (en) | Cloud platform interface generation method and device | |
CN117472716A (en) | Non-invasive application log acquisition method, device, equipment and storage medium | |
CN115309404A (en) | File generation method and device, electronic equipment and storage medium | |
CN118394331A (en) | Cloud native standard application engineering template generation method and device |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination |