Detailed Description
Example embodiments will now be described more fully with reference to the accompanying drawings. Example embodiments may, however, be embodied in many different forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the concept of example embodiments to those skilled in the art.
Furthermore, the described features, structures, or characteristics may be combined in any suitable manner in one or more embodiments. In the following description, numerous specific details are provided to give a thorough understanding of embodiments of the application. One skilled in the relevant art will recognize, however, that the subject matter of the present application can be practiced without one or more of the specific details, or with other methods, components, devices, steps, and so forth. In other instances, well-known methods, devices, implementations, or operations have not been shown or described in detail to avoid obscuring aspects of the application.
The block diagrams shown in the figures are functional entities only and do not necessarily correspond to physically separate entities. I.e. these functional entities may be implemented in the form of software, or in one or more hardware modules or integrated circuits, or in different networks and/or processor means and/or microcontroller means.
The flow charts shown in the drawings are merely illustrative and do not necessarily include all of the contents and operations/steps, nor do they necessarily have to be performed in the order described. For example, some operations/steps may be decomposed, and some operations/steps may be combined or partially combined, so that the actual execution sequence may be changed according to the actual situation.
In migrating an Oracle database to a PostgreSQL database, although PostgreSQL is also designed to be compatible with the Oracle syntax system, there are still many differences in syntax. This results in that the Oracle function still needs to be manually transformed by a database expert to be packaged into the PostgreSQL database, which consumes a lot of time and manpower, and prolongs the upgrade period of the enterprise architecture. Although the tools of the Oracle database migration PostgreSQL database are various, the data migration can be performed, and the function migration cannot be performed in many cases. Or even if function migration can be performed, the problem of function migration failure is caused due to incorrect object migration sequence in the function migration process, so that the success rate of function migration is low.
In order to solve the above problems, the present application provides a method, an apparatus, and a computer readable medium for function migration of an Oracle database, which implement improving the migration success rate of functions by establishing an association relation tree and a syntax relation tree, specifying a function migration sequence and repairing a function syntax difference, automatically adapting the function syntax difference in the migration process, and automatically adapting the Oracle syntax to a PostgreSQL syntax.
The following describes in detail an Oracle database function migration method, apparatus, and computer readable medium provided by the present application with reference to specific embodiments.
Referring to fig. 1, fig. 1 schematically shows a flow of steps of a method for migrating an Oracle database function according to an embodiment of the present application. The execution subject of the method may be a server, and the method may mainly include steps S101 to S105 as follows.
Step S101, acquiring a function in an Oracle database, and creating an incidence relation tree associated with the function, wherein the incidence relation tree is used for displaying a dependent object having an incidence relation with the function.
First, the function in the Oracle database is obtained, and an incidence relation tree of the function is created. The incidence relation between the function objects is reflected through the incidence relation tree. Therefore, the incidence relation tree is created firstly, so that the migration sequence of the functions can be conveniently determined in the function migration process, and the migration failure of a certain function due to the fact that the dependent object of the function is not migrated is avoided.
Step S102, reading the original definition of the function and disassembling the original definition of the function to generate a syntax relation tree, wherein the syntax relation tree is used for representing the composition structure of the function.
Reading the original definition of the Oracle function and decomposing the Oracle function into a syntax relation tree, so that the subsequent syntax conversion is convenient. And performing difference repair between different database functions based on the syntax relation tree.
And step S103, carrying out grammar conversion and function object reduction on the grammar relation tree to generate a function definition of the preset type database.
The syntax relation tree is subjected to syntax conversion and function object restoration to generate a function definition of a preset type database, wherein the preset type database is a PostgreSQL database as an example. I.e. converting functions in the Oracle database into PostgreSQL function definitions, thereby facilitating migration of subsequent functions.
And step S104, replacing the same structure in the association relation tree with the function definition of the preset type database.
And replacing the same structure in the incidence relation tree by the function definition of the preset type database, so that the Oracle syntax is adapted to the PostgreSQL syntax.
And step S105, reversely traversing the replaced incidence relation tree to transfer the function definition in the incidence relation tree to a preset type database.
After the replaced incidence relation tree is obtained, the function definitions in the incidence relation tree are migrated to the PostgreSQL database according to the reverse order, so that migration failure of a certain function due to the fact that a dependent object of the function is not migrated is avoided.
According to the technical scheme provided by the embodiment of the application, the association relation tree and the grammar relation tree are established, the function migration sequence and the function grammar difference are respectively appointed, the function grammar difference is automatically adapted in the migration process, the Oracle grammar is automatically adapted to the grammar of the preset type database, and therefore the migration success rate of the function is improved.
In one embodiment of the present application, referring to fig. 2, fig. 2 schematically shows a flow of steps for creating an association tree associated with a function in an embodiment of the present application. Creating the association relation tree associated with the function mainly includes steps S201 to S204 as follows.
Step S201, using a function of the association relation tree to be created as a first-level node.
For example, if an association relation tree of function a is to be created, function a is taken as a first-level node.
Step S202, obtaining the dependent object of the function, and taking the dependent object of the function as a second layer node.
After determining the function A as a first-layer node, connecting the JDBC to the source library to obtain database objects such as tables, other functions, stored procedures and the like which depend on the function A, and taking the database objects as a second-layer node, wherein if the dependent objects of the function A are an object A1 and an object A2, an object A1 and an object A2 are taken as the second-layer node.
Step S203, traversing the second layer node, and determining the dependent object of the second layer node.
Next, the dependent objects of the second node are determined, and if the dependent objects of the object A1 are the object A11 and the object A12, and the dependent object of the object A2 is the object A22, the object A11, the object A12, and the object A22 are used as the third level nodes.
And step S204, traversing the next layer node of the second layer node and determining the dependent object of the next layer node until the node has no dependent object.
Next, the dependent objects of the third level node are determined, i.e., whether object A11, object A12, and object A22 have dependent objects. And if the dependent objects exist, taking the dependent objects as nodes of a fourth layer, then traversing the nodes of the fourth layer, determining whether the nodes of the fourth layer have the dependent objects, and so on until the nodes do not have the dependent objects.
Therefore, the dependent objects of the nodes of each layer of the function are determined in a layer-by-layer traversal mode, and a relatively comprehensive incidence relation tree is conveniently constructed.
In order to facilitate understanding of the construction process of the association relation tree, in an embodiment of the present application, referring to fig. 3, fig. 3 schematically illustrates a schematic diagram of the association relation tree in an embodiment of the present application. For example, taking the creation of the association relation tree of the function a as an example, the function a is first used as a first-level node. After determining the function A as a first-layer node, connecting the JDBC to the source library to obtain database objects such as tables, other functions, stored procedures and the like which depend on the function A, and taking the database objects as a second-layer node, wherein if the dependent objects of the function A are an object A1 and an object A2, an object A1 and an object A2 are taken as the second-layer node. Next, the dependent objects of the second node are determined, and if the dependent objects of the object A1 are the object A11 and the object A12, and the dependent object of the object A2 is the object A22, the object A11, the object A12, and the object A22 are used as the third level nodes. Next, the dependent objects of the third level node are determined, i.e., whether object A11, object A12, and object A22 have dependent objects. And if the dependent objects exist, taking the dependent objects as nodes of a fourth layer, then traversing the nodes of the fourth layer, determining whether the nodes of the fourth layer have the dependent objects, and so on until the nodes do not have the dependent objects.
In one embodiment of the present application, referring to fig. 4, fig. 4 schematically shows a flow of steps for creating an association tree associated with a function in another embodiment of the present application. Creating the association relation tree associated with the function may mainly include steps S401 to S402 as follows.
Step S401, in the process of creating the association relation tree, marking the repeated dependent objects.
In step S402, when the current node is traversed to have repeated dependent objects with other nodes, the dependent object of the current node is not queried any more.
In order to facilitate understanding of the technical solution of the present application, taking the association relation tree of the function a as an example, in the process of creating the association relation tree, taking the function a as a first-layer node, and the dependent object of the function a includes the object a11 and the object a12, the object a11 and the object a12 as a second-layer node, and so on to determine the dependent object of each layer of nodes. When the current node and other nodes are traversed to have repeated dependent objects, the dependent object of the current node is not continuously queried, which means that if the dependent object of a certain node in other layers is the object A11, the dependent object of the object A11 is not continuously queried. In this way, the association tree is prevented from performing the query phase of the dead loop.
In the process of creating the association relation tree, repeated dependent objects need to be marked, and when the repeated dependent objects are encountered, query is not carried out any more, so that the association relation tree is prevented from forming dead loops. Similarly, all function association relation trees to be migrated are generated for other functions in the same way.
In one embodiment of the present application, referring to fig. 5, fig. 5 schematically shows a flow of steps for creating an association tree associated with a function in yet another embodiment of the present application. Creating the association relation tree associated with the function may mainly include steps S501 to S502 as follows.
Step S501, deleting repeated functions or repeated nodes in the association relation tree to simplify the association relation tree;
step S502, the simplified association relation tree is stored in a cache region of the database.
After obtaining the association relation trees of all the functions to be migrated, all the association relation trees need to be simplified, and part of the association relation trees or repeated nodes need to be deleted. For example, the association relation tree whose vertex is the function a, if the node of the association relation tree has the function B, the association relation tree whose vertex is the function B is deleted; in another case, if the association tree whose vertex is the a function and the association tree whose vertex is the B function both have the node C table, the node C table and the dependent subsequent nodes in the association tree whose vertex is the B function are removed.
In the process of generating the incidence relation tree of the function, the generated incidence relation tree is simplified, so that no cross node exists among the incidence relation trees, and the incidence relation trees are simplified, so that the migration cost is reduced.
In one embodiment of the present application, since there is a collection within the code, there is no duplicate data in the collection. In the process of simplifying the association relation tree, after a node is determined, the node is firstly found in the set to find whether the node exists, if so, the downward traversal is not continued, and if not, the object is followed to traverse downward.
In one embodiment of the present application, referring to fig. 6, fig. 6 schematically shows a flow of steps of reading an original definition of a function and performing parsing to generate a syntax relation tree in an embodiment of the present application. Reading the original definition of the function and performing parsing to generate the syntax relation tree, which mainly includes the following steps S601 to S603.
Step S601, scan the structure of the function to read the original definition of the function.
In the first step, a structure scan is performed to read the original definition of the Oracle function. Taking one of the functions to be migrated as an example, for example, the function a, the original definition is extracted from the Oracle database, and the structure of the function a is scanned first to read the original definition of the function a.
Step S602, merging the structures of the functions into an identification array according to a preset rule, wherein the identification array at least comprises a function name, a parameter statement and a function body.
Then, the structures of the functions A are combined into a function A identification array according to a preset rule. And in the identification array, identification storage is carried out according to the granularity of function names, parameter declarations, function bodies, keywords, system function calls and the like.
Step S603, performing layer-by-layer parsing on the identifier array until a minimum granularity is reached, so as to generate a syntax relation tree, where the minimum granularity is a minimum refinement level of data in the database.
And (4) carrying out layer-by-layer disassembly on the function A mark array until the function A mark array cannot be disassembled at last so as to form a grammatical relation tree.
Therefore, the abstract syntax relation tree is not dependent on concrete syntax, and any heterogeneous migration can be realized as long as the same syntax tree structure is constructed during syntax analysis. And the method is convenient to realize the migration of any isomerism by constructing the syntax relation tree.
In an embodiment of the present application, referring to fig. 7, fig. 7 schematically illustrates a flow of steps of performing layer-by-layer disassembly on an identifier array until a minimum granularity is reached in an embodiment of the present application. The tag array is disassembled layer by layer until the minimum granularity is reached, which mainly includes the following steps S701 to S704.
Step S701, taking the function name in the identification array as a first-layer child node;
step S702, taking the parameter declaration and the function body in the identification array as the second layer of child nodes;
step S703, disassembling the parameter declaration into grammar and data type, and disassembling the function body into function expression and return domain object, to obtain the third layer child node;
and step S704, disassembling the third-layer child node until the minimum refinement level is reached.
Referring to fig. 8, fig. 8 schematically shows a schematic diagram of a syntax relation tree in an embodiment of the present application. First the function name becomes the top level node, i.e. as the first level child node. Then, the parameter declaration and the function body are changed into a next layer node, namely a second layer child node. Then, continuously disassembling the parameter declaration into third-layer nodes such as declaration grammar and data types, wherein the data types are parameter types; the function body can be decomposed into third-layer nodes such as expressions and return domain objects; the function expression can be continuously disassembled, and a fourth layer node of the tree is formed according to keywords, grammar, system functions and calling objects; the system function and the calling object in the expression can continue to be disassembled into the fifth-layer node, for example, when the calling object is a system function, the system function and the calling object can be disassembled into the granularity of the system function name, the function parameter and the like. The disassembly is continued in this order until finally impossible.
Therefore, after the function is disassembled into the relation tree, the nodes of the tree are matched, the granularity is smaller, the conversion is more accurate, a plurality of function structures are linked and migrated by matching with the incidence relation tree, and the migration efficiency and the migration success rate are improved.
In an embodiment of the present application, referring to fig. 9, fig. 9 schematically shows a flow of steps of subjecting a syntax relation tree to syntax transformation and function object reduction to generate a function definition of a preset type database in an embodiment of the present application. The syntax relation tree is subjected to syntax conversion and function object reduction to generate a function definition of the preset type database, and the following steps S901 to S902 may be mainly included.
Step S901, traverse nodes of the syntax relation tree, and perform syntax conversion processing according to node types to satisfy syntax formats of the preset type database.
Traversing from the node at the top layer, and performing different processing on each node according to different node types: for example, the function name or calling object name node needs to be subjected to lower case processing, the parameter data type node needs to be replaced, the Oracle function node needs to replace the function name, and the parameter node can be subjected to left and right node replacement due to the replacement of the function node; the key node is changed to a key in PostgreSQL, etc.
And step S902, restoring the grammar relation tree after grammar conversion into a function definition form of a preset type database so as to generate a function definition of the preset type database.
Therefore, the Oracle grammar can be automatically adapted to the grammar of the preset type database conveniently, and the migration success rate of the function is improved.
In one embodiment of the present application, referring to fig. 10, fig. 10 schematically shows an exemplary system architecture block diagram to which the present solution is applied. The system architecture includes: an incidence relationtree generating module 1001, an Oracleside extracting module 1002, a PostgreSQLside loading module 1003 and a syntax relationtree generating module 1004. The incidence relationtree generating module 1001 is configured to sort call relations between functions and between functions, and call relations between functions and other types of objects; the Oracle-side extraction module 1002 is used for extracting original definitions of Oracle functions; the postgreSQLend loading module 1003 is used for loading the conversion definition of the Oracle function according to the incidence relation tree and acquiring part of postgreSQL database information; the syntax relationtree generating module 1004 is used for disassembling the original definition of the Oracle function, generating a syntax relation tree and replacing nodes in the syntax relation tree; and restoring the syntax relation tree into function definitions, and filling the function definitions into the association relation tree.
It should be noted that although the steps of the methods in this application are depicted in the drawings in a particular order, this does not require or imply that these steps must be performed in this particular order, or that all of the shown steps must be performed, to achieve desirable results. Additionally or alternatively, certain steps may be omitted, multiple steps combined into one step execution, and/or one step broken down into multiple step executions, etc.
The following describes an embodiment of an apparatus of the present application, which may be used to execute the Oracle database function migration method in the above embodiment of the present application. Fig. 11 schematically shows a block diagram of a structure of an Oracle database function migration apparatus according to an embodiment of the present application. As shown in fig. 11, an Oracle databasefunction migration apparatus 1100 includes:
an obtainingmodule 1101, configured to obtain a function in an Oracle database, and create an association relation tree associated with the function, where the association relation tree is used to display a dependent object having an association relation with the function;
afirst generating module 1102, configured to read an original definition of a function and disassemble the original definition to generate a syntax relationship tree, where the syntax relationship tree is used to represent a composition structure of the function;
asecond generating module 1103, configured to perform syntax transformation and function object reduction on the syntax relation tree to generate a function definition of the preset type database;
a replacingmodule 1104, configured to replace the same structure in the association relation tree with a function definition of a preset type database;
amigration module 1105, configured to reversely traverse the replaced incidence relation tree, so as to migrate the function definition in the incidence relation tree to the preset type database.
In some embodiments of the present application, based on the above technical solution, the obtainingmodule 1101 is further configured to take a function of an association relation tree to be created as a first-layer node; acquiring a dependent object of the function, and taking the dependent object of the function as a second layer node; traversing the second-layer nodes and determining the dependent objects of the second-layer nodes; and traversing the next level node of the second level node and determining the dependent object of the next level node until the node has no dependent object.
In some embodiments of the present application, based on the above technical solution, the obtainingmodule 1101 is further configured to mark a repeated dependent object in a process of creating an association relation tree; when the current node is traversed to have repeated dependent objects with other nodes, the dependent objects of the current node are not continuously inquired.
In some embodiments of the present application, based on the above technical solution, the obtainingmodule 1101 is further configured to delete a repeated function or a repeated node in the association relation tree to simplify the association relation tree; and storing the simplified association relation tree in a cache region of the database.
In some embodiments of the present application, based on the above technical solution, thefirst generating module 1102 is further configured to scan a structure of the function to read an original definition of the function; combining the structures of the functions into an identification array according to a preset rule, wherein the identification array at least comprises a function name, a parameter statement and a function body; and (4) the identification array is disassembled layer by layer until the minimum granularity is reached so as to generate a grammatical relation tree, wherein the minimum granularity is the minimum refinement level of the data in the database.
In some embodiments of the present application, based on the above technical solution, thefirst generating module 1102 is further configured to use the function name in the identification array as a first-layer child node; taking the parameter declaration and the function body in the identification array as a second layer of child nodes; resolving the parameter statement into a grammar and a data type, resolving the function body into a function expression and returning to a domain object to obtain a third-layer child node; and disassembling the third layer of child nodes until the minimum refinement level is reached.
In some embodiments of the present application, based on the above technical solution, thesecond generating module 1103 is further configured to traverse nodes of the syntax relationship tree, and perform syntax transformation processing according to node types to meet syntax formats of the preset type database; and restoring the grammar relation tree after grammar conversion into a function definition form of the preset type database so as to generate the function definition of the preset type database.
The specific details of the Oracle database function migration apparatus provided in each embodiment of the present application have been described in detail in the corresponding method embodiment, and are not described herein again.
Fig. 12 schematically shows a block diagram of a computer system of an electronic device for implementing an embodiment of the present application.
It should be noted that thecomputer system 1200 of the electronic device shown in fig. 12 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present application.
As shown in fig. 12, thecomputer system 1200 includes a Central Processing Unit 1201 (CPU), which can perform various appropriate actions and processes according to a program stored in a Read-Only Memory 1202 (ROM) or a program loaded from astorage section 1208 into a Random Access Memory 1703 (RAM). In therandom access memory 1203, various programs and data necessary for system operation are also stored. Thecpu 1201, therom 1202, and theram 1203 are connected to each other by abus 1204. An Input/Output interface 1205(Input/Output interface, i.e., I/O interface) is also connected to thebus 1204.
The following components are connected to the input/output interface 1205: aninput section 1206 including a keyboard, a mouse, and the like; anoutput section 1207 including a Display device such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and a speaker; astorage section 1208 including a hard disk and the like; and acommunication section 1209 including a network interface card such as a local area network card, a modem, or the like. Thecommunication section 1209 performs communication processing via a network such as the internet. Thedriver 1210 is also connected to the input/output interface 1205 as necessary. A removable medium 1211, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like, is mounted on thedrive 1210 as necessary, so that a computer program read out therefrom is mounted into thestorage section 1208 as necessary.
In particular, according to embodiments of the present application, the processes described in the method flowcharts may be implemented as computer software programs. For example, embodiments of the present application include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated by the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through thecommunication section 1209, and/or installed from theremovable medium 1211. The computer program, when executed by thecentral processing unit 1201, performs various functions defined in the system of the present application.
It should be noted that the computer readable medium shown in the embodiments of the present application may be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a Read-Only Memory (ROM), an Erasable Programmable Read-Only Memory (EPROM), a flash Memory, an optical fiber, 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 present application, 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. In this application, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wired, etc., or any suitable combination of the foregoing.
The flowchart 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 application. 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.
It should be noted that although in the above detailed description several modules or units of the device for action execution are mentioned, such a division is not mandatory. Indeed, the features and functionality of two or more modules or units described above may be embodied in one module or unit, according to embodiments of the application. Conversely, the features and functions of one module or unit described above may be further divided into embodiments by a plurality of modules or units.
Through the above description of the embodiments, those skilled in the art will readily understand that the exemplary embodiments described herein may be implemented by software, or by software in combination with necessary hardware. Therefore, the technical solution according to the embodiments of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a usb disk, a removable hard disk, etc.) or on a network, and includes several instructions to enable a computing device (which can be a personal computer, a server, a touch terminal, or a network device, etc.) to execute the method according to the embodiments of the present application.
Other embodiments of the present application will be apparent to those skilled in the art from consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the invention following, in general, the principles of the application and including such departures from the present disclosure as come within known or customary practice within the art to which the invention pertains.
It will be understood that the present application is not limited to the precise arrangements described above and shown in the drawings and that various modifications and changes may be made without departing from the scope thereof. The scope of the application is limited only by the appended claims.