CN113535141A - Database operation code generation method and device - Google Patents

Database operation code generation method and device Download PDF

Info

Publication number
CN113535141A
CN113535141A CN202010300597.7A CN202010300597A CN113535141A CN 113535141 A CN113535141 A CN 113535141A CN 202010300597 A CN202010300597 A CN 202010300597A CN 113535141 A CN113535141 A CN 113535141A
Authority
CN
China
Prior art keywords
database
target database
user
project
technology type
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
Application number
CN202010300597.7A
Other languages
Chinese (zh)
Inventor
陈浩翔
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Zhejiang Dasou Vehicle Software Technology Co Ltd
Original Assignee
Zhejiang Dasou Vehicle Software Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Zhejiang Dasou Vehicle Software Technology Co Ltd filed Critical Zhejiang Dasou Vehicle Software Technology Co Ltd
Priority to CN202010300597.7A priority Critical patent/CN113535141A/en
Publication of CN113535141A publication Critical patent/CN113535141A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • G06F8/315Object-oriented languages
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/25Integrating or interfacing systems involving database management systems
    • G06F16/252Integrating or interfacing systems involving database management systems between a Database Management System and a front-end application
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/20Software design
    • G06F8/22Procedural

Abstract

The application provides a method and a device for generating database operation codes, wherein the method comprises the following steps: acquiring structural parameters of a target database by establishing connection with the target database; determining the selected technology type according to a technology type selection instruction sent by a user; and injecting the structural parameters into a template file corresponding to the technology type to generate an operation code for the target database. Through the technical scheme, developers can freely select proper technical types to automatically generate the database operation codes, and the development efficiency of software projects is improved to a certain extent.

Description

