Skip to content

Commit

Permalink
调整nop-dyn模型。修改NopDynEntityMeta和OrmModel之间的相互转换
Browse files Browse the repository at this point in the history
  • Loading branch information
entropy-cloud committed Aug 7, 2024
1 parent 6e656d9 commit a6147df
Show file tree
Hide file tree
Showing 19 changed files with 343 additions and 172 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<grid id="list" x:abstract="true">
<cols>
<c:for var="prop" items="${visibleProps}">
<c:out escape="none"><![CDATA[<!-- ${prop.displayName.$safeXmlComment()} -->]]></c:out>
<c:out escape="none"><![CDATA[<!-- ${prop.displayName?.$safeXmlComment()} -->]]></c:out>
<col id="${prop.name}" mandatory="${prop.mandatory ? true: null}"
sortable="${prop.sortable?true:null}" x:abstract="${listProps.contains(prop)?null:true}"/>
</c:for>
Expand Down
1 change: 1 addition & 0 deletions nop-dyn/deploy/sql/mysql/_create_nop-dyn.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ CREATE TABLE nop_dyn_module(
DISPLAY_NAME VARCHAR(200) NOT NULL COMMENT '显示名',
BASE_MODULE_ID VARCHAR(100) NULL COMMENT '基础模块ID',
BASE_PACKAGE_NAME VARCHAR(200) NULL COMMENT 'Java包名',
ENTITY_PACKAGE_NAME VARCHAR(200) NULL COMMENT '实体包名',
MAVEN_GROUP_ID VARCHAR(200) NULL COMMENT 'Maven组名',
STATUS INTEGER NOT NULL default '0' COMMENT '状态',
VERSION INTEGER NOT NULL COMMENT '数据版本',
Expand Down
3 changes: 3 additions & 0 deletions nop-dyn/deploy/sql/oracle/_create_nop-dyn.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ CREATE TABLE nop_dyn_module(
DISPLAY_NAME VARCHAR2(200) NOT NULL ,
BASE_MODULE_ID VARCHAR2(100) ,
BASE_PACKAGE_NAME VARCHAR2(200) ,
ENTITY_PACKAGE_NAME VARCHAR2(200) ,
MAVEN_GROUP_ID VARCHAR2(200) ,
STATUS INTEGER NOT NULL default '0' ,
VERSION INTEGER NOT NULL ,
Expand Down Expand Up @@ -317,6 +318,8 @@ CREATE TABLE nop_dyn_prop_meta(

COMMENT ON COLUMN nop_dyn_module.BASE_PACKAGE_NAME IS 'Java包名';

COMMENT ON COLUMN nop_dyn_module.ENTITY_PACKAGE_NAME IS '实体包名';

COMMENT ON COLUMN nop_dyn_module.MAVEN_GROUP_ID IS 'Maven组名';

COMMENT ON COLUMN nop_dyn_module.STATUS IS '状态';
Expand Down
3 changes: 3 additions & 0 deletions nop-dyn/deploy/sql/postgresql/_create_nop-dyn.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ CREATE TABLE nop_dyn_module(
DISPLAY_NAME VARCHAR(200) NOT NULL ,
BASE_MODULE_ID VARCHAR(100) ,
BASE_PACKAGE_NAME VARCHAR(200) ,
ENTITY_PACKAGE_NAME VARCHAR(200) ,
MAVEN_GROUP_ID VARCHAR(200) ,
STATUS INT4 NOT NULL default '0' ,
VERSION INT4 NOT NULL ,
Expand Down Expand Up @@ -317,6 +318,8 @@ CREATE TABLE nop_dyn_prop_meta(

COMMENT ON COLUMN nop_dyn_module.BASE_PACKAGE_NAME IS 'Java包名';

COMMENT ON COLUMN nop_dyn_module.ENTITY_PACKAGE_NAME IS '实体包名';

COMMENT ON COLUMN nop_dyn_module.MAVEN_GROUP_ID IS 'Maven组名';

COMMENT ON COLUMN nop_dyn_module.STATUS IS '状态';
Expand Down
Binary file modified nop-dyn/model/nop-dyn.orm.xlsx
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ public interface NopDynDaoConstants extends _NopDynDaoConstants {
String EXT_ORM_REF_TABLE = "orm:ref-table";

String DEFAULT_BASE_PACKAGE_NAME = "app.dyn";

String NAME_REF_ENTITY1 = "refEntity1";
String NAME_REF_ENTITY2 = "refEntity2";

String DEFAULT_ENTITY_PACKAGE_NAME = "app.dyn.entity";
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.nop.commons.lang.ITagSetSupport;
import io.nop.commons.util.StringHelper;
import io.nop.commons.util.TagsHelper;
import io.nop.dyn.dao.NopDynDaoConstants;
import io.nop.dyn.dao.entity._gen._NopDynEntityMeta;
import io.nop.orm.model.IEntityModel;

Expand Down Expand Up @@ -59,10 +60,12 @@ public String getFullEntityName() {
return entityName;
NopDynModule module = getModule();
if (module == null)
return "app." + entityName;
if (!module.getBasePackageName().endsWith(".entity"))
return module.getBasePackageName() + ".entity." + entityName;
return module.getBasePackageName() + "." + entityName;
return NopDynDaoConstants.DEFAULT_ENTITY_PACKAGE_NAME + '.' + entityName;
String entityPackageName = module.getEntityPackageName();
if (entityPackageName == null) {
entityPackageName = NopDynDaoConstants.DEFAULT_ENTITY_PACKAGE_NAME;
}
return entityPackageName + "." + entityName;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,36 +44,40 @@ public class _NopDynModule extends DynamicOrmEntity{
public static final String PROP_NAME_basePackageName = "basePackageName";
public static final int PROP_ID_basePackageName = 6;

/* 实体包名: ENTITY_PACKAGE_NAME VARCHAR */
public static final String PROP_NAME_entityPackageName = "entityPackageName";
public static final int PROP_ID_entityPackageName = 7;

/* Maven组名: MAVEN_GROUP_ID VARCHAR */
public static final String PROP_NAME_mavenGroupId = "mavenGroupId";
public static final int PROP_ID_mavenGroupId = 7;
public static final int PROP_ID_mavenGroupId = 8;

/* 状态: STATUS INTEGER */
public static final String PROP_NAME_status = "status";
public static final int PROP_ID_status = 8;
public static final int PROP_ID_status = 9;

/* 数据版本: VERSION INTEGER */
public static final String PROP_NAME_version = "version";
public static final int PROP_ID_version = 9;
public static final int PROP_ID_version = 10;

/* 创建人: CREATED_BY VARCHAR */
public static final String PROP_NAME_createdBy = "createdBy";
public static final int PROP_ID_createdBy = 10;
public static final int PROP_ID_createdBy = 11;

/* 创建时间: CREATE_TIME TIMESTAMP */
public static final String PROP_NAME_createTime = "createTime";
public static final int PROP_ID_createTime = 11;
public static final int PROP_ID_createTime = 12;

/* 修改人: UPDATED_BY VARCHAR */
public static final String PROP_NAME_updatedBy = "updatedBy";
public static final int PROP_ID_updatedBy = 12;
public static final int PROP_ID_updatedBy = 13;

/* 修改时间: UPDATE_TIME TIMESTAMP */
public static final String PROP_NAME_updateTime = "updateTime";
public static final int PROP_ID_updateTime = 13;
public static final int PROP_ID_updateTime = 14;


private static int _PROP_ID_BOUND = 14;
private static int _PROP_ID_BOUND = 15;


/* relation: 基础模块 */
Expand Down Expand Up @@ -104,7 +108,7 @@ public class _NopDynModule extends DynamicOrmEntity{
protected static final List<String> PK_PROP_NAMES = Arrays.asList(PROP_NAME_moduleId);
protected static final int[] PK_PROP_IDS = new int[]{PROP_ID_moduleId};

private static final String[] PROP_ID_TO_NAME = new String[14];
private static final String[] PROP_ID_TO_NAME = new String[15];
private static final Map<String,Integer> PROP_NAME_TO_ID = new HashMap<>();
static{

Expand All @@ -126,6 +130,9 @@ public class _NopDynModule extends DynamicOrmEntity{
PROP_ID_TO_NAME[PROP_ID_basePackageName] = PROP_NAME_basePackageName;
PROP_NAME_TO_ID.put(PROP_NAME_basePackageName, PROP_ID_basePackageName);

PROP_ID_TO_NAME[PROP_ID_entityPackageName] = PROP_NAME_entityPackageName;
PROP_NAME_TO_ID.put(PROP_NAME_entityPackageName, PROP_ID_entityPackageName);

PROP_ID_TO_NAME[PROP_ID_mavenGroupId] = PROP_NAME_mavenGroupId;
PROP_NAME_TO_ID.put(PROP_NAME_mavenGroupId, PROP_ID_mavenGroupId);

Expand Down Expand Up @@ -168,6 +175,9 @@ public class _NopDynModule extends DynamicOrmEntity{
/* Java包名: BASE_PACKAGE_NAME */
private java.lang.String _basePackageName;

/* 实体包名: ENTITY_PACKAGE_NAME */
private java.lang.String _entityPackageName;

/* Maven组名: MAVEN_GROUP_ID */
private java.lang.String _mavenGroupId;

Expand Down Expand Up @@ -281,6 +291,9 @@ public Object orm_propValue(int propId) {
case PROP_ID_basePackageName:
return getBasePackageName();

case PROP_ID_entityPackageName:
return getEntityPackageName();

case PROP_ID_mavenGroupId:
return getMavenGroupId();

Expand Down Expand Up @@ -373,6 +386,16 @@ public void orm_propValue(int propId, Object value){
break;
}

case PROP_ID_entityPackageName:{
java.lang.String typedValue = null;
if(value != null){
typedValue = ConvertHelper.toString(value,
err-> newTypeConversionError(PROP_NAME_entityPackageName));
}
setEntityPackageName(typedValue);
break;
}

case PROP_ID_mavenGroupId:{
java.lang.String typedValue = null;
if(value != null){
Expand Down Expand Up @@ -494,6 +517,13 @@ public void orm_internalSet(int propId, Object value) {
break;
}

case PROP_ID_entityPackageName:{
onInitProp(propId);
this._entityPackageName = (java.lang.String)value;

break;
}

case PROP_ID_mavenGroupId:{
onInitProp(propId);
this._mavenGroupId = (java.lang.String)value;
Expand Down Expand Up @@ -663,6 +693,25 @@ public void setBasePackageName(java.lang.String value){
}
}

/**
* 实体包名: ENTITY_PACKAGE_NAME
*/
public java.lang.String getEntityPackageName(){
onPropGet(PROP_ID_entityPackageName);
return _entityPackageName;
}

/**
* 实体包名: ENTITY_PACKAGE_NAME
*/
public void setEntityPackageName(java.lang.String value){
if(onPropSet(PROP_ID_entityPackageName,value)){
this._entityPackageName = value;
internalClearRefs(PROP_ID_entityPackageName);

}
}

/**
* Maven组名: MAVEN_GROUP_ID
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import io.nop.orm.model.IEntityRelationModel;
import io.nop.orm.model.OrmAliasModel;
import io.nop.orm.model.OrmColumnModel;
import io.nop.orm.model.OrmComputePropModel;
import io.nop.orm.model.OrmDomainModel;
import io.nop.orm.model.OrmEntityFilterModel;
import io.nop.orm.model.OrmEntityModel;
Expand All @@ -42,6 +41,7 @@
import io.nop.orm.model.OrmToManyReferenceModel;
import io.nop.orm.model.OrmToOneReferenceModel;
import io.nop.orm.support.DynamicOrmEntity;
import io.nop.orm.support.DynamicOrmKeyValueTable;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -148,6 +148,7 @@ void addExternalExtTable(OrmModel model) {
external.setDisplayName(refModel.getDisplayName());
external.setNotGenCode(true);
external.setName(refModel.getName());
external.setClassName(refModel.getClassName());
for (IColumnModel col : refModel.getColumns()) {
forceAddCol(external, col);
}
Expand All @@ -160,7 +161,7 @@ List<OrmEntityModel> toOrmEntityModels(Collection<NopDynEntityMeta> entityMetas,
return entityMeta.isHasProp() || Boolean.TRUE.equals(entityMeta.getIsExternal());
}).map(this::toOrmEntityModel).collect(Collectors.toList());

addRelationTables(ret, entityMetas, basePackageName);
addMiddleTables(ret, entityMetas, basePackageName);
return ret;
}

Expand Down Expand Up @@ -272,12 +273,6 @@ private void handleRelationMeta(OrmEntityModel entityModel, NopDynEntityRelation
}
}

private void addRefField(OrmEntityModel entityModel, NopDynEntityMeta refEntityMeta, String refPropName) {
NopDynPropMeta propMeta = refEntityMeta.requirePropByName(refPropName);

}


private OrmReferenceModel toRelationModel(NopDynEntityRelationMeta rel) {
OrmReferenceModel ret;
if (rel.isOneToMany()) {
Expand Down Expand Up @@ -474,16 +469,18 @@ protected StdSqlType toStdSqlType(String sqlTypeName) {
return sqlType;
}

protected void addRelationTables(List<OrmEntityModel> ret, Collection<NopDynEntityMeta> entityMetas,
String basePackageName) {
protected void addMiddleTables(List<OrmEntityModel> ret, Collection<NopDynEntityMeta> entityMetas,
String basePackageName) {
middleInfos.forEach((middleName, middleInfo) -> {
middleInfo.sort();

NopDynEntityRelationMeta relA = middleInfo.relationA;
NopDynEntityRelationMeta relB = middleInfo.relationB;

OrmEntityModel middleEntity = new OrmEntityModel();
ret.add(middleEntity);
middleEntity.setName(middleName);
middleEntity.setTagSet(Set.of(OrmModelConstants.TAG_MANY_TO_MANY));
boolean useShareTable = false;

if (relA.getMiddleTableName() != null) {
Expand Down Expand Up @@ -514,22 +511,52 @@ protected void addRelationTables(List<OrmEntityModel> ret, Collection<NopDynEnti
addStdColumns(middleEntity);
}

if (relA != null)
addToManyRelation(middleInfo.entityModelA, middleName, relA);
OrmToOneReferenceModel ref1 = newToOneRef(NopDynDaoConstants.NAME_REF_ENTITY1,
middleInfo.getEntityNameA(),
NopDynEntityRelation.PROP_NAME_entityId1, OrmModelConstants.PROP_ID);
middleEntity.addRelation(ref1);

OrmToOneReferenceModel ref2 = newToOneRef(NopDynDaoConstants.NAME_REF_ENTITY2,
middleInfo.getEntityNameB(),
NopDynEntityRelation.PROP_NAME_entityId2, OrmModelConstants.PROP_ID);
middleEntity.addRelation(ref2);

addToManyRelation(middleInfo.entityModelA, middleName, relA, NopDynEntityRelation.PROP_NAME_entityId1);

if (relB != null)
addToManyRelation(middleInfo.entityModelB, middleName, relB);
addToManyRelation(middleInfo.entityModelB, middleName, relB, NopDynEntityRelation.PROP_NAME_entityId1);
});

}

private void addToManyRelation(OrmEntityModel entityModel, String middleName, NopDynEntityRelationMeta rel) {
private OrmToOneReferenceModel newToOneRef(String propName, String entityName, String leftProp, String rightProp) {
OrmToOneReferenceModel ref = new OrmToOneReferenceModel();
ref.setName(propName);
ref.setDisplayName(propName);
ref.setRefEntityName(entityName);
List<OrmJoinOnModel> joins = new ArrayList<>(1);
OrmJoinOnModel join = new OrmJoinOnModel();
join.setLeftProp(leftProp);
join.setRightProp(rightProp);
joins.add(join);
ref.setJoin(joins);
return ref;
}

private void addToManyRelation(OrmEntityModel entityModel, String middleName, NopDynEntityRelationMeta rel,
String refPropName) {
OrmToManyReferenceModel ref = new OrmToManyReferenceModel();
ref.setName(rel.getRelationName() + "_middle");
ref.setDisplayName(rel.getRelationDisplayName());
ref.setRefEntityName(middleName);
entityModel.addRelation(ref);
List<OrmJoinOnModel> joins = new ArrayList<>(1);
OrmJoinOnModel join = new OrmJoinOnModel();
join.setLeftProp(OrmModelConstants.PROP_ID);
join.setRightProp(refPropName);
joins.add(join);
ref.setJoin(joins);

OrmComputePropModel computed = new OrmComputePropModel();
entityModel.addRelation(ref);
}


Expand All @@ -539,35 +566,4 @@ private OrmEntityFilterModel buildFilter(String propName, String value) {
filter.setValue(value);
return filter;
}


private OrmEntityModel buildVirtualRelationTable(NopDynEntityRelationMeta rel, String basePackageName) {
OrmEntityModel relTable = new OrmEntityModel();
relTable.setClassName(NopDynEntityRelation.class.getName());
relTable.setTableName(dynRelationModel.getTableName());

// String entityName1 = StringHelper.fullClassName(rel.getEntityMeta1().getEntityName(), basePackageName);
// String entityName2 = StringHelper.fullClassName(rel.getEntityMeta2().getEntityName(), basePackageName);
//
// List<OrmEntityFilterModel> filters = new ArrayList<>();
// filters.add(OrmEntityFilterModel.of(NopDynEntityRelation.PROP_NAME_entityName1, entityName1));
// filters.add(OrmEntityFilterModel.of(NopDynEntityRelation.PROP_NAME_entityName2, entityName2));
return relTable;
}


private OrmEntityModel buildRealRelationTable(NopDynEntityRelationMeta rel, String basePackageName) {
OrmEntityModel relTable = new OrmEntityModel();
relTable.setClassName(DynamicOrmEntity.class.getName());
return relTable;
}

private void addJoinRelation(OrmEntityModel relTable, NopDynEntityRelationMeta rel) {
// OrmReferenceModel ref1 = toRelationRefModel(NopDynEntityRelation.PROP_NAME_entityId1,
// rel.getEntity1PropName(), rel.getEntity1DisplayName());
// OrmReferenceModel ref2 = toRelationRefModel(NopDynEntityRelation.PROP_NAME_entityId2,
// rel.getEntity2PropName(), rel.getEntity2DisplayName());
// relTable.addRelation(ref1);
// relTable.addRelation(ref2);
}
}
Loading

0 comments on commit a6147df

Please sign in to comment.