CN115048109A - Code generation method and device based on metadata - Google Patents

Code generation method and device based on metadata Download PDF

Info

Publication number
CN115048109A
CN115048109A CN202210788866.8A CN202210788866A CN115048109A CN 115048109 A CN115048109 A CN 115048109A CN 202210788866 A CN202210788866 A CN 202210788866A CN 115048109 A CN115048109 A CN 115048109A
Authority
CN
China
Prior art keywords
code
file
description
metadata
code generation
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210788866.8A
Other languages
Chinese (zh)
Inventor
颜颖滨
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Individual
Original Assignee
Individual
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Individual filed Critical Individual
Priority to CN202210788866.8A priority Critical patent/CN115048109A/en
Publication of CN115048109A publication Critical patent/CN115048109A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/44Encoding
    • G06F8/447Target code generation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/36Software reuse

Landscapes

  • Engineering & Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)

Abstract

The invention discloses a code generation method and a device based on metadata, which are code generation methods and devices without limitation of programming languages, high flexibility and strong multiplexing capability, and comprise the following steps: the method comprises the steps of writing a metadata description file in advance, making a code template file, pushing the metadata description file, the code template file and an operation parameter file to a code generation device when preparing to generate a target code, and generating the target code and storing the target code to a specified storage medium by the code generation device. Because the multiplexing degree of the metadata description file is high, the generated codes can be in place in one step, and the development and programming efficiency of computer software is improved.

Description