Database operation code generation method and device
Technical Field
The present application relates to the field of software programming technologies, and in particular, to a method and an apparatus for generating database operation codes.
Background
Under the condition that a software project is connected with a database, data in the connected database generally needs to be processed in the running process of the project, so that developers need to write corresponding database operation codes in the development stage of the project. Although the service functions and the implementation logics thereof implemented by different functional modules in the same project may not be the same, the basic operations performed on the data in the database are often the same, such as adding, deleting, modifying, searching, summing, sorting and the like on the data, so the operation codes of the databases connected to the projects of the plurality of functional modules are often the same or similar, and the workload of repeatedly writing the operation codes of the databases is huge.
To address the above-mentioned problems, in the related art, project developers generate database operation codes through an open-source code generation framework. However, the technical type for generating the database operation code in such a framework is fixed in advance at the framework building stage, so that on one hand, the fixing technology may have a compatibility problem with other codes of a project, resulting in a limited application scenario of the open-source code generation framework; on the other hand, in the case where the fixing technique is not familiar, the developer needs to spend much time and effort to learn the fixing technique, resulting in a reduction in development efficiency.
Disclosure of Invention
In view of the above, the present application provides a method and an apparatus for generating a database operation code, so as to solve the problems in the related art.
In order to achieve the above purpose, the present application provides the following technical solutions:
according to a first aspect of the present application, a method for generating database operation codes is provided, the method including:
acquiring structural parameters of a target database by establishing connection with the target database;
determining the selected technology type according to a technology type selection instruction sent by a user;
and injecting the structural parameters into a template file corresponding to the technology type to generate an operation code for the target database.
According to a second aspect of the present application, an apparatus for generating database operation codes includes:
the system comprises a structural parameter acquisition unit, a structural parameter acquisition unit and a data processing unit, wherein the structural parameter acquisition unit is used for acquiring structural parameters of a target database by establishing connection with the target database;
the technical type determining unit is used for determining the selected technical type according to a technical type selection instruction sent by a user;
and the operation code generating unit is used for injecting the structure parameters into the template file corresponding to the technology type so as to generate the operation code aiming at the target database.
According to a third aspect of the present application, there is provided an electronic device comprising:
a processor;
a memory for storing processor-executable instructions;
wherein the processor is configured to implement the steps of the method according to any one of the aspects of the first aspect.
According to a fourth aspect of the present application, a computer-readable storage medium is proposed, on which computer instructions are stored, which instructions, when executed by a processor, carry out the steps of the method according to any one of the above-mentioned aspects of the first aspect.
According to the technical scheme, the method and the device allow developers to select the appropriate technical type through the instruction, and automatically generate the database operation code based on the template file corresponding to the technical type selected by the developers. Therefore, developers can select the technical type suitable for the current project from the multiple technical types to generate the corresponding database operation code, and the problem of code compatibility caused by the fixed technical type is solved; and the familiar technology types can be selected to reduce the technology learning cost and improve the project development efficiency.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments or related technologies of the present application, the drawings needed to be used in the description of the embodiments or related technologies will be briefly described below, and it is obvious for those skilled in the art to obtain other drawings without any creative effort.
FIG. 1 is a flow chart illustrating a method for generating database operation code according to an exemplary embodiment of the present application;
FIG. 2 is a flow chart illustrating another method for generating database operation code according to an exemplary embodiment of the present application;
FIG. 3 is a block diagram illustrating a database operation code generation framework according to an exemplary embodiment of the present application;
FIG. 4 is a flowchart illustrating a method for generating database operation codes corresponding to a user-selected DAO layer technology type according to an exemplary embodiment of the present application;
FIG. 5 is a schematic diagram of an electronic device according to an exemplary embodiment of the present application;
fig. 6 is a block diagram illustrating an apparatus for generating database operation codes according to an exemplary embodiment of the present application.
Detailed Description
Reference will now be made in detail to the exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, like numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the present application, as detailed in the appended claims.
The terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. As used in this application and the appended claims, the singular forms "a", "an", "the" and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It should also be understood that the term "and/or" as used herein refers to and encompasses any and all possible combinations of one or more of the associated listed items.
For a software project which needs to be connected with a database during service implementation, service functions and implementation logics thereof implemented by different functional modules in the software project may not be the same, but basic operations performed on data in the database are often the same, for example, for data addition, deletion, modification, search, summation, sequencing and the like, database operation codes corresponding to the operations are also basically the same, and if developers write the database operation codes one by one, code repetition is avoided, and workload of project development is increased meaninglessly. Therefore, some open source communities provide a code generation framework with a code automatic generation function, but such a framework is often built based on a certain fixed technology, so that database operation codes generated by such a framework are necessarily based on the fixed technology integrated in the framework, developers cannot select other technical types to perform automatic generation of the database operation codes, application scenarios are limited, and the development efficiency of the developers is reduced on the contrary under the conditions that project requirements are repeatedly modified or the developers are not familiar with the fixed technology.
In order to solve the above technical problem, the present application provides a method for generating a database operation code. The following examples are provided to further illustrate the present application and it should be understood that the examples described are only a portion of the present application and are not intended to be exhaustive. All other embodiments that can be derived from the embodiments given herein by a person of ordinary skill in the art are intended to be within the scope of the present disclosure.
Fig. 1 is a flowchart illustrating a method for generating database operation codes according to an exemplary embodiment of the present application. As shown in fig. 1, the method may include the steps of:
102, establishing connection with a target database to obtain structural parameters of the target database.
Because the databases connected with each software project are different, the database operation codes in the functional modules in the software project are also different, namely the database operation codes in the software project have pertinence to the databases connected with the database, so that the database operation codes need to be connected with the database before being generated, and the connected database is the target database. And after connecting the target database, acquiring the structural parameters of the target database.
The target database in the solution of the present application may be a relational database such as Oracle, MySQL, DB2, Microsoft SQL Server, Microsoft Access, or a non-relational database such as Oracle BDB, HBase, MongoDB, Redis, Memcache, and the like, which is not limited in this application. In one embodiment, the target database is a relational database, and the structural parameters may include: library information of the target database, table information of a data table in the target database, a table structure and other parameters.
In one embodiment, connection is established with a target database according to database connection parameters set by a user; and reading the parameter configuration information of the target database to determine the structural parameters of the target database. The user sets the connection parameters of the target database, such as the name, type, access interface address and the like of the target database, through the sent database connection instruction, so as to establish connection with the target database according to the connection parameters.
In one embodiment, a target data table in the target database is determined according to a data table configuration instruction sent by a user, so as to generate an operation code for the target data table. The database usually has a plurality of data tables, and the software project may perform data operations only on some data tables in the target database, and these data tables are the target data tables. The target data table may be set by the user according to the data table configuration instruction sent by the user, or the target data table in the target database may be determined according to default settings when the user does not send the data table configuration instruction, or may be determined according to the software item or other parameters in the target database.
And 104, determining the selected technology type according to a technology type selection instruction sent by the user.
The programming language used by the database operation code generated by the present application may be any one of Java language, C # language, easy language, Python language, and the like, which is not limited in the present application. Accordingly, the type of technology that a user (typically a developer of a software project) may select may be a specific type of technology for one of the programming languages described above or a general type of technology for a plurality of the programming languages described above. In one embodiment, the selected technology type is based on Java language, wherein the technology type of DAO (Data Access Object) layer includes at least one of the following: MyBatis framework, Hibernate framework, MyBatis-Plus framework.
In one embodiment, the selected technology type is a user-defined technology type, and the user-defined technology type and a user-defined template file corresponding to the user-defined technology type are defined by a user; the method further comprises the following steps: and converting the structural parameters of the target database into custom structural parameters which conform to the corresponding format of the custom template file. The technical type selected by the user can be a preset technical type in the frame or a user-defined technical type, different template files are respectively corresponding to one of the different technical types selected by the user, the user-defined template file corresponding to the user-defined technical type selected by the user can be defined by the user, and the data format corresponding to the directly acquired structural parameters of the target database is probably not matched with the data format in the user-defined template file, so that the structural parameters of the target database need to be converted into the user-defined structural parameters conforming to the corresponding format of the user-defined template file, so that the user-defined template file can be used for generating the database operation codes.
And 106, injecting the structural parameters into a template file corresponding to the technology type to generate an operation code for the target database.
In an embodiment, the generated operation code is used to create an API project, and the method further includes: determining a project package name and/or a project name corresponding to the API project according to a project configuration instruction sent by a user; and generating the operation code under the project package name and/or the project name corresponding path. The operation code generated by the scheme can be applied to an API project or RESTful API project constructed based on a Spring framework, a Spring Boot or Struts 2 and other frameworks.
In an embodiment, the operation performed by the finally generated operation code on the data in the target database may include: one or more of add, delete, modify, find, sum, sort, etc.
According to the scheme, multiple optional technical types are provided for a user, so that the problem of code compatibility caused by a fixed technical type is solved; and the user is allowed to select familiar technology types to reduce the technology learning cost and improve the project development efficiency.
Fig. 2 is a flowchart illustrating another method for generating database operation codes according to an exemplary embodiment of the present application. The method may comprise the steps of:
step 202, receiving an instruction sent by a user.
First, it should be noted that the method for generating the database operation code according to the present application may be implemented in the form of independent functional software, an executable file, or a functional plug-in that can be called in project development software such as IDEA. Specifically, if the software is an independent functional software, the functional software needs to be installed in a software and hardware environment with corresponding operation capability in advance; if the executable file is the executable file, the executable file needs to be configured in a proper path under a hardware environment with software operation capacity in advance; if the function plug-in is the function plug-in, the function plug-in needs to be connected with the project development software in advance so as to call the function plug-in for generating the operation code at a reasonable position of the project and at a reasonable time of the project development using the project development software.
Taking the above functional plug-in as an example, after the functional plug-in is called in the project development software, the user may send an instruction to the plug-in, such as a database connection instruction, a technical model selection instruction, or another instruction for setting a corresponding parameter. Specifically, the user may perform parameter configuration such as JDBC (Java Database Connectivity), a project package name corresponding to a project to be developed, and the like on an application-dev.properties and/or an application-init.properties configuration file, where the configuration file may be stored in an src/resources path of the project to be developed. The technical type selection instruction is used for designating a certain technical type selected by a user, for example, the user can select a programming language corresponding to the generated database operation code, and the selectable programming language comprises a Java language, a C # language, an easy language, a Python language and the like; after the user selects the Java language, the database connection technology corresponding to the DAO layer may be further selected, and a MyBatis frame, a Hibernate frame, a MyBatis-Plus frame, and the like may be selected. In addition, the user can also select a user-defined technical type, and both the user-defined technical type and the corresponding user-defined template file can be defined by the user.
Specifically, controls corresponding to different technology types may be displayed in the plug-in interface for the user to click and select, a technology type name input box may also be displayed in the plug-in interface for the user to input a technology type name or a name keyword to be selected in the input box, and of course, other manners may also be used, which is not limited in this application.
The method not only allows a user to select the familiar technical type from the preset technical types of the plug-ins, but also allows the user to define the technical type by self, thereby meeting different programming requirements of the user on various project functions and greatly expanding the application scene of the method.
And step 204, connecting the target database according to the database connection instruction.
After the user setting is completed, the following steps 204-214 can be automatically executed by the main testing method in the code generator CodeAuthGenerator, and the main testing method constitutes the main entry of the database operation code generation method, which can be located under the src/test path of the software project to be developed.
And after the user sends a database connection instruction, establishing connection with the target database according to database connection parameters such as the name, the type, the access interface address and the like of the target database contained in the instruction.
Step 206, obtaining the structural parameters of the target database.
After the functional plug-in is connected with the target database, the structural parameters of the target database can be obtained from the connected target database. The structural parameter of the target database may be library information of the target database, such as name and state of the target database, instance name and state of the target database, name and location of a control file, group name of a log file, number of members, member state, member size, member location, size and location of a data file, object and type owned by a user, temporary file information, archive log information, etc.; the table information of the data table can be information such as table name, table size, table establishing time, remarks and the like; the table structure of the data table may be a field, a type, a primary key, a foreign key, an index, etc. Of course, the specific parameters obtained by the functional plug-in from the target database may be one or more of the above parameters, and the parameters are not limited thereto.
Just because the operation code is generated based on the structure parameter of the target database selected by the user, the operation code with pertinence to the target database is finally generated, that is, the operation code generated aiming at a certain target database can be pertinently applied to the target database. Thereby enabling better database manipulation functionality when the operation code is applied to a software project.
In addition, in step 204, the user may also issue a data table configuration instruction to select a target data table in the target database as an operation object of the database operation code, where the data table configuration instruction may include information such as name, size, and data format of the target data table in the target database. And under the condition that the user sends the data table configuration instruction, determining a target data table in a target database according to the instruction so as to generate an operation code aiming at the target data table. Therefore, the method and the device allow the user to select the target data table in a large number of data tables of the target database in a user-defined mode, and only generate the operation codes for the selected target database, so that the data table corresponding to the codes is more flexible in selection mode and has pertinence, and the generated codes are simpler than the codes generated by taking all the data tables as the target data tables in a default mode.
And step 208, determining a template file corresponding to the selected technology type according to the technology type selection instruction.
In fact, each technology type to be selected corresponds to a specific template file, such as a database connection technology, e.g., a MyBatis frame, a Hibernate frame, or a MyBatis-Plus frame, corresponding to a DAO layer selected by a user, and corresponds to different template files respectively for generating operation codes of the DAO layer. It is to be understood that there may be one or more template files corresponding to any technology type, which is not limited in this application, but the template file corresponding to any technology type should be distinguished from the template files corresponding to other technology types. Since the template file usually stores basic code information such as keywords, variables, or classes, and the basic information in the template file corresponding to any one technology type has a fixed format corresponding to the technology type, the database operation code generated based on the template file also conforms to the fixed format.
When the user selects any one technology type, the final database operation code is generated based on the template file corresponding to the selected technology type, for example, when the user selects the MyBatis frame as the database connection technology of the DAO layer, the database operation code of the DAO layer is generated by subsequently adopting the MyBatis frame. After the user selects a technology type, the specific process of generating the operation code based on the technology type may refer to the content disclosed in the related art, and details of the process are not repeated in this application. The functional plug-in can also be used for selecting a user-defined technical type by a user, wherein the user-defined technical type and a user-defined template file corresponding to the user-defined technical type are defined or parameter-set by the user.
If the user selects the standard technology type, the template file may be obtained from a template file library pre-stored in the functional plug-in, or may be obtained from a standard file library, an open source file library, a self-created file library, or other paths in which the template file is stored, which is not limited in the present application.
Generally, the standard technology type available for the user to select in the functional plug-in usually has a corresponding standard template file, and the user-defined technology type corresponds to a user-defined template file. Because the template files corresponding to different technology types are different, the technology type selected by the user needs to be judged: when the user selects the user-defined technology type, go to step 210; otherwise, when the user selects the standard technology type, go to step 212.
Step 210, converting the structural parameters into the self-defined structural parameters of the corresponding format of the self-defined template file.
When the user selects the user-defined technical type, the user-defined template file corresponding to the user-defined technical type is defined by the user, and because the code format in the user-defined template file is usually inconsistent with the structural parameters of the obtained target database, the structural parameters of the target database need to be changed into the user-defined structural parameters of the format corresponding to the user-defined template file, and actually, the current format of the structural parameters of the target database is changed into the format conforming to the user-defined template file.
Therefore, even if all the provided standard technology types are not suitable for current project development or users are not familiar with all the standard technology types, the users can customize proper or familiar customized technology types to develop the projects, so that various development requirements of the users can be met, and application scenes are further expanded.
Step 212, structure parameters are injected into the template file.
Under the condition that the standard technology type is selected by the user, directly injecting the structural parameters of the target database into a template file corresponding to the technology type selected by the user; in the case that the user selects the custom technology type, the custom structure parameters converted in step 210 are injected into the custom template file. In practice, dynamic data associated with the target database or the software project may also be injected into the template file along with the structural parameters. It can be understood that, according to actual situations such as different project requirements, the structural parameters of the target database and the dynamic data may be further processed and then injected into the template file, and the specific process of the injection operation may refer to the content disclosed in the related art, which is not limited in this application.
It can be seen that, just because any one technology type corresponds to a specific template file, and the static data and the dynamic data injected into the template file both satisfy the fixed format preset in the template file, after a user selects a certain technology type, the basic formats of the operation codes generated based on the template file corresponding to the technology type are the same, thereby realizing unification and normalization of the operation codes and the comments thereof, and facilitating subsequent code modification and project maintenance.
At step 214, an operation code corresponding to the target database is generated.
The implantation operation in step 212 and this step can be performed in the FreeMarket framework. The finally generated operation code for the target database is used in a software project, in an exemplary embodiment, the software project may be an API or RESTful API project constructed based on a Spring framework, a Spring Boot framework, or a Struts 2 framework, and correspondingly, the user may further issue a project configuration instruction including project package name and/or project name and other project information corresponding to the project in step 202, so that this step 214 generates a database operation code under a path corresponding to the project entry and/or the project name. Because the user is allowed to define the code generation path, the error report problem caused by directly using the default path in the code generation process is avoided, and the complicated code path transfer operation which is possibly required to be carried out after the default path is generated is also avoided.
After the operation code of the target database is generated, the user can expand specific service functions and other necessary configurations and connections on the basis of the operation code so as to realize the development of the final software project. After the development work is completed, the user can start the software project after configuring the application-dev.
In conclusion, the scheme of the application can realize one-key generation of the operation codes of the standardized database, reduces the basic code writing workload of developers, enables the developers to concentrate more energy on writing the service codes, and is beneficial to improving the quality and efficiency of project development.
The method of the present application is further described below by taking a database operation code generation framework corresponding to the functional plug-in as an example. FIG. 3 is a block diagram illustrating a database operation code generation framework according to an exemplary embodiment of the present application. The frame may essentially comprise: an item core 301 and item dependencies 302. The project core 301 may further include a plurality of classes, and the project dependency 302 may further include a plurality of dependencies, where the classes and the dependencies have specific functions in the framework, as shown in table 1 below.
TABLE 1
Figure BDA0002453835460000111
When a developer develops a software project with data interaction with a database, an overall framework with the software project to be developed can be built, then an operation code for a connected target database is generated by using a generation framework of the database operation code, the generated database operation code is used as a basic code of the overall framework of the software project to be developed, and finally the service function of the project to be developed is expanded on the basis of the operation code, so that the overall development of the software project is realized.
The specific operation process of the database operation code generation framework shown in fig. 3 will be described below with reference to fig. 4 in the case where the user selects the DAO layer technology type. Fig. 4 is a flowchart illustrating a method for generating a database operation code corresponding to a user-selected DAO layer technology type according to an exemplary embodiment of the present application. First, it is assumed that the code generation framework in the embodiment shown in fig. 4 is built based on a FreeMarker framework, and the database operation codes generated based on the Java language are output after the framework is operated. The method may include the following steps (performed under control of the processing class 3011):
at step 402, user configured data is retrieved.
First, after a user instructs a basic configuration (corresponding configuration class 3012) on a database operation code generation framework (hereinafter, referred to as a code generation framework), user configured data is retrieved. The configuration instructions sent by the user comprise technology type selection instructions for selecting corresponding technology types; database connection instructions, data table configuration instructions, project configuration instructions, and the like may also be included. Specifically, a database connection instruction containing database connection parameters is sent, and a target database needing to generate an operation code is specified, so that the code generation framework establishes connection with the target database after receiving the instruction; if the user does not send the database connection instruction, the framework determines the target database according to default settings or other information of the database and establishes connection with the target database, wherein the default settings can be all databases connected with corresponding software projects or partial databases meeting preset conditions.
The frame determines a target data table needing to generate operation codes after receiving the data table configuration instruction by sending the data table configuration instruction containing the data table information to specify the target database needing to generate the operation codes, and only obtains parameters such as the table information, the table structure and the like of the target data table in the subsequent process, so that the operation codes aiming at the data in the target data table are finally generated. The data table configuration instruction may be issued before the framework is executed, or may be temporarily issued during the framework execution process, which is not limited in the present application. It is understood that, in the case where the user issues the data table configuration instruction, the framework determines the target data table based on the instruction, and in the case where the user does not issue the data table configuration instruction, the framework determines the target data table according to the default setting or the information such as the structural parameters of the target data table, wherein the default setting may be all the data tables in the target data table or a part of the data tables meeting the preset condition.
And specifying a software project to which the generated operation code is applied by issuing a project configuration instruction including a project package name and/or a project name, so that the framework generates the operation code under a path corresponding to the project package name and/or the project name, and directly using the generated operation code as a part of the software project code. The software project can be an API, RESTful API project or other functional project constructed based on a Spring framework, a Spring Boot framework or Struts 2 and other frameworks. It is understood that, in the case that the user issues the item configuration instruction, the framework may generate a database operation code under the item path specified by the instruction; in the event that the user does not issue the project configuration instruction, the framework may generate the database operation code in the default path and then copy the generated operation code from the default path into the appropriate path of the software project. The default path may be a path located in a saving path of the software project, or may be a preset path located outside the saving path of the software project.
In the event that the user issues one or more of the above instructions, the code generation framework may determine the corresponding configuration data in accordance with the user-issued instructions.
Step 404, connecting the database and obtaining the structural parameters of the database.
And establishing connection between the code generation framework and the database, and then acquiring the structural parameters of the database. As described above, in the case where the user issues the database connection instruction, the target database specified by the configuration data included in the database connection instruction is first determined, and then the code generation framework establishes a connection with the target database. After the connection is established, the code generation framework can actively send a structural parameter acquisition request to the target database and receive structural parameters returned by the target database based on the structural parameter acquisition request; the code generation framework can also passively receive the structural parameters actively sent by the target database, at this time, the target database determines the structural parameters to be sent according to a preset parameter list, and sends the structural parameters to the code generation framework according to a preset sending format.
It can be understood that, when a user issues a data table configuration instruction, the above configuration parameters include not only library information of the target database, but also table information and table structure of the target data table.
And 406, selecting a corresponding template file according to the DAO layer technology type selected by the user.
In practice, the user may select a MyBatis framework, a Hibernate framework, a MyBatis-Plus framework, etc. as the technology type for the DAO layer (corresponding to the configuration class 3012). It is not assumed that the user selects the MyBatis frame, and at this time, the processing class 3011 in the code generation frame determines the template file corresponding to the MyBatis frame according to the selection of the user, which is not referred to as a MyBatis template file.
Of course, the code generation frame should have a table of correspondence between different technology types and corresponding template files prestored therein, and the code generation frame may have a plurality of template files prestored therein, or may have only the addresses of the plurality of template files prestored therein, such as a standard file library, an open source file library, a self-built file library, or other paths in which template files are stored, and at this time, the code generation frame may download the MyBatis template file from the saved paths after determining the MyBatis template file. Accordingly, the template file 3016 may store an actual template file, or may store only a correspondence table between the above-described technique type and the template file or the download address thereof.
In this embodiment, since the MyBatis technology type selected by the user is a standard technology type provided by the code generation framework, format conversion of the structural parameters and other data of the target database is not required, and the class converter 3017 is not actually used.
Step 408, loading the template file and the dynamic data to generate the DAO layer code.
And under a Freemarker framework, injecting the structural parameters of the target database acquired in the step and other dynamic data of the target database or the code generation framework into the MyBatis template file, and generating a DAO layer operation code aiming at the target database by combining basic operations such as addition, deletion, modification and check of a form recorded in the universal class 3015.
Step 410, sequentially generating Service layer and Controller layer codes.
Similarly, under the framework of FreeMarker, basic operations such as batch add/delete check of the Service layer and request operation of the Controller layer recorded in the generic class 3015 are combined to generate Service layer and Controller layer operation codes for the target database, respectively.
It can be seen that the basic processing of data in the code generation process needs to use a tool class 3013 and an enumeration & exception 3014; normal operation information such as successful data acquisition, code generation completion and the like in the code generation process and abnormal information such as possible alarms, errors and the like are recorded in a log by the Locback 3023, so that a user can analyze the working condition or the error reason of the code generation framework.
Because the code generation process uses the structural parameters of the target database, the structural parameters can reflect the information of the type (structured and unstructured) of the target database, the data storage mode (table, key value pair, graph structure or document), the table structure (the file name of the data table, which fields the data table contains, the field name of each field, the field type and the field width), and the like, the DAO layer, Service layer and Controller layer operation codes generated by the process can realize basic operations such as adding, deleting, modifying, checking and the like of data in the target database in a targeted manner.
Fig. 5 is a schematic structural diagram of an electronic device according to an exemplary embodiment of the present application. Referring to fig. 5, at the hardware level, the electronic device includes a processor 501, an internal bus 502, a network interface 503, a memory 504, and a non-volatile memory 505, but may also include hardware required for other services. The processor 501 reads a corresponding computer program from the nonvolatile memory 505 to the memory 504 and runs the computer program, and forms a generating device of the database operation code on a logic level. Of course, besides the software implementation, the present application does not exclude other implementations, such as logic devices or a combination of software and hardware, and the like, that is, the execution subject of the following processing flow is not limited to each logic unit, and may also be hardware or logic devices.
Fig. 6 is a block diagram illustrating an apparatus for generating database operation codes according to an exemplary embodiment of the present application. Referring to fig. 6, in a software implementation, the database operation code generation apparatus may include a structure parameter obtaining unit 601, a technology type determining unit 602, and an operation code generating unit 603. Wherein:
a structural parameter obtaining unit 601, configured to obtain a structural parameter of a target database by establishing a connection with the target database;
a technology type determining unit 602, configured to determine a selected technology type according to a technology type selection instruction issued by a user;
an operation code generating unit 603, configured to inject the structure parameter into a template file corresponding to the technology type to generate an operation code for the target database.
Optionally, the structural parameter obtaining unit 601 is specifically configured to:
establishing connection with a target database according to database connection parameters set by a user;
and reading the parameter configuration information of the target database to determine the structural parameters of the target database.
Optionally, the selected technology type is based on Java language, wherein the technology type of the DAO layer includes at least one of:
MyBatis framework, Hibernate framework, MyBatis-Plus framework.
Optionally, the selected technology type is a user-defined technology type, and the user-defined technology type and a user-defined template file corresponding to the user-defined technology type are user-defined by a user; the apparatus for generating database operation codes further comprises:
a format converting unit 604, configured to convert the structure parameter into a custom structure parameter that conforms to a format corresponding to the custom template file.
Optionally, the generated operation code is used to create an API project, and the apparatus for generating database operation code further includes:
a configuration instruction receiving unit 605, configured to determine, according to a project configuration instruction sent by a user, a project package name and/or a project name corresponding to the API project;
a specified path generating unit 606, configured to generate the operation code under the item package name and/or the path corresponding to the item name.
Optionally, the API project is constructed based on a Spring framework or a Spring Boot framework.
Optionally, the apparatus for generating database operation codes further includes:
the target data table determining unit 607 is configured to determine a target data table in the target database according to a data table configuration instruction sent by a user, so as to generate the operation code for the target data table.
Optionally, the target database is a relational database, and the structural parameters include: library information of the target database, table information of a data table in the target database, and a table structure.
Optionally, the operation performed by the operation code on the data in the target database includes: add, delete, modify, and/or lookup.
The implementation process of the functions and actions of each unit in the device is detailed in the implementation process of the corresponding step in the method, and is not described herein again.
In a typical configuration, an electronic device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
The memory may include forms of volatile memory in a computer readable medium, Random Access Memory (RAM) and/or non-volatile memory, such as Read Only Memory (ROM) or flash memory (flash RAM). Memory is an example of a computer-readable medium.
Computer-readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), Digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. As defined herein, a computer readable medium does not include a transitory computer readable medium such as a modulated data signal and a carrier wave.
For the above-mentioned apparatus embodiments, since they basically correspond to the method embodiments, reference may be made to the partial description of the method embodiments for relevant points. The above-described embodiments of the apparatus are merely illustrative, and the units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the scheme of the application. One of ordinary skill in the art can understand and implement it without inventive effort.
The above description is only exemplary of the present application and should not be taken as limiting the present application, as any modification, equivalent replacement, or improvement made within the spirit and principle of the present application should be included in the scope of protection of the present application.

