Method for mapping associated object and relation

文档序号:1087055 发布日期:2020-10-20 浏览:4次 中文

阅读说明:本技术 一种映射关联对象与关系的方法 (Method for mapping associated object and relation ) 是由 陈瑞 于 2020-05-19 设计创作,主要内容包括:公开了映射关联对象与关系的方法,其包括建立用于描述关联对象内部结构的关联数据模型,所述关联数据模型包括关联端和关联属性;指定关联的映射表;配置所述关联端的映射;配置所述关联属性的映射;生成SQL语句;执行SQL语句。其能够根据关联内部结构自动生成映射SQL,实现关联对象与关系的相互转换。(A method for mapping an associated object and a relationship is disclosed, which comprises establishing an associated data model for describing the internal structure of the associated object, wherein the associated data model comprises an associated end and an associated attribute; specifying an associated mapping table; configuring the mapping of the associated end; configuring a mapping of the associated attributes; generating an SQL statement; the SQL statement is executed. The method can automatically generate mapping SQL according to the correlation internal structure, and realizes the mutual conversion of the correlation object and the relationship.)

1. A method of mapping associated objects and relationships, comprising the steps of:

establishing an associated data model for describing the internal structure of an associated object, wherein the associated data model comprises an associated end and associated attributes;

specifying an associated mapping table;

configuring the mapping of the associated end;

configuring a mapping of the associated attributes;

generating an SQL statement;

the SQL statement is executed.

2. The method for mapping an associated object and a relationship according to claim 1, wherein the association end comprises a data item representing a name and a data item representing a physical type.

3. The method for mapping an associated object and relationship according to claim 2, wherein the associated attribute comprises a data item representing a name and a data item representing a data type.

4. The method for mapping associated objects and relationships according to claim 1, wherein the associated mapping table can be an independent table or a mapping table of any associated end.

5. The method for mapping association objects and relationships according to claim 1, wherein configuring the mapping of the association end requires specifying, for each association end, a mapping field of the identification attribute of its body type in the association mapping table.

6. The method for mapping an associated object and relationship according to claim 1, wherein configuring the mapping of the associated attributes requires specifying a mapping field for each associated attribute.

7. The method for mapping associated objects and relationships according to claim 1, wherein the method for generating SQL statements is different in different scenarios.

8. A system for mapping associated objects and relationships, comprising: the system comprises a processor, a communication bus, a user interface, a network interface and a memory.

9. The system of claim 8, wherein the memory comprises an operating system, a data storage module, a network communication module, a user interface module, and a system program that maps associated objects and relationships.

10. A terminal device comprising a memory, a processor and a program stored in the memory and executable on the processor for associating objects with relationships, wherein the program when executed by the processor implements the steps of associating objects with relationships according to any one of claims 1 to 7.

Technical Field

The invention relates to the technical field of computer programs, in particular to a method for mapping associated objects and relations.

Background

The object-oriented software development idea regards a software system as an object and a relationship between objects (i.e., an object system), and an object system refers to an object (e.g., both refer to an entity object without specific description) and a relationship between objects (i.e., an association). The operation of the system is embodied as an interaction between objects, while the storage of system data is treated as a persistence operation performed on the current state of the subject system. Almost all current storage systems employ relational data structures, and the structure of an object system often differs significantly from the structure of a relational data structure, so that it has been a difficult problem to "crowd" objects into a relational system (commonly referred to as ORM, i.e., object relational mapping) since object-oriented.

Currently, the object-to-relation mapping can be well implemented by the ORM technology, and most technical solutions (for example, chinese patent application No. 2014106483227) are to correspond an object type to a relation table and an object attribute to a field of the relation table, and then generate SQL based on the correspondence (using write SQL and query SQL in two directions from object to relation and from relation to object, respectively), and complete the mapping by executing SQL statements.

Compared with the object, the internal structure of the association is more complex, and the prior art for realizing association and relational mapping is less. The Entity Framework developed by microsoft is one of the most common ORM programs, and the technical scheme for realizing the association and relationship table mapping comprises the following steps: specifying a solid type associated with both ends; configuring a correlation end mapping; specifying an associated mapping table; generating an Sql statement; the Sql statement is executed.

