1
1
package io .nop .orm .support ;
2
2
3
+ import io .nop .api .core .util .Guard ;
3
4
import io .nop .commons .util .CollectionHelper ;
4
5
import io .nop .commons .util .StringHelper ;
5
- import io .nop .orm .OrmConstants ;
6
6
import io .nop .orm .model .IEntityModel ;
7
7
import io .nop .orm .model .IEntityRelationModel ;
8
8
import io .nop .orm .model .OrmModelConstants ;
9
- import io .nop .orm .model .OrmRelationType ;
10
9
11
10
import java .util .List ;
12
11
13
- import static io .nop .core .reflect .utils .BeanReflectHelper .getValueByFactoryMethod ;
14
-
15
- public class OrmManyToManyMappingMeta {
12
+ /**
13
+ * 专用于多对多关联的中间表
14
+ */
15
+ public class OrmMappingTableMeta {
16
16
private final IEntityModel mappingTable ;
17
17
private final IEntityRelationModel refProp1 ;
18
18
private final IEntityRelationModel refProp2 ;
19
19
20
- public OrmManyToManyMappingMeta (IEntityModel mappingTable ) {
20
+ public OrmMappingTableMeta (IEntityModel mappingTable ) {
21
21
this .mappingTable = mappingTable ;
22
22
List <? extends IEntityRelationModel > rels = mappingTable .getToOneRelations ();
23
23
this .refProp1 = CollectionHelper .first (rels );
24
24
this .refProp2 = CollectionHelper .last (rels );
25
+
26
+ Guard .checkArgument (rels .size () == 2 , "mappingTable must contains two to-one relations" );
27
+ }
28
+
29
+ /**
30
+ * 中间表具有mapping标签或者many-to-man标签
31
+ */
32
+ public static boolean isMappingTable (IEntityModel entityModel ) {
33
+ return entityModel .containsTag (OrmModelConstants .TAG_MAPPING ) || entityModel .containsTag (OrmModelConstants .TAG_MANY_TO_MANY );
25
34
}
26
35
27
36
public boolean isOneToOne () {
28
- return getRelationType () == OrmRelationType .o2o ;
37
+ return mappingTable .containsTag (OrmModelConstants .TAG_ONE_TO_ONE );
38
+ }
39
+
40
+ public boolean isManyToMany () {
41
+ return mappingTable .containsTag (OrmModelConstants .TAG_MANY_TO_MANY );
29
42
}
30
43
31
44
public IEntityModel getMappingTable () {
@@ -40,13 +53,30 @@ public IEntityRelationModel getRefProp2() {
40
53
return refProp2 ;
41
54
}
42
55
43
- public String getRefSetPropName1 () {
44
- String refSetName = (String ) mappingTable .prop_get (OrmModelConstants .ORM_MANY_TO_MANY_REF_SET_NAME1 );
56
+ public String getRefPropName1 () {
57
+ String refSetName = (String ) mappingTable .prop_get (OrmModelConstants .ORM_MAPPING_PROP_NAME1 );
45
58
if (StringHelper .isEmpty (refSetName ))
46
59
refSetName = "related" + StringHelper .capitalize (refProp2 .getName ()) + "List" ;
47
60
return refSetName ;
48
61
}
49
62
63
+ public String getRefPropName2 () {
64
+ String refSetName = (String ) mappingTable .prop_get (OrmModelConstants .ORM_MAPPING_PROP_NAME2 );
65
+ if (StringHelper .isEmpty (refSetName ))
66
+ refSetName = "related" + StringHelper .capitalize (refProp1 .getName ()) + "List" ;
67
+ return refSetName ;
68
+ }
69
+
70
+ public String getRefPropDisplayName1 () {
71
+ String displayName = (String ) mappingTable .prop_get (OrmModelConstants .ORM_MAPPING_PROP_DISPLAY_NAME1 );
72
+ return displayName ;
73
+ }
74
+
75
+ public String getRefPropDisplayName2 () {
76
+ String displayName = (String ) mappingTable .prop_get (OrmModelConstants .ORM_MAPPING_PROP_DISPLAY_NAME2 );
77
+ return displayName ;
78
+ }
79
+
50
80
public String getJoinPropName1 () {
51
81
if (refProp1 .isSingleColumn ()) {
52
82
return refProp1 .getSingleColumnJoin ().getLeftProp ();
@@ -61,27 +91,20 @@ public String getJoinPropName2() {
61
91
return refProp2 .getName ();
62
92
}
63
93
64
- public String getRefSetPropName1_label () {
65
- return getRefSetPropName1 () + "_label" ;
94
+ public String getRefPropName1_label () {
95
+ return getRefPropName1 () + "_label" ;
66
96
}
67
97
68
- public String getRefSetPropName1_ids () {
69
- return getRefSetPropName1 () + "_ids" ;
98
+ public String getRefPropName1_ids () {
99
+ return getRefPropName1 () + "_ids" ;
70
100
}
71
101
72
- public String getRefSetPropName2 () {
73
- String refSetName = (String ) mappingTable .prop_get (OrmModelConstants .ORM_MANY_TO_MANY_REF_SET_NAME2 );
74
- if (StringHelper .isEmpty (refSetName ))
75
- refSetName = "related" + StringHelper .capitalize (refProp1 .getName ()) + "List" ;
76
- return refSetName ;
77
- }
78
-
79
- public String getRefSetPropName2_label () {
80
- return getRefSetPropName2 () + "_label" ;
102
+ public String getRefPropName2_label () {
103
+ return getRefPropName2 () + "_label" ;
81
104
}
82
105
83
- public String getRefSetPropName2_ids () {
84
- return getRefSetPropName2 () + "_ids" ;
106
+ public String getRefPropName2_ids () {
107
+ return getRefPropName2 () + "_ids" ;
85
108
}
86
109
87
110
public String getRefEntityName1 () {
@@ -100,14 +123,14 @@ public String getRefBizObjName2() {
100
123
return StringHelper .simpleClassName (getRefEntityName2 ());
101
124
}
102
125
103
- public String getRefLabelPropName1 () {
126
+ public String getRefLabelProp1 () {
104
127
String labelProp = refProp1 .getRefEntityModel ().getLabelProp ();
105
128
if (StringHelper .isEmpty (labelProp ))
106
129
labelProp = OrmModelConstants .PROP_ID ;
107
130
return labelProp ;
108
131
}
109
132
110
- public String getRefLabelPropName2 () {
133
+ public String getRefLabelProp2 () {
111
134
String labelProp = refProp2 .getRefEntityModel ().getLabelProp ();
112
135
if (StringHelper .isEmpty (labelProp ))
113
136
labelProp = OrmModelConstants .PROP_ID ;
@@ -121,9 +144,4 @@ public String getMappingEntityName() {
121
144
public String getMappingTableName () {
122
145
return mappingTable .getTableName ();
123
146
}
124
-
125
- public OrmRelationType getRelationType () {
126
- return getValueByFactoryMethod (OrmRelationType .class , mappingTable ,
127
- OrmConstants .EXT_ORM_RELATION_TYPE );
128
- }
129
147
}
0 commit comments