Claims (12)

1. A method for generating database operation codes, the method comprising:
acquiring structural parameters of a target database by establishing connection with the target database;
determining the selected technology type according to a technology type selection instruction sent by a user;
and injecting the structural parameters into a template file corresponding to the technology type to generate an operation code for the target database.
2. The method of claim 1, wherein the obtaining the structural parameters of the target database by establishing a connection with the target database comprises:
establishing connection with a target database according to database connection parameters set by a user;
and reading the parameter configuration information of the target database to determine the structural parameters of the target database.
3. The method of claim 1, wherein the selected technology type is based on Java language, and wherein the technology type of the DAO layer includes at least one of:
MyBatis framework, Hibernate framework, MyBatis-Plus framework.
4. The method of claim 1, wherein the selected technology type is a custom technology type, and the custom technology type and its corresponding custom template file are customized by a user; the method further comprises the following steps:
and converting the structural parameters into custom structural parameters which conform to the corresponding format of the custom template file.
5. The method of claim 1, wherein the generated operation code is used to create an API project, the method further comprising:
determining a project package name and/or a project name corresponding to the API project according to a project configuration instruction sent by a user;
and generating the operation code under the path corresponding to the project package name and/or the project name.
6. The method of claim 5, wherein the API project is constructed based on a Spring framework or a Spring Boot framework.
7. The method of claim 1, further comprising:
and determining a target data table in the target database according to a data table configuration instruction sent by a user so as to generate the operation code aiming at the target data table.
8. The method of claim 1, wherein the target database is a relational database, and wherein the configuration parameters comprise: library information of the target database, table information of a data table in the target database, and a table structure.
9. The method of claim 1, wherein the operations performed by the operation code on the data in the target database comprise: add, delete, modify, and/or lookup.
10. An apparatus for generating database operation codes, comprising:
the system comprises a structural parameter acquisition unit, a structural parameter acquisition unit and a data processing unit, wherein the structural parameter acquisition unit is used for acquiring structural parameters of a target database by establishing connection with the target database;
the technical type determining unit is used for determining the selected technical type according to a technical type selection instruction sent by a user;
and the operation code generating unit is used for injecting the structure parameters into the template file corresponding to the technology type so as to generate the operation code aiming at the target database.
11. An electronic device, comprising:
a processor;
a memory for storing processor-executable instructions;
wherein the processor is configured to implement the method of any one of claims 1-9.
12. A computer-readable storage medium having stored thereon computer instructions, which, when executed by a processor, carry out the steps of the method according to any one of claims 1-9.
CN202010300597.7A 2020-04-16 2020-04-16 Database operation code generation method and device Pending CN113535141A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010300597.7A CN113535141A (en) 2020-04-16 2020-04-16 Database operation code generation method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010300597.7A CN113535141A (en) 2020-04-16 2020-04-16 Database operation code generation method and device