Code generation method and device based on metadata
Technical Field
The invention relates to the field of computer software development, in particular to a code generation method and device based on metadata.
Background
In the software development industry, the development time can be shortened, the development cost can be saved by multiplexing codes, the market competitiveness of enterprises is improved, and the problem that how to multiplex the existing codes to the maximum extent is always solved by the enterprises so as to improve the production efficiency.
The traditional way in the industry is to reuse the existing codes by using a code generation technology, and the method is to compile the existing codes into a code template in advance based on the codes which are developed in the past. When generating code, connecting to relational database in code template, reading table and field information of 1 or 2 tables (master-slave table) to generate primary object code, and manually modifying and developing based on the primary object code to obtain the object code. The traditional code generation method has the following four main disadvantages:
the method has the advantages that firstly, a dependency relationship type database is often operated by the database, some codes generated in practical application do not need to use the database, for example, when a table is not created, a table building statement needs to be generated, and the table building statement cannot be generated in the mode, so that the method has limited use scenes;
secondly, the number of the supporting tables is limited, and the supporting tables can only support master-slave tables, when more than 3 tables exist, or the relationships among the tables or more complex scenes exist, the table and field definitions of the database are not enough to convey complete relationship information among the tables to a code generation program; relevant information such as an operation interface, a check rule and the like needs to be explained additionally, so that a generated code cannot be put in place in one step, a plurality of manual developments are needed to meet the requirements, and the development efficiency is low;
thirdly, in a relational database, the relationship between a table and a table is established by adopting foreign key association or constraint, but in actual development, a lot of software is controlled in a software program in order to improve the performance of the database without carrying out foreign key association or constraint on the database layer, so that the code generation lacks the table association or constraint information, the generated code cannot be put in place in one step, and the requirement can be met by carrying out more than one manual development, so that the development efficiency is low;
the fourth disadvantage is that the table building statements of different types of relational databases are not completely compatible in percentage, for example, tables in the oracle database cannot be directly multiplexed into mysql. Therefore, a table created in one database for generating a code cannot be directly multiplexed into another database and used for generating the code, and different databases used for different items are different, so that the multiplexing capability of the table used for generating the code is low.
Therefore, the present invention provides a method and an apparatus for generating metadata-based code, which are not limited to programming languages, and have high flexibility and reusability, to solve the above problems.
Disclosure of Invention
The invention solves the problem of improving the development and programming efficiency of computer software.
In order to solve the above problems, the present invention provides a code generation method and apparatus, which push a metadata description file, a code template file, and a parameter description file to a code generation apparatus, and generate an object code in the code generation apparatus and store the object code in a specified storage medium.
The code generation method comprises the following steps:
step S1, writing metadata description file step:
writing a metadata description file, and describing entity information, relationship information among entities, entity human-computer interfaces and other information in the metadata description file. The metadata is data used to describe data. The description made in the metadata description file includes but is not limited to entities, entity attributes and methods, relationships between the entities, default values of the entity attributes, value verification rules, attributes and methods of a human-computer operation interface and the like;
step S2, making a code template file:
according to the business requirements, the program codes to be multiplexed are made into a code template file, executable program instructions are embedded into the code template file, and an output mode template of the target codes is defined. The executable program instructions embedded in the code template file are used for reading the metadata description file and generating object codes; the target code output mode template defined in the code template file is used for storing the target code to a specified storage medium in a specified mode after the target code is generated;
step S3, generating object code step:
and pushing the operation parameter file, the metadata description file and the code template file to a code generation device through a file pipeline to generate a target code. The operation parameter file is a parameter required by the code generation device for initializing a program instruction executor and running. After receiving the operation parameter file, the metadata description file and the code template file, the code generation device reads information defined in the metadata description file according to parameter configuration in the operation parameter file, executes a program instruction embedded in a code template and generates a target code;
step S4, storing object code step:
and storing the generated target code into a target storage device according to the storage mode and the storage medium definition in the code template file. The code generation device reads the target output storage system and the device path template, generates a target storage medium path, and stores text-based codes, logs, scripts, and the like that generate the target code in the target storage device.
The code generation apparatus S34 of the present invention includes: a code template file unit S341, a metadata description file unit S342, an operation parameter file unit S343, a program instruction execution unit S344, and an object code output unit S345.
The invention has the following advantages:
the method comprises the steps that firstly, a metadata description file is adopted as input information, the method is not limited by a relational database, the table quantity and the complexity of the relations among the tables, the programming language is not limited, and the application scene is wider;
one metadata description file is only used for defining one entity, so that one metadata description file can be multiplexed among different code templates, can be multiplexed among different projects, can be shared and multiplexed in and among industries, can form a metadata market in the future, and has higher multiplexing capability;
and thirdly, the target code can be generated in one step, and by defining a target output storage mode and a device path template, the target code can be stored in a target storage medium and a path in batch after the target code template is generated, and the template code and the generated target code basically do not need additional manual intervention, so that the production efficiency is higher.
Drawings
FIG. 1 is a schematic overall flow chart of a metadata-based code generation method according to the present invention
FIG. 2 is a schematic diagram of a metadata description file structure according to the present invention
FIG. 3 is a schematic diagram of a code template file structure according to the present invention
FIG. 4 is a schematic diagram of a logic structure of a metadata-based code generation method according to the present invention
FIG. 5 is a schematic structural diagram of a code generation apparatus according to the present invention
Detailed Description
The invention is described in further detail below with reference to the figures and specific examples of embodiments. The following examples are intended to illustrate the invention, but are not intended to limit the scope of the invention.
Fig. 1 is a schematic overall flow diagram of a metadata-based code generation method according to the present invention, and as shown in fig. 1, the present invention provides a metadata-based code generation method, including:
step S1, writing a metadata description file S11, wherein the metadata is used for describing data, and defines and describes entities, entity attributes and methods, relationships between the entities, default values of the entity attributes, value checking rules, attributes and methods of a human-computer operation interface and the like in the metadata description file;
step S2, making a code template file S21, aiming at the existing code to be multiplexed, making the code template file, embedding a program instruction for reading a metadata description file and generating a target code in the code template file, and defining a target output storage mode and a device path template in the code template file;
step S3, starting to generate object code, pushing the operation parameter file S31, the metadata description file S11 and the code template file S21 to the code generation device S34, initializing the code generation device according to the operation parameter file, reading the information defined and described in the metadata description file, executing the executable program instruction embedded in the code template file, and generating the object code;
in step S4, the storage of the object code is started, and the code generation device S34 reads the object output storage method and the device path template defined in the code template file S21, generates an object storage medium path, and stores the text-based code, log, script, and the like that have generated the object code in the object storage device.
Such as: the organization and employee information management function in the human resource management software can define the organization entity and the employee entity in the organization and employee information data structure, and further describe other relevant information in the organization metadata description file and the employee metadata description file. The relationship between the organization entity and the employee entity is a many-to-many relationship, i.e., there are multiple employees under an organization, and an employee may be affiliated with multiple organizations. Defining that one attribute in an organized entity is a subordinate employee entity set in an entity relationship description area in an organization metadata description file; defining that one attribute in an employee entity is an affiliated organization set in an entity relationship description area in an employee metadata description file; in addition, the daily maintenance of organization and staff information is not free from the need of corresponding human-computer interfaces, the interface for adding staff information and the interface for modifying staff information are different, for example, the ID field of the staff in adding staff time is empty, while the ID field of the staff in modifying staff time is not empty and is read only, and the difference between the adding interface and the modifying interface can be described in the human-computer interface description area in the metadata description file.
Fig. 2 is a schematic structural diagram of a metadata description file S11 according to the present invention, where the metadata description file is internally divided into an entity attribute description area, a field set description area, an entity relationship description area, a human-computer interface description area, a default value description area, and a verification rule description area.
The entity attribute description area S12 is used for describing the attribute set of the entity, including but not limited to entity name, entity code, entity classification, etc.
The field set description area S13 is used for describing a field set of the entity, including but not limited to a field name, a field code, a value type, a value length, a null allowed value, and the like.
The entity relationship description area S14 is used for describing the relationship between the entity and other entities, including but not limited to associated field codes, associated entity codes, associated foreign key codes, tag field codes, filtering conditions, sorting modes, and the like.
The human-machine interface description area S15 is used for describing human-machine interface information required for maintaining the entity data, including but not limited to common page description, toolbar description, list page description, add page description, modify page description.
The common page description including, but not limited to, page title, page style, default layout, etc.;
the toolbar description includes but is not limited to the description of the addition, modification and deletion buttons on the list page;
the list page description includes but is not limited to query conditions, list titles, field sets and the like, and the field set description includes but is not limited to field codes, field widths, input modes, alignment modes and the like displayed by the list;
the added page description includes, but is not limited to, a field set filled in by the added record, an arrangement mode, a button description and the like, the field set includes, but is not limited to, a field code, an input mode, whether to fill in, and the like, and the button description includes, but is not limited to, a button title, a button event and the like.
The modified page description includes, but is not limited to, a field set filled in by the modified record, a saved button description, etc., the field set includes, but is not limited to, a field code, an input mode, whether to fill in, etc., and the button description includes, but is not limited to, a button title, a button event, etc.
The default value area S16 is used to describe default values of the attributes and fields of the entity, and default values when a record of the entity is newly added, including but not limited to field codes, default values, and value formulas.
The verification rule description area S17 is used to describe the verification rule for the value of each attribute and field of the entity, and when the record of the entity is added or modified, the data input by the user is verified, including but not limited to the field code, whether the field needs to be filled, the prompt information, the verification formula, etc.
Fig. 3 is a schematic structural diagram of a code template file S21 according to the present invention, where the interior of the code template file is divided into a template parameter description area, a template attribute description area, an executable program instruction area, and an output mode description area.
The template parameter description area S22 is used to describe parameters of the template, where the template parameters may be referred to by the executable program instructions in the template executable program instruction area S24, and the template parameters include, but are not limited to, a parameter code, a parameter name, a parameter type, a default value, and the like.
The template attribute description area S23 is used for describing various attributes of the template, where the template attributes include, but are not limited to, a template code, a template name, a template category, a parent template code, and the like.
The executable program instruction description area S24 is used for describing how executable program instructions are embedded in the object program code to be multiplexed, including but not limited to object program code fragments, parameter placeholders, instruction placeholders, executable program instruction syntax trees, and the like.
The output mode description area S25 is used to describe the storage mode of the generated object code, and may embed executable program instructions in the storage mode description, including but not limited to storage container name, storage container code, storage file type, storage container path, and directory, file name and file suffix of the generated object code storage file.
Fig. 4 is a schematic flow chart of the code generation method according to the present invention, and a service person pushes an operation parameter file S31, a metadata description file S11, and a code template file S21 to a code generation apparatus S34 through a file pipeline according to service requirements, and after receiving by the code generation apparatus, the code generation apparatus executes instructions in an executable program instruction region in the code template file to generate an object code S35.
The operating parameter files S31 include, but are not limited to, project code, project name, project directory, executable program instruction language, character code, buffer size, and the like.
The object code S35 includes, but is not limited to, program source codes of various programming languages, various text-based scripts, texts in XML, JSON, and other formats, plain texts, and the like.
Fig. 5 is a schematic diagram of a code generation apparatus S34 according to the present invention. The code generating means S34 includes a code template file unit S341, a metadata description file unit S342, an operation parameter file unit S343, a program instruction executing unit S344, and an object code outputting unit S345.
The code template file unit S341 is configured to collect the received code template file, provide daily maintenance functions of performing classification management on the code template file, querying, adding, modifying, and deleting the code template file, provide code multiplexing functions of copying, inheriting, embedding, and the like of the code template file, and implement maximum multiplexing of the code template file.
The metadata description file unit S342 is configured to collect the received metadata description file, provide daily maintenance functions of performing classification management on the metadata description file, querying, adding, modifying, and deleting the metadata description file, provide a copy function of the metadata description file, and implement maximum multiplexing of the metadata description file.
The operation parameter file unit S343 is configured to collect the received operation parameter files, provide the functions of performing classification management on the operation parameter files, querying, adding, modifying, deleting, and copying the operation parameter files, and implement multiplexing of the operation parameter files.
The program instruction executing unit S344 is configured to receive the pushed operation parameter file S31, the metadata description file S11, and the code template file S21, first read and parse the operation parameter file, initialize a program instruction executor, then read and parse the metadata description file, perform recursive reference to generate a metadata description file set, read and parse the code template file again, perform recursive reference to generate a pre-compiled code template file set, and finally read the metadata description file set and the pre-compiled code template file by the program instruction executor to execute an executable program instruction in the pre-compiled code template file to generate an object code.
The object code output unit S345 is configured to read the object code storage manner described in the output manner description area S25 in the code template file S21, execute the executable program instructions embedded in the storage manner, generate directories and files and suffixes stored in the object code, and finally store the object code in the object code storage device, and provide the functions of performing classification management, query, modification, deletion and copy on the object code file. The storage modes include but are not limited to: storage medium type, storage medium attributes, storage directory name, storage file name, file suffix, and the like.
Such as: an employee information management module in a human resource management software needs to realize the functions of employee inquiry, employee addition, employee modification and employee deletion. In the past, code template files have been prepared for other information such as inquiry function, newly-added function, modification function and deletion function of organization information, and a target code storage path is defined in the code template files. Before the target code is generated, business personnel directly reuse the compiled organization metadata description file, compile the staff metadata description file from zero, and compile the operation parameter file. When the target code is generated, business personnel push the organization metadata description file, the employee metadata description file and the operation parameter file to the code generation device through a file pipeline. The code generating device receives the files, the program instruction unit of the code generating device is responsible for reading and analyzing the files and executing executable program instructions in the files, the target code output unit of the code generating device stores generated target codes into an instruction directory respectively according to a target code storage path defined by the code template file, for example, a plurality of generated program source code files are directly stored into a directory or a sub-directory where a development project is located, and the plurality of source code files are stored according to different modules respectively.