In addition to object and association, a special object, an associated object, exists in the object system. In essence it is an association, bearing a relationship of two or more objects, while having attributes as with an entity object. If the mapping scheme of the entity object is adopted, the associated information is lost, and if the mapping scheme of the association is adopted, the attribute information is lost, in practice, a service layer developer usually avoids using the associated object, or takes a supplementary measure according to a specific service scene. The former can lead to incomplete object system, unable to fully bear service requirement, and cause partial service logic overflow to the scheduling layer, thereby leading to overstaffed scheduling layer; which in turn increases developer workload. Therefore, a mapping scheme specific to the associated object is urgently needed in development practice.

Disclosure of Invention

In order to achieve the above object, the present invention provides a method for mapping an associated object and a relationship, which automatically generates a mapping SQL according to an associated internal structure to realize the interconversion between the associated object and the relationship, and comprises the following steps.

Firstly, establishing an associated data model for describing the internal structure of an associated object, wherein the associated data model comprises an associated end and associated attributes.

In a second step, the associated mapping table is specified.

Thirdly, configuring the mapping of the associated end;

fourthly, configuring the mapping of the associated attribute;

fifthly, generating SQL sentences;

and sixthly, executing the SQL statement.

Wherein the association end comprises a data item representing a name and a data item representing a physical type.

Wherein the associated attribute includes a data item representing a name and a data item representing a data type.

The associated mapping table may be an independent table or a mapping table of any associated end.

And configuring the mapping of the association end requires specifying, for each association end, a mapping field of the identification attribute of the body type of the association end in the association mapping table.

Wherein configuring the associated attribute map requires specifying a map field for each associated attribute.

The method for generating the SQL statement is different under different scenes.

In an embodiment of the present invention, there is also provided a system for mapping an associated object and a relationship, including: the system comprises a processor, a communication bus, a user interface, a network interface and a memory.

Wherein the memory may include an operating system, a data storage module, a network communication module, a user interface module, and a system program that maps associated objects and relationships.

According to the method for mapping the associated object and the relationship, the mapping SQL can be automatically generated according to the associated internal structure, and the mutual conversion of the associated object and the relationship is realized. Not only the loss of the associated information but also the loss of the attribute information is avoided. Meanwhile, the integrity of an object system can be ensured, and the aim of fully bearing the service requirement is fulfilled.

Drawings

Various other advantages and benefits will become apparent to those of ordinary skill in the art upon reading the following detailed description of the preferred embodiments. The drawings are only for purposes of illustrating the preferred embodiments and are not to be construed as limiting the invention. Also, like reference numerals are used to refer to like parts throughout the drawings. In the drawings:

fig. 1 is a relational data model for describing an internal structure of a relational object according to an embodiment of the present invention.

Fig. 2 is a flowchart of a procedure for traversing an association end according to an embodiment of the present invention.

Fig. 3 is a flowchart of a procedure for traversing an association attribute according to an embodiment of the present invention.

Fig. 4 is a flowchart of a procedure for generating a relational table linkage condition according to an embodiment of the present invention.

Fig. 5 is a schematic structural diagram of a system device for mapping associated objects and relationships in a hardware operating environment according to an embodiment of the present invention.

Detailed Description

To further illustrate the technical means and effects of the present invention adopted to achieve the predetermined objects, the following detailed description of the method, apparatus, computer-readable storage medium and terminal device for mapping related objects and relationships according to the present invention with reference to the accompanying drawings and preferred embodiments will be provided to explain the detailed implementation, structure, features and effects thereof. In the following description, different "one embodiment" or "an embodiment" refers to not necessarily the same embodiment. Furthermore, the features, structures, or characteristics of one or more embodiments may be combined in any suitable manner.

The term "and/or" herein is merely an association describing an associated object, meaning that three relationships may exist, e.g., a and/or B, with the specific understanding that: both a and B may be included, a may be present alone, or B may be present alone, and any of the three cases can be provided.

While preferred embodiments of the present invention have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including preferred embodiments and all such alterations and modifications as fall within the scope of the invention.

The invention provides a method for mapping an object system and a relation system for solving the problems in the prior art, which comprises the following steps:

s1, as shown in FIG. 1, establishing an associated data model for describing the internal structure of the associated object, wherein the associated data model comprises an associated end and an associated attribute.

The association type shown in fig. 1 refers to the type of the associated object to be mapped. Generally, all instances (i.e. associated objects) of an association type have the same internal structure, and the same model is applied, that is, the association type and the associated data model are in one-to-one correspondence. In the model, the association end and the attribute of the association type are required to be indicated, the body type and the name of each association end are indicated, and the name and the data type of each attribute are indicated. The number of associated ends and attributes is not limited.

