A data bus service code generation system based on BNF paradigm

Through the data bus service code generation system based on the BNF paradigm, data bus service code is automatically generated, which solves the problems of large development workload, long cycle and high difficulty in the existing technology, and realizes automated, efficient and low-cost data synchronous sharing between systems.

CN119166124BActive Publication Date: 2025-02-28NORTHLAB (SHENYANG) INC LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411630486.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-15
Publication Date
2025-02-28
Estimated Expiration
2044-11-15

AI Technical Summary

Technical Problem

When the prior art realizes data synchronization and sharing among systems, the development workload is large, the cycle is long and the difficulty is high, and there is a lack of automated, efficient and low-cost solutions.

Method used

The data bus service code generation system based on the BNF paradigm is adopted. Through the file setting module, the file analysis module and the code generation module, the data bus service code is automatically generated to realize real-time data synchronization between systems.

Benefits of technology

The automated generation of data bus service codes is realized, which greatly reduces the implementation cost and development difficulty of data synchronization sharing, and provides an automated, efficient and low-cost data synchronization sharing solution.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure FT_1
    Figure FT_1
  • Figure FT_2
    Figure FT_2
  • Figure FT_3
    Figure FT_3
Patent Text Reader

Abstract

The present invention provides a data bus service code generation system based on the BNF paradigm, and relates to the technical field of digital data processing. The system includes a file setting module, a file parsing module and a code generation module; the file setting module, based on the BNF paradigm description, constructs a data bus service description file according to a grammatical structure customized according to BNF rules; the file parsing module includes a symbol list generation unit and a service description structure generation unit; the code generation module includes a code template generation unit and a code generator; the code template generation unit designs and generates corresponding code templates according to the structural definition of the service description structure and in accordance with the grammatical rules of various programming languages; the code generator takes the service description structure as input and directly generates data bus service code based on the code template. The system provides an automated, efficient and low-cost data synchronization and sharing solution.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of digital data processing, and in particular to a data bus service code generation system based on the BNF paradigm. Background Art

[0002] With the deepening of information construction, various business systems may have data islands due to the lack of unified early planning, resulting in the inability to synchronize and share data between systems.

[0003] At present, data synchronization and sharing solutions mainly rely on customized programming by developers, usually by building a data middle platform to achieve real-time synchronization, or using a targeted data synchronization tool for offline scheduled synchronization. However, no matter which method is adopted, it faces problems such as large development workload, long cycle and high difficulty. Therefore, there is an urgent need for an automated, efficient and low-cost data synchronization and sharing solution to achieve real-time data synchronization between systems. Summary of the invention

[0004] The technical problem to be solved by the present invention is to provide a data bus service code generation system based on the BNF paradigm to achieve automatic generation of data bus service code in view of the above-mentioned deficiencies in the prior art.

[0005] In order to solve the above technical problems, the technical solution adopted by the present invention is: a data bus service code generation system based on the BNF paradigm, including a file setting module, a file parsing module and a code generation module;

[0006] The file setting module constructs a data bus service description file based on the BNF paradigm description and a custom grammatical structure according to BNF rules, including two items: message and service;

[0007] The message message includes a message name messageName and a message attribute field; wherein the message name messageName is used to define the input and output of the data bus service; the message attribute field includes two parts: an attribute name fieldName and an attribute type fieldType; the message includes one or more attributes;

[0008] The service service includes the service name serviceName and the method name methodName in the service; the service includes one or more methods method; each method method defines input and output based on the message, and defines the data source option; the data source option includes the database name dbname, the database address ip, the database port port, the database user name username, the database password userpwd and the database execution statement sql;

[0009] The file parsing module includes a symbol list generation unit and a service description structure generation unit;

[0010] The symbol list generation unit parses the data bus service file, converts it into a symbol list, and outputs it to the service description structure generation unit, specifically:

[0011] Step s1: Parameter initialization: set the symbol variable parameter to empty, set the symbol list parameter to empty;

