CN112817580A - Data processing method and device, electronic equipment and storage medium - Google Patents

Data processing method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN112817580A
CN112817580A CN202110113666.8A CN202110113666A CN112817580A CN 112817580 A CN112817580 A CN 112817580A CN 202110113666 A CN202110113666 A CN 202110113666A CN 112817580 A CN112817580 A CN 112817580A
Authority
CN
China
Prior art keywords
file
layer
data
generating
database
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.)
Granted
Application number
CN202110113666.8A
Other languages
Chinese (zh)
Other versions
CN112817580B (en
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.)
Beijing QIYI Century Science and Technology Co Ltd
Original Assignee
Beijing QIYI Century Science and Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing QIYI Century Science and Technology Co Ltd filed Critical Beijing QIYI Century Science and Technology Co Ltd
Priority to CN202110113666.8A priority Critical patent/CN112817580B/en
Publication of CN112817580A publication Critical patent/CN112817580A/en
Application granted granted Critical
Publication of CN112817580B publication Critical patent/CN112817580B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2457Query processing with adaptation to user needs
    • G06F16/24573Query processing with adaptation to user needs using data annotations, e.g. user-defined metadata
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/28Databases characterised by their database models, e.g. relational or object models
    • G06F16/284Relational databases
    • G06F16/288Entity relationship models
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/36Software reuse
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The application relates to a data processing method, a data processing device, an electronic device and a storage medium. According to the technical scheme, a set of codes for executing the persistence operation can be automatically generated based on the metadata table which can be automatically generated by the database management system after the database is created and the pre-extracted public data packet, developers only need to specify the metadata table and the public data packet, database persistence operation codes with relatively fixed formats do not need to be repeatedly written for different databases, even if the database is transformed, the codes do not need to be modified one by one, and the database operation codes corresponding to the transformed database can be regenerated through the metadata table which is re-created after the database is transformed. Therefore, the probability of errors in the compiling and modifying process is reduced, a large amount of time cost and labor cost are saved, and the development efficiency is improved.

Description