Publications (1)

Publication Number Publication Date
CN113535141A true CN113535141A (en) 2021-10-22

Family

ID=78088448

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010300597.7A Pending CN113535141A (en) 2020-04-16 2020-04-16 Database operation code generation method and device

Country Status (1)

Country Link
CN (1) CN113535141A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114089976A (en) * 2022-01-21 2022-02-25 通联支付网络服务股份有限公司 Method, apparatus, and medium for generating database operation statements
CN114115826A (en) * 2021-11-04 2022-03-01 湖北美和易思教育科技有限公司 Code generation method, terminal and readable storage medium
CN115495442A (en) * 2022-11-16 2022-12-20 深圳市明源云采购科技有限公司 Database operation file generation method, device, equipment and storage medium

Citations (14)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20080162531A1 (en) * 2007-01-03 2008-07-03 Blue Reference, Inc. Object-Oriented Framework for Data-Analysis Having Pluggable Platform Runtimes and Export Services
US20080270980A1 (en) * 2007-04-27 2008-10-30 Azadeh Ahadian Rapid application development for database-aware applications
US20080320441A1 (en) * 2007-06-23 2008-12-25 Azadeh Ahadian Extensible rapid application development for disparate data sources
CN102156640A (en) * 2011-04-19 2011-08-17 山东浪潮金融信息系统有限公司 Method for generating data operation code
CN105677323A (en) * 2015-12-31 2016-06-15 合肥大多数信息科技有限公司 Method for automatically generating database operation layer codes
CN107391153A (en) * 2017-07-31 2017-11-24 深圳乐信软件技术有限公司 A kind of code generating method and device based on Spring Yu MyBatis framework integrations
WO2018145635A1 (en) * 2017-02-08 2018-08-16 深圳壹账通智能科技有限公司 File generation method, device, server, and storage medium
CN108563435A (en) * 2018-04-19 2018-09-21 北京百度网讯科技有限公司 The method and device of code building
CN109062568A (en) * 2018-06-19 2018-12-21 链家网(北京)科技有限公司 A kind of project generation method and tool
CN109725893A (en) * 2018-05-17 2019-05-07 平安普惠企业管理有限公司 Code generating method, unit and computer readable storage medium
CN109885291A (en) * 2019-01-25 2019-06-14 深圳市元征科技股份有限公司 A kind of code automatic generation method and code generator
CN110032369A (en) * 2019-04-24 2019-07-19 成都市映潮科技股份有限公司 A kind of code automatic generation method, device and medium
CN110674625A (en) * 2019-08-29 2020-01-10 浙江数链科技有限公司 Code generation method and device, computer equipment and storage medium
CN110955418A (en) * 2019-12-13 2020-04-03 中国南方电网有限责任公司 Code generation method and device, computer equipment and storage medium