[0012] Step s2: Read the characters in the data bus service file one by one, store them in symbol variables, and execute the following logic:

[0013] If the current character is a special character or a space or line break, the symbol variable is recorded in the symbol list and the symbol variable is reset to empty;

[0014] If the current character is not a special character, append the current character to the end of the symbol variable;

[0015] Step s3: traverse and read all characters in the data bus service file to obtain a symbol list;

[0016] The service description structure generating unit reads the input symbol list, parses the symbol list according to the data bus service file structure, and generates a service description structure;

[0017] The service description structure is a tree structure consisting of multiple nodes, each of which includes three attributes: node type, node value, and children.

[0018] The node type type includes six types: root, service service, method method, message message, attribute field and data source option. Root represents the root node, service service, method method, message message, attribute field and data source option are the types of child nodes, which are consistent with the content of the data bus service file;

[0019] When the node type is root, the node value is fixed to root;

[0020] When the node type is service, the node value is the service name serviceName in the data bus service description file;

[0021] When the node type is method, the node value is the method name methodName in the data bus service description file;

[0022] When the node type is message, the node value is "messageName#input and output identifiers" in the data bus service description file. # is a fixed separator. The input and output identifiers are determined by the BNF rule and are fixed as "input" or "output".

[0023] When the node type type is the attribute field, the node value value is "fieldName#fieldType" in the data bus service description file, and # is a fixed separator;

[0024] When the node type is data source option, the node value is "dbname#{database name}, ip#{database address}, port#{database port}, username#{database user name}, userpwd#{database password} and sql#{database execution statement}", and the content enclosed in curly brackets {} is the corresponding setting value in the data bus service description file;

[0025] Children are the child nodes contained in the current node. A node contains multiple child nodes;

[0026] The process of generating a service description structure by the service description structure generating unit is specifically as follows:

[0027] Step C1. Set message, service, field, option, return, stream, dbname, ip, port, username, userpwd, and sql as keywords;

[0028] Step C2. Initialize the root node of the service description structure and set the child nodes to empty;

[0029] Step C3. Read the symbol values ​​in the symbol list one by one, match the read symbol values ​​with the keywords set in step C1, parse the symbol values ​​according to the data bus service file structure and convert them into nodes;

[0030] Step C4. Determine the corresponding parent node of the converted node according to the data bus service file structure, and use it as the child node of the parent node;

[0031] Step C5. After all symbol values ​​are parsed, a service description structure is obtained;

[0032] The code generation module includes a code template generation unit and a code generator;

[0033] The code template generation unit is based on the open source Jinja2 template engine, and designs and generates corresponding code templates according to the structural definition of the service description structure and the grammatical rules of various programming languages; the code templates are composed of fixed strings and variable strings, including service service class code templates, bean entity class code templates, operate operation class code templates and db data source configuration code templates;

[0034] The code generator takes the service description structure as input, relies on four types of code templates, and performs rendering based on the open source Jinja2 template engine to directly generate the data bus service code.

[0035] The beneficial effect of adopting the above technical solution is that: the data bus service code generation system based on the BNF paradigm provided by the present invention introduces a data bus service file structure based on the BNF paradigm. The system can automatically generate data bus service code. The generated code can be directly compiled and deployed, and provide data synchronization and sharing services to the outside world, which greatly reduces the implementation cost and development difficulty of data synchronization and sharing, and provides an automated, efficient and low-cost data synchronization and sharing solution. BRIEF DESCRIPTION OF THE DRAWINGS

[0036] Figure 1 A framework diagram of a data bus service code generation system based on the BNF paradigm provided by an embodiment of the present invention;

[0037] Figure 2 A flowchart of a symbol list generating unit provided by an embodiment of the present invention;

[0038] Figure 3 A flow chart of a service description structure generation unit provided in an embodiment of the present invention;

[0039] Figure 4 A flowchart of a data bus service code generation system based on the BNF paradigm provided in an embodiment of the present invention for generating code. DETAILED DESCRIPTION

