A code generation method, apparatus, device, medium, and program
By connecting to the database through a Java driver to obtain metadata and generate code templates, the problem of repeated code development in business system development is solved and development efficiency is improved.
Patent Information
- Application Number
- CN202310110305.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-13
- Publication Date
- 2025-10-21
- Estimated Expiration
- 2043-02-13
AI Technical Summary
In the existing technology, when developing business systems, developers are required to redevelop the code, which results in a large workload and a long time, affecting development efficiency.
By using the Java driver to connect to various databases, obtain metadata and convert the format, use the adapter interface and code template to generate business system code, fill in the variable name and variable type of the metadata, and generate code files.
It reduces the workload of code development, improves the development efficiency of business systems, and avoids repetitive code development.
Smart Images

Figure CN115951871B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of software, and specifically to a code generation method, apparatus, device, medium and program. Background Art
[0002] With the rapid advancement of the IT industry and the continuous emergence of internet technologies, all industries are joining the wave of development in the internet age. To quickly capture market share, expand business areas, and ensure stable profit growth, companies need to constantly adjust their development strategies, continuously iterate their business operations, and rapidly update their business systems. Due to the unpredictable nature of market demand, launching products earlier during business adjustments can potentially gain an advantage. Therefore, the development of business systems must be expedited, and methods and tools are needed to improve their efficiency.
[0003] However, in the existing technology, when developing business systems, developers need to redevelop the code. This code development workload is very heavy and the development time is long. Therefore, how to reduce the workload of code development and improve the development efficiency of business systems has become a problem that needs to be solved. Summary of the Invention
[0004] In view of the above-mentioned shortcomings of the prior art, the present application provides a code generation method, apparatus, device, medium and program product to solve the above-mentioned problem of how to improve the development efficiency of business systems.
[0005] In a first aspect, the present application provides a code generation method comprising:
[0006] Create connection information, including the database address and Java driver of each database;
[0007] Connecting to a data source using the database address in the connection information, and acquiring metadata from the data source through the Java driver;
[0008] Converting the metadata into a new format using a preset adapter interface.
[0009] After the format conversion is completed, the metadata variable set is obtained, where the metadata variable set includes at least one of a variable name of the metadata and a variable type of the metadata;
[0010] Obtaining a code template corresponding to the metadata;
[0011] Obtain a custom snippet for developing a business system from the code template, fill the variable name and variable type of the metadata into the custom snippet, and after filling, set the code template as the code file of the business system. In one embodiment of the present application, obtaining the code template corresponding to the metadata is specifically as follows:
[0012] Purpose of obtaining the metadata;
[0013] Querying whether the usage of the metadata exists in pre-stored template usages;
[0014] When the usage of the metadata exists in the pre-stored template usages, the code template corresponding to the usage of the metadata is obtained according to the correspondence between the pre-stored template usages and code templates.
[0015] In one embodiment of the present application, the code template corresponding to the metadata is obtained as follows:
[0016] Obtaining a development language for the metadata;
[0017] Querying pre-stored development languages to determine whether the development language of the metadata exists;
[0018] When the development language of the metadata exists in the pre-stored development languages, the code template corresponding to the development language of the metadata is obtained according to the correspondence between the pre-stored development languages and code templates.
[0019] In one embodiment of the present application, the code template corresponding to the metadata is obtained as follows:
[0020] Acquire the purpose of the metadata and the development language of the metadata;
[0021] Querying whether the usage of the metadata exists in pre-stored template usages, and querying whether the development language of the metadata exists in pre-stored development languages;
[0022] When the pre-stored template usage includes the usage of the metadata and the pre-stored development language includes the development language of the metadata, the code template corresponding to the metadata is obtained according to the correspondence between the pre-stored template usage, the pre-stored development language and the code template.
[0023] In one embodiment of the present application, after obtaining a custom segment for developing the business system from the code template, filling the variable name and variable type of the metadata into the custom segment, and after completing the filling, setting the code template as a code file for the business system, the method includes:
[0024] Authorize the test server to test the code files of the business system;
[0025] Obtaining the test results of the code files of the business system returned by the test server;
[0026] Determining whether the test result is an expected result;
[0027] When the test result is the expected result, the code file of the business system is exported to a specified directory.
[0028] In one embodiment of the present application, the authorization test server tests the code file of the business system, specifically:
[0029] Providing a communication interface to the test server and receiving a test request sent by the test server, wherein the test request includes the test server authority level;
[0030] Determining whether the test server authority level is greater than or equal to the interface authority level of the communication interface;
[0031] If the test server authority level is greater than or equal to the interface authority level, the test server is authorized to call and test the code file of the business system through the communication interface.
[0032] In a second aspect, the present application provides a code generation device, the device comprising:
[0033] A connection management module is used to create connection information, including the database address and Java driver of each database;
[0034] A metadata acquisition module, configured to connect to a data source using the database address in the connection information, and acquire metadata from the data source via the Java driver;
[0035] An adapter module, configured to convert the format of the metadata through a preset adapter interface;
[0036] A metadata variable module, configured to obtain the metadata variable set after format conversion is completed, wherein the metadata variable set includes at least one of a variable name of the metadata and a variable type of the metadata;
[0037] A template management module, used to obtain the code template corresponding to the metadata;
[0038] The code generation module is used to obtain the custom fragment used to develop the business system in the code template, fill the variable name and variable type of the metadata into the custom fragment, and after filling, set the code template as the code file of the business system.
[0039] In a third aspect, the present application provides an electronic device, comprising:
[0040] one or more processors;
[0041] The storage device is used to store one or more programs, and when the one or more programs are executed by the one or more processors, the electronic device implements the above-mentioned code generation method.
[0042] In a fourth aspect, the present application provides a computer-readable storage medium having computer-readable instructions stored thereon. When the computer-readable instructions are executed by a processor of a computer, the computer executes the above-mentioned code generation method.
[0043] In a fifth aspect, the present application provides a computer program product or a computer program, wherein the computer program product or the computer program includes computer instructions, wherein the computer instructions are stored in a computer-readable storage medium, and a computer processor reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer executes the above-mentioned code generation method.
[0044] The beneficial effects of this application are twofold. On the one hand, the Java drivers for various databases are used to connect to various data sources. This allows any business system that needs metadata to obtain metadata from the data source by calling the Java driver. On the other hand, the variable names and variable types of the metadata are filled into the custom snippet. After filling, the code template is set as the code file of the business system. Since the code contains the variable names and variable types of the metadata, there is no need for developers to redevelop the code, which greatly reduces the workload of developing code and thus improves the development efficiency of the business system.
[0045] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] The accompanying drawings are incorporated into and constitute a part of the specification, illustrating embodiments consistent with the present application and, together with the specification, serving to explain the principles of the present application. It is obvious that the drawings described below are merely some embodiments of the present application, and a person of ordinary skill in the art can derive other drawings based on these drawings without inventive effort. In the drawings:
[0047] Figure 1 is a schematic diagram of an implementation environment of a code generation method shown in an exemplary embodiment of the present application;
[0048] Figure 2 is a flowchart of a code generation method shown in an exemplary embodiment of the present application;
[0049] Figure 3 is a schematic diagram of a code generation device shown in an exemplary embodiment of the present application;
[0050] Figure 4 is an operational flow chart illustrating a code generation method according to an exemplary embodiment of the present application;
[0051] Figure 5 is a structural block diagram of a code generation device shown in an exemplary embodiment of the present application;
[0052] Figure 6 It is a structural diagram of a computer system of an electronic device shown in an exemplary embodiment of the present application. DETAILED DESCRIPTION
[0053] The following will describe the embodiments of the present application with reference to the accompanying drawings and preferred embodiments. Those skilled in the art can easily understand the other advantages and effects of the present application from the contents disclosed in this specification. The present application can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present application. It should be understood that the preferred embodiments are only for the purpose of illustrating the present application and are not intended to limit the scope of protection of the present application.
[0054] It should be noted that the illustrations provided in the following embodiments are only schematic illustrations of the basic concept of the present application. Therefore, the illustrations only show components related to the present application and are not drawn according to the number, shape and size of components in actual implementation. In actual implementation, the type, quantity and proportion of each component can be changed at will, and the component layout type may also be more complicated.
[0055] In the following description, a large number of details are discussed to provide a more thorough explanation of the embodiments of the present application. However, it is obvious to those skilled in the art that the embodiments of the present application can be implemented without these specific details. In other embodiments, well-known structures and devices are shown in the form of block diagrams rather than in detail to avoid making the embodiments of the present application difficult to understand.
[0056] See Figure 1 , Figure 1 FIG. 1 is a schematic diagram of an implementation environment of a code generation method shown in an exemplary embodiment of the present application. Figure 1As shown, the implementation environment application network architecture may include a server 101 (server cluster) and a user terminal cluster. The user terminal cluster may include one or more user terminals, and the number of user terminals is not limited here. Figure 1 As shown, it may specifically include user terminal 10a, user terminal 10b, user terminal 10c, ..., user terminal 10n. Figure 1 As shown, user terminal 10a, user terminal 10b, user terminal 10c, ..., user terminal 10n can respectively establish a network connection with the server 101, so that each user terminal can exchange data with the server 101 through the network connection. The specific connection method of the network connection is not limited here, for example, it can be directly or indirectly connected through a wired communication method, or directly or indirectly connected through a wireless communication method.
[0057] Each user terminal in the user terminal cluster may include: smart phones, tablet computers, laptop computers, desktop computers, smart speakers, smart watches, car terminals, smart TVs and other smart terminals with image data processing functions. Figure 1 Each user terminal in the user terminal cluster shown can be installed with a target application (ie, an application client). When the application client runs in each user terminal, it can be respectively connected to the above Figure 1 Data is exchanged between the server 101 shown. The application client may include a social client, a multimedia client (e.g., a video client), an entertainment client (e.g., a game client), an educational client, a live broadcast client, and the like. The application client may be a standalone client or a mini-program integrated into a client (e.g., a social client, an educational client, a multimedia client, etc.), without limitation herein.
[0058] like Figure 1 As shown, the server 101 in the embodiment of the present application can be the server corresponding to the application client. The server 101 can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing cloud computing services.
[0059] For ease of understanding, the embodiments of the present application can be Figure 1 Select one user terminal from the multiple user terminals shown as the target user terminal. For example, the embodiment of the present application can Figure 1The user terminal 10a shown serves as the target user terminal. The target user terminal may integrate a target application (i.e., an application client). In this case, the target user terminal can exchange data with the server 101 via the business data platform corresponding to the application client. The code generation method described above can be performed on any device, such as a server, terminal, server cluster, or cloud computing service cluster.
[0060] See also Figure 2 , Figure 2 FIG. 1 is a flowchart of a code generation method shown in an exemplary embodiment of the present application, which is described in detail as follows:
[0061] Step S201: Create connection information, including the database address and Java driver of each database;
[0062] The database includes at least one of a relational database and a non-relational database.
[0063] Step S202: Use the database address in the connection information to connect to a data source, and obtain metadata from the data source through the Java driver;
[0064] Step S203: converting the metadata into a format through a preset adapter interface;
[0065] Step S204: After the format conversion is completed, the metadata variable set is obtained, where the metadata variable set includes at least one of a variable name of the metadata and a variable type of the metadata;
[0066] Step S205: Obtain the code template corresponding to the metadata;
[0067] Wherein, step S205 is specifically as follows:
[0068] Purpose of obtaining the metadata;
[0069] Querying whether the usage of the metadata exists in pre-stored template usages;
[0070] When the usage of the metadata exists in the pre-stored template usages, the code template corresponding to the usage of the metadata is obtained according to the correspondence between the pre-stored template usages and code templates.
[0071] Wherein, step S205 is specifically as follows:
[0072] Obtaining a development language for the metadata;
[0073] Querying pre-stored development languages to determine whether the development language of the metadata exists;
[0074] When the development language of the metadata exists in the pre-stored development languages, the code template corresponding to the development language of the metadata is obtained according to the correspondence between the pre-stored development languages and code templates.
[0075] Wherein, step S205 is specifically as follows:
[0076] Acquire the purpose of the metadata and the development language of the metadata;
[0077] Querying whether the usage of the metadata exists in pre-stored template usages, and querying whether the development language of the metadata exists in pre-stored development languages;
[0078] When the pre-stored template usage includes the usage of the metadata and the pre-stored development language includes the development language of the metadata, the code template corresponding to the metadata is obtained according to the correspondence between the pre-stored template usage, the pre-stored development language and the code template.
[0079] Step S206, obtaining a custom segment for developing a business system in the code template, filling the variable name and variable type of the metadata into the custom segment, and after filling, setting the code template as the code file of the business system.
[0080] After step S206, the method includes:
[0081] Obtaining modification instructions for the code template through a preset code development tool;
[0082] Modify the code template according to the modification instruction.
[0083] After step S206, the method includes:
[0084] An update time is obtained, and when the update time arrives, a preset server is connected to update the code template.
[0085] After step S206, the method includes:
[0086] Authorize the test server to test the code files of the business system;
[0087] Obtaining the test results of the code files of the business system returned by the test server;
[0088] Determining whether the test result is an expected result;
[0089] When the test result is the expected result, the code file of the business system is exported to a specified directory.
[0090] The authorized test server tests the code in the code file, and obtains the test result of the code file of the business system returned by the test server.
[0091] The designated directory can be set by the user or the system, and there is no restriction here.
[0092] The authorization test server tests the code files of the business system, specifically:
[0093] Providing a communication interface to the test server and receiving a test request sent by the test server, wherein the test request includes the test server authority level;
[0094] Determining whether the test server authority level is greater than or equal to the interface authority level of the communication interface;
[0095] If the test server authority level is greater than or equal to the interface authority level, the test server is authorized to call and test the code file of the business system through the communication interface.
[0096] The beneficial effects of this application are twofold. On the one hand, the Java drivers for various databases are used to connect to various data sources. This allows any business system that needs metadata to obtain metadata from the data source by calling the Java driver. On the other hand, the variable names and variable types of the metadata are filled into the custom snippet. After filling, the code template is set as the code file of the business system. Since the code contains the variable names and variable types of the metadata, there is no need for developers to redevelop the code, which greatly reduces the workload of developing code and thus improves the development efficiency of the business system.
[0097] refer to Figure 3 , Figure 3 This is a schematic diagram of a code generation device shown in an exemplary embodiment of the present application, which is described in detail as follows:
[0098] The adapter connects to various databases, converts the metadata objects of the database into Class objects, converts the format of the metadata through the preset type mapping and adapter interface, and obtains the metadata variable set after the format conversion is completed; the various databases include at least one of MySQL, MongoDB, and Elasticsearch.
[0099] Obtain the custom fragment used to develop the business system in the code template, and fill the variable name and variable type of the metadata into the custom fragment through the Velocity engine. After filling, set the code of the code template as the code of the business system to generate the code file of the business system.
[0100] The code template includes at least one of a Java code template, a JavaScript code template, and a C++ code template, and the code file includes at least one of a Java code file, a JavaScript code file, and a C++ code file.
[0101] For the sake of convenience, a practical application is taken as an example and described in detail as follows:
[0102] The present invention includes a connection management module, an adapter module, a metadata variable module, a type mapping module, a template management module, a code generation module, etc. The functions of each module are described as follows.
[0103] The connection management module is also used to maintain the connection configuration information of various database middleware, including address, account, password, driver, etc. The connection tool class loads the configuration information and driver to connect to the database middleware through the network to obtain metadata information.
[0104] The adapter module is also used to maintain various adapter information, including the implemented Java class path and the database connection used. Its function is to convert various database middleware metadata information into a metadata object collection of a unified standard data type to facilitate the use of these metadata in subsequent code generation.
[0105] The adapter interface AdaptiveInterFace of the present invention defines that the adapter should have functions such as establishing connection, loading metadata, and metadata conversion. When there is no appropriate adapter to use, the interface development can be implemented independently.
[0106] Since the present invention is not only aimed at relational or non-relational databases, when performing metadata conversion, the table in the relational database and the collection and mapping in the non-relational database will be converted into Class objects, and the field will be converted into Field. Field contains attributes such as database field type, Java type, length, ref Class object, etc.
[0107] When processing non-relational databases, they may store data in JSON format, which is a very flexible format. A field inside a document may nest documents of other types. When the present invention converts such a field into a Field, the database field type does not change, the Java type is set to Object or Array, and the embedded document type is still converted into a new Class object, and the ref Class object attribute is saved as the converted Class object, thereby ensuring nested format conversion.
[0108] Database metadata conversion relies on the mapping between database field types and Java language types established in the type mapping table. For example, in MySQL, varchar corresponds to String, int corresponds to Integer, and char corresponds to Character. MongoDB's Object corresponds to Object and Array corresponds to Array. Both varchar and char can store strings.
[0109] All database field types are mapped only to Java types, which act as a bridge.
[0110] The metadata variable module also maintains and stores converted metadata collection information, establishes standardized variable names and types, and defines commonly used global variables for easy use in code templates. Each table structure corresponds to a Class object, which contains multiple Field objects. Fields include attributes such as name, original type, mapping type, regular expression, required, non-null, length, format, dictionary entry, description, dependent type object, and target type.
[0111] The type mapping module also maintains the relationship between database field types and Java types, as well as the relationship between Java types and other language types. It maintains database type mapping tables and language type mapping tables, both of which contain fields such as the original type, original length, target type, and target length. Configuring the length accurately identifies the target type, ensuring the correct data type when generating target language code. The type mapping tables are used in the adapter module and the code generation module, respectively.
[0112] The template management module also maintains information about various code templates, including their purpose and the language they are generated in. It also uses Velocity technology to create code templates in various languages. One metadata object corresponds to multiple templates, and the template generation logic is controlled using the language-specific variable set according to Velocity syntax. Velocity is an engine that generates various text files by mixing templates with Java class data.
[0113] The code generation module also integrates the aforementioned configuration information, selects a metadata object, loads the metadata variable collection into the Velocity engine, parses expressions in the code template, renders the code template, and generates the code file to the specified path. The Velocity tool class loads the metadata Class object into a variable collection. When mapping the target language type, it relies on the mapping relationships in the language type mapping table. The target type of the field is determined based on the original type, target type, and length.
[0114] For example, a Java string of length 100 is mapped to a C++ type char
[100] . After conversion from a non-relational database, the Class object contains Fields that depend on other Class object types. The dependent Class objects are recursively loaded into the object and saved to the ref Class object attribute.
[0115] To prevent circular dependencies, this paper uses a concurrent Hash Map to store loaded Class objects. The Class object name is used as the key and the Class object as the value. When a Field depends on another Class object, it is first searched in the concurrent container. If no such object is found, it is loaded and saved again. After loading the variable collection, the Velocity engine is called to render the code template, replacing the custom snippet in the code template to generate a code file, which is then exported to a specified directory.
[0116] The beneficial effects of this embodiment are in several aspects, which are detailed as follows:
[0117] First, the Java development language is used to connect to all database middleware involved. The language itself has excellent cross-platform features, extremely wide user adoption, and an active open source ecosystem. Due to these characteristics, even very niche database middleware will produce excellent Java drivers as user adoption increases. This invention uses Java drivers for various databases to connect to various data sources, thereby achieving a unified style for connecting different databases.
[0118] Secondly, to convert metadata into objects in a unified format, we define the AdaptiveInterFace adapter interface, Class, Field, and other class files, and establish a database type mapping table. The role of the adapter is to standardize metadata with multiple different rules into a single type of metadata, achieving unified metadata management and distribution. This allows pluggable use, and by replacing different adapters, metadata of a unified data type can be generated based on different database middleware. The adapters have functions such as establishing connections, loading metadata, and converting metadata. Each database metadata object corresponds to a Class object, and each of its fields corresponds to a Field object. The database type mapping table configures the mapping relationship between field types and Java types for all databases. The adapter loads database metadata information and converts this metadata information into common Class objects and Field objects according to the database type mapping table. Field types are mapped to standard Java language data types.
[0119] Third, support for non-relational databases, whose data structures are flexible and changeable, can involve nesting other data types within one data type, similar to JSON data types. To address this issue, the Field class has a ref_class attribute. When nested JSON data types, such as object or array, are present, the adapter converts the nested metadata into another class. This attribute stores the referenced data type. This allows complex, multi-layered metadata types to be converted into independent classes with dependencies.
[0120] The fourth aspect is to generate the target language code, which involves multiple development languages and numerous data types, and the mapping relationship between the database type and the development language type is complex. The present invention uses the Java language data type as a bridge. As mentioned above, an adapter has been used to convert the metadata types of various databases into Java types according to the database type mapping table. All converted fields have Java types. Here, a language type mapping table is provided, which configures the mapping relationship between Java types and other language types. The language type mapping table has fields such as Java type, length, target language, and target type. Subsequently, the target language code is generated according to the Field, and the target language data type can be calculated based on the relationship between Java type, length, and language type mapping table.
[0121] refer to Figure 4 , Figure 4 The following is an operational flow chart of a code generation method according to an exemplary embodiment of the present application, which is described in detail as follows:
[0122] Configure connection information;
[0123] Determine whether there is a suitable adapter. If yes, configure the adapter information. If no, return to determine whether there is a suitable adapter.
[0124] Determine whether the adapter is working properly. If yes, import metadata. If no, return information about configuring the adapter.
[0125] Check the adjustment metadata;
[0126] Determine whether you have a matching code template. If yes, create a code template. If not, make a code template and upload it to the specified directory.
[0127] Generate code files;
[0128] Preview the code file to see if it meets expectations. If yes, export the code file to the specified directory and finish. If no, adjust the code template and export the code file to the specified directory and finish.
[0129] For the sake of convenience, a practical application is taken as an example and described in detail as follows:
[0130] Step 1: Configure the connection information, including but not limited to the database address, account with metadata read permission, password, and driver. After the test connection is successful, save the configuration.
[0131] Step 2: Configure the adapter information, select the connection information, the adapter implementation class path, and then test whether the adapter can work properly, whether it can preview and display metadata information, and whether the metadata import function is normal. If there is no suitable adapter to choose, you can also implement the interface method yourself and then configure the adapter.
[0132] Step 3: Check whether the metadata imported by the adapter module meets the expected standards, including its name, database type, mapping type, regular rule, whether it is required, non-empty, length, format, dictionary items, description information, etc. If the metadata does not meet the expectations, you can modify and adjust it yourself.
[0133] Step 4: Create a code template. Create a code template according to your needs, use Velocity syntax variables to replace the changed content in the code template, then upload the code template to the specified directory, and then configure the template purpose, applicable development language, and other information.
[0134] Step 5: Generate code files. Select multiple metadata Class object information for the code files to be generated, select multiple template information to be generated, and preview the generated code files to see if they meet your expectations. If they do not meet your requirements, you can adjust the code template and metadata information. Finally, confirm the code files and export them to the specified directory.
[0135] In this embodiment, the target code language is diverse and the code formats are different, so how to generate multiple target codes. The present invention does not specify a fixed format for the target code. Instead, the developer provides a code template. The developer is most clear about the required code format. The code template is the basic text character information file. The present invention uses Velocity technology to render the code template. The code template is also pluggable and no longer limited to generating a few specific methods or files. As long as a standard code template is provided according to the needs and the variable name and variable type of the metadata are used to fill in the custom fragment, various code files can be generated.
[0136] See also Figure 5 , Figure 5 This is a structural block diagram of a code generation device shown in an exemplary embodiment of the present application. The device can be applied to Figure 1 The device may also be applicable to other exemplary implementation environments and specifically configured in other devices. This embodiment does not limit the implementation environment to which the device is applicable.
[0137] like Figure 5 As shown, the exemplary code generating device includes:
[0138] A connection management module is used to create connection information, including the database address and Java driver of each database;
[0139] A metadata acquisition module, configured to connect to a data source using the database address in the connection information, and acquire metadata from the data source via the Java driver;
[0140] An adapter module, configured to convert the format of the metadata through a preset adapter interface;
[0141] A metadata variable module, configured to obtain the metadata variable set after format conversion is completed, wherein the metadata variable set includes at least one of a variable name of the metadata and a variable type of the metadata;
[0142] A template management module, used to obtain the code template corresponding to the metadata;
[0143] The code generation module is used to obtain the custom fragment used to develop the business system in the code template, fill the variable name and variable type of the metadata into the custom fragment, and after filling, set the code template as the code file of the business system.
[0144] This exemplary code generation device provides two beneficial effects. First, it uses Java drivers for various databases to connect to various data sources. This allows any business system that requires metadata to obtain metadata from the data source by calling the Java driver. Second, the variable names and types of the metadata are populated into the custom snippet. Once completed, the code template is set as the code file for the business system. Because the code already contains the metadata variable names and types, developers do not need to redevelop the code, significantly reducing the workload and improving the efficiency of business system development.
[0145] It should be noted that the code generation device provided in the above embodiment and the code generation method provided in the above embodiment are based on the same concept. The specific manner in which each module and unit performs operations has been described in detail in the method embodiment and will not be repeated here. In actual applications, the code generation device provided in the above embodiment can distribute the above functions to different functional modules as needed, that is, divide the internal structure of the device into different functional modules to complete all or part of the functions described above, and this is not limited here.
[0146] An embodiment of the present application also provides an electronic device, comprising: one or more processors; a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the electronic device implements the code generation method provided in the above-mentioned embodiments.
[0147] See also Figure 6 , Figure 6 This is a schematic diagram of the structure of a computer system of an electronic device according to an exemplary embodiment of the present application. Figure 6 The computer system 1000 of the electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0148] like Figure 6As shown, computer system 1000 includes a central processing unit (CPU) 1001, which can perform various appropriate actions and processes, such as the methods described in the above embodiments, based on programs stored in read-only memory (ROM) 1002 or programs loaded from storage 1008 into random access memory (RAM) 1003. RAM 1003 also stores various programs and data required for system operation. CPU 1001, ROM 1002, and RAM 1003 are interconnected via bus 1004. An input / output (I / O) interface 1005 is also connected to bus 1004.
[0149] The following components are connected to the I / O interface 1005: an input section 1006 including a keyboard, mouse, and the like; an output section 1007 including devices such as a cathode ray tube (CRT), a liquid crystal display (LCD), and speakers; a storage section 1008 including a hard disk; and a communication section 1009 including a network interface card such as a LAN (Local Area Network) card or a modem. The communication section 1009 performs communication processing via a network such as the Internet. A drive 1010 is also connected to the I / O interface 1005 as needed. Removable media 1011, such as a magnetic disk, optical disk, magneto-optical disk, or semiconductor memory, is installed in the drive 1010 as needed, so that computer programs read from the media can be installed in the storage section 1008 as needed.
[0150] In particular, according to embodiments of the present application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of the present application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program including a computer program for executing the methods illustrated in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via the communication section 1009 and / or installed from removable media 1011. When executed by the central processing unit (CPU) 1001, the computer program performs the various functions defined in the system of the present application.
[0151] It should be noted that the computer-readable medium described in the embodiments of this application may be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium may, for example, be an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or component, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to, an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), flash memory, optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In this application, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, carrying a computer-readable computer program. This propagated data signal may take a variety of forms, including, but not limited to, an electromagnetic signal, an optical signal, or any suitable combination thereof. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. A computer program embodied on a computer-readable medium may be transmitted using any suitable medium, including but not limited to wireless, wired, or any suitable combination thereof.
[0152] The flowcharts and block diagrams in the accompanying drawings illustrate the possible implementation architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present application. Among them, each box in the flowchart or block diagram can represent a module, program segment, or part of the code, and the above-mentioned module, program segment, or part of the code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in an order different from that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flowchart, and the combination of boxes in the block diagram or flowchart, can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0153] The units involved in the embodiments described in this application can be implemented by software or hardware, and the units described can also be set in a processor. In some cases, the names of these units do not constitute limitations on the units themselves.
[0154] Another aspect of the present application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the code generation method described above. The computer-readable storage medium may be included in the electronic device described in the above embodiments, or may exist independently and not be incorporated into the electronic device.
[0155] Another aspect of the present application further provides a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the code generation method provided in each of the above embodiments.
[0156] The above embodiments are merely illustrative of the principles and effects of this application and are not intended to limit this application. Anyone skilled in the art may modify or alter the above embodiments without departing from the spirit and scope of this application. Therefore, any equivalent modifications or alterations accomplished by a person of ordinary skill in the art without departing from the spirit and technical concepts disclosed in this application shall be covered by the claims of this application.
Claims
1. A code generation method, characterized in that: include: Create connection information, including the database address and Java driver of each database; Connecting to a data source using the database address in the connection information, and acquiring metadata from the data source through the Java driver; Converting the metadata into a new format using a preset adapter interface. After the format conversion is completed, the metadata variable set is obtained, where the metadata variable set includes at least one of a variable name of the metadata and a variable type of the metadata; Get the code template corresponding to the metadata, specifically: Purpose of obtaining the metadata; querying whether the use of the metadata exists in the pre-stored template uses; when the use of the metadata exists in the pre-stored template uses, obtaining the code template corresponding to the use of the metadata according to the correspondence between the pre-stored template uses and code templates; or, obtaining a development language of the metadata; Querying whether the development language of the metadata exists in the pre-stored development languages; when the development language of the metadata exists in the pre-stored development languages, obtaining the code template corresponding to the development language of the metadata according to the correspondence between the pre-stored development languages and the code templates; or, obtaining the purpose of the metadata and the development language of the metadata; querying whether the metadata usage exists in pre-stored template usages, and querying whether the metadata development language exists in pre-stored development languages; when the metadata usage exists in the pre-stored template usages and the metadata development language exists in the pre-stored development languages, obtaining a code template corresponding to the metadata based on the correspondence between the pre-stored template usages, the pre-stored development languages, and the code templates; Obtain a custom segment for developing a business system in the code template, fill the variable name and variable type of the metadata into the custom segment, and after filling, set the code template as the code file of the business system.
2. The method according to claim 1, characterized in that After obtaining a custom segment for developing the business system from the code template, filling the variable name and variable type of the metadata into the custom segment, and after completing the filling, setting the code template as a code file for the business system, the method includes: Authorize the test server to test the code files of the business system; Obtaining the test results of the code files of the business system returned by the test server; Determining whether the test result is an expected result; When the test result is the expected result, the code file of the business system is exported to a specified directory.
3. The method according to claim 2, wherein the authorized test server tests the code files of the business system, specifically: Providing a communication interface to the test server and receiving a test request sent by the test server, wherein the test request includes the test server authority level; Determining whether the test server authority level is greater than or equal to the interface authority level of the communication interface; If the test server authority level is greater than or equal to the interface authority level, the test server is authorized to call and test the code file of the business system through the communication interface.
4. A code generating device, characterized in that: The device comprises: A connection management module is used to create connection information, including the database address and Java driver of each database; A metadata acquisition module, configured to connect to a data source using the database address in the connection information, and acquire metadata from the data source via the Java driver; An adapter module, configured to convert the format of the metadata through a preset adapter interface; A metadata variable module, configured to obtain the metadata variable set after format conversion is completed, wherein the metadata variable set includes at least one of a variable name of the metadata and a variable type of the metadata; The template management module is used to obtain the code template corresponding to the metadata, specifically: Obtaining the purpose of the metadata; querying whether the purpose of the metadata exists in the pre-stored template purposes; when the purpose of the metadata exists in the pre-stored template purposes, obtaining the code template corresponding to the purpose of the metadata based on the correspondence between the pre-stored template purposes and the code template; or, Obtaining the development language of the metadata; querying whether the development language of the metadata exists in pre-stored development languages; when the development language of the metadata exists in the pre-stored development languages, obtaining the code template corresponding to the development language of the metadata based on the correspondence between the pre-stored development languages and code templates; or, Obtaining the purpose of the metadata and the development language of the metadata; querying whether the purpose of the metadata exists in the pre-stored template purposes, and querying whether the development language of the metadata exists in the pre-stored development languages; when the purpose of the metadata exists in the pre-stored template purposes and the development language of the metadata exists in the pre-stored development languages, obtaining the code template corresponding to the metadata according to the correspondence between the pre-stored template purposes, the pre-stored development language and the code template; The code generation module is used to obtain the custom fragment used to develop the business system in the code template, fill the variable name and variable type of the metadata into the custom fragment, and after filling, set the code template as the code file of the business system.
5. An electronic device, characterized in that: include: one or more processors; A storage device for storing one or more programs, which, when executed by the one or more processors, enables the electronic device to implement the method according to any one of claims 1 to 3.
6. A computer-readable storage medium, characterized in that Computer-readable instructions are stored thereon, and when the computer-readable instructions are executed by a processor of a computer, the computer is caused to execute the method according to any one of claims 1 to 3.
7. A computer program product, characterized in that The computer program product includes computer instructions, which are stored in a computer-readable storage medium. A computer processor reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer executes the method according to any one of claims 1 to 3.
Citation Information
Patent Citations
Metadata file creating method and system and server
CN102567500A
Data processing method, device, electronic equipment and storage medium
CN112131289A