Claims (10)

1. A code generation method and apparatus, characterized by: and pushing the metadata description file, the code template file and the parameter description file to a code generation device, and generating a target code by the code generation device and saving the target code to a specified storage medium.
2. A code generation method and apparatus according to claim 1, comprising the steps of: writing a metadata description file, making a code template file, generating an object code and storing the object code, wherein the steps comprise:
writing a metadata description file: compiling a metadata description file containing entities, relationships among the entities, entity human-computer interfaces and other information;
making a code template file: writing a code template file containing executable program instructions, output modes of target codes and other information;
generating an object code: pushing the operation parameter file, the metadata description file and the code template file to a code generation device to generate a target code;
storing the object code: and storing the target code according to the storage mode and the storage medium defined in the code template file.
3. The code generation method and device according to claim 2, characterized by comprising the following units: the code template file unit, metadata description file unit, operation parameter file unit, program instruction execution unit and object code output unit include:
code template file unit: the code template file is used for classifying, inquiring, adding, modifying, deleting, copying, inheriting and embedding;
metadata description file unit: the metadata description files are used for classifying, inquiring, adding, modifying, deleting and copying the metadata description files;
operating a parameter file unit: the operation parameter files are used for classifying, inquiring, adding, modifying, deleting and copying;
the program instruction execution unit: the system comprises a code template file, a running parameter file, a metadata description file and a code template file, wherein the code template file is used for storing a running parameter file, a metadata description file and a code template file;
an object code output unit: the system is used for storing and saving the generated target codes, and classifying, inquiring, adding, modifying, deleting and copying the target codes.
4. The code generation method and device according to claim 3, wherein the metadata description file internally includes an entity attribute description area, a field set description area, an entity relationship description area, a human-computer interface description area, a default value description area, and a check rule description area.
5. The method and the device for generating the code according to claim 4, wherein the code template file internally comprises a template parameter description area, a template attribute description area, an executable program instruction area and an output mode description area.
6. The code generation method and device according to claim 5, wherein the code generation device internally comprises a code template file unit, a metadata description file unit, an operation parameter file unit, a program instruction execution unit and an object code output unit.
7. The code generation method and device according to claim 6, wherein the entity attribute description area, the field set description area, and the entity relationship description area are used to describe the attribute set, the field set, and the relationship between the entity and other entities.
8. The method and apparatus for code generation according to claim 7, wherein the human-machine interface description area, the default value description area, and the verification rule description area are used to describe human-machine interface information required for maintaining the entity data, default values of fields when adding the record of the entity, and verification rules for data input by the user.
9. The code generation method and device of claim 8, wherein the programming language is not limited, the database type is not limited, and the number of tables and the complexity of the relationship between tables are not limited.
10. The method and apparatus of claim 9, wherein the metadata description file, the code template file and the operation parameter file are all flexibly reusable.
CN202210788866.8A 2022-07-06 2022-07-06 Code generation method and device based on metadata Pending CN115048109A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210788866.8A CN115048109A (en) 2022-07-06 2022-07-06 Code generation method and device based on metadata

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210788866.8A CN115048109A (en) 2022-07-06 2022-07-06 Code generation method and device based on metadata