[0040] The specific implementation of the present invention is further described in detail below in conjunction with the accompanying drawings and examples. The following examples are used to illustrate the present invention, but are not intended to limit the scope of the present invention.

[0041] In this embodiment, a data bus service code generation system based on the BNF paradigm is provided. Figure 1 As shown, it includes a file setting module, a file parsing module and a code generation module;

[0042] The file setting module is based on the Backus-Naur Form (BNF) description and constructs a data bus service file according to a grammatical structure customized according to BNF rules, including two items: message and service.

[0043] The message message includes a message name messageName and a message attribute field; wherein the message name messageName is used to define the input and output of the data bus service; the message attribute field includes an attribute name fieldName and an attribute type fieldType (which can be int, long, string, boolean); the message includes one or more attributes;

[0044] In this embodiment, the message may be as shown in Table 1:

[0045] Table 1 Message table

[0046]

[0047] The service service includes the service name serviceName and the method name methodName in the service; the service includes one or more methods method; each method method defines input and output based on the message, and defines the data source option; the data source option includes the database name dbname, the database address ip, the database port port, the database user name username, the database password userpwd and the database execution statement sql;

[0048] In this embodiment, the services may be as shown in Table 2:

[0049] Table 2 Service Table

[0050]

[0051] The file parsing module includes a symbol list generation unit and a service description structure generation unit;

[0052] The symbol list generation unit parses the data bus service file, converts it into a symbol list, and outputs it to the service description structure generation unit, such as Figure 2 As shown, specifically:

[0053] Step s1: Parameter initialization: set the symbol variable parameter to empty, set the symbol list parameter to empty;

[0054] Step s2: Read the characters in the data bus service file one by one, store them in symbol variables, and execute the following logic:

[0055] If the current character is a special character or a space or line break, the symbol variable is recorded in the symbol list and the symbol variable is reset to empty;

[0056] If the current character is not a special character, append the current character to the end of the symbol variable;

[0057] Step s3: traverse and read all characters in the data bus service file to obtain a symbol list;

[0058] The service description structure generating unit reads the input symbol list, parses the symbol list according to the data bus service file structure, and generates a service description structure;

[0059] The service description structure is a tree structure consisting of multiple nodes, each of which includes three attributes: node type, node value, and children.

[0060] The node type type includes six types: root, service service, method method, message message, attribute field and data source option. Root represents the root node, service service, method method, message message, attribute field and data source option are the types of child nodes, which are consistent with the content of the data bus service file;

[0061] When the node type is root, the node value is fixed to root;

[0062] When the node type is service, the node value is the service name serviceName in the data bus service description file;

[0063] When the node type is method, the node value is the method name methodName in the data bus service description file;

[0064] When the node type is message, the node value is "messageName#input and output identifiers" in the data bus service description file. # is a fixed separator. The input and output identifiers are determined by the BNF rule and are fixed as "input" or "output".

[0065] When the node type is attribute field, the node value is "fieldName#fieldType" in the data bus service description file, and # is a fixed separator;

[0066] When the node type is data source option, the node value is "dbname#{database name}, ip#{database address}, port#{database port}, username#{database user name}, userpwd#{database password} and sql#{database execution statement}", and the content enclosed in curly brackets {} is the corresponding setting value in the data bus service description file;

[0067] Children are the child nodes contained in the current node. A node contains multiple child nodes;

[0068] The process of the service description structure generating unit generating the service description structure is as follows: Figure 3 As shown, specifically:

[0069] Step C1. Set message, service, field, option, return, stream, dbname, ip, port, username, userpwd, and sql as keywords;

[0070] Step C2. Initialize the root node of the service description structure and set the child nodes to empty;

[0071] Step C3. Read the symbol values ​​in the symbol list one by one, match the read symbol values ​​with the keywords set in step C1, parse the symbol values ​​according to the data bus service file structure and convert them into nodes;

[0072] Step C4. Determine the corresponding parent node of the converted node according to the data bus service file structure, and use it as the child node of the parent node;

[0073] Step C5. After all symbol values ​​are parsed, a service description structure is obtained;

[0074] The code generation module includes a code template generation unit and a code generator;

[0075] The code template generation unit is based on the open source Jinja2 template engine, and designs and generates corresponding code templates according to the structural definition of the service description structure and the grammatical rules of various programming languages; the code templates are composed of fixed strings and variable strings, including service service class code templates, bean entity class code templates, operate operation class code templates and db data source configuration code templates;

[0076] In this embodiment, the service class template design is shown in Table 3:

[0077] Table 3 Service class template

[0078]

[0079] The bean entity class template design is shown in Table 4:

[0080] Table 4 bean entity class template

[0081]

[0082] The design of the operate class template is shown in Table 5:

[0083] Table 5 operate operation template

[0084]

[0085] The db data source configuration template design is shown in Table 6:

[0086] Table 6 db data source configuration template

[0087]

[0088] The code generator takes the service description structure as input, relies on four types of code templates, and performs rendering based on the open source Jinja2 template engine to directly generate the data bus service code.

[0089] In this embodiment, the process of generating code by the data bus service code generation system based on the BNF paradigm is as follows: Figure 4 As shown, first define the input of the message message of the data bus service description file, messageName is Input, fieldName:fieldType are: id: string; timestamp: long. id is the user id, and timestamp is the timestamp.

[0090] Define the output of the message message, messageName is Output, fieldName:fieldType are: id: string; name: string; dept: string; timestamp: long. id is the user id, name is the user name, dept is the user's department, and timestamp is the timestamp.

[0091] Define the service service, with serviceName as UserInfoSync, methodName as getUserInfoByTimestamp, the method's function is to obtain user information based on the timestamp, the input parameter is the message input entity Input, and the output parameter is the message output entity Output.

[0092] Define the data source of service service, dbname is userdb, ip is 127.0.0.1, port is 3306, username is root, userpwd is 123456, and sql is "select id,name,dept,timestamp from userwhere timestamp>= #{Input.timestamp}".

[0093] Based on the above, the defined data bus service description file is shown in Table 7 below:

[0094] Table 7 Data bus service description file

[0095]

[0096] The data bus service description file is analyzed and the symbol list is shown in Table 8:

[0097] Table 8 Symbol list

[0098]

[0099] The symbol list is read and parsed, and a service description structure is generated after parsing, as shown in Table 9:

[0100] Table 9 Service Description Structure

[0101]

[0102] Using the service description structure generated above, the code generator calls the service class template to automatically generate the service class code of the data bus service, as shown in Table 10:

[0103] Table 10 Service class codes for data bus services

[0104]

[0105] Using the service description structure generated above, the code generator calls the bean entity class template to automatically generate the input and output class codes of the data bus service, as shown in Table 11 and Table 12;

[0106] Table 11 Input class codes for data bus services

[0107]

[0108] Table 12 Output class codes for data bus services

[0109]

[0110] Using the service description structure generated above, the code generator calls the operate operation class template to automatically generate the operation class code of the data bus service, as shown in Table 13:

[0111] Table 13 Operation class codes for data bus services

[0112]

[0113] Using the service description structure generated above, the code generator calls the db data source configuration template to automatically generate the data source configuration code for the data bus service, as shown in Table 14:

[0114] Table 14 Data source configuration code for data bus service

[0115]

[0116] Based on the above generated code, the data bus service can be compiled into a plug-in package and pushed to the deployed container, so that the data bus service can be provided externally and the synchronous sharing of user information can be realized.

[0117] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some or all of the technical features therein. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope defined by the claims of the present invention.

Claims

1. A data bus service code generation system based on BNF paradigm, characterized by: Including file setting module, file parsing module and code generation module; The file setting module constructs a data bus service description file based on the BNF paradigm description and a custom grammatical structure according to BNF rules, including two items: message and service; The file parsing module includes a symbol list generation unit and a service description structure generation unit; The symbol list generating unit parses the data bus service file, converts it into a symbol list, and outputs it to the service description structure generating unit; The service description structure generating unit reads the input symbol list, parses the symbol list according to the data bus service file structure, and generates a service description structure; The code generation module includes a code template generation unit and a code generator; The code template generation unit is based on the open source Jinja2 template engine, and designs and generates corresponding code templates according to the structure definition of the service description structure and the grammar rules of various programming languages; The code generator takes the service description structure as input, relies on the code template, and performs rendering based on the open source Jinja2 template engine to directly generate the data bus service code.

2. A data bus service code generation system based on BNF paradigm according to claim 1, characterized in that: The message message includes a message name messageName and a message attribute field; wherein the message name messageName is used to define the input and output of the data bus service; the message attribute field includes two parts: an attribute name fieldName and an attribute type fieldType; the message includes one or more attributes.

3. A data bus service code generation system based on BNF paradigm according to claim 2, characterized in that: The service service includes the service name serviceName and the method name methodName in the service; the service includes one or more methods method; each method method defines input and output based on the message, and defines the data source option; the data source option includes the database name dbname, database address ip, database port port, database user name username, database password userpwd and database execution statement sql.

4. A data bus service code generation system based on BNF paradigm according to claim 3, characterized in that: The specific method of the symbol list generating unit parsing the data bus service file and converting it into a symbol list is as follows: Step s1: Parameter initialization: set the symbol variable parameter to empty, set the symbol list parameter to empty; Step s2: Read the characters in the data bus service file one by one, store them in symbol variables, and execute the following logic: If the current character is a special character or a space or line break, the symbol variable is recorded in the symbol list and the symbol variable is reset to empty; If the current character is not a special character, append the current character to the end of the symbol variable; Step s3: traverse and read all characters in the data bus service file to obtain a symbol list.

5. The data bus service code generation system based on BNF paradigm according to claim 4 is characterized in that: The service description structure is a tree structure consisting of multiple nodes, each of which includes three attributes: node type, node value, and children. The node type type includes six types: root, service service, method method, message message, attribute field and data source option. Root represents the root node, service service, method method, message message, attribute field and data source option are the types of child nodes, which are consistent with the content of the data bus service file; When the node type is root, the node value is fixed to root; When the node type is service, the node value is the service name serviceName in the data bus service description file; When the node type is method, the node value is the method name methodName in the data bus service description file; When the node type is message, the node value is "messageName#input and output identifier" in the data bus service description file. # is a fixed separator. The input and output identifier is determined by the BNF rule and is fixed to "input" or "output". When the node type is attribute field, the node value is "fieldName#fieldType" in the data bus service description file, and # is a fixed separator; When the node type is data source option, the node value is "dbname#{database name}, ip#{database address}, port#{database port}, username#{database user name}, userpwd#{database password} and sql#{database execution statement}", and the content enclosed in curly brackets {} is the corresponding setting value in the data bus service description file; Children are the child nodes contained in the current node. A node contains multiple child nodes.

6. A data bus service code generation system based on BNF paradigm according to claim 5, characterized in that: The process of generating a service description structure by the service description structure generating unit is specifically as follows: Step C1. Set message, service, field, option, return, stream, dbname, ip, port, username, userpwd, and sql as keywords; Step C2. Initialize the root node of the service description structure and set the child nodes to empty; Step C3. Read the symbol values ​​in the symbol list one by one, match the read symbol values ​​with the keywords set in step C1, parse the symbol values ​​according to the data bus service file structure and convert them into nodes; Step C4. Determine the corresponding parent node of the converted node according to the data bus service file structure, and use it as the child node of the parent node; Step C5. After all symbol values ​​are parsed, a service description structure is obtained.

7. A data bus service code generation system based on BNF paradigm according to claim 6, characterized in that: The code templates are composed of fixed strings and variable strings, including a service class code template, a bean entity class code template, an operate class code template, and a db data source configuration code template.

Citation Information

Patent Citations

  • System and method for creating and executing highly extended cloud applications

    CN116391172A

  • Resolver based on custom grammar and derivation tree code generation system

    CN116909572A