In an embodiment of the present invention, the association data model includes an association end and an association attribute, where the association end is a complex data structure, and is stored by a set assoeds, and includes a Name data item representing a Name and an EntityType data item representing a solid type; the association attribute is a complex data structure, stored as a set of associattrs, containing a Name data item representing the Name and a DataType data item representing the data type. Further, the number of elements of the sets assoeds and assoatrs is not limited.

S2, specifying the associated mapping table.

In an embodiment of the present invention, the associated mapping table may be an independent table, or may be a mapping table of any associated end. Specifically, the associated mapping table is identified by a string type variable targetTable.

S3, configuring the mapping of the correlation end.

I.e. a mapping field in the association mapping table specifying for each association end the identity attribute of its body type. In one embodiment, the entity of the association end has a plurality of identification attributes, each attribute has a mapping field, so that the association end is a set. Defining a data item Mappings in the complex data structure representing the associated end to store the set. Wherein, the item of the set is called a mapping item, and is also a complex data structure, and comprises a keyAttribute data item representing an identification attribute and a targetField data item representing a mapping field.

S4, configuring the mapping of the associated attribute.

Specifically, a mapping field is specified for each associated attribute in the set of assoAttrs. A data item, TargetField, is defined in the complex data structure representing the associated attribute to store the mapping field, i.e. the associated attribute.

And S5, generating the SQL statement.

Specifically, the associated end object is obtained from the associated object according to the associated end name, the attribute value is obtained according to the attribute name, and then the SQL statement is generated.

Different scenarios generate SQL statements differently, the following embodiments may illustrate the method for generating SQL statements for different scenarios, but those skilled in the art should appreciate that the following scenarios and methods are not limited to:

in an embodiment of the present invention, the scenario is to convert a new association object into a relationship, and the SQL statement structure to be generated is as follows:

insert Into Association mapping table (identification field List, Attribute field List) values (identification field value List, Attribute field value List), where:

the association mapping table is a value stored by a variable targetTable;

the identification field list and the identification field value list are generated according to the association end set, specifically, a key value pair set is output according to the flow shown in fig. 2, wherein the key is the identification field and the value is the value of the field, then values of all items are sequentially taken out from the key value pair set to be combined into the identification field list, and the values of all items are taken out to be combined into the identification field value list; the method GetValue (obj, element) has the function of taking a value from the object obj, taking out an attribute value when the element is an attribute, and taking out an associated end object when the element is an associated end.

The attribute field list and the attribute field value list are generated according to the associated attribute set, specifically, a key-value pair set is output according to the flow shown in fig. 3, wherein the key is the attribute field, and the value is the value of the field, and then the keys of each item are sequentially taken out from the key-value pair set to be combined into the attribute field list; values of the items are taken and combined into a list of attribute field values. Wherein, the method GetValue (obj, attr) is used for taking out the value of the attribute attr from the object obj.

In an embodiment of the present invention, the scenario is to modify an existing associated object, and the SQL statement structure to be generated is as follows:

an Update association mapping table Set attribute field 1 is an attribute field value 1, an attribute field 2 is an attribute field value 2.

The association mapping table is a value stored by a variable targetTable;

generating an attribute field sequence (attribute field 1, attribute field 2.)) and an attribute field value sequence (attribute field 1, attribute field 2.)) according to the associated attribute set, specifically, firstly, outputting a key-value pair set according to the flow shown in fig. 3, wherein a key is an attribute field, and a value is the value of the field, and then, sequentially taking out keys of each item from the key-value pair set to combine into the attribute field sequence; the values of the items are taken out and combined into a property field value sequence.

And the screening condition is generated according to the association end set. Specifically, first, a key-value pair set is output according to the flow shown in fig. 2, where a key is an identification field and a value is a value of the field; then traversing the set, and generating a relational expression such as 'key ═ value' for each item; and finally, performing logical AND operation on all the generated relational expressions.

In an embodiment of the present invention, the scenario is to delete an existing associated object, and the SQL statement structure to be generated is as follows:

the Delete From association mapping table Where screening condition, wherein:

the association mapping table is a value stored by a variable targetTable;

and the screening condition is generated according to the association end set. Specifically, first, a key-value pair set is output according to the flow shown in fig. 2, where a key is an identification field and a value is a value of the field; then traversing the set, and generating a relational expression such as 'key ═ value' for each item; and finally, performing logical AND operation on all the generated relational expressions.

In an embodiment of the present invention, the scenario is to query the association from a relational table, and the structure of the SQL statement to be generated is as follows:

selecting identification field list, and associating attribute field list From with mapping table Where query condition;

specifically, if a correlation end is to be synchronously loaded, the SQL statement structure to be generated is as follows:

a Select association identification field list, an association attribute field list, an association end field list From an association mapping table Inner Join association end mapping table On Join condition Where query conditions are:

the association mapping table is a value stored by a variable targetTable;

the association end mapping table is a mapping table of the entity type of the association end;

an identification field list (association identification field list) is generated according to the association end set, specifically, the association end set assonds is traversed, then, for each association end assond, the association end mapping set assond. maps is traversed, the value of the data item TargetField is taken out for each mapping item, and the data items are sequentially combined into an identification field list;

an attribute field list (associated attribute field list) is generated according to the associated attribute set, specifically, the associated attribute set assoAttrs is traversed, the value of a data item TargetField is taken out for each attribute, and the data items are sequentially combined into an attribute field list;

generating a related end field list according to the attribute set of the related end entity type, specifically, traversing the entity type attribute set, taking out the mapping field of each attribute, and sequentially combining the mapping fields into a related end field list;

the join condition is generated according to the flowchart shown in fig. 4, where assoEnd is the association end to be synchronously loaded;

the query conditions are generated according to the actual service scene.

In an embodiment of the present invention, the scene is navigated from the associated object to the associated end object, and the format of the SQL statement to be generated is as follows:

a field list of a Select associated end receives a query condition of an On Join condition of an Inner Join associated end table From an associated mapping table;

or navigating from the associated object to the associated object, wherein the format of the SQL statement to be generated is as follows:

selecting identification field list, attribute field list From association end mapping table Inner Join association mapping table On Join condition Where query condition, wherein:

the association mapping table is a value stored by a variable targetTable;

the association end mapping table is a mapping table of the entity type of the association end;

the method for generating the association end field list, the identification field list and the attribute field list is the same as that in the relation table query association;

the join condition is generated according to the flowchart shown in fig. 4, where the assoEnd represents the associated end participating in the navigation.

The query conditions are generated according to the actual service scene.

The above embodiments may illustrate the method for generating SQL statements in different scenarios, but those skilled in the art should know that the above scenarios and methods are not limited.

And S6, executing the SQL sentence generated in the previous step.

In one embodiment of the invention, if the relationship is converted to an Association object, the Association class is further instantiated and the Association object is initialized with data returned by executing the query SQL statement.

In another embodiment of the invention, if the associated ends are loaded simultaneously, the associated end type is instantiated, and the associated end object is initialized with the data returned by executing the query SQL statement, and then a reference to the associated end object is set in the associated object.

Referring to fig. 5, fig. 5 is a schematic structural diagram of a mapping object system and a relationship system device of a hardware operating environment according to an embodiment of the present invention.

As shown in fig. 5, the mapping object system and relationship system device may include: a processor 1001, such as a Central Processing Unit (CPU), a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. Wherein a communication bus 1002 is used to enable connective communication between these components. The user interface 1003 may include a Display screen (Display), an input unit such as a Keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface, a wireless interface. The network interface 1004 may optionally include a standard wired interface, a WIreless interface (e.g., a WIreless-FIdelity (WI-FI) interface). The Memory 1005 may be a Random Access Memory (RAM) Memory, or may be a Non-Volatile Memory (NVM), such as a disk Memory. The memory 1005 may alternatively be a storage device separate from the processor 1001.

Those skilled in the art will appreciate that the architecture shown in FIG. 5 does not constitute a definition of a map object system and a relationship system apparatus, and may include more or fewer components than those shown, or some components in combination, or a different arrangement of components.

As shown in fig. 5, the memory 1005, which is a storage medium, may include therein an operating system, a data storage module, a network communication module, a user interface module, and a map object system and relationship system program.

In the mapping object system and relationship system apparatus shown in fig. 5, the network interface 1004 is mainly used for data communication with a network server; the user interface 1003 is mainly used for data interaction with a user; the processor 1001 and the memory 1005 in the mapping object system and the relationship system apparatus of the present invention may be disposed in the mapping object system and the relationship system apparatus, and the mapping object system and the relationship system apparatus call the mapping object system and the relationship system program stored in the memory 1005 through the processor 1001, and execute the mapping object system and the relationship system method provided in the embodiment of the present invention.

It will be apparent to those skilled in the art that various changes and modifications may be made in the present invention without departing from the spirit and scope of the invention. Thus, if such modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include such modifications and variations.

11页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:一种存储数据的方法及装置

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!