Data processing method and device, electronic equipment and storage medium
Technical Field
The present application relates to the field of computer technologies, and in particular, to a data processing method and apparatus, an electronic device, and a storage medium.
Background
Spring Boot is a completely new framework provided by the Pivotal team, and is designed to simplify the initial set-up and development processes of new Spring applications. The Java Persistence API (JPA) is a Persistence mechanism based on a simple irregular Java Object (POJO).
A JPA persistence framework is adopted in the Spring Boot, and the JPA persistence framework is actually Spring Data JPA. The Spring Data JPA is a set of JPA application framework packaged by Spring based on an Object Relational Mapping (ORM) framework and JPA specification, and can enable a developer to access and operate a database by using extremely simple codes. It provides common functions including adding, deleting, modifying and checking, etc. and is easy to expand. Using the Spring Data JPA, writing of Data Access Objects (DAO) layer by developers is released, and basically all of the cut (representing Create, Update, read, and Delete) can be implemented depending on it.
However, as the business is continuously developed, the number of used underlying metadata tables is increasingly large, developers need to repeatedly write database persistent codes with relatively fixed formats for different database configurations in the writing process, and need to modify the codes one by one when the databases are changed, and various errors are easy to occur in the writing and modifying processes, thereby greatly wasting the time of the developers and influencing the development efficiency.
Disclosure of Invention
In order to solve the technical problem or at least partially solve the technical problem, embodiments of the present application provide a data processing method, an apparatus, an electronic device, and a storage medium.
According to an aspect of an embodiment of the present application, there is provided a data processing method, including:
acquiring metadata structure information in a metadata table, wherein the metadata table is generated after a database is created;
generating a data entity file according to the metadata structure information;
generating an operation layer file corresponding to the data entity according to the data entity file and a preset public data packet;
obtaining a database operation code corresponding to the database according to the data entity file and the operation layer file;
and carrying out persistence operation on the data in the database by adopting the database operation code.
Optionally, obtaining metadata structure information corresponding to the metadata table includes:
based on the input database parameters and the data table names, reading a metadata table corresponding to the data table names from an information database corresponding to the database parameters;
extracting the metadata structure information from the metadata table, wherein the metadata structure information includes: data table name, field name, and field type.
Optionally, the generating a data entity file according to the metadata structure information includes:
acquiring storage path information corresponding to the data entity;
splicing to obtain first packet path information of a data packet where the data entity is located according to the storage path information and the entity class name of the data entity;
generating a first reference statement for referencing the class library corresponding to the data entity;
configuring persistent annotation information corresponding to the data entity;
setting access authority corresponding to the data entity, and generating a class format statement corresponding to the data entity;
and obtaining the data entity file according to the first packet path information, the first reference statement, the persistent annotation information, the access authority and the class format statement.
Optionally, the operation layer file includes: access layer files, service implementation layer files and control layer files; the common data packet includes: the system comprises an access layer public packet, a service implementation layer public packet and a control layer public packet;
the generating of the operation layer file corresponding to the data entity according to the data entity file and the preset public data packet includes:
generating the access layer file according to the data entity file and the access layer public packet;
generating the service layer file according to the data entity file and the service layer public packet;
generating the service implementation layer file based on the access layer file, the service layer file and the service implementation layer public package;
and generating the control layer file according to the service layer file and the control layer public packet.
Optionally, the generating the access layer file according to the data entity file and the access layer public packet includes:
splicing to obtain second packet path information of a data packet where the access layer file is located according to the storage path information and the access layer class name corresponding to the access layer;
generating a second reference statement that references the data entity file;
generating a first inheritance statement inheriting the access layer public packet;
and splicing the second packet path information, the second reference statement and the first inheritance statement to obtain the access layer file.
Optionally, the generating the service layer file according to the data entity file and the service layer public package includes:
splicing to obtain third package path information of a data package where the service layer file is located according to the storage path information and the service layer class name corresponding to the service layer;
generating a third reference statement that references the data entity file;
generating a second inheritance statement inheriting the service layer public package;
and splicing the third packet path information, the third reference statement and the second inheritance statement to obtain the service layer file.
Optionally, the generating the service implementation layer file based on the access layer file, the service layer file, and the service implementation layer public package includes:
generating a first dependency statement for the access layer file and a third inheritance statement for inheriting the service implementation layer public package;
and splicing the first dependent statement and the third inherited statement based on the service layer file to obtain the service implementation layer file.
Optionally, the generating the control layer file according to the service layer file and the control layer public package includes:
generating a second dependency statement for the service layer file and a fourth inheritance statement for inheriting the control layer public packet;
and splicing the second dependent statement and the fourth inherited statement to obtain the control layer file.
According to another aspect of the embodiments of the present application, there is provided a data processing apparatus including:
the system comprises an acquisition module, a database management module and a data processing module, wherein the acquisition module is used for acquiring metadata structure information corresponding to a metadata table, and the metadata table is created after a database is installed;
the entity generating module is used for generating a data entity file according to the metadata structure information;
the file generation module is used for generating an operation layer file corresponding to the data entity according to the data entity file and a preset public data packet;
the code generation module is used for obtaining a database operation code corresponding to the database according to the data entity file and the operation layer file;
and the operation module is used for carrying out persistence operation on the data in the database by adopting the database operation code.
According to another aspect of the embodiments of the present application, there is also provided a storage medium including a stored program that executes the above steps when the program is executed.
According to another aspect of an embodiment of the present application, there is provided an electronic device including: the system comprises a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory complete mutual communication through the communication bus;
the memory is used for storing a computer program;
the processor is configured to implement the above method steps when executing the computer program.
According to another aspect of embodiments of the present application, there is provided a computer-readable storage medium having stored thereon a computer program which, when executed by a processor, performs the above-mentioned method steps.
Compared with the prior art, the technical scheme provided by the embodiment of the application has the following advantages:
the method comprises the steps that a set of codes for executing persistent operation can be automatically generated based on a metadata table which can be automatically generated after a database is created by a database management system and a pre-extracted public data packet, developers only need to designate the metadata table and the public data packet, database persistent operation codes with relatively fixed formats do not need to be repeatedly written for different databases, even if the databases are transformed, the codes do not need to be modified one by one, and database operation codes corresponding to the transformed databases can be regenerated through the metadata table which is re-created after the databases are transformed. Therefore, the probability of errors in the compiling and modifying process is reduced, a large amount of time cost and labor cost are saved, and the development efficiency is improved.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and together with the description, serve to explain the principles of the invention.
In order to more clearly illustrate the embodiments or technical solutions in the prior art of the present invention, the drawings used in the description of the embodiments or prior art will be briefly described below, and it is obvious for those skilled in the art that other drawings can be obtained based on these drawings without creative efforts.
Fig. 1 is a flowchart of a data processing method according to an embodiment of the present application;
fig. 2 is a flowchart of a data processing method according to another embodiment of the present application;
fig. 3 is a flowchart of a data processing method according to another embodiment of the present application;
fig. 4 is a flowchart of a data processing method according to another embodiment of the present application;
fig. 5 is a flowchart of a data processing method according to another embodiment of the present application;
fig. 6 is a flowchart of a data processing method according to another embodiment of the present application;
fig. 7 is a flowchart of a data processing method according to another embodiment of the present application;
FIG. 8 is a flowchart illustrating the generation of database operation codes according to an embodiment of the present application;
fig. 9 is a block diagram of a data processing apparatus according to another embodiment of the present application;
FIG. 10 is an example of an inheritance relationship between operation layer files and a common data package according to the present application;
fig. 11 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are some embodiments of the present application, but not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
After a database is created, the MySQL database management system automatically generates an information database information _ schema for managing metadata at the same level, wherein a metadata table column in the information database records user-defined metadata structure information, wherein the column comprises: TABLE _ SCHEMA (database NAME), TABLE _ NAME (DATA TABLE NAME), COLUMN _ NAME (field NAME), original _ POSITION (field order POSITION), IS _ null (whether null IS allowed), DATA _ TYPE (field TYPE), and the like.
In addition, to extend the types of Jave languages, Jave generic is introduced. Generic, i.e. "parameterized type". In the embodiment, the creation of the parameterized types is supported, and the common layer code logic is extracted to form the common data packet, so that the types are determined during the operation without paying attention to the specific types in the package of the common data packet, thereby realizing the multiplexing of the common data packet.
According to the embodiment of the application, a set of JPA-based CURD codes can be automatically generated based on the metadata structure information in the metadata table COLUMNS and the pre-extracted public data packet. The persistence operation on the data in the database is performed based on the CURD code.
First, a data processing method provided in an embodiment of the present invention is described below.
Fig. 1 is a flowchart of a data processing method according to an embodiment of the present application. As shown in fig. 1, the method comprises the steps of:
in step S11, metadata structure information in a metadata table created after the database is installed is acquired.
In this step, the metadata table read from the information database information _ schema is information _ schema.
Step S12, generating a data entity file according to the metadata structure information.
In this case, the data Entity (Entity), i.e., POJO, is used in the program only as a data container to persistently store data in the database. In this step, a data entity file, i.e., a data entity code, corresponding to the database may be generated through the metadata structure information. The metadata structure information may include a plurality of fields, and the data Entity file includes entities corresponding to each of the fields one to one.
Step S13, generating an operation layer file corresponding to the data entity according to the data entity file and the preset public data packet.
Wherein, the operation layer file comprises: access layer files, service implementation layer files and control layer files.
And generating an Entity file according to the steps and extracting a common layer code logic in advance to form a common data packet, and sequentially generating an access layer (hierarchy) file, a Service layer (Service) file, a Service implementation layer (Service Impl) file and a control layer (Controller) file.
Because a certain dependency relationship exists among the Entity, the hierarchy Service, the serviceImpl and the Controller, and codes of the hierarchy Service, the serviceImpl and the Controller can be automatically generated by inheriting the public data packet.
And step S14, obtaining a database operation code corresponding to the database according to the data entity file and the operation layer file.
And combining the codes generated in the step S12 and the step S13 to obtain the GURD code finally used for the database persistence operation.
And step S15, performing persistence operation on the data in the database by using the database operation code.
Among them, Persistence (Persistence) is to save data (e.g. objects in memory) to a storage device (e.g. a disk) that can be permanently saved, for example, objects in memory are stored in a database, or stored in a disk file, an XML data file, and so on.
In step S15, the data in the database can be persisted by directly running the database operation code.
Through the above steps S11 to S15, a set of codes for performing a persistence operation can be automatically generated based on the metadata table that the database management system automatically generates after creating the database and the pre-extracted common data package. Developers only need to specify a metadata table and a public data packet, and do not need to repeatedly write database persistent operation codes with relatively fixed formats for different databases; even if the database is transformed, the database operation codes corresponding to the transformed database can be regenerated through the metadata table which is re-created after the database is transformed without modifying the codes one by one. Therefore, the probability of errors in the compiling and modifying process is reduced, a large amount of time cost and labor cost are saved, and the development efficiency is improved.
In an alternative embodiment, the step S11 includes:
step A1, based on the input database parameters and data table names, the metadata table corresponding to the data table name is read from the information database corresponding to the database parameters.
The database parameters include parameters required for connecting to the database, such as a database connection path jdbccurl, a database user name USERNAME, a database PASSWORD, a database driver DRIVERCLASSNAME, and the like.
The database parameters and the data table names can be input by a user according to needs, the database driver is loaded, the database is accessed based on the database connection path, and the database parameters and the data table names enter the database through the database user name and the database password.
Step a2, extracting metadata structure information from the metadata table, wherein the metadata structure information includes: data table name, field name, and field type.
Wherein, extracting the metadata structure information, namely reading the following fields in the data table information _ schema. TableNAME (DATA table NAME), COLUMN _ NAME (field NAME), DATA _ TYPE (field TYPE), COLUMN _ KEY (primary KEY or not), etc., which are metadata structure information.
In the embodiment, developers can specify the metadata table corresponding to the database to be operated by inputting the database parameters, and then the database operation codes can be automatically generated according to the metadata structure information in the metadata table and the pre-extracted public data packet, so that a large amount of time cost and labor cost are saved, and the development efficiency is improved.
Fig. 2 is a flowchart of a data processing method according to another embodiment of the present application. As shown in fig. 2, the step S12 includes the following steps:
step S21, obtaining storage path information corresponding to the data entity;
the basepath information is basic path information for storing Entity.
Step S22, according to the storage path information and the entity class name of the data entity, splicing to obtain first packet path information of a data packet where the data entity is located;
that is, the storage path information and the Entity class name are connected by ". times", so as to obtain first packet path information, which may be represented as:
the first packet path information is stored as the path information + Entity class name.
Step S23, generating a first reference statement for referencing the class library corresponding to the data entity;
for example, class libraries that need to be referenced include: dat, java. io. serializable, java. util. date, etc.
Step S24, configuring the persistent annotation information corresponding to the data entity;
wherein the annotation of Entity in JPA includes: @ Entity, @ Table, and @ Data.
@ Entity, represents annotating an Entity.
@ Table declares the mapping of this object to a data Table of a database, by which the names of tables (tables), directories (Catalog) and schema can be specified for an entity. For example, an @ Table (name) is used to specify the name of the database Table to which the data entity corresponds for the entity.
@ Data, is an annotation in the Lombok plug-in, which is mainly used to simplify the Java code. The @ Data can provide a read-write function for the class, so that a large number of methods such as get (), set () and the like can be omitted, and methods such as equals (), HashCode (), toString () and the like can be provided for the class. Corresponding to the collection of these annotations @ Getter, @ Setter, @ RequireddArgsConstructor, @ equialsANDHashCode, @ toString.
Step S25, setting the access authority corresponding to the data entity, and generating a class format statement corresponding to the data entity;
for example, the access rights can be set to the following situations:
through public statement, the access authority of the data entity is set to be public, namely all the stated data can be accessed;
setting the access right of the data entity to be private through a private declaration, namely only the data in the class can be accessed;
by means of the protect statement, the access right of the data entity is set to be protected, i.e. the data in the packet path can be accessed.
Optionally, if the access right is not set, the access right may be defaulted to "protect".
And step S26, obtaining a data entity file according to the first packet path information, the first reference statement, the persistent annotation information, the access authority and the class format statement.
Specifically, the code of each part of the data entity file is exemplified as follows:
the code of the first packet path information of the data packet where the Entity is located is as follows:
"package"+package_.replaceAll("\\\\",".")+"pojo;\n"+
wherein, the package represents the storage path information of the Entity, and the package \ \ replaceAll ("\ \", "") represents replacing "\" with "-", and the pojo is the class name of the Entity.
If the Entity references the class libraries hook.dat, java.persecunce, java.io.serializable and java.util.date, the code of the first referenced statement is:
"import lombok.Data;\n"+
"import javax.persistence.*;\n"+
"import java.io.Serializable;\n"+
"import java.util.Date;\n"+
the code of the persistent annotation information corresponding to the Entity is as follows:
"@Entity\n"+
"@Table(name=\""+tableName+"\")\n"+
"@Data\n"+
the access right and class format statement of Entity is:
"publicclass"+StringUtil.captureName(StringUtil.camelCaseName(tab leName))+"implements Serializable
public, the business, camel case name (tableName) indicates that the name tableName is named hump-wise, the business, capturename () is a method for capturing naming, and the implementation, serialization, indicates that the class is serialized.
In step S26, the first packet path information, the first reference statement, the persistent annotation information, the access right, and the class format statement are combined to obtain the data entity file.
Through the steps S21 to S26, the data entity codes can be automatically generated based on the metadata structure information, developers do not need to repeatedly write the entity codes of the database with a relatively fixed format, a large amount of time cost and labor cost are saved, and the development efficiency is improved.
Fig. 10 is an inheritance relationship between operation layer files and a common data package according to an embodiment of the present application. As shown in fig. 10, in the embodiment of the present application, each operation layer file xxxrepositiory, xxxService, xxxServiceImpl, and xxxController of the Personal Package corresponding to the database xxx has a corresponding common packet. The Common packet includes: the access layer common package (E, T), the service layer common package (V, E, T), the service implementation layer common package (V, E, T) and the control layer common package (V, E, T). The common service implementation layer packet common < V, E, T > uses the common service layer packet common < V, E, T > through instances statement.
Each public package is implemented based on a Java generic, where E denotes Element (used in a set, and stored in a set is an Element), V denotes Value, and T denotes Type (Java class).
The access layer common packet (E, T) inherits the JpaRemonitor and JpaSpecificatiExecutor interfaces. The Jpa replication interface is a key interface for realizing the Spring Data JPA technology to access the database, inherits from the PagingAndSortingreplication interface, and can greatly reduce the JPA as a code for Data access based on the JPA replication interface. The JpaSpecificatiExecutor interface is defined around the Specification interface, and is packaged with the Specification standard aiming at the criterion API, and the query and use details through the EntityManager are packaged, so that the criterion operation is more convenient.
The common service packet of the service layer provides basic methods for data addition, query, deletion, modification and the like.
The Service in the common packet common Service Impl < V, E, T > of the Service implementation layer realizes the method defined in common Service < V, E, T >.
The common control packet of the control layer V, E and T defines and realizes the web interface corresponding to the basic method.
Fig. 3 is a flowchart of a data processing method according to another embodiment of the present application. As shown in fig. 3, in step S13, the inheritance relationship of the corresponding public package is added to each operation layer file, and then each operation layer file can be obtained based on the dependency relationship between the operation layers, which includes the following specific steps:
step S31, generating an access layer file according to the data entity file and the access layer public package;
step S32, generating a service layer file according to the data entity file and the service layer public packet;
step S33, generating a service implementation layer file based on the access layer file, the service layer file and the service implementation layer public package;
and step S34, generating a control layer file according to the service layer file and the control layer public package.
The following describes in detail the process of generating each operation layer file.
Fig. 4 is a flowchart of a data processing method according to another embodiment of the present application. As shown in fig. 4, in step S31, the process of generating the hierarchy level file is specifically as follows:
step S41, according to the storage path information and the access layer class name corresponding to the access layer, splicing to obtain second packet path information of the data packet where the access layer file is located;
step S42, generating a second reference statement for referencing the data entity file;
for example, the reference to the data entity file may be implemented by an Import statement.
Step S43, generating a first inheritance statement inheriting the access layer public package;
for example, inheritance to the access layer common package can be implemented through extensions statements.
And step S44, splicing the second packet path information, the second reference statement and the first inheritance statement to obtain an access layer file.
The hierarchy layer code is generated as follows:
package storage path information + hierarchy class name
Import store Path information + entity class name
public interface xxxRepository extends CommonRepository<E,T>,{
}
The "xxx" in the code may be a user-defined class name string, such as MyUser.
Fig. 5 is a flowchart of a data processing method according to another embodiment of the present application. As shown in fig. 5, in the step S32, the process of generating the Service layer file is specifically as follows:
step S51, according to the storage path information and the service layer class name corresponding to the service layer, splicing to obtain third package path information of the data package where the service layer file is located;
step S52, generating a third reference sentence for referencing the data entity file;
step S53, generating a second inheritance statement inheriting the service layer public package;
and step S54, splicing the third packet path information, the third reference statement and the second inheritance statement to obtain a service layer file.
The Service layer code is generated as follows:
package storage path information + Service class name
Import store Path information + entity class name
public interface xxxService extends CommonService<V,E,T>,{
}
The Service layer may encapsulate various data operation methods, or may be set as a Service interface layer to encapsulate interfaces corresponding to the data operations.
Fig. 6 is a flowchart of a data processing method according to another embodiment of the present application. As shown in fig. 6, in the step S33, the process of generating the ServiceImpl layer file is specifically as follows:
step S61, generating a first dependency statement for the access layer file and a third inheritance statement for inheriting the service realization layer public package and the service layer file;
wherein, the dependence on the file of the hierarchy layer is realized through the Import; the CommonServiceImpl < V, E, T > is inherited through extensions statements, and the Service layer file is inherited through instances.
And step S62, splicing the first dependent statement and the third inherited statement to obtain a service implementation layer file.
Wherein, the Service Impl layer file needs to use the Service layer file
The ServiceImpl layer code is generated as follows:
Import package path.xxxRepository
@Service
public class xxxServiceImpl extends CommonServiceImpl<V,E,T>implements xxxService{
}
fig. 7 is a flowchart of a data processing method according to another embodiment of the present application. As shown in fig. 7, in step S34, the process of generating the Controller layer file is specifically as follows:
step S71, generating a second dependency statement for the service layer file and a fourth inheritance statement for inheriting the control layer public packet;
and step S72, splicing the second dependent statement and the fourth inherited statement to obtain a control layer file.
Generating the Controller layer code is as follows:
Import package path.xxxService
@RestController
@RequestMapping("/myPath")
public class xxxController extends CommonController<V,E,T>,{
}
through the embodiment, based on the inheritance relationship between the operation layer files and the public data packet and the dependency relationship between the operation layer files, the hierarchy, Service Impl and Controller files can be automatically generated, so that the operation layer files corresponding to the data entities are generated, developers are prevented from repeatedly writing database operation codes with relatively fixed formats, a large amount of time cost and labor cost are saved, and the development efficiency is improved.
Fig. 8 is a flowchart of generating a database operation code according to an embodiment of the present application, and as shown in fig. 8, a specific flow of generating the database operation code is as follows:
step S81, obtaining a database table name tableName and storage path information (basepath) input by a user, accessing an external dependence item based on the tableName, namely, automatically generating an information database information _ schema after a database management system creates a database, and reading a metadata table COLUMNS in the information database _ schema;
step S82, generating a data entity file xxxEntity based on the metadata structure information and basepath in the metadata table COLUMNS;
step S83, generating access layer file xxxRepeationy based on the reference relationship of Repeationy to Entity and the inheritance relationship of common package CommonRepeationy < E, T >;
step S84, generating a Service layer file xxxService based on the reference relationship of Service to Entity and the inheritance relationship of common Service < V, E, T > of the Service layer;
step S85, generating a service implementation layer file xxxServiceImpl based on the dependency relationship of the ServiceImpl on the reproducibility and the inheritance relationship of the common package CommonServiceImpl < V, E, T > of the service implementation layer;
and step S86, generating a control layer file xxxConroller based on the dependency relationship of the Controller on Service and the inheritance relationship of the common control packet CommonController < V, E, T >.
Through the steps S81 to S86, a set of codes for executing the persistence operation can be automatically generated based on the metadata table which is automatically generated by the database management system after the database is created and the pre-extracted public data packet, developers only need to specify the metadata table and the public data packet, database persistence operation codes with relatively fixed formats do not need to be repeatedly written for different databases, even if the databases are changed, the codes do not need to be modified one by one, the probability of errors in the writing and modifying processes is reduced, a large amount of time cost and labor cost are saved, and the development efficiency is improved.
When the above method is actually used to generate a code, a user only needs to add a dependency on the common data package in a POM file (POM is an abbreviation of Project Object Model) which is used to manage a source code, a configuration file, information and roles of a developer, a problem tracking system, organization information, Project authorization, URL of a Project, dependency relationship of a Project, and the like, and is a configuration file of a Project level), call the above method in a main class main method, create a database operation code (base) with a table name of tabelame and a path of base by a source code generator CodeDom), and configure a database configuration item of a database used by a user Project in the configuration file.
The following are embodiments of the apparatus of the present application that may be used to perform embodiments of the method of the present application.
Fig. 9 is a block diagram of a data processing apparatus provided in an embodiment of the present application, which may be implemented as part of or all of an electronic device through software, hardware, or a combination of the two. As shown in fig. 9, the data processing apparatus includes:
an obtaining module 91, configured to obtain metadata structure information corresponding to a metadata table, where the metadata table is created after a database is installed;
an entity generating module 92, configured to generate a data entity file according to the metadata structure information;
the file generating module 93 is configured to generate an operation layer file corresponding to the data entity according to the data entity file and a preset public data packet;
the code generation module 94 is used for obtaining a database operation code corresponding to the database according to the data entity file and the operation layer file;
and the operation module 95 is configured to perform a persistence operation on data in the database by using the database operation code.
Optionally, the obtaining module 91 is configured to, based on the input database parameter and the data table name, read a metadata table corresponding to the data table name from an information database corresponding to the database parameter; extracting metadata structure information from the metadata table, wherein the metadata structure information includes: data table name, field name, and field type.
Optionally, the entity generating module 92 is configured to obtain storage path information corresponding to the data entity; splicing to obtain first packet path information of a data packet where the data entity is located according to the storage path information and the entity class name of the data entity; generating a first reference statement for referencing a class library corresponding to the data entity; configuring persistent annotation information corresponding to the data entity; setting access authority corresponding to the data entity, and generating a class format statement corresponding to the data entity; and obtaining a data entity file according to the first packet path information, the first reference statement, the persistent annotation information, the access authority and the class format statement.
Optionally, the operation layer file includes: access layer files, service implementation layer files and control layer files; the common data packet includes: the system comprises an access layer public packet, a service implementation layer public packet and a control layer public packet;
the file generating module 93 is configured to generate an access layer file according to the data entity file and the access layer public package; generating a service layer file according to the data entity file and the service layer public packet; generating a service implementation layer file based on the access layer file, the service layer file and the service implementation layer public package; and generating a control layer file according to the service layer file and the control layer public packet.
Optionally, the file generating module 93 is configured to splice to obtain second packet path information of a data packet in which the access layer file is located according to the storage path information and the access layer class name corresponding to the access layer; generating a second reference statement which references the data entity file; generating a first inheritance statement inheriting the access layer public package; and splicing the second packet path information, the second reference statement and the first inheritance statement to obtain the access layer file.
Optionally, the file generating module 93 is configured to splice to obtain third packet path information of a data packet in which the service layer file is located according to the storage path information and the service layer class name corresponding to the service layer; generating a third reference statement for referencing the data entity file; generating a second inheritance statement inheriting the service layer public package; and splicing the third packet path information, the third reference statement and the second inheritance statement to obtain a service layer file.
Optionally, the file generating module 93 is configured to generate a first dependency statement for the access layer file, and a third inheritance statement for inheriting the service implementation layer public package and the service layer file; and splicing the first dependent statement and the third inherited statement to obtain a service implementation layer file.
Optionally, the file generating module 93 is configured to generate a second dependency statement on the service layer file and a fourth inheritance statement inheriting the control layer public package; and splicing the first dependent statement and the third inherited statement to obtain a control layer file.
An embodiment of the present application further provides an electronic device, as shown in fig. 11, the electronic device may include: the system comprises a processor 1501, a communication interface 1502, a memory 1503 and a communication bus 1504, wherein the processor 1501, the communication interface 1502 and the memory 1503 complete communication with each other through the communication bus 1504.
A memory 1503 for storing a computer program;
the processor 1501, when executing the computer program stored in the memory 1503, implements the steps of the method embodiments described below.
The communication bus mentioned in the electronic device may be a Peripheral component interconnect (pci) bus, an Extended Industry Standard Architecture (EISA) bus, or the like. The communication bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one thick line is shown, but this does not mean that there is only one bus or one type of bus.
The communication interface is used for communication between the electronic equipment and other equipment.
The Memory may include a Random Access Memory (RAM) or a Non-Volatile Memory (NVM), such as at least one disk Memory. Optionally, the memory may also be at least one memory device located remotely from the processor.
The Processor may be a general-purpose Processor, including a Central Processing Unit (CPU), a Network Processor (NP), and the like; but may also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA) or other Programmable logic device, discrete Gate or transistor logic device, discrete hardware component.
The present application also provides a computer-readable storage medium having stored thereon a computer program which, when being executed by a processor, carries out the steps of the method embodiments described below.
It should be noted that, for the above-mentioned apparatus, electronic device and computer-readable storage medium embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and for the relevant points, reference may be made to the partial description of the method embodiments.
It is further noted that, herein, relational terms such as "first" and "second," and the like, may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
The foregoing are merely exemplary embodiments of the present invention, which enable those skilled in the art to understand or practice the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended 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 (11)

1. A data processing method, comprising:
acquiring metadata structure information in a metadata table, wherein the metadata table is generated after a database is created;
generating a data entity file according to the metadata structure information;
generating an operation layer file corresponding to the data entity according to the data entity file and a preset public data packet;
obtaining a database operation code corresponding to the database according to the data entity file and the operation layer file;
and carrying out persistence operation on the data in the database by adopting the database operation code.
2. The method according to claim 1, wherein obtaining metadata structure information corresponding to the metadata table comprises:
based on the input database parameters and the data table names, reading a metadata table corresponding to the data table names from an information database corresponding to the database parameters;
extracting the metadata structure information from the metadata table, wherein the metadata structure information includes: data table name, field name, and field type.
3. The method of claim 1, wherein the generating a data entity file according to the metadata structure information comprises:
acquiring storage path information corresponding to the data entity;
splicing to obtain first packet path information of a data packet where the data entity is located according to the storage path information and the entity class name of the data entity;
generating a first reference statement for referencing the class library corresponding to the data entity;
configuring persistent annotation information corresponding to the data entity;
setting access authority corresponding to the data entity, and generating a class format statement corresponding to the data entity;
and obtaining the data entity file according to the first packet path information, the first reference statement, the persistent annotation information, the access authority and the class format statement.
4. The method of claim 3, wherein operating the layer file comprises: access layer files, service implementation layer files and control layer files; the common data packet includes: the system comprises an access layer public packet, a service implementation layer public packet and a control layer public packet;
the generating of the operation layer file corresponding to the data entity according to the data entity file and the preset public data packet includes:
generating the access layer file according to the data entity file and the access layer public packet;
generating the service layer file according to the data entity file and the service layer public packet;
generating the service implementation layer file based on the access layer file, the service layer file and the service implementation layer public package;
and generating the control layer file according to the service layer file and the control layer public packet.
5. The method of claim 4, wherein generating the access layer file from the data entity file and the access layer common package comprises:
splicing to obtain second packet path information of a data packet where the access layer file is located according to the storage path information and the access layer class name corresponding to the access layer;
generating a second reference statement that references the data entity file;
generating a first inheritance statement inheriting the access layer public packet;
and splicing the second packet path information, the second reference statement and the first inheritance statement to obtain the access layer file.
6. The method of claim 4, wherein generating the service layer file according to the data entity file and the service layer common package comprises:
splicing to obtain third package path information of a data package where the service layer file is located according to the storage path information and the service layer class name corresponding to the service layer;
generating a third reference statement that references the data entity file;
generating a second inheritance statement inheriting the service layer public package;
and splicing the third packet path information, the third reference statement and the second inheritance statement to obtain the service layer file.
7. The method of claim 4, wherein generating the service implementation layer file based on the access layer file, the service layer file, and the service implementation layer common package comprises:
generating a first dependency statement for the access layer file and a third inheritance statement for inheriting the service implementation layer public package and the service layer file;
and splicing the first dependent statement and the third inherited statement to obtain the service implementation layer file.
8. The method according to claim 4, wherein the generating the control layer file according to the service layer file and the control layer public package comprises:
generating a second dependency statement for the service layer file and a fourth inheritance statement for inheriting the control layer public packet;
and splicing the second dependent statement and the fourth inherited statement to obtain the control layer file.
9. A data processing apparatus, comprising:
the system comprises an acquisition module, a database management module and a data processing module, wherein the acquisition module is used for acquiring metadata structure information corresponding to a metadata table, and the metadata table is created after a database is installed;
the entity generating module is used for generating a data entity file according to the metadata structure information;
the file generation module is used for generating an operation layer file corresponding to the data entity according to the data entity file and a preset public data packet;
the code generation module is used for obtaining a database operation code corresponding to the database according to the data entity file and the operation layer file;
and the operation module is used for carrying out persistence operation on the data in the database by adopting the database operation code.
10. An electronic device, comprising: the system comprises a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory complete mutual communication through the communication bus;
the memory is used for storing a computer program;
the processor, when executing the computer program, implementing the method steps of any of claims 1-8.
11. A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the method steps of any one of claims 1 to 8.
CN202110113666.8A 2021-01-27 2021-01-27 Data processing method and device, electronic equipment and storage medium Active CN112817580B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110113666.8A CN112817580B (en) 2021-01-27 2021-01-27 Data processing method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110113666.8A CN112817580B (en) 2021-01-27 2021-01-27 Data processing method and device, electronic equipment and storage medium