Patent Citations (14)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20080162531A1 (en) * 2007-01-03 2008-07-03 Blue Reference, Inc. Object-Oriented Framework for Data-Analysis Having Pluggable Platform Runtimes and Export Services
US20080270980A1 (en) * 2007-04-27 2008-10-30 Azadeh Ahadian Rapid application development for database-aware applications
US20080320441A1 (en) * 2007-06-23 2008-12-25 Azadeh Ahadian Extensible rapid application development for disparate data sources
CN102156640A (en) * 2011-04-19 2011-08-17 山东浪潮金融信息系统有限公司 Method for generating data operation code
CN105677323A (en) * 2015-12-31 2016-06-15 合肥大多数信息科技有限公司 Method for automatically generating database operation layer codes
WO2018145635A1 (en) * 2017-02-08 2018-08-16 深圳壹账通智能科技有限公司 File generation method, device, server, and storage medium
CN107391153A (en) * 2017-07-31 2017-11-24 深圳乐信软件技术有限公司 A kind of code generating method and device based on Spring Yu MyBatis framework integrations
CN108563435A (en) * 2018-04-19 2018-09-21 北京百度网讯科技有限公司 The method and device of code building
CN109725893A (en) * 2018-05-17 2019-05-07 平安普惠企业管理有限公司 Code generating method, unit and computer readable storage medium
CN109062568A (en) * 2018-06-19 2018-12-21 链家网(北京)科技有限公司 A kind of project generation method and tool
CN109885291A (en) * 2019-01-25 2019-06-14 深圳市元征科技股份有限公司 A kind of code automatic generation method and code generator
CN110032369A (en) * 2019-04-24 2019-07-19 成都市映潮科技股份有限公司 A kind of code automatic generation method, device and medium
CN110674625A (en) * 2019-08-29 2020-01-10 浙江数链科技有限公司 Code generation method and device, computer equipment and storage medium
CN110955418A (en) * 2019-12-13 2020-04-03 中国南方电网有限责任公司 Code generation method and device, computer equipment and storage medium

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114115826A (en) * 2021-11-04 2022-03-01 湖北美和易思教育科技有限公司 Code generation method, terminal and readable storage medium
CN114089976A (en) * 2022-01-21 2022-02-25 通联支付网络服务股份有限公司 Method, apparatus, and medium for generating database operation statements
CN114089976B (en) * 2022-01-21 2022-04-26 通联支付网络服务股份有限公司 Method, apparatus, and medium for generating database operation statements
CN115495442A (en) * 2022-11-16 2022-12-20 深圳市明源云采购科技有限公司 Database operation file generation method, device, equipment and storage medium
CN115495442B (en) * 2022-11-16 2023-08-04 深圳市明源云采购科技有限公司 Database operation file generation method, device, equipment and storage medium

