CN114238527A - Data processing method and data processing device based on object relation mapping - Google Patents

Data processing method and data processing device based on object relation mapping Download PDF

Info

Publication number
CN114238527A
CN114238527A CN202210171215.4A CN202210171215A CN114238527A CN 114238527 A CN114238527 A CN 114238527A CN 202210171215 A CN202210171215 A CN 202210171215A CN 114238527 A CN114238527 A CN 114238527A
Authority
CN
China
Prior art keywords
column
data
mapping
type
class
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
CN202210171215.4A
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.)
Ankon Technologies Co Ltd
Original Assignee
Ankon Technologies 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 Ankon Technologies Co Ltd filed Critical Ankon Technologies Co Ltd
Priority to CN202210171215.4A priority Critical patent/CN114238527A/en
Publication of CN114238527A publication Critical patent/CN114238527A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • 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/289Object oriented databases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/73Program documentation

Abstract

The application discloses a data processing method based on object relationship mapping. The data processing method comprises the following steps: defining a Java object class; analyzing the Java object class to obtain class attributes; querying a database to obtain a result set; analyzing the metadata of the result set to obtain data column attributes; establishing a mapping relation according to the class attribute; and mapping the result set into an instance list of the Java object class according to the mapping relation, wherein at least one of a plurality of mapping methods is executed according to the type of the mapping annotation in the class attribute when the mapping relation is established. The data processing method utilizes the mapping annotation to carry out mapping configuration, thereby simplifying the mapping configuration, allowing a plurality of mapping methods when establishing a mapping relation, and improving the flexibility and the success rate of mapping.

Description

