Skip to content

Commit 21f6e30

Browse files
committed
重命名为OrmManyToManyMappingMeta和OrmMappingTableMeta
1 parent 6673d47 commit 21f6e30

File tree

5 files changed

+67
-44
lines changed

5 files changed

+67
-44
lines changed

nop-demo/nop-quarkus-demo/src/main/resources/nop-vfs-index.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@
290290
/nop/codegen/xlib/web-gen.xlib
291291
/nop/core/_module
292292
/nop/core/app.module.yaml
293+
/nop/core/model/DictProvider/DictProvider.xbiz
293294
/nop/core/registry/api.register-model.xml
294295
/nop/core/registry/dao-rule.register-model.xml
295296
/nop/core/registry/dao-wf.register-model.xml

nop-dyn/nop-dyn-dao/src/main/java/io/nop/dyn/dao/model/OrmModelToDynEntityMeta.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import io.nop.orm.model.IOrmModel;
2323
import io.nop.orm.model.OrmModelConstants;
2424
import io.nop.orm.model.OrmRelationType;
25-
import io.nop.orm.support.OrmManyToManyMappingMeta;
25+
import io.nop.orm.support.OrmMappingTableMeta;
2626
import org.slf4j.Logger;
2727
import org.slf4j.LoggerFactory;
2828

@@ -67,19 +67,19 @@ public void transformModule(IOrmModel ormModel, NopDynModule dynModule) {
6767
entityMetas.put(entityMeta.getEntityName(), entityMeta);
6868
});
6969

70-
List<OrmManyToManyMappingMeta> mappingTables = new ArrayList<>();
70+
List<OrmMappingTableMeta> mappingTables = new ArrayList<>();
7171
ormModel.getEntityModels().forEach(entityModel -> {
7272
// many-to-many的中间表不转换为实体表
7373
if (entityModel.containsTag(OrmModelConstants.TAG_MANY_TO_MANY)) {
74-
mappingTables.add(new OrmManyToManyMappingMeta(entityModel));
74+
mappingTables.add(new OrmMappingTableMeta(entityModel));
7575
return;
7676
}
7777

7878
NopDynEntityMeta entityMeta = makeEntityMeta(entityModel.getName());
7979
transformEntityMeta(entityModel, entityMeta);
8080
});
8181

82-
for (OrmManyToManyMappingMeta mappingMeta : mappingTables) {
82+
for (OrmMappingTableMeta mappingMeta : mappingTables) {
8383
if (mappingMeta.getRefProp2() == null) {
8484
LOG.warn("nop.dyn.ignore-invalid-many-to-many-mapping-table:{}", mappingMeta.getMappingTable());
8585
continue;
@@ -99,7 +99,7 @@ public void transformModule(IOrmModel ormModel, NopDynModule dynModule) {
9999
relMeta1.setTagsText(TagsHelper.toString(mappingMeta.getMappingTable().getTagSet()));
100100
relMeta1.setRemark(mappingMeta.getMappingTable().getComment());
101101
relMeta1.setRelationType(OrmRelationType.m2m.name());
102-
relMeta1.setRelationName(mappingMeta.getRefSetPropName1());
102+
relMeta1.setRelationName(mappingMeta.getRefPropName1());
103103
relMeta1.setLeftPropName(OrmModelConstants.PROP_ID);
104104
relMeta1.setRightPropName(OrmModelConstants.PROP_ID);
105105
entityMeta1.getRelationMetasForEntity().add(relMeta1);
@@ -113,7 +113,7 @@ public void transformModule(IOrmModel ormModel, NopDynModule dynModule) {
113113
relMeta2.setTagsText(TagsHelper.toString(mappingMeta.getMappingTable().getTagSet()));
114114
relMeta2.setRemark(mappingMeta.getMappingTable().getComment());
115115
relMeta2.setRelationType(OrmRelationType.m2m.name());
116-
relMeta2.setRelationName(mappingMeta.getRefSetPropName2());
116+
relMeta2.setRelationName(mappingMeta.getRefPropName2());
117117
relMeta2.setLeftPropName(OrmModelConstants.PROP_ID);
118118
relMeta2.setRightPropName(OrmModelConstants.PROP_ID);
119119
entityMeta2.getRelationMetasForEntity().add(relMeta2);

nop-orm-model/src/main/java/io/nop/orm/model/OrmModelConstants.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ public interface OrmModelConstants {
6868

6969
String TAG_MANY_TO_MANY = "many-to-many";
7070

71+
String TAG_ONE_TO_ONE = "one-to-one";
72+
73+
String TAG_MAPPING = "mapping";
74+
7175
String PROP_NAME_nopRevType = "nopRevType";
7276
String PROP_NAME_nopRevBeginVer = "nopRevBeginVer";
7377
String PROP_NAME_nopRevEndVer = "nopRevEndVer";
@@ -124,13 +128,13 @@ public interface OrmModelConstants {
124128

125129
String ORM_MANY_TO_MANY_REF_PROP = "orm:manyToManyRefProp";
126130

127-
String ORM_MANY_TO_MANY_REF_SET_NAME1 = "orm:manyToManyRefSetName1";
131+
String ORM_MAPPING_PROP_NAME1 = "orm:mappingPropName1";
128132

129-
String ORM_MANY_TO_MANY_REF_SET_NAME2 = "orm:manyToManyRefSetName2";
133+
String ORM_MAPPING_PROP_NAME2 = "orm:mappingPropName2";
130134

131-
String ORM_MANY_TO_MANY_REF_SET_DISPLAY_NAME1 = "orm:manyToManyRefSetDisplayName1";
135+
String ORM_MAPPING_PROP_DISPLAY_NAME1 = "orm:mappingPropDisplayName1";
132136

133-
String ORM_MANY_TO_MANY_REF_SET_DISPLAY_NAME2 = "orm:manyToManyRefSetDisplayName2";
137+
String ORM_MAPPING_PROP_DISPLAY_NAME2 = "orm:mappingPropDisplayName2";
134138

135139

136140
String VAR_ENTITY = "entity";
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,44 @@
11
package io.nop.orm.support;
22

3+
import io.nop.api.core.util.Guard;
34
import io.nop.commons.util.CollectionHelper;
45
import io.nop.commons.util.StringHelper;
5-
import io.nop.orm.OrmConstants;
66
import io.nop.orm.model.IEntityModel;
77
import io.nop.orm.model.IEntityRelationModel;
88
import io.nop.orm.model.OrmModelConstants;
9-
import io.nop.orm.model.OrmRelationType;
109

1110
import java.util.List;
1211

13-
import static io.nop.core.reflect.utils.BeanReflectHelper.getValueByFactoryMethod;
14-
15-
public class OrmManyToManyMappingMeta {
12+
/**
13+
* 专用于多对多关联的中间表
14+
*/
15+
public class OrmMappingTableMeta {
1616
private final IEntityModel mappingTable;
1717
private final IEntityRelationModel refProp1;
1818
private final IEntityRelationModel refProp2;
1919

20-
public OrmManyToManyMappingMeta(IEntityModel mappingTable) {
20+
public OrmMappingTableMeta(IEntityModel mappingTable) {
2121
this.mappingTable = mappingTable;
2222
List<? extends IEntityRelationModel> rels = mappingTable.getToOneRelations();
2323
this.refProp1 = CollectionHelper.first(rels);
2424
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);
2534
}
2635

2736
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);
2942
}
3043

3144
public IEntityModel getMappingTable() {
@@ -40,13 +53,30 @@ public IEntityRelationModel getRefProp2() {
4053
return refProp2;
4154
}
4255

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);
4558
if (StringHelper.isEmpty(refSetName))
4659
refSetName = "related" + StringHelper.capitalize(refProp2.getName()) + "List";
4760
return refSetName;
4861
}
4962

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+
5080
public String getJoinPropName1() {
5181
if (refProp1.isSingleColumn()) {
5282
return refProp1.getSingleColumnJoin().getLeftProp();
@@ -61,27 +91,20 @@ public String getJoinPropName2() {
6191
return refProp2.getName();
6292
}
6393

64-
public String getRefSetPropName1_label() {
65-
return getRefSetPropName1() + "_label";
94+
public String getRefPropName1_label() {
95+
return getRefPropName1() + "_label";
6696
}
6797

68-
public String getRefSetPropName1_ids() {
69-
return getRefSetPropName1() + "_ids";
98+
public String getRefPropName1_ids() {
99+
return getRefPropName1() + "_ids";
70100
}
71101

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";
81104
}
82105

83-
public String getRefSetPropName2_ids() {
84-
return getRefSetPropName2() + "_ids";
106+
public String getRefPropName2_ids() {
107+
return getRefPropName2() + "_ids";
85108
}
86109

87110
public String getRefEntityName1() {
@@ -100,14 +123,14 @@ public String getRefBizObjName2() {
100123
return StringHelper.simpleClassName(getRefEntityName2());
101124
}
102125

103-
public String getRefLabelPropName1() {
126+
public String getRefLabelProp1() {
104127
String labelProp = refProp1.getRefEntityModel().getLabelProp();
105128
if (StringHelper.isEmpty(labelProp))
106129
labelProp = OrmModelConstants.PROP_ID;
107130
return labelProp;
108131
}
109132

110-
public String getRefLabelPropName2() {
133+
public String getRefLabelProp2() {
111134
String labelProp = refProp2.getRefEntityModel().getLabelProp();
112135
if (StringHelper.isEmpty(labelProp))
113136
labelProp = OrmModelConstants.PROP_ID;
@@ -121,9 +144,4 @@ public String getMappingEntityName() {
121144
public String getMappingTableName() {
122145
return mappingTable.getTableName();
123146
}
124-
125-
public OrmRelationType getRelationType() {
126-
return getValueByFactoryMethod(OrmRelationType.class, mappingTable,
127-
OrmConstants.EXT_ORM_RELATION_TYPE);
128-
}
129147
}

nop-xdefs/src/main/resources/_vfs/nop/schema/orm/entity.xdef

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@
5555
maxBatchLoadSize="int" checkVersionWhenLazyLoad="!boolean=true"
5656
labelProp="string" stateProp="var-name"
5757
entityModeEnabled="!boolean=false" dimensionalType="string"
58-
biz:moduleId="string" orm:relationType="string"
59-
orm:manyToManyRefSetName1="string" orm:manyToManyRefSetName2="string"
60-
orm:manyToManyRefSetDisplayName1="string" orm:manyToManyRefSetDisplayName2="string"
58+
biz:moduleId="string"
59+
orm:mappingPropName1="string" orm:mappingPropName2="string"
60+
orm:mappingPropDisplayName1="string" orm:mappingPropDisplayName2="string"
6161
xdef:default-extends="/nop/core/defaults/default.entity.xml"
6262
xdef:name="OrmEntityModel" xdef:bean-package="io.nop.orm.model"
6363
x:schema="/nop/schema/xdef.xdef" xdef:check-ns="ui,biz"

0 commit comments

Comments
 (0)