Publications (2)

Publication Number Publication Date
CN112817580A true CN112817580A (en) 2021-05-18
CN112817580B CN112817580B (en) 2023-09-01

Family

ID=75859731

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110113666.8A Active CN112817580B (en) 2021-01-27 2021-01-27 Data processing method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN112817580B (en)

Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5682535A (en) * 1989-09-01 1997-10-28 Amdahl Corporation Operating system and data base using table access method with dynamic binding
US6085198A (en) * 1998-06-05 2000-07-04 Sun Microsystems, Inc. Integrated three-tier application framework with automated class and table generation
US20050071342A1 (en) * 2003-09-25 2005-03-31 International Business Machines Corporation Data processing for objects with unknown data structures
EP1865411A1 (en) * 2006-06-05 2007-12-12 Research In Motion Limited System and method for generating runtime metadata for use in the development of mobile device applications
US20080098358A1 (en) * 2006-09-29 2008-04-24 Sap Ag Method and system for providing a common structure for trace data
CN102081661A (en) * 2011-01-19 2011-06-01 吉林大学 Data integration method and system of heterogeneous relational database based on XML (Extensive Makeup Language)
CN108289118A (en) * 2017-12-12 2018-07-17 北京奇艺世纪科技有限公司 A kind of management method and device of distributed message stream
US20190065554A1 (en) * 2017-08-29 2019-02-28 Promontory Financial Group, Llc Generating a data structure that maps two files
CN110188071A (en) * 2019-04-19 2019-08-30 北京奇艺世纪科技有限公司 Data processing method, device, electronic equipment and computer-readable medium
CN111078205A (en) * 2019-11-22 2020-04-28 北京锐安科技有限公司 Modular programming method and device, storage medium and electronic equipment