Similar Documents

Publication Publication Date Title
CN107273286B (en) Scene automatic test platform and method for task application
CN113535141A (en) Database operation code generation method and device
US8086642B2 (en) Apparatus, system, and method for processing hierarchical data in disparate data repositories
CN106775744B (en) Method and device for generating static library
US20180046675A1 (en) Automatic adjustment of an execution plan for a query
CN102222012A (en) Static type checking against external data sources
CN108614702B (en) Byte code optimization method and device
CN107330014B (en) Data table creating method and device
CN104794048A (en) Automatic UI testing method and system
US20210103514A1 (en) Reusable test cases for identifiable patterns
CN111695827B (en) Business process management method and device, electronic equipment and storage medium
CN112765023A (en) Test case generation method and device
CN110795091B (en) Modularized route decoupling method, storage medium, electronic equipment and system
CN111581920A (en) Document conversion method, device, equipment and computer storage medium
CN113434158A (en) User-defined management method, device, equipment and medium for big data component
US10459698B2 (en) Framework for generating adapters in an integrated development environment
CN115878092A (en) Code generation method, device and medium based on micro-service architecture
CN114416547A (en) Test case based test method
CN114328250A (en) Automatic self-checking method, medium and device for software system
US7305653B2 (en) Standard application development framework
CN114443039A (en) Input parameter verification method and device, electronic equipment and storage medium
CN113590179B (en) Plug-in detection method and device, electronic equipment and storage medium
CN113901025A (en) Database management method, device, equipment and storage medium
CN114489674A (en) Data verification method and device of dynamic data model
CN115705297A (en) Code call detection method, device, computer equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination