Code generation method based on resource allocation, isolation and recovery and related device
By receiving user requests and generating code, this method solves the problems of database resource allocation, isolation, and reclamation in existing technologies, improving development efficiency and resource management efficiency, and is suitable for temporary test projects in large companies.
Patent Information
- Application Number
- CN202210926918.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-03
- Publication Date
- 2026-11-24
- Estimated Expiration
- 2042-08-03
AI Technical Summary
Existing code generation tools cannot effectively solve the problems of database resource allocation, resource isolation, and recycling, resulting in low development efficiency.
This paper provides a code generation method based on resource allocation, isolation, and recycling. It receives user requests, creates applications and allocates database resources, generates code and then recycles resources. The method includes receiving application creation requests, review requests, code generation requests and resource recycling requests, using a template engine to render code and allocate and recycle database resources.
It enables efficient allocation, isolation, and reclamation of database resources, improving development efficiency and reducing the time required for resource allocation and reclamation processes, making it suitable for temporary testing projects in large companies.
Smart Images

Figure CN115269194B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of Java development technology, and in particular to a code generation method and related equipment based on resource allocation, isolation and recycling. Background Technology
[0002] With the rapid development of the Internet, developers are facing an increasing workload, needing to maintain or develop multiple projects simultaneously. If each project requires developers to build the code framework from scratch, especially if each project designs multiple tables, each table corresponding to multiple classes and methods such as controller class, service class, implementation class, dao class, and bean class, it is very time-consuming and the development efficiency of developers is low.
[0003] In existing technologies, most code generation tools need to apply for their own database resources before generating code. For large companies, this is a very time-consuming process. The applied resources are physically isolated through different servers. If it is a temporary test project, the resource recycling process needs to be followed.
[0004] Therefore, it can be seen that existing code generation tools cannot solve the problems of database resource allocation, resource isolation, and recycling during the code generation process. Summary of the Invention
[0005] In view of this, embodiments of the present invention provide a code generation method and related equipment based on resource allocation, isolation and reclamation to solve the problems of database resource application, resource isolation and reclamation in the prior art.
[0006] To achieve the above objectives, the embodiments of the present invention provide the following technical solutions:
[0007] The first aspect of this invention discloses a code generation method based on resource allocation, isolation, and recycling, applied to a server, the method comprising:
[0008] The system receives an application creation request submitted by a user through the management backend. The application creation request is obtained by the user through the management backend after triggering the create button, filling in the application information of the application to be created in the application creation box, and then triggering the confirmation button. The application information includes at least the application name, application number, description, and resource selection. The resource selection is whether to select the database DB.
[0009] Based on the application creation request, create an application for the user and set the application's status to "created".
[0010] Receive a submission review request from the user for any of the applications submitted through the management backend;
[0011] Based on the submitted review request, the application's status is set to pending review;
[0012] Receive the application's review request submitted by the administrator through the management backend;
[0013] Determine whether the user has selected the database DB;
[0014] If not, change the application's status to "approved";
[0015] If so, allocate database resources to the application and create a test table. The database resources include the application's database name, database account, and password. The database name and database account are the application ID.
[0016] The system receives a code generation request submitted by the user through the management backend. The code generation request is obtained by the user selecting the test form to be generated through the management backend and triggering the generate button.
[0017] Based on the code generation request and the database resources, code is generated according to a pre-established directory structure.
[0018] Optional, also includes:
[0019] After any of the applications is taken offline, a resource reclamation request submitted by the user through the management backend is received;
[0020] Based on the resource reclamation request, the application performs resource reclamation.
[0021] Optionally, if so, allocating database resources for the application and creating test tables includes:
[0022] If so, assign a database name, database account, and password to the application;
[0023] Create a database based on the pre-defined first creation statement and the database name;
[0024] An account is created for the database based on the pre-set second creation statement, the database account, and the password;
[0025] Grant all permissions to the database for the account based on the pre-set authorization statement, the database name, the database account, and the password;
[0026] Based on the database name, the database account, and the password, connect to the database using Java Database Connectivity (JDBC).
[0027] A test table is created using a pre-defined update method.
[0028] Optionally, generating code according to the code generation request and the database resources, following a pre-established directory structure, includes:
[0029] Define template files according to a pre-established directory structure and obtain the resource files of the template files, wherein the template files include a template engine;
[0030] Traverse the resource files;
[0031] Determine the template type of the template file;
[0032] If it is a general template, retrieve the variable information in the parameters, which are the database name, the database account, and the password;
[0033] The variable information is encapsulated into the context of the template engine;
[0034] Based on the context of the template engine, the template file is rendered to obtain a first character stream and output.
[0035] Write the data in the first character stream to the first file stream, and output the first file stream to the first specific file;
[0036] All files are generated based on the general template and the first specific file.
[0037] Optional, also includes:
[0038] If it is not a general template, iterate through the table names in the database;
[0039] Based on the table name, the current application's database name, database account, and password, query the basic table information and table field information in the database;
[0040] Define a first entity class and a second entity class, using the first entity class to carry the basic information of the table and the second entity class to carry the field information of the table;
[0041] The basic information of the table and the field information of the table are encapsulated into the context of the template engine;
[0042] Based on the context of the template engine, the template file is rendered to obtain a second character stream and then output.
[0043] Write the data in the second character stream to the second file stream, and output the second file stream to the second specific file;
[0044] All files are generated based on the non-generic template and the second specific file.
[0045] Optionally, receiving a resource reclamation request submitted by the user through the management backend after any of the applications goes offline includes:
[0046] After any of the applications is taken offline, a deletion request for any of the applications submitted by the user through the management backend is received.
[0047] Accordingly, the step of reclaiming resources from the application based on the resource reclamation request includes:
[0048] Based on the deletion request, determine the current state of the application;
[0049] If the application's status is "Created" or "Under Review", set the application's status to "Deleted".
[0050] If the application's status is "approved" or "generated", set the application's status to "recycled".
[0051] Delete the database containing the application according to the pre-defined first deletion statement and the database name;
[0052] Delete the authorized account corresponding to the application according to the pre-set second deletion statement and the database account;
[0053] Set the application's status to deleted.
[0054] A second aspect of this invention discloses a code generation apparatus based on resource allocation, isolation, and recycling, applied to a server. The apparatus includes:
[0055] The first receiving module is used to receive an application creation request submitted by a user through the management backend. The application creation request is obtained by the user through the management backend after triggering the create button, filling in the application information of the application to be created in the application creation box, and then triggering the confirmation button. The application information includes at least the application name, application number, description, and resource selection. The resource selection is whether to select the database DB.
[0056] A creation module is used to create an application for the user based on the application creation request, and set the application's status to "created".
[0057] The second receiving module is used to receive a submission review request for any of the applications submitted by the user through the management backend;
[0058] The settings module is used to set the application's status to pending review based on the submitted review request;
[0059] The third receiving module is used to receive the application review request submitted by the administrator through the management backend;
[0060] The judgment module is used to determine whether the user has selected the database DB. If not, the change module is executed; if yes, the allocation module is executed.
[0061] The change module is used to change the status of the application to "approved".
[0062] The allocation module is used to allocate database resources to the application and create test tables. The database resources include the application's database name, database account, and password. The database name and database account are the application ID.
[0063] The fourth receiving module is used to receive the code generation request submitted by the user through the management backend. The code generation request is obtained by the user triggering the generation button after selecting the test form to be generated through the management backend.
[0064] The generation module is used to generate code according to the code generation request and the database resources, following a pre-established directory structure.
[0065] Optional, also includes:
[0066] The fifth receiving module is used to receive a resource reclamation request submitted by the user through the management backend after any of the applications are taken offline.
[0067] The resource recycling module is used to recycle resources from the application based on the resource recycling request.
[0068] A third aspect of the present invention discloses an electronic device, the electronic device including a processor;
[0069] The memory is used to store computer programs;
[0070] When the processor is used to call and execute the computer program stored in the memory, it implements the code generation method based on resource allocation, isolation and reclamation as described in any one of the first aspects of the present invention.
[0071] The fourth aspect of the present invention discloses a computer storage medium storing computer-executable instructions. When the computer-executable instructions are loaded and executed by a processor, they implement the code generation method based on resource allocation, isolation, and reclamation as described in any one of the first aspects of the present invention.
[0072] Based on the above embodiments of the present invention, a code generation method and related equipment based on resource allocation, isolation, and recycling are provided. The method includes: receiving an application creation request submitted by a user through a management backend, wherein the application creation request is obtained by the user through the management backend after triggering a create button, filling in the application information of the application to be created in the application creation box, and then triggering a confirmation button. The application information includes at least an application name, application number, description, and resource selection, wherein the resource selection is whether to select database DB; creating an application for the user according to the application creation request, and setting the status of the application to created; receiving a submission review request for any of the applications submitted by the user through the management backend; and submitting the application according to the submission review request. The application's status is set to "Pending Review"; a review request for the application is received from the administrator through the management backend; it is determined whether the user has selected the database (DB); if not, the application's status is changed to "Reviewed"; if so, database resources are allocated to the application, and a test table is created. The database resources include the application's database name, database account, and password, where the database name and database account are the application's ID; a code generation request is received from the user through the management backend, triggered by the user selecting the test table to be generated through the management backend; code is generated according to the code generation request and the database resources, following a pre-established directory structure. In this solution, the application is first created for the user based on the received application creation request. Upon receiving the review request, if the user selects the database (DB), database resources are allocated to the application, and a test table is created. Upon receiving the code generation request, code is generated according to the code generation request and database resources, following a pre-established directory structure, thereby achieving database resource allocation, resource isolation, and reclamation during the code generation process. Attached Figure Description
[0073] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0074] Figure 1 A flowchart illustrating a code generation method based on resource allocation, isolation, and recycling provided in an embodiment of the present invention;
[0075] Figure 2 An application scenario diagram of a management backend provided in an embodiment of the present invention;
[0076] Figure 3An application scenario diagram of an application creation box provided in an embodiment of the present invention;
[0077] Figure 4 This is an application scenario diagram of another management backend provided in an embodiment of the present invention;
[0078] Figure 5 This is an application scenario diagram of a code generation interface provided by an embodiment of the present invention;
[0079] Figure 6 A flowchart illustrating another code generation method based on resource allocation, isolation, and recycling provided in an embodiment of the present invention;
[0080] Figure 7 This is a schematic diagram illustrating a process for allocating database resources and creating a test table, as provided in an embodiment of the present invention.
[0081] Figure 8 This is a flowchart illustrating a process for generating code according to a pre-established directory structure, provided as an embodiment of the present invention.
[0082] Figure 9 This is a schematic diagram of a process for resource recycling of an application, provided as an embodiment of the present invention.
[0083] Figure 10 A schematic diagram of a code generation device based on resource allocation, isolation, and recycling provided in an embodiment of the present invention;
[0084] Figure 11 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0085] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0086] In this application, the terms "comprising," "including," or any other variations thereof are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0087] The terms "first," "second," "third," "fourth," etc. (if present) in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments described herein can be implemented in a sequence other than that illustrated or described herein.
[0088] As can be seen from the background technology, existing code generation tools cannot solve the problems of database resource allocation, resource isolation, and recycling during the code generation process.
[0089] Therefore, this invention provides a code generation method and related equipment based on resource allocation, isolation, and recycling. In this solution, an application is first created for the user based on the received application creation request. When an audit request is received, if the user selects the database DB, database resources are allocated to the application, and a test table is created. When a code generation request is received, code is generated according to the code generation request and database resources, following a pre-established directory structure. Thus, database resource application, resource isolation, and recycling are achieved during the code generation process.
[0090] like Figure 1 The diagram shown is a flowchart of a code generation method based on resource allocation, isolation, and recycling provided in an embodiment of the present invention. This code generation method based on resource allocation, isolation, and recycling is applied to the server side.
[0091] It should be noted that the server maintains a set of table structures to store basic application information for easy application management.
[0092] This code generation method based on resource allocation, isolation, and recycling mainly includes the following steps:
[0093] Step S101: Receive the application creation request submitted by the user through the management backend.
[0094] In step S101, the application creation request is obtained by the user through the management backend after triggering the create button, filling in the application information of the application to be created in the application creation box, and then triggering the confirmation button.
[0095] Application information includes at least the application name, application number, description, and resource selection, where the resource selection is whether DB (DataBase) is selected.
[0096] It should be noted that the application ID can be represented as appCode.
[0097] like Figure 2 The diagram shown illustrates an application scenario of a management backend provided in an embodiment of the present invention.
[0098] exist Figure 2 The system displays created applications, excluding deleted ones. Applications have six states: created, pending review, reviewed, generated, resources pending recycling, and deleted. Each state includes information such as application name, application ID, description, project owner, and creation time.
[0099] Newly created applications have not been allocated resources and cannot generate code; they require administrator approval. After submission for approval, this record will be entered into... Figure 4 The list of approved applications.
[0100] When a new user enters the management backend, the application list is empty (they can only see applications they have created). Clicking "Create Application" will bring up the application creation dialog box, as shown below. Figure 3 As shown, in the application creation box, fill in the application name, application number, description, and whether to select the database DB. After clicking OK, the application creation request will be generated.
[0101] It should be noted that users can choose whether or not they need database resources based on their needs.
[0102] In the specific implementation of step S101, after completing the pre-application creation operations through the management backend, the user triggers the generation of an application creation request, and the server receives the application creation request.
[0103] Step S102: Based on the application creation request, create an application for the user and set the application's status to "created".
[0104] In the specific implementation step S102, the server creates an application for the user based on the received application creation request. At this time, a record is added to the application table to store the application name, application number, description and domain name generated based on the application number filled in by the user. Then, the status of the application is set to created.
[0105] Step S103: Receive a submission review request from a user for any application submitted through the management backend.
[0106] In the specific implementation of step S103, the user selects the application to be submitted for review through the management backend, clicks "submit for review," triggers the generation of a submission review request, and the server receives the submission review request.
[0107] At once Figure 2 For example, if a user needs to submit test1 for review, clicking the "Submit for Review" button for test1 will trigger the generation of a submission request, which will then be received by the server.
[0108] Step S104: Based on the submitted review request, set the application status to pending review.
[0109] In the specific implementation of step S104, after receiving the submission review request, the server sets the application status to pending review based on the submission review request.
[0110] It should be noted that applications awaiting review enter... Figure 4 The audit list shown is only accessible to administrators.
[0111] Step S105: Receive the application review request submitted by the administrator through the management backend.
[0112] In the specific implementation of step S105, the administrator determines the application to be reviewed through the management backend, clicks "review," triggers the generation of a review request, and the server receives the review request.
[0113] Step S106: Determine whether the user has selected the database DB. If not, proceed to step S107; if yes, proceed to step S108.
[0114] Step S107: Change the application's status to "approved".
[0115] In the specific implementation of step S107, assuming that the user has not selected the database DB, the application status is changed to "approved". That is, the application status is changed to "approved". At this time, no database resources need to be allocated and the application is created successfully.
[0116] Step S108: Allocate database resources for the application and create test tables.
[0117] In step S108, the database resources include the application's database name, database account, and password.
[0118] The database name and database account are the application IDs, which are the appCodes entered when creating the application.
[0119] The password is an 8-character random string generated by a randomization algorithm. The 8-character random string contains numbers and letters, for example, 9phsl6cx.
[0120] In the specific implementation of step S108, under the premise that the user selects the database DB, database resources are allocated, that is, the application is assigned the database name, database account and password, and a test table is temporarily created for subsequent code generation.
[0121] Understandably, after the administrator approves the request, database resources are allocated according to the user's needs.
[0122] It should be noted that the machine where the database service is located, the port, and the management backend are two different services. Each service has its own independent port, meaning that the database is allocated on the existing machine.
[0123] It should be noted that since resource allocation is an operation on a fixed single data source, the database information can be written in the configuration file, and CRUD operations can be implemented based on the MyBatis standard: First, create an interface file and decorate it with the @mapper annotation, and define related methods such as creating an application, creating an account, and authorizing an account. Then, create an XML file corresponding to the interface file. The XML file writes the specific SQL according to the interface definition methods to implement the methods for operating the database.
[0124] Step S109: Receive the code generation request submitted by the user through the management backend.
[0125] In step S109, the code generation request is obtained by the user selecting the test table to be generated through the management backend and triggering the generate button.
[0126] In the specific implementation of step S109, the user selects the test table to be generated through the management backend, clicks "generate," triggers a code generation request, and the server receives the code generation request.
[0127] Step S110: Generate code according to the code generation request and database resources, following the pre-established directory structure.
[0128] In step S110, the directory structure includes, but is not limited to, the controller layer, service layer, dao layer, and model layer.
[0129] In the specific implementation of step S110, after receiving the code generation request, the server generates code according to the code generation request and the allocated database resources, following the pre-established directory structure.
[0130] Meanwhile, according to the directory structure, the generated code is packaged into a compressed file, downloaded to the local machine via a browser, and after decompressing the compressed file, the decompressed files are imported into the Integrated Development Environment (IDE).
[0131] like Figure 5 The diagram shown illustrates an application scenario of a code generation interface provided in an embodiment of the present invention.
[0132] exist Figure 5 In the process, the user selects the test table for which code needs to be generated, and clicks "Generate" to trigger a code generation request. After receiving the code generation request, the server generates the code according to the code generation request and the allocated database resources, following the pre-established directory structure.
[0133] Optionally, after executing step S110, which generates code according to the code generation request and database resources and follows a pre-established directory structure, based on... Figure 1 ,like Figure 6 As shown, it also includes the following steps:
[0134] Step S111: After any application goes offline, receive resource reclamation requests submitted by users through the management backend.
[0135] In the specific implementation of step S111, after any application goes offline, the user determines the application that needs to be recycled through the management backend, clicks on resource recycling, triggers a resource recycling request, and the server receives the resource recycling request.
[0136] Step S112: Perform resource reclamation on the application based on the resource reclamation request.
[0137] In this embodiment of the invention, resource recycling of an application is equivalent to deleting the application.
[0138] Based on the code generation method provided by the embodiments of the present invention, which is based on resource allocation, isolation and recycling, an application is first created for the user according to the received application creation request. When the review request is received, if the user selects the database DB, database resources are allocated to the application and a test table is created. When the code generation request is received, the code is generated according to the code generation request and the database resources, and the code is generated according to the pre-established directory structure. Thus, database resource application, resource isolation and recycling are realized in the code generation process.
[0139] Based on the code generation method based on resource allocation, isolation, and reclamation shown above, step S108 is executed to allocate database resources to the application and create test tables, as follows: Figure 7 The diagram illustrates a process for allocating database resources and creating a test table according to an embodiment of the present invention, mainly including the following steps:
[0140] Step S701: Assign a database name, database account, and password to the application.
[0141] In the specific implementation step S701, assuming that the user has selected the database DB, the application is assigned the database name, database account and password.
[0142] Step S702: Create the database according to the pre-defined first creation statement and database name.
[0143] In step S702, the first creation statement is CREATE DATABASE${databaseName}.
[0144] Where databaseName is the database name.
[0145] In the specific implementation step S702, the first creation statement in the structured query SQL statement is configured, and the database is created through the first creation statement and the assigned database name, that is, through CREATE DATABASE${databaseName}.
[0146] Step S703: Create an account for the database according to the pre-set second creation statement, database account and password.
[0147] In step S703, the second creation statement is CREATE USER#{username}IDENTI FIED BY#{password}.
[0148] In this context, username is the database account, and password is the password.
[0149] In the specific implementation step S703, the second creation statement in the configuration SQL statement is used to create an account for the database using the second creation statement and the assigned database account and password, i.e., by using CREATE USER#{user name}IDENTIFIED BY#{password}.
[0150] Step S704: Grant all permissions to the database account based on the pre-set authorization statement, database name, database account and password.
[0151] In step S704, the authorization statement is: grant all privileges on ${databaseName}.*to#{username}@'%'identified by#{password}with grant option.
[0152] In the specific implementation step S704, the authorization statement in the SQL statement is configured. Through this authorization statement, the assigned database name, database account and password, that is, by granting all privileges on ${databaseName}.*to#{username}@'%'identified by#{password}with grant option, all permissions of the created database are granted to the account.
[0153] Step S705: Connect to the database using the database name, database account, and password via Java Database Connectivity (JDBC).
[0154] In the specific implementation of step S705, since each application has its own independent database and account, which are multiple data sources that are not fixed, MyBatis cannot be used to operate. Therefore, based on the database name, database account and password, the driver database is loaded and the connection is obtained in real time through Java database connection JDBC.
[0155] Step S706: Create a test table using a pre-defined update method.
[0156] In step S706, the update method is executeUpdate(sql).
[0157] In the specific implementation step S706, the update method in the SQL statement is configured, and the test table is created through this update method, namely executeUpdate(sql).
[0158] Based on the code generation method provided by the embodiments of the present invention, which is based on resource allocation, isolation and reclamation, after determining that the user selects the database DB, the application is allocated database resources, the database is created according to the allocated database resources and the pre-set relevant SQL statements, an account is created for the database and all permissions of the database are granted to the account, and after connecting to the database, a test table is created through a pre-set update method, thereby providing a data foundation for the subsequent code generation process to realize database resource application, resource isolation and reclamation.
[0159] Based on the code generation method based on resource allocation, isolation, and reclamation shown above, step S110 involves generating code according to the code generation request and database resources, following a pre-established directory structure. Figure 8 The diagram illustrates a process for generating code according to a pre-established directory structure, as provided in an embodiment of the present invention. The process mainly includes the following steps:
[0160] Step S801: Define template files according to the pre-established directory structure and obtain the resource files of the template files.
[0161] In step S801, the template file includes a template engine.
[0162] Template engines include, but are not limited to, Velocity.
[0163] In this embodiment of the invention, the template file is a template file with the suffix ".vm".
[0164] The directory structure is mainly divided into controller layer, DAO layer, model layer, service layer, configuration files, pom files, etc. The main templates include Controller.java.vm, Mapper.java.vm, Mapper.xml.vm, Model.java.vm, Service.java.vm, ServiceImpl.java.vm, logback.xml.vm, application.yml.vm, pom.xml.vm, Application.java.vm, RedisConfig.java.vm, Result.java.vm, etc., which are placed under the preset directory structure according to the different layers to which the template files belong.
[0165] In the specific implementation step S801, a directory structure is pre-established, a template file is defined according to the established directory structure, and the resource files of the template file are obtained.
[0166] Preferably, in one specific embodiment, the resource files of the template file are obtained through the getResources(url) method of the PathMatchingResourcePatternResolver class.
[0167] Step S802: Traverse the resource files.
[0168] Step S803: Determine the template type of the template file. If it is a general template, proceed to step S804; if it is a non-general template, proceed to step S809.
[0169] It should be noted that general templates can be generated without querying the database. Most of the content of this type of template is fixed, such as: logback.xml, application.yml, pom.xml, Application.java, RedisConfig.java, Result.java, etc. Only a small part of the information needs to be obtained in real time, such as the application's database name, database account and password, current time, etc.
[0170] It should be noted that non-generic templates require querying the database.
[0171] Step S804: Obtain variable information from the parameters.
[0172] In step S804, the parameters are database name, database account, and password.
[0173] It should be noted that the database name, database account, and password mentioned above are different for each application and need to be passed as parameters to the backend, i.e., the server, when clicking to generate code.
[0174] In the specific implementation step S804, under the premise that the template type of the current template file is determined to be a general model, the variable information in the above-assigned database name, database account and password as parameters is obtained.
[0175] Step S805: Encapsulate the variable information into the template engine's context.
[0176] In the specific implementation step S805, the variable information is encapsulated into the template engine context using the VelocityContext.put(key,value) method.
[0177] When rendering the template file later, the key is directly referenced to get the corresponding value. The template file mentioned above uses ${key} as a placeholder for the application.
[0178] For example, the application name appName needs a ${key} placeholder. When generating the application, the value of the current key is used to replace the placeholder content.
[0179] Step S806: Based on the context of the template engine, render the template file, obtain the first character stream, and output it.
[0180] In the specific implementation step S806, the VelocityEngine.mergeTemplate(StringWriter, VelocityContext) method is used to replace the changed parts of the template with the real-time values and output them to the StringWriter character stream, that is, to the first character stream.
[0181] For example, in a blog table, the complete code to query a blog is Blob blog = blogService.getById(id), where blog is a variable factor. The template file can be written as ${className}${classname} = ${classname}Service.getById(id), and className is encapsulated into the template engine context through VelocityContext.put(“className”, className).
[0182] Step S807: Write the data in the first character stream to the first file stream, and output the first file stream to the first specific file.
[0183] In the specific implementation step S807, the IOUtils.write(StringWriter fileOutputStream) method is called to write the data in the first character stream to the first file stream and output the first file stream to the first specific file.
[0184] Step S808: Generate all files based on the general template and the first specific file.
[0185] It should be noted that the generated files include, but are not limited to, logback.xml, application.yml, pom.xml, Application.java, RedisConfig.java, and Result.java.
[0186] Step S809: Traverse the table names in the database.
[0187] In the specific implementation of step S809, under the premise that the template type of the current template file is determined to be a non-general model, the table names in the database created above are traversed.
[0188] Step S810: Query the basic information of the table and the field information of the table in the database based on the table name, the database name of the current application, the database account and password.
[0189] In step S810, the basic information of the table includes, but is not limited to, the table's engine and the table's comments.
[0190] Table field information includes, but is not limited to, the names and types of the table fields.
[0191] Step S811: Define a first entity class and a second entity class, using the first entity class to carry the basic information of the table and the second entity class to carry the field information of the table.
[0192] In step S811, the first entity class is TableEntity and the second entity class is ColumnEntity.
[0193] The TableEntity identifies table information, including the table name (tableName), table comments (comment), table primary key (pk), table column names (columns is a list containing multiple elements, each of which is a ColumnEntity object), class name (className), and other attributes.
[0194] ColumnEntity identifies column information, including attributes such as column name (columnName), column type (dataType), and column comments (comments).
[0195] Step S812: Encapsulate the table basic information and table field information into the template engine context.
[0196] In the specific implementation step S812, the VelocityContext.put(key,value) method is used to encapsulate the basic information of the table and the information of the table fields into the context of the template engine.
[0197] The keys added to VelocityContext include, but are not limited to, tableName, comment, pk, columns, and className.
[0198] Step S813: Based on the context of the template engine, render the template file to obtain the second character stream and output it.
[0199] In the specific implementation step S813, the VelocityEngine.mergeTemplate(StringWriter, VelocityContext) method is used to replace the changed parts of the template with the real-time values and output them to the StringWriter character stream, that is, to the second character stream.
[0200] Step S814: Write the data in the second character stream to the second file stream, and output the second file stream to the second specific file.
[0201] In the specific implementation step S814, the IOUtils.write(StringWriterfileOutputStream) method is called to write the data in the second character stream to the second file stream and output the second file stream to the second specific file.
[0202] Step S815: Generate all files based on the non-general template and the second specific file.
[0203] It should be noted that the generated files include, but are not limited to, Controller.java, Mapper.java, Mapper.xml, Model.java, Service.java, and ServiceImpl.java.
[0204] It should be noted that after generating the files, return to steps S802 and S803 until all templates have generated corresponding files. Then, according to the directory structure, package all files into a compressed package, download it to the local machine via a browser, and after decompressing the compressed package, import the decompressed files into the integrated development environment (IDE). Running the IDE will then generate the code.
[0205] Based on the code generation method based on resource allocation, isolation and reclamation provided by the embodiments of the present invention, when a code generation request is received, code is generated according to the code generation request and database resources in accordance with a pre-established directory structure, thereby realizing database resource allocation, resource isolation and reclamation in the code generation process.
[0206] Based on the code generation method based on resource allocation, isolation, and reclamation shown above, step S111 involves receiving a resource reclamation request submitted by the user through the management backend after any application goes offline, and step S112 involves reclaiming resources from the application according to the resource reclamation request. Figure 9 The diagram shown illustrates a process for resource recycling in an application according to an embodiment of the present invention, mainly including the following steps:
[0207] Step S901: After any application is taken offline, receive a deletion request from a user submitted through the management backend for any application.
[0208] In the specific implementation of step S901, after any application goes offline, the user determines the application that needs to be recycled through the management backend, clicks on resource recycling, triggers a resource recycling request, and the server receives the resource recycling request.
[0209] Understandably, after any application is taken offline, the user selects the application to be deleted through the management backend, clicks delete, triggers a deletion request, and the server receives the deletion request.
[0210] Step S902: Based on the deletion request, determine the application's status. If the application's status is "Created" or "Under Review", proceed to step S903. If the application's status is "Reviewed" or "Generated", proceed to step S904.
[0211] Step S903: Set the application's status to deleted.
[0212] In the specific implementation step S903, if the application status is determined to be created or under review, since the application has not yet been allocated database resources, the application status is directly set to deleted.
[0213] Step S904: Set the application's status to resource reclamation.
[0214] In the specific implementation of step S904, under the premise that the application status is verified or generated, the application status is set to resource recycling.
[0215] Step S905: Delete the database where the application resides based on the pre-defined first deletion statement and database name.
[0216] In step S905, the first deletion statement is DROP DATABASE${databaseName}.
[0217] Where databaseName is the database name.
[0218] In the specific implementation step S905, the first delete statement in the SQL statement is configured to determine the database where the application to be deleted is located and to determine the assigned database name. The database where the application is located is deleted through the first delete statement and the assigned database name, i.e., through DROP DATABASE${databaseName}.
[0219] Step S906: Delete the authorized account corresponding to the application according to the pre-set second deletion statement and database account.
[0220] In step S906, the second deletion statement is DROP USER'${username}'@'%'.
[0221] In the specific implementation step S906, the second delete statement in the SQL statement is configured to determine the database and database name where the application to be deleted is located, and to determine the database account corresponding to the database name. The authorized account corresponding to the application is deleted by using the second delete statement and the database account, i.e., by DROP USER'${username}'@'%'.
[0222] After deleting the database where the application resides and the authorized account corresponding to the application, the application's status is set to deleted, i.e., step S903 is executed. At this point, resource reclamation is complete, meaning resource reclamation is finished.
[0223] Based on the code generation method provided by the embodiments of the present invention, which is based on resource allocation, isolation and recycling, when a resource recycling request (deletion request) is received, the application performs resource recycling according to the resource recycling request, thereby realizing database resource allocation, resource isolation and recycling in the process of code generation.
[0224] Compared with the above embodiments of the present invention Figure 1 Corresponding to the code generation method based on resource allocation, isolation, and reclamation shown, this embodiment of the invention also provides a code generation apparatus based on resource allocation, isolation, and reclamation. This code generation apparatus based on resource allocation, isolation, and reclamation is applied to the server side, such as... Figure 10As shown, the code generation device based on resource allocation, isolation and recycling includes: a first receiving module 1001, a creation module 1002, a second receiving module 1003, a setting module 1004, a third receiving module 1005, a judgment module 1006, a change module 1007, an allocation module 1008, a fourth receiving module 1009 and a generation module 1010.
[0225] The first receiving module 1001 is used to receive the application creation request submitted by the user through the management backend.
[0226] The application creation request is obtained by the user through the management backend after triggering the create button, filling in the application information of the application to be created in the application creation box, and then triggering the confirmation button. The application information includes at least the application name, application number, description, and resource selection, and the resource selection is whether to select the database DB.
[0227] The creation module 1002 is used to create an application for the user based on the application creation request and set the application status to "created".
[0228] The second receiving module 1003 is used to receive a submission review request for any application submitted by a user through the management backend.
[0229] The setting module 1004 is used to set the application status to pending review based on the submitted review request.
[0230] The third receiving module 1005 is used to receive application review requests submitted by the administrator through the management backend.
[0231] The judgment module 1006 is used to determine whether the user has selected the database DB. If not, the change module 1007 is executed; if so, the allocation module 1008 is executed.
[0232] Module 1007 is used to change the application's status to "approved".
[0233] The allocation module 1008 is used to allocate database resources to applications and create test tables.
[0234] The database resources include the application's database name, database account, and password. The database name and database account are the application IDs.
[0235] The fourth receiving module 1009 is used to receive the code generation request submitted by the user through the management backend.
[0236] The code generation request is triggered by the user selecting the test form to be generated through the management backend and then clicking the generate button.
[0237] The generation module 1010 is used to generate code according to a pre-established directory structure based on the code generation request and database resources.
[0238] Optionally, based on the above Figure 10 The code generation apparatus shown is based on resource allocation, isolation, and reclamation, combined with Figure 10 The code generation device based on resource allocation, isolation, and recycling is further equipped with a fifth receiving module and a resource recycling module.
[0239] The fifth receiving module is used to receive resource reclamation requests submitted by users through the management backend after any application goes offline.
[0240] The resource recycling module is used to recycle application resources based on resource recycling requests.
[0241] It should be noted that the specific principles and execution processes of each module in the code generation device based on resource allocation, isolation and recycling disclosed in the above embodiments of the present invention are the same as those of the code generation method based on resource allocation, isolation and recycling disclosed in the above embodiments of the present invention. Please refer to the corresponding parts of the code generation method based on resource allocation, isolation and recycling disclosed in the above embodiments of the present invention, and they will not be repeated here.
[0242] Based on the code generation device provided by the embodiments of the present invention, which is based on resource allocation, isolation and recycling, an application is first created for the user according to the received application creation request. When an audit request is received, if the user selects the database DB, database resources are allocated to the application and a test table is created. When a code generation request is received, code is generated according to the code generation request and the database resources, and the code is generated according to the pre-established directory structure. Thus, database resource application, resource isolation and recycling are realized in the code generation process.
[0243] Optionally, based on the above Figure 10 The code generation apparatus shown is based on resource allocation, isolation, and recycling. The allocation module 1008 includes: an allocation unit, a first creation unit, a second creation unit, an granting unit, a connection unit, and a third creation unit.
[0244] The allocation unit, if applicable, is used to assign a database name, database account, and password to the application.
[0245] The first creation unit is used to create a database based on a pre-defined first creation statement and database name.
[0246] The second creation unit is used to create accounts for the database based on the pre-set second creation statement, database account, and password.
[0247] The granting unit is used to grant all permissions to an account on the database based on a pre-defined authorization statement, database name, database account, and password.
[0248] The connection unit is used to connect to a database via Java Database Connectivity (JDBC) based on the database name, database username, and password.
[0249] The third creation unit is used to create test tables using a pre-defined update method.
[0250] Based on the code generation device based on resource allocation, isolation, and recycling provided in this embodiment of the invention, after determining that the user selects database DB, database resources are allocated to the application. The database is created according to the allocated database resources and pre-set related statements. An account is created for the database and all permissions of the database are granted to the account. After connecting to the database, a test table is created through a pre-set update method, thereby providing a data foundation for the subsequent database resource application, resource isolation, and recycling process.
[0251] Optionally, based on the above Figure 10 The code generation apparatus shown is based on resource allocation, isolation, and recycling. The generation module 1010 includes:
[0252] The processing unit is used to define template files according to a pre-established directory structure and to obtain the resource files of the template files.
[0253] The template files include the template engine.
[0254] The first traversal unit is used to traverse the resource files.
[0255] The judgment unit is used to determine the template type of the template file.
[0256] The retrieval unit is used to retrieve variable information from the parameters if it is a general template.
[0257] The parameters are the database name, database account, and password.
[0258] The first encapsulation unit is used to encapsulate variable information into the context of the template engine.
[0259] The first rendering unit is used to render the template file based on the context of the template engine, obtain the first character stream, and output it.
[0260] The first writing unit is used to write data from the first character stream to the first file stream and output the first file stream to the first specific file.
[0261] The first generation unit is used to generate all files based on the general template and the first specific file.
[0262] The second traversal unit is used to traverse the table names in the database if it is not a general template.
[0263] The query unit is used to query basic table information and table field information in the database based on the table name, the database name of the current application, the database account, and the password.
[0264] The definition unit is used to define the first entity class and the second entity class, using the first entity class to carry the basic information of the table and the second entity class to carry the field information of the table.
[0265] The second encapsulation unit is used to encapsulate the table's basic information and table field information into the template engine's context.
[0266] The second rendering unit is used to render the template file based on the context of the template engine, obtain the second character stream, and output it.
[0267] The second writing unit is used to write data from the second character stream to the second file stream and output the second file stream to the second specific file.
[0268] The second generation unit is used to generate all files based on the non-general template and the second specific file.
[0269] Based on the code generation device based on resource allocation, isolation and reclamation provided in the embodiments of the present invention, when a code generation request is received, code is generated according to the code generation request and database resources in accordance with a pre-established directory structure, thereby realizing database resource application, resource isolation and reclamation in the code generation process.
[0270] Optionally, based on the above Figure 10 The code generation apparatus shown, based on resource allocation, isolation, and reclamation, includes a fifth receiving module specifically used for:
[0271] After any application is taken offline, it can receive deletion requests from users submitted through the management backend for any application.
[0272] Accordingly, the resource recycling module includes:
[0273] The judgment unit is used to determine the application's status based on the deletion request. If the application's status is "Created" or "Under Review", the first setting unit is executed; if the application's status is "Approved" or "Generated", the second setting unit is executed.
[0274] The first setting unit is used to set the application's status to deleted.
[0275] The second setting unit is used to set the application's status to resource reclamation.
[0276] The first deletion unit is used to delete the database where the application resides based on a pre-defined first deletion statement and database name.
[0277] The second deletion unit is used to delete the corresponding authorized account based on the pre-set second deletion statement and database account, and execute the first setting unit.
[0278] Based on the code generation apparatus provided by the embodiments of the present invention, which is based on resource allocation, isolation and recycling, when a resource recycling request (deletion request) is received, the application performs resource recycling according to the resource recycling request, thereby realizing database resource application, resource isolation and recycling in the process of code generation.
[0279] Based on the code generation apparatus for resource allocation, isolation, and reclamation disclosed in the above embodiments of the present invention, each of the above modules can be implemented by a hardware device consisting of a processor and a memory. Specifically, each of the above modules is stored as a program unit in the memory, and the processor executes the program units stored in the memory to realize code generation based on resource allocation, isolation, and reclamation.
[0280] The processor contains a kernel, which retrieves the corresponding program units from memory. One or more kernels can be configured, and code generation based on resource allocation, isolation, and reclamation can be achieved by adjusting kernel parameters.
[0281] This invention provides a computer storage medium, which includes a code generation program based on resource allocation, isolation, and reclamation. When the program is executed by a processor, it implements the code generation method based on resource allocation, isolation, and reclamation as described in any of the above embodiments.
[0282] This invention provides a processor for running a program, wherein the program executes the code generation method based on resource allocation, isolation, and recycling disclosed in the above embodiments.
[0283] This invention provides an electronic device, such as... Figure 11 The diagram shown is a structural schematic of an electronic device 110 provided in an embodiment of the present invention.
[0284] The electronic devices in the embodiments of the present invention can be servers, PCs, PADs, mobile phones, etc.
[0285] The electronic device includes at least one processor 1101, at least one memory 1102 connected to the processor, and a bus 1103.
[0286] The processor 1101 and the memory 1102 communicate with each other via the bus 1103. The processor 1101 is used to execute the program stored in the memory 1102.
[0287] The memory 1102 is used to store a program that at least performs the following functions: receiving an application creation request submitted by a user through the management backend. This application creation request is obtained by the user entering the application information in the application creation box after triggering the create button through the management backend, and then triggering the confirmation button. The application information includes at least the application name, application number, description, and resource selection, with the resource selection specifying whether the database (DB) is selected. Based on the application creation request, the program creates the application for the user and sets the application status to "created." It also receives a submission review request for any application submitted by a user through the management backend; based on the submission review request, the program sets the application status to "pending review." Furthermore, it receives an application review request submitted by an administrator through the management backend; it determines whether the user has selected the database (DB); if not, it changes the application status to "reviewed"; if so, it allocates database resources to the application and creates a test table. The database resources include the application's database name, database account, and password, with the database name and database account being the application number. Finally, it receives a code generation request submitted by a user through the management backend. This code generation request is obtained by the user selecting the test table to be generated through the management backend and triggering the generate button. Based on the code generation request and the database resources, it generates code according to a pre-established directory structure.
[0288] This application also provides a computer program product, which, when executed on an electronic device, is suitable for executing a program that initializes the following method steps:
[0289] The system receives application creation requests submitted by users through the management backend. These requests are generated by the user clicking the "Create" button, filling in the application information in the application creation box, and then clicking the "Confirm" button. The application information includes at least the application name, application ID, description, and resource selection, including whether the database (DB) is selected. Based on the application creation request, the system creates the application for the user and sets its status to "Created." It also receives application submission review requests from users through the management backend for any application. Based on these requests, the system sets the application status to "Pending Review." Furthermore, it receives application review requests from administrators through the management backend. The system checks whether the user has selected the database (DB). If not, it changes the application status to "Reviewed." If so, it allocates database resources to the application and creates a test table. The database resources include the application's database name, database account, and password. The database name and database account are the application ID. Finally, it receives code generation requests from users through the management backend. These requests are generated by the user selecting the test table to be generated and then clicking the "Generate" button. Based on the code generation request and the database resources, the system generates code according to a pre-established directory structure.
[0290] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0291] In a typical configuration, the device includes one or more processors (CPUs), memory, and a bus. The device may also include input / output interfaces, network interfaces, etc.
[0292] Memory may include non-persistent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, like read-only memory (ROM) or flash RAM, and memory includes at least one memory chip. Memory is an example of computer-readable media.
[0293] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, 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 technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0294] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, for system or system embodiments, since they are basically similar to method embodiments, the description is relatively simple, and relevant parts can be referred to the descriptions in the method embodiments. The systems and system embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without creative effort.
[0295] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.
[0296] The above description of the disclosed embodiments enables those skilled in the art to make or use the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the invention. Therefore, the invention is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A code generation method based on resource allocation, isolation, and recycling, characterized in that, Applied to the server side, the method includes: The system receives an application creation request submitted by a user through the management backend. The application creation request is obtained by the user through the management backend after triggering the create button, filling in the application information of the application to be created in the application creation box, and then triggering the confirmation button. The application information includes at least the application name, application number, description, and resource selection. The resource selection is whether to select the database DB. Based on the application creation request, create an application for the user and set the application's status to "created". Receive a submission review request from the user for any of the applications submitted through the management backend; Based on the submitted review request, the application's status is set to pending review; Receive the application's review request submitted by the administrator through the management backend; Determine whether the user has selected the database DB; If not, change the application's status to "approved"; If so, automatically allocate independent database resources to the application and create a test table. The database resources include a database name, database account, and password allocated to the application. The database name and database account are set to the application number to achieve a one-to-one correspondence between the application and the database resources and resource isolation. The system receives a code generation request submitted by the user through the management backend. The code generation request is obtained by the user selecting the test form to be generated through the management backend and triggering the generate button. Based on the code generation request and the database resources, code is generated according to a pre-established directory structure.
2. The method according to claim 1, characterized in that, Also includes: After any of the applications is taken offline, a resource reclamation request submitted by the user through the management backend is received; Based on the resource reclamation request, the application performs resource reclamation.
3. The method according to claim 1, characterized in that, If so, automatically allocate independent database resources to the application and create test tables, including: If so, assign a database name, database account, and password to the application; Create a database based on the pre-defined first creation statement and the database name; An account is created for the database based on the pre-set second creation statement, the database account, and the password; Grant all permissions to the database for the account based on the pre-set authorization statement, the database name, the database account, and the password; Based on the database name, the database account, and the password, connect to the database using Java Database Connectivity (JDBC). A test table is created using a pre-defined update method.
4. The method according to claim 1, characterized in that, The step of generating code according to the code generation request and the database resources, and in accordance with a pre-established directory structure, includes: Define template files according to a pre-established directory structure and obtain the resource files of the template files, wherein the template files include a template engine; Traverse the resource files; Determine the template type of the template file; If it is a general template, retrieve the variable information in the parameters, which are the database name, the database account, and the password; The variable information is encapsulated into the context of the template engine; Based on the context of the template engine, the template file is rendered to obtain a first character stream and output. Write the data in the first character stream to the first file stream, and output the first file stream to the first specific file; All files are generated based on the general template and the first specific file.
5. The method according to claim 4, characterized in that, Also includes: If it is not a general template, iterate through the table names in the database; Based on the table name, the current application's database name, database account, and password, query the basic table information and table field information in the database; Define a first entity class and a second entity class, using the first entity class to carry the basic information of the table and the second entity class to carry the field information of the table; The basic information of the table and the field information of the table are encapsulated into the context of the template engine; Based on the context of the template engine, the template file is rendered to obtain a second character stream and then output. Write the data in the second character stream to the second file stream, and output the second file stream to the second specific file; All files are generated based on the non-generic template and the second specific file.
6. The method according to claim 2, characterized in that, The step of receiving a resource reclamation request submitted by the user through the management backend after any of the applications is taken offline includes: After any of the applications is taken offline, a deletion request for any of the applications submitted by the user through the management backend is received. Accordingly, the step of reclaiming resources from the application based on the resource reclamation request includes: Based on the deletion request, determine the current state of the application; If the application's status is "Created" or "Under Review", set the application's status to "Deleted". If the application's status is "approved" or "generated", set the application's status to "recycled". Delete the database containing the application according to the pre-defined first deletion statement and the database name; Delete the authorized account corresponding to the application according to the pre-set second deletion statement and the database account; Set the application's status to deleted.
7. A code generation device based on resource allocation, isolation, and reclamation, characterized in that, Applied to the server side, the device includes: The first receiving module is used to receive an application creation request submitted by a user through the management backend. The application creation request is obtained by the user through the management backend after triggering the create button, filling in the application information of the application to be created in the application creation box, and then triggering the confirmation button. The application information includes at least the application name, application number, description, and resource selection. The resource selection is whether to select the database DB. A creation module is used to create an application for the user based on the application creation request, and set the application's status to "created". The second receiving module is used to receive a submission review request for any of the applications submitted by the user through the management backend; The settings module is used to set the application's status to pending review based on the submitted review request; The third receiving module is used to receive the application review request submitted by the administrator through the management backend; The judgment module is used to determine whether the user has selected the database DB. If not, the change module is executed; if yes, the allocation module is executed. The change module is used to change the status of the application to "approved". The allocation module is used to automatically allocate independent database resources to the application and create test tables. The database resources include a database name, database account and password allocated to the application. The database name and database account are set to the application number to achieve a one-to-one correspondence between the application and the database resources and resource isolation. The fourth receiving module is used to receive the code generation request submitted by the user through the management backend. The code generation request is obtained by the user triggering the generation button after selecting the test form to be generated through the management backend. The generation module is used to generate code according to the code generation request and the database resources, following a pre-established directory structure.
8. The apparatus according to claim 7, characterized in that, Also includes: The fifth receiving module is used to receive a resource reclamation request submitted by the user through the management backend after any of the applications are taken offline. The resource recycling module is used to recycle resources from the application based on the resource recycling request.
9. An electronic device, characterized in that, The electronic device includes a memory and a processor; The memory is used to store computer programs; When the processor calls and executes the computer program stored in the memory, it implements the code generation method based on resource allocation, isolation, and reclamation as described in any one of claims 1 to 6.
10. A computer storage medium, characterized in that, The computer storage medium stores computer-executable instructions, which, when loaded and executed by a processor, implement the code generation method based on resource allocation, isolation, and reclamation as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Database resource division method, system and related device
CN112685381A
Database service method and system
CN113515499A
Code generation method and device and terminal equipment
CN114217783A