Patent Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5682535A (en) * 1989-09-01 1997-10-28 Amdahl Corporation Operating system and data base using table access method with dynamic binding
US6085198A (en) * 1998-06-05 2000-07-04 Sun Microsystems, Inc. Integrated three-tier application framework with automated class and table generation
US20050071342A1 (en) * 2003-09-25 2005-03-31 International Business Machines Corporation Data processing for objects with unknown data structures
EP1865411A1 (en) * 2006-06-05 2007-12-12 Research In Motion Limited System and method for generating runtime metadata for use in the development of mobile device applications
US20080098358A1 (en) * 2006-09-29 2008-04-24 Sap Ag Method and system for providing a common structure for trace data
CN102081661A (en) * 2011-01-19 2011-06-01 吉林大学 Data integration method and system of heterogeneous relational database based on XML (Extensive Makeup Language)
US20190065554A1 (en) * 2017-08-29 2019-02-28 Promontory Financial Group, Llc Generating a data structure that maps two files
CN108289118A (en) * 2017-12-12 2018-07-17 北京奇艺世纪科技有限公司 A kind of management method and device of distributed message stream
CN110188071A (en) * 2019-04-19 2019-08-30 北京奇艺世纪科技有限公司 Data processing method, device, electronic equipment and computer-readable medium
CN111078205A (en) * 2019-11-22 2020-04-28 北京锐安科技有限公司 Modular programming method and device, storage medium and electronic equipment