Data processing method and data processing device based on object relation mapping
Technical Field
The present invention relates to the field of database technologies, and in particular, to a data processing method and a data processing apparatus based on Object Relationship Mapping (ORM).
Background
With the sophistication of software systems, a variety of software production techniques have been developed to improve development efficiency, quality, and reliability, including component technology, visual programming, schema, and framework. A framework is the design and implementation of a subsystem that is part of a complex software system. The secondary development is carried out on the basis of the framework, and the secondary development can be reused in different software systems similar to application scenes.
In database applications, Object Relational Mapping (ORM) is used to convert data in a relational database into objects in a program or to automatically persist objects in a relational database by using metadata describing the mapping between the objects and the database.
In the main stream persistence framework, for example, Hibernate, MyBatis, Spring Data JDBC, all implement object relationship mapping.
Hibernate is a full-table mapping framework, has high automation degree, is very convenient for mapping and converting Java objects to a single data table, only needs to define Java objects and mapping relations (the mapping relations between fields of the Java objects and columns of the data table), and even does not need to write SQL for query. But its support for multi-table associations is poor. Also, the flexibility of customization is relatively poor due to the high degree of automation.
Relative to Hibernate, MyBatis is a semi-automatic mapping framework that requires manual matching of Java objects, SQL and mapping relationships. Because SQL needs to be written manually, the flexibility is strong. However, the mapping relationships are configured by manually configuring the XML file, which not only increases the complexity of the operation, but also makes the configuration very complicated.
The Spring Data JDBC framework provides a simple conversion mechanism, developers only need to define Java objects and SQL, the conversion of the result set to the Java objects is completed by a tool of BeanPropertyRowMapper, and the conversion of one line in the result set to JavaBean is realized. The method depends on the corresponding relation between the column names in the database structure of the guess database and the variable names in the attributes of the Java object classes. For example: and according to the column name biz _ type in the database structure, presuming that the variable name of the Java object class is bizType. Compared with Hibernate and MyBatis, the framework is moderate in flexibility and operation complexity, self-defined SQL can be supported by single-table or multi-table connection, a large number of mapping configuration files are not required to be defined, operation is simplified, and most of conversion scenes can be met.
The main defect of the Spring Data JDBC framework is that normalization (naming specification) dependence of variable names in the column names of the Data columns in the result set and the attributes of Java object classes is strong, and once the column names and the variable names of the object classes are not in accordance with the specification, matching fails, so that conversion fails. For example, for the column name "reverse _1", the variable name of the Java object class is "reverse 1"; for the column name is _ force (mandatory), the variable name of the Java object class is "force" (for Boolean fields, according to the specification, it cannot be isface).
Therefore, it is desirable to develop an object relational mapping framework technique that can simplify the mapping configuration and has strong adaptability.
Disclosure of Invention
In view of the foregoing problems, it is an object of the present invention to provide a data processing method and a data processing apparatus based on object relationship mapping, in which at least one of a plurality of mapping methods is performed according to the type of a mapping annotation in a class attribute to simplify mapping configuration and improve flexibility and success rate of mapping.
According to a first aspect of the present invention, there is provided a data processing method based on object relationship mapping, including: defining a Java object class; analyzing the Java object class to obtain class attributes; querying a database to obtain a result set; analyzing the metadata of the result set to obtain data column attributes; establishing a mapping relation according to the class attribute; and mapping the result set into an instance list of the Java object class according to the mapping relation, wherein at least one of a plurality of mapping methods is executed according to the type of the mapping annotation in the class attribute when the mapping relation is established.
Preferably, the plurality of mapping methods include a first mapping method and a second mapping method, the first mapping method is executed in a case where the class attribute includes a mapping annotation, the first mapping method obtains a column name of a data column corresponding to the class attribute according to the mapping annotation, and the second mapping method is executed in a case where the class attribute does not include a mapping annotation, the second mapping method obtains a column name of a data column corresponding to the class attribute according to a variable name in the class attribute.
Preferably, the plurality of mapping methods further includes a third mapping method, and in a case where the first mapping method and the second mapping method are adopted and the column name of the data column corresponding to the class attribute is not successfully obtained, the third mapping method is executed, and the third mapping method includes: presume the column name according to the column name in the attribute of said data column; acquiring a data list name corresponding to the class attribute by adopting the first mapping method and the second mapping method; and acquiring the data column name corresponding to the class attribute according to the corresponding relation between the column name and the column name.
Preferably, the step of inferring comprises: and according to the naming specification of the variable names in the class attributes, carrying out character string replacement on the column names in the data column attributes to obtain column names.
Preferably, the class attribute is obtained by using a reflection mechanism of a Java system when a program runs, and the class attribute includes: at least one of variable name, data type, and mapping annotation.
Preferably, the mapping annotation comprises a reserved word, an annotation name and a plurality of annotation members, wherein the plurality of annotation members comprises at least a column name.
Preferably, the mapping method of the corresponding annotation specification is performed according to the annotation name.
Preferably, the plurality of annotation members further comprises variable annotations.
Preferably, the step of mapping the result set to the list of instances of the Java object class comprises: establishing a list; reading the result set line by line to obtain line data; converting the line data into instances of Java object classes; and adding an instance of the Java object class to a list.
Preferably, the step of converting the line data into instances of Java object classes comprises: constructing an instance of a Java object class; setting variables in the Java object class as default values; obtaining an alias corresponding to the variable according to the mapping relation; reading column values from the row data of the result set by using a column reading method; and setting the variable of the Java object class to a corresponding column value.
Preferably, before the step of reading column values from row data of the result set, the method further comprises: acquiring variable data types in the Java object class and data types of corresponding data columns in the result set; and selecting the column reading method according to the data type.
Preferably, when the variable data type in the Java object class is one of a character type, a numerical type, and a time type, a corresponding column reading method is selected according to the class attribute data type, and a column value is read from the row data of the result set.
Preferably, when the type of the class attribute data is a date type, a corresponding column reading method is selected according to the data type of the data column.
Preferably, the step of selecting the corresponding column reading method comprises: selecting a time stamp type column reading method if the data type of the data column is a date-time type, selecting a date-type column reading method if the data type of the data column is a date type, selecting a time stamp type column reading method if the data type of the data column is a time stamp type, and selecting a time type column reading method if the data type of the data column is a time type.
Preferably, when the type of the class attribute data is boolean, a corresponding column reading method and data conversion method are selected according to the data type of the data column.
Preferably, the step of selecting the corresponding column reading method and data conversion method includes: selecting a Boolean-type column reading method if the data type of the data column is Boolean, selecting an integer-type column reading method if the data type of the data column is integer, and converting the read column value into a Boolean quantity, and selecting a character-type column reading method if the data type of the data column is character-type, and converting the read column value into a Boolean quantity.
According to a second aspect of the present invention, there is provided a data processing apparatus based on object relationship mapping, comprising: the calling module is used for providing a database query interface and an instance list interface of the Java object class, and executing database query through the database query interface to obtain a result set; the Java object analysis module is used for analyzing the Java object class to obtain class attributes; the result set metadata analysis module is used for analyzing the metadata of the result set to acquire the data column attributes; a result set reading module for reading the result set line by line to obtain line data; and the result set mapping module is used for establishing a mapping relation according to the class attributes and mapping the result set to the instance list of the Java object class, wherein at least one of a plurality of mapping methods is executed according to the types of mapping annotations in the class attributes when the mapping relation is established.
According to the data processing method provided by the embodiment of the invention, when the Java object class is defined, the mapping relation is established according to the class attribute, and no additional mapping configuration step is required, so that the mapping configuration process can be simplified.
Preferably, if the variable name of the Java object class is the same as the column name of the data column, the variable name can be directly mapped to the column name of the data column without adding any mapping annotation in the Java object class, so that the mapping configuration process can be further simplified.
According to the data processing method of the embodiment of the invention, a plurality of mapping methods can be adopted in the Java object class. For example, a part of variable names of the Java object classes can adopt direct mapping of the variable names, and another part of variable names adopt mapping annotation mapping. And executing the mapping method of the corresponding annotation specification according to the annotation name of the mapping annotation. Even if the variable name of the Java object class is different from the column name of the data column, the mapping configuration process can be simplified, and meanwhile, the flexibility and the success rate of mapping can be improved.
Preferably, a column reading method is used to read column values from the row data of the result set. Before reading a column value, acquiring a variable data type in the Java object class and a data type of a corresponding data column in the result set, and selecting the column reading method according to the data type. The selected column reading method can ensure the integrity and correctness of data.
Preferably, with the annotation specification provided by the present invention, variable annotations may also be included in the mapping annotation, so that additional variable information may be provided in the mapping process, and further, the flexibility and success rate of mapping, and the data integrity and accuracy are improved.
Drawings
The above and other objects, features and advantages of the present invention will become more apparent from the following description of the embodiments of the present invention with reference to the accompanying drawings, in which:
fig. 1 shows a flow chart of a data processing method according to a first embodiment of the invention.
Fig. 2 shows a schematic block diagram of a data processing device according to a second embodiment of the present invention.
Detailed Description
The present invention will be described in detail below with reference to specific embodiments shown in the drawings. These embodiments are not intended to limit the present invention, and structural, methodological, or functional changes made by those skilled in the art according to these embodiments are included in the scope of the present invention.
Fig. 1 shows a flow diagram of a data processing method implemented according to a first implementation of the invention.
In step S01, a Java object class is defined.
The Java object class includes a plurality of class attributes, each class attribute including: at least one of variable name, data type, and mapping annotation. The mapping annotations in the Java object class utilize the annotation syntax of the Java object class. The annotation grammar includes a reserved word @, an annotation name, and at least one member, each member represented as a key-value pair.
In this embodiment, the mapping annotation is used to describe the mapping of at least some of the class attributes. The mapping annotations adopt custom specifications and are also compatible with the standard ORM interface, i.e., jpa (java Persistence api) specifications.
In the custom specification, the mapping annotation defines metadata that includes a reserved word @, an annotation name VoColumn, and a plurality of annotation members. The plurality of annotation members includes, for example, column names and variable annotations for the data columns. Each annotation member is represented by a key-value pair, e.g., the column name of a data column is col and the variable annotation is comment. The following are the mapping annotations and variable definitions for the boolean type class attribute hasSys.
@ VoColumn (col = "has _ sys", comment = "whether there is a system account (1 is 0 no)")
private boolean hasSys = false;
In the JPA specification, mapping annotations defines metadata that includes a reserved word @, an annotation name Column, and a number of annotation members. The plurality of annotation members, for example, includes a plurality of data column attributes. Each annotation member is represented by a key-value pair. For example, the key name of the column name of the data column is name, and the key name that is allowed to be empty is nullable. The following are the mapping annotations and variable definitions for the string type class attribute name.
@Column(name = "PERSONNAME", unique = true, nullable = false, updatable = true)
private String name;
The data column attributes comprise name, column name, unique, nullable, insertable, updatable, columnDefinition, DDL (distributed data language) for defining the column when the table is built, and secondary table name. If this column is not built on the master table (by default on the master table), the attribute defines the name of the slave table where the column is located.
In the following Java object class, Patient's name, system account number, reserved field, and variable name of creation timestamp, name, hasSys, reserve1, createTsp, respectively, are defined. The name and creation timestamp createTsp are simple class attributes, no mapping annotation is included, and the system account number hasSys and reserved field reserve1 are complex class attributes, each of which further includes a respective mapping annotation.
public class Patient {
V. name
private String name = null;
@ VoColumn (col = "has _ sys", comment = "whether there is a system account (1 is 0 no)")
private boolean hasSys = false;
@ VoColumn (col = "reserve _1", comment = "reserved field 1")
private String reserve1 = "";
V. record creation timestamp
private Date createTsp = null;
……
}
In the present embodiment, the simple class attribute and the complex class attribute of the Java object class are defined according to the mapping relationship between the variable name and the column name of the data column. If the variable name of the Java object class is the same as the column name of the data column in the result set, the simple class attribute is obtained, and if the variable name of the Java object class is different from the column name of the data column in the result set, the complex class attribute is obtained. The complex class attributes in the Java object class include mapping annotations, thereby defining the correspondence of variable names to column names.
In this embodiment, the mapping annotations in the class attributes adopt custom specifications. In contrast to the JPA specification, the custom specification modifies the mapping name of the mapping annotation, as well as the key name in the annotation member. Further, the annotation member not only comprises the key-value pair of the data column attribute, but also comprises the key-value pair of the variable annotation, so that additional variable information can be provided in the mapping process, and the flexibility and success rate of mapping as well as the data integrity and accuracy are improved.
In the above Java object class parent, Java-supported comment statements are also used. The annotation statement starts with "/", and ends with "/", which instructs the compiler to ignore all content from/, to/". Unlike the annotation statement, the mapping annotation defines the corresponding relationship between the variable name and the column name, and the compiler realizes the mapping between the variable name and the column name according to the corresponding relationship, so the mapping annotation is still a valid execution statement.
In step S02, the Java object class is parsed to obtain class attributes.
The Java system is characterized in that Java object classes are compiled in front of a program line, and the compiled Java object classes are dynamically loaded when the program runs. Thus, class properties cannot be obtained directly from the static definition of the Java object classes at program run time. The Java system also provides a reflection mechanism, which can be used to obtain class attributes during program running, including: variable names, data types, mapping annotations, etc.
For example, the class attribute of the system account in the Java object class parent can be obtained by using the reflection mechanism of the Java system, which includes: variable name hasSys, data type boilean, and two members of the mapping annotation: col = "has _ sys", comment = "whether there is a system account (1 is 0 or not)".
In step S03, a query is made to the database to obtain a result set.
Querying the database includes the steps of generating an SQL statement and executing the SQL statement. The SQL statement may be a complete statement written in advance. Preferably, populating placeholders in the SQL template with context parameters (i.e., query condition parameters) generates a complete SQL statement.
In the present embodiment, a standard JDBC API (i.e., JAVA database connection interface) is used to access the database. Before executing the SQL statement, a database connection is established. The database then executes the SQL statement, returning a result set from the database. After the SQL statement is executed, the database connection is closed. The result set includes at least row data of one data row. Each row of data includes a plurality of column values.
In step S04, the metadata of the result set is parsed to obtain the data column attributes.
A metadata parsing method is provided in the JDBC API to obtain metadata for the result set, which is represented as a ResultSetMetaData class, including a number of data column attributes, such as: column name, column remark, whether empty, data type, display size, numeric length (when type is numeric), decimal number (when type is numeric), etc.
In step S05, a mapping relationship is established according to the class attribute.
According to the type of the mapping annotation, the mapping method in the Java object class is divided into three types:
a) if the annotation name of the mapping annotation is VoColumn, judging the class attribute to be a complex class attribute, adopting the mapping annotation with the self-defined specification, and taking the value of the member col in the mapping annotation as a column name;
b) if the annotation name of the mapping annotation is Column, judging that the class attribute is a complex class attribute, adopting the JPA standard mapping annotation, and taking the value of the member name in the mapping annotation as a Column name;
c) if no mapping annotation is used, the class attribute is judged to be a simple class attribute, and the variable name is taken as the default column name.
The mapping relationship of the Java object class parent is shown in the following table.
TABLE 1 mapping relationship of variable names to column names
Name of variable Column name Mapping method
name name Method c)
hasSys has_sys Method a)
reserve1 reserve_1 Method a)
createTsp createTsp Method c)
In step S06, the result set is mapped to an instance list of Java object classes according to the mapping relationship.
The mapping process includes building a list, reading the result set line by line to obtain line data, converting the line data to Java object class instances, and adding the Java object class instances to the list.
In this embodiment, the result set is accessed using a standard JDBC API (i.e., JAVA database connection interface). The JDBC API provides row cursor and column read methods. After reading a row of data corresponding to the row cursor in the result set, the row cursor is moved to the next row. Each row of data includes a plurality of column values. Reading the row data of the result set row by row, and reading all the row data by traversing the result set.
In the embodiment, after reading the line data of the query result, a Java object class instance is constructed, and the variable is set to a default value. Further, for each class attribute in the Java object class, a column value of a data column corresponding to the game name is obtained from the row data of the query result according to the correspondence between the variable name and the column name, and the variable is set to the column value of the corresponding data column.
The key to whether the object relationship mapping (abbreviated as ORM) is successful is whether a plurality of column names of row data match corresponding variable names. In order to improve the success rate of mapping, a mapping method d is further supplemented: the column names are presumed according to the column names, and the mapping relation between the variable names and the column names is obtained according to the mapping methods a) to c), so that the success rate of matching the variable names and the column names can be further improved.
The method for inferring the column name according to the column name comprises the following steps: according to the naming specification of the variable names, character string replacement is carried out on the column names to obtain the column names. For example, when the variable name of the Java object class includes multiple words, the multiple words are directly stitched together and the second word is capitalized on the beginning in accordance with the naming convention of the variable name. In the case where a plurality of words in the column names of the data columns in the result set are divided by underlining, for example, the column name create _ tsp, the underlining is replaced with an empty character string, and the second word start initial is replaced with an uppercase, the column name create tsp can be obtained.
In the Java object class parent, it is assumed that the column names of the data columns in the result set obtained by database query are: name, has _ sys, reserve _1, create _ tsp, using the mapping methods a) to c) above, the variable name create tsp of the Java object class parent cannot successfully match the column name create _ tsp of the data column in the result set. However, the mapping method d) can be adopted to obtain the column name createTsp of the column name create _ tsp of the data column in the result set, and the successful matching of the variable name createTsp of the Java object class Patient and the column name create _ tsp of the data column in the result set is realized through the matching relation of the variable name createTsp of the Java object class Patient and the column name createTsp.
The mapping relationship of the Java object class parent is shown in the following table.
TABLE 2 mapping of column names to variable names
Column name Name of variable Mapping method Whether or not to succeed
name name Method c) Successful
has_sys hasSys Method a) Successful
reserve_1 reserve1 Method a) Successful
create_tsp createTsp Method d), presuming the column name as createTsp Successful
With reference to tables 1 and 2, the data processing method according to this embodiment may be applied to most scenarios of object relationship mapping, for example: column names composed of single words such as name, sender, etc., or column names composed of multiple words such as biz _ type, create _ time, etc., can also support complex scenarios, such as: the column names in the database structure are far from the meaning of the variable names in the Java object class.
In the present embodiment, after the correspondence relationship between the variable name and the column name is acquired, the column value of the data column corresponding to the variable name is acquired from the row data of the query result according to the correspondence relationship between the variable name and the column name.
The JDBC API provides a column read method that is data type dependent. Before the column value corresponding to the Java object class is obtained from the row data of the query result, the variable in the Java object class and the data type of the data column in the database structure need to be obtained, and a corresponding column reading method is selected according to the data type. The selected column reading method can ensure the integrity and correctness of data.
If the data type of the variable is a first set of data types: character type (char or varchar), numerical type (int or Integer, Long or Long, Double or Double, Float or Float, BigDecimal), Time type (Time), directly obtaining column value according to column reading method corresponding to data type in class attribute. For example: the integer in the numerical type is read by using the getInt method in the JDBC API, and the character string is read by using the getString method in the JDBC API.
If the data type of the variable is a second set of data types: date type (Date), which combines the data type of the column to select the column reading method, otherwise the precision is lost.
If the data type of the column is datetime type (datetime), the column value is obtained by a timestamp type column reading method getTimestamp.
If the data type of the column is a date type (date), a column value is obtained by a column reading method getDate of the date type.
If the data type of the column is a time stamp type (timestamp), a column value is obtained by a time stamp type column reading method getTimestamp.
If the data type of the column is time type (time), the column value is obtained in a time type column reading method getTime.
If the data type of the variable is a third set of data types: boolean (Boolean) selects the column reading method and the data conversion method in conjunction with the data type of the column, otherwise the problem of data errors arises.
If the data type of the column is a Boolean type (boolean), the column value is obtained in a Boolean type column reading method getBoolean, and the variable is set to the column value.
If the data type of the column is integer (int), a column value is obtained by an integer column reading method getInt, and then the value of the column value is converted into a boolean quantity. A boolean value true is indicated when the column value equals 1 and a boolean value false is indicated when the column value does not equal 1.
If the data type of the column is character type (char or varchar), a column value is obtained by a character type column reading method getString, and then a string of the column value is converted into a Boolean quantity. The boolean value true is indicated when the string of column values is equal to "1" and the boolean value false is indicated when the string of column values is not equal to "1".
Fig. 2 shows a schematic block diagram of a data processing device according to a second embodiment of the present invention.
The data processing apparatus 100 includes a calling module 101, a Java object class parsing module 102, a result set metadata parsing module 103, a result set reading module 104, and a result set mapping module 105.
The invocation module 101 provides a database query interface via which a database query is executed to obtain a result set, and an instance list interface for Java object classes. The Java object parsing module 102 parses the Java object class to obtain class attributes. The result set metadata parsing module 103 parses the metadata of the result set to obtain the data column attributes. Result set read module 104 is to read the result set row by row to obtain row data. The result set mapping module 105 establishes a mapping relationship according to the class attributes and maps the result set to a list of instances of the Java object class.
In establishing the mapping relationship, the result set mapping module 105 performs a plurality of mapping methods according to the type of mapping annotations in the class attributes.
In case the class attribute comprises a mapping annotation, a first mapping method is performed, which obtains the column name of the data column corresponding to the class attribute from the mapping annotation. And in the case that the class attribute does not comprise the mapping annotation, executing a second mapping method, wherein the second mapping method obtains the column name of the data column corresponding to the class attribute according to the variable name of the class attribute. And executing the third mapping method in the case that the column names of the data columns corresponding to the class attributes cannot be successfully obtained by adopting the first mapping method and the second mapping method. The third mapping method comprises the following steps: presume the column name according to the column name in the data column attribute of the result set; acquiring a data list name corresponding to the class attribute by adopting a first mapping method and a second mapping method; and acquiring the data column name corresponding to the class attribute according to the corresponding relation between the column name and the column name.
The above-described embodiments of the apparatus are merely illustrative, and the modules described as separate parts may or may not be physically separate, and the parts displayed as modules may or may not be physical modules, may be located in one place, or may be distributed on a plurality of network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the embodiment. One of ordinary skill in the art can understand and implement it without inventive effort.
It should be understood that although the present description refers to embodiments, not every embodiment contains only a single technical solution, and such description is for clarity only, and those skilled in the art should make the description as a whole, and the technical solutions in the embodiments can also be combined appropriately to form other embodiments understood by those skilled in the art.
The above-listed detailed description is only a specific description of a possible embodiment of the present invention, and they are not intended to limit the scope of the present invention, and equivalent embodiments or modifications made without departing from the technical spirit of the present invention should be included in the scope of the present invention.

Claims (17)

1. A data processing method based on object relationship mapping comprises the following steps:
defining a Java object class; and
when the program runs, the following steps are executed:
analyzing the Java object class to obtain class attributes;
querying a database to obtain a result set;
analyzing the metadata of the result set to obtain data column attributes;
establishing a mapping relation according to the class attribute; and
mapping the result set to an instance list of the Java object class according to the mapping relation,
and when the mapping relation is established, executing at least one of a plurality of mapping methods according to the type of the mapping annotation in the class attribute.
2. The data processing method of claim 1, wherein the plurality of mapping methods includes a first mapping method and a second mapping method,
in case the class attribute comprises a mapping annotation, the first mapping method is performed, the first mapping method obtains from the mapping annotation a column name of the data column corresponding to the class attribute, an
And executing the second mapping method under the condition that the class attribute does not comprise mapping annotation, wherein the second mapping method obtains the column name of the data column corresponding to the class attribute according to the variable name in the class attribute.
3. The data processing method of claim 2, wherein the plurality of mapping methods further includes a third mapping method,
in the case where the column names of the data columns corresponding to the class attributes are not successfully obtained by using the first mapping method and the second mapping method, performing the third mapping method,
the third mapping method includes:
presume the column name according to the column name in the attribute of said data column;
acquiring a data list name corresponding to the class attribute by adopting the first mapping method and the second mapping method; and
and acquiring the data column name corresponding to the class attribute according to the corresponding relation between the column name and the column name.
4. A data processing method as claimed in claim 3, wherein said step of speculating comprises: and according to the variable name naming specification in the class attribute, carrying out character string replacement on the column names in the data column attribute to obtain column names.
5. The data processing method according to claim 2, wherein the class attribute is obtained at program run time using a reflection mechanism of a Java system, the class attribute comprising: at least one of variable name, data type, and mapping annotation.
6. The data processing method of claim 5, wherein the mapping annotation comprises a reserved word, an annotation name, and a plurality of annotation members, wherein the plurality of annotation members comprises at least a column name.
7. The data processing method of claim 6, wherein the mapping method of the corresponding annotation specification is performed according to the annotation name.
8. The data processing method of claim 6, wherein the plurality of annotation members further comprise variable annotations.
9. The data processing method of claim 1, wherein mapping the result set to the list of instances of the Java object class comprises:
establishing a list;
reading the result set line by line to obtain line data;
converting the line data into instances of Java object classes; and
adding an instance of the Java object class to a list.
10. The data processing method of claim 8, wherein converting the line data into an instance of a Java object class comprises:
constructing an instance of a Java object class;
setting variables in the Java object class as default values;
obtaining an alias corresponding to the variable according to the mapping relation;
reading column values from the row data of the result set by using a column reading method; and
the variable is set to the corresponding column value.
11. The data processing method of claim 10, further comprising, prior to the step of reading column values from row data of the result set:
acquiring variable data types in the Java object class and data types of corresponding data columns in the result set; and
selecting the column read method according to the data type.
12. The data processing method according to claim 11, wherein when the variable data type in the Java object class is one of a character type, a numerical type, and a temporal type, a corresponding column reading method is selected according to the variable data type in the Java object class, and a column value is read from the row data of the result set.
13. The data processing method according to claim 11, wherein when the variable data type in the Java object class is a date type, a corresponding column reading method is selected according to the data type of the data column.
14. The data processing method of claim 13, wherein selecting a respective column read method comprises:
if the data type of the data column is a time-of-day type, a time-stamp type column reading method is selected,
if the data type of the data column is date type, selecting a column reading method by date type,
selecting a time-stamped column reading method if the data type of the data column is time-stamped, an
And if the data type of the data column is time type, selecting a time type column reading method.
15. The data processing method according to claim 11, when the variable data type in the Java object class is boolean, selecting a corresponding column reading method and data conversion method according to the data type of the data column.
16. The data processing method of claim 15, wherein the step of selecting the respective column reading method and data conversion method comprises:
if the data type of the data column is Boolean type, a Boolean type column reading method is selected,
if the data type of the data column is integer, selecting an integer column reading method, and converting the read column value into a Boolean quantity, an
If the data type of the data column is character type, a character type column reading method is selected, and the read column value is converted into a Boolean quantity.
17. A data processing apparatus based on object relational mapping, comprising:
the calling module is used for providing a database query interface and an instance list interface of the Java object class, and executing database query through the database query interface to obtain a result set;
the Java object analysis module is used for analyzing the Java object class to obtain class attributes;
the result set metadata analysis module is used for analyzing the metadata of the result set to acquire the data column attributes;
a result set reading module for reading the result set line by line to obtain line data; and
a result set mapping module for establishing a mapping relation according to the class attribute and mapping the result set to an instance list of the Java object class,
and when the mapping relation is established, executing at least one of a plurality of mapping methods according to the type of the mapping annotation in the class attribute.
CN202210171215.4A 2022-02-24 2022-02-24 Data processing method and data processing device based on object relation mapping Pending CN114238527A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210171215.4A CN114238527A (en) 2022-02-24 2022-02-24 Data processing method and data processing device based on object relation mapping

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210171215.4A CN114238527A (en) 2022-02-24 2022-02-24 Data processing method and data processing device based on object relation mapping

Publications (1)

Publication Number Publication Date
CN114238527A true CN114238527A (en) 2022-03-25

Family

ID=80748044

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210171215.4A Pending CN114238527A (en) 2022-02-24 2022-02-24 Data processing method and data processing device based on object relation mapping

Country Status (1)

Country Link
CN (1) CN114238527A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114756554A (en) * 2022-06-13 2022-07-15 中建电子商务有限责任公司 Data query processing method based on MyBatis framework
CN115729935A (en) * 2022-11-23 2023-03-03 北京水脉科技有限公司 Data interaction processing method and system based on ORM framework

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103020064A (en) * 2011-09-20 2013-04-03 佳都新太科技股份有限公司 Method and configuration for generating query condition in annotation way
CN104182484A (en) * 2014-08-07 2014-12-03 北京京东尚科信息技术有限公司 Method and device for realizing mapping of HBase data and Java domain objects
CN105843609A (en) * 2016-03-18 2016-08-10 浪潮软件集团有限公司 MVC frame based on Spring and MyBatis
CN106126540A (en) * 2016-06-15 2016-11-16 中国传媒大学 Data base access system and access method thereof
CN108108483A (en) * 2018-01-09 2018-06-01 政采云有限公司 The methods, devices and systems of DAO layers of verification SQL are intercepted based on SpringAop

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103020064A (en) * 2011-09-20 2013-04-03 佳都新太科技股份有限公司 Method and configuration for generating query condition in annotation way
CN104182484A (en) * 2014-08-07 2014-12-03 北京京东尚科信息技术有限公司 Method and device for realizing mapping of HBase data and Java domain objects
CN105843609A (en) * 2016-03-18 2016-08-10 浪潮软件集团有限公司 MVC frame based on Spring and MyBatis
CN106126540A (en) * 2016-06-15 2016-11-16 中国传媒大学 Data base access system and access method thereof
CN108108483A (en) * 2018-01-09 2018-06-01 政采云有限公司 The methods, devices and systems of DAO layers of verification SQL are intercepted based on SpringAop

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114756554A (en) * 2022-06-13 2022-07-15 中建电子商务有限责任公司 Data query processing method based on MyBatis framework
CN114756554B (en) * 2022-06-13 2022-09-30 中建电子商务有限责任公司 Data query processing method based on MyBatis framework
CN115729935A (en) * 2022-11-23 2023-03-03 北京水脉科技有限公司 Data interaction processing method and system based on ORM framework