Publications (1)

Publication Number Publication Date
CN115048109A true CN115048109A (en) 2022-09-13

Family

ID=83166125

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210788866.8A Pending CN115048109A (en) 2022-07-06 2022-07-06 Code generation method and device based on metadata

Country Status (1)

Country Link
CN (1) CN115048109A (en)

Similar Documents

Publication Publication Date Title
US11907247B2 (en) Metadata hub for metadata models of database objects
US10698682B1 (en) Computerized software development environment with a software database containing atomic expressions
CN101334728B (en) Interface creating method and platform based on XML document description
Wimmer et al. Bridging grammarware and modelware
US11726969B2 (en) Matching metastructure for data modeling
EP1347394B1 (en) Schema-oriented content management system
US8954375B2 (en) Method and system for developing data integration applications with reusable semantic types to represent and process application data
US6003039A (en) Data repository with user accessible and modifiable reuse criteria
US20090282066A1 (en) Method and system for developing data integration applications with reusable semantic identifiers to represent application data sources and variables
US20060218160A1 (en) Change control management of XML documents
US20100185701A1 (en) Method and system for enabling life cycle maintenance of hierarchical database schemas in modeling tool
CN112463149B (en) Software-defined satellite-oriented reusable code library construction method and device
CN111367893A (en) Method and device for database version iteration
CN101901265A (en) Objectification management system of virtual test data
US6915313B2 (en) Deploying predefined data warehouse process models
JP2015536498A (en) Cohort identification system
CN104573053B (en) A kind of configuration item template dynamic customization method based on XML
CN113342325A (en) Visual modeling method, system, electronic device and storage medium
Thao A configuration management system for software product lines
CN116821098A (en) Data warehouse management method, service system and storage medium
Schauerhuber et al. Bridging WebML to model-driven engineering: from document type definitions to meta object facility
Kalinichenko et al. Constructing of Mappings of Heterogeneous Information Models into the Canonical Models of Integrated Information Systems.
CN115048109A (en) Code generation method and device based on metadata
CN113687827A (en) Data list generation method, device and equipment based on widget and storage medium
Masson et al. Defining Referential Integrity Constraints in Graph-oriented Datastores.

Legal Events

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