Also Published As

Publication number Publication date
CN112817580B (en) 2023-09-01

Similar Documents

Publication Publication Date Title
US6023578A (en) Systems, methods and computer program products for generating an object oriented application for an object oriented environment
US9940108B2 (en) Automated merging in a software development environment
US6385767B1 (en) Method and system for creating and manipulating extensions to version control systems
US20060242195A1 (en) Technique for platform-independent service modeling
US20160004516A1 (en) Code Generation Framework for Application Program Interface for Model
US20070067766A1 (en) Infrastructure for the automation of the assembly of schema maintenance scripts
CN105164641A (en) Extending development environment
WO2006133053A2 (en) Structuring data for spreadsheet documents
CN106951231B (en) Computer software development method and device
US8793706B2 (en) Metadata-based eventing supporting operations on data
US8407235B2 (en) Exposing and using metadata and meta-metadata
US20050108684A1 (en) Method and system for generating an application object repository from application framework metadata
CN101663663B (en) Describing expected entity relationships in a model
CN114138748A (en) Database mapping file generation method, device, equipment and storage medium
WO2002046909A1 (en) Automatically deploy and upgrade an application based on markup language application definition
JP2009059351A (en) System, method, and computer program product for recording operation performed to computer source code
CN112817580B (en) Data processing method and device, electronic equipment and storage medium
CN111241064A (en) Database configuration file processing method and device and storage medium
CN117193802A (en) Merge space providing access to multiple instances of application content
Dong et al. Design pattern evolutions in QVT
CN111427581B (en) Method, device, equipment and medium for realizing type multi-inheritance
Mak et al. Hibernate Recipes: A Problem-Solution Approach
CN112905453A (en) Method for quickly generating database operation code in automatic test
JP5237030B2 (en) Software development support program, software development support apparatus, and software development support method
Perkins Working with NHibernate 3.0

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
GR01 Patent grant
GR01 Patent grant