Skip to content

Commit

Permalink
修正非租户模式下动态模块的查找
Browse files Browse the repository at this point in the history
  • Loading branch information
entropy-cloud committed Aug 23, 2024
1 parent d5c2c54 commit 51ebb7c
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2426,6 +2426,10 @@
"name": "clone",
"parameterTypes": []
},
{
"name": "destroyOnRemove",
"parameterTypes": []
},
{
"name": "expireAfterAccess",
"parameterTypes": [
Expand Down Expand Up @@ -15209,6 +15213,14 @@
"name": "getExpandType",
"parameterTypes": []
},
{
"name": "getExportFormattedValue",
"parameterTypes": []
},
{
"name": "getExportFormula",
"parameterTypes": []
},
{
"name": "getField",
"parameterTypes": []
Expand Down Expand Up @@ -15367,12 +15379,24 @@
"boolean"
]
},
{
"name": "setExportFormattedValue",
"parameterTypes": [
"java.lang.Boolean"
]
},
{
"name": "setExportFormula",
"parameterTypes": [
"boolean"
]
},
{
"name": "setExportFormula",
"parameterTypes": [
"java.lang.Boolean"
]
},
{
"name": "setField",
"parameterTypes": [
Expand Down Expand Up @@ -17805,6 +17829,12 @@
{
"name": "reloadOrmModel",
"parameterTypes": []
},
{
"name": "setOrmModelHolder",
"parameterTypes": [
"io.nop.orm.factory.IOrmModelHolder"
]
}
],
"name": "io.nop.orm.factory.OrmSessionFactoryBean",
Expand Down Expand Up @@ -18857,6 +18887,10 @@
"name": "isTableView",
"parameterTypes": []
},
{
"name": "isTenantModel",
"parameterTypes": []
},
{
"name": "isUseGlobalCache",
"parameterTypes": []
Expand Down Expand Up @@ -19412,6 +19446,10 @@
"name": "isGlobalUniqueId",
"parameterTypes": []
},
{
"name": "isTenantModel",
"parameterTypes": []
},
{
"name": "setDependByOtherEntity",
"parameterTypes": [
Expand All @@ -19430,6 +19468,12 @@
"java.util.List"
]
},
{
"name": "setTenantModel",
"parameterTypes": [
"boolean"
]
},
{
"name": "toString",
"parameterTypes": []
Expand Down
1 change: 0 additions & 1 deletion nop-cli-core/src/main/resources/nop-vfs-index.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@
/nop/report/xlib/xpt-rt.xlib
/nop/report/xlib/xpt.xlib
/nop/rpc/imp/api.imp.xml
/nop/rpc/imp/api.imp.xml.rej
/nop/rpc/imp/template.api.xlsx
/nop/schema/action-auth.xdef
/nop/schema/api.xdef
Expand Down
11 changes: 10 additions & 1 deletion nop-core/src/main/java/io/nop/core/module/ModuleManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public class ModuleManager {

private static ModuleManager _instance = new ModuleManager();

private final AtomicReference<Map<String, ModuleModel>> dynamicModules = new AtomicReference<>();

public static void registerInstance(ModuleManager instance) {
_instance = instance;
}
Expand Down Expand Up @@ -122,6 +124,10 @@ public Map<String, ModuleModel> getEnabledModuleMap(boolean includeTenant) {
ret.putAll(map);
}

Map<String, ModuleModel> dynamics = dynamicModules.get();
if (dynamics != null)
ret.putAll(dynamics);

if (includeTenant) {
String tenantId = getTenantId();
if (!StringHelper.isEmpty(tenantId) && ResourceTenantManager.instance().getTenantModuleDiscovery() != null) {
Expand All @@ -134,9 +140,12 @@ public Map<String, ModuleModel> getEnabledModuleMap(boolean includeTenant) {
return ret;
}

public void updateDynamicModules(Map<String, ModuleModel> dynamicModules) {
this.dynamicModules.set(dynamicModules);
}

public Collection<ModuleModel> getEnabledModules(boolean includeTenant) {
return getEnabledModuleMap(includeTenant).values();

}

public Set<String> getEnabledModuleNames(boolean includeTenant) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@
/nop/dyn/model/NopDynFunctionMeta/_NopDynFunctionMeta.xbiz
/nop/dyn/model/NopDynFunctionMeta/_NopDynFunctionMeta.xmeta
/nop/dyn/model/NopDynModule/NopDynModule.xbiz
/nop/dyn/model/NopDynModule/NopDynModule.xbiz.rej
/nop/dyn/model/NopDynModule/NopDynModule.xmeta
/nop/dyn/model/NopDynModule/_NopDynModule.xbiz
/nop/dyn/model/NopDynModule/_NopDynModule.xmeta
Expand Down Expand Up @@ -1059,6 +1060,7 @@
/nop/web/xlib/view-gen.xlib
/nop/web/xlib/view-gen/impl_GenFromMeta.xpl
/nop/web/xlib/web.xlib
/nop/web/xlib/web.xlib.rej
/nop/web/xlib/web/grid_crud.xpl
/nop/web/xlib/web/impl_GenForm.xpl
/nop/web/xlib/web/impl_GenGrid.xpl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ entity:
NopDynModule: Module Definition
NopDynModuleDep: Module Dependency
NopDynPage: Page Definition
NopDynPatch: Patch
NopDynPatchFile: Patch File
NopDynPropMeta: Property Meta
NopDynSql: Module SQL
prop:
Expand Down Expand Up @@ -271,6 +273,38 @@ prop:
module: Module
module.displayName: Module
pageContentComponent: null
NopDynPatch:
patchId: Patch ID
patchName: Patch Name
patchOrder: Patch Order
displayName: Display Name
status: Status
version: Version
createdBy: Created By
createTime: Create Time
updatedBy: Updated By
updateTime: Update Time
patchFiles: Patch Files
NopDynPatchFile:
fileId: File ID
patchId: Patch ID
moduleId: Module ID
filePath: File Path
fileName: File Name
fileType: File Type
fileLength: File Length
status: Status
status_label: null
version: Version
createdBy: Created By
createTime: Create Time
updatedBy: Updated By
updateTime: Update Time
remark: Remark
module: Module
module.displayName: Module
patch: Patch
patch.displayName: Patch
NopDynPropMeta:
propMetaId: Prop Meta ID
entityMetaId: Entity Meta ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ entity:
NopDynModule: 模块定义
NopDynModuleDep: 模块依赖
NopDynPage: 页面定义
NopDynPatch: 补丁定义
NopDynPatchFile: 补丁文件
NopDynPropMeta: 属性元数据
NopDynSql: SQL定义
prop:
Expand Down Expand Up @@ -271,6 +273,38 @@ prop:
updateTime: 修改时间
updatedBy: 修改人
version: 数据版本
NopDynPatch:
createTime: 创建时间
createdBy: 创建人
displayName: 显示名
patchFiles: 补丁文件
patchId: 补丁ID
patchName: 补丁名
patchOrder: 补丁顺序
status: 状态
updateTime: 修改时间
updatedBy: 修改人
version: 数据版本
NopDynPatchFile:
createTime: 创建时间
createdBy: 创建人
fileId: 文件ID
fileLength: 文件大小
fileName: 文件名称
filePath: 文件路径
fileType: 文件类型
module: 所属模块
module.displayName: 所属模块
moduleId: 模块ID
patch: 所属补丁
patch.displayName: 所属补丁
patchId: 补丁ID
remark: 备注
status: 状态
status_label: 状态
updateTime: 修改时间
updatedBy: 修改人
version: 数据版本
NopDynPropMeta:
createTime: 创建时间
createdBy: 创建人
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.nop.codegen.XCodeGenerator;
import io.nop.commons.util.StringHelper;
import io.nop.core.lang.eval.IEvalScope;
import io.nop.core.module.ModuleManager;
import io.nop.core.module.ModuleModel;
import io.nop.core.resource.IResource;
import io.nop.core.resource.ResourceHelper;
Expand Down Expand Up @@ -257,7 +258,8 @@ public synchronized void generateBizModel(NopDynEntityMeta entityMeta) {
}
}

public synchronized void reloadModel(IOrmSessionFactory ormSessionFactory, IBizObjectManager bizObjectManager) {
public synchronized void reloadModel(IOrmSessionFactory ormSessionFactory,
IBizObjectManager bizObjectManager) {
InMemoryResourceStore merged = new InMemoryResourceStore();

this.moduleCoreStores.values().forEach(merged::merge);
Expand All @@ -272,6 +274,7 @@ public synchronized void reloadModel(IOrmSessionFactory ormSessionFactory, IBizO
ResourceTenantManager.instance().updateTenantResourceStore(tenantId, merged);
} else {
VirtualFileSystem.instance().updateInMemoryLayer(merged);
ModuleManager.instance().updateDynamicModules(dynModules);
}

ormSessionFactory.reloadModel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,21 @@ public class TestDynCodeGen extends JunitBaseTestCase {
@Inject
IGraphQLEngine graphQLEngine;

@Inject
DynOrmModelHolder ormModelHolder; // 单元测试时所有的bean都是延迟初始化,这里引入bean强制要求初始化

@Test
public void testGen() {
saveModule();

ormTemplate.runInSession(() -> {
codeGen.generateForAllModules();

// 更新模型后在当前session中不可见,需要在下一次打开session时才课教案
codeGen.reloadModel();
});

ormTemplate.runInSession(() -> {

IEntityDao<NopDynEntity> dao = daoProvider.dao("MyDynEntity");
dao.findAll();
Expand All @@ -81,6 +89,9 @@ public void testGenBizModel() {
ormTemplate.runInSession(() -> {
codeGen.generateForAllModules();
codeGen.reloadModel();
});

ormTemplate.runInSession(() -> {

NopDynFunctionMeta func = getFuncMeta("myMethod");
func.setSource("return 321");
Expand Down
2 changes: 1 addition & 1 deletion nop-orm/src/main/java/io/nop/orm/IOrmSessionFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,5 @@ ICompiledSql compileSql(String name, String sqlText, boolean disableLogicalDelet

IQueryExecutor getQueryExecutor(String querySpace);

void reloadModel();
ILoadedOrmModel reloadModel();
}
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,8 @@ public Object getBean(String name, boolean mustPrototype) {
}

@Override
public void reloadModel() {
public ILoadedOrmModel reloadModel() {
ormModelHolder.clearCache();
ormModelHolder.getOrmModel(this);
return ormModelHolder.getOrmModel(this);
}
}

0 comments on commit 51ebb7c

Please sign in to comment.