Similar Documents

Publication Publication Date Title
US8707279B2 (en) Method and apparatus for executing stored code objects in a database
US8086998B2 (en) transforming meta object facility specifications into relational data definition language structures and JAVA classes
CN107861728B (en) Method and system for converting traditional program language into modern program language
CN110347598B (en) Test script generation method and device, server and storage medium
US9229984B2 (en) Parameter expressions for modeling user defined function execution in analytical data processing systems
CN114238527A (en) Data processing method and data processing device based on object relation mapping
WO2012102707A1 (en) Analytical data processing
CN114281342A (en) Automatic code generation method
CN112235311A (en) OVSDB client code automatic generation method, system, device and medium
US20220222253A1 (en) Sql statement generator
CN114691704A (en) Metadata synchronization method based on MySQL binlog
CN112667598B (en) Data model rapid construction system based on business demand change
CN112765180B (en) Method and device for analyzing column names of table building logs of DB2 database
US20070255750A1 (en) System to disclose the internal structure of persistent database objects
CN112181996B (en) Unified data access middleware method and system for relational database
CN115390936A (en) Unified verification method, device, equipment and storage medium
CN113885970A (en) Method, system and medium for generating report data based on script
CN112860584A (en) Test method and device based on workflow model
CN115617773A (en) Data migration method, device and system
CN116755684B (en) OAS Schema generation method, device, equipment and medium
CN113761040A (en) Database and application program bidirectional mapping method, device, medium and program product
CN116955393A (en) Data processing method and device, electronic equipment and storage medium
CN117951134A (en) Method for building table based on annotation reverse generation model
Chang et al. Improvement of Excel data processing function based on Spring MVC framework
CN115408453A (en) Configured report generation method and device, computer equipment and storage medium

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
RJ01 Rejection of invention patent application after publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20220325