Skip to content

Commit

Permalink
加载ORM模型时允许跳过循环依赖检测
Browse files Browse the repository at this point in the history
  • Loading branch information
entropy-cloud committed Dec 1, 2024
1 parent deaa15a commit 308f42f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
14 changes: 14 additions & 0 deletions nop-orm-model/src/main/java/io/nop/orm/model/OrmModelConfigs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.nop.orm.model;

import io.nop.api.core.annotations.core.Description;
import io.nop.api.core.config.IConfigReference;
import io.nop.api.core.util.SourceLocation;

import static io.nop.api.core.config.AppConfig.varRef;

public interface OrmModelConfigs {
SourceLocation s_loc = SourceLocation.fromClass(OrmModelConfigs.class);

@Description("是否检查实体模型的循环依赖")
IConfigReference<Boolean> CFG_ORM_CHECK_ENTITY_LOOP_DEPENDENCY = varRef(s_loc, "nop.orm.check-entity-loop-dependency", Boolean.class, true);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import io.nop.orm.model.OrmEntityModel;
import io.nop.orm.model.OrmJoinOnModel;
import io.nop.orm.model.OrmModel;
import io.nop.orm.model.OrmModelConfigs;
import io.nop.orm.model.OrmModelConstants;
import io.nop.orm.model.OrmRefSetModel;
import io.nop.orm.model.OrmReferenceModel;
Expand Down Expand Up @@ -489,7 +490,7 @@ void checkRefPrimary(OrmEntityModel entityModel, OrmReferenceModel ref) {
}

private boolean isDynamicRelation(IEntityRelationModel rel) {
if(rel.isDynamicRelation())
if (rel.isDynamicRelation())
return true;

// 左实体没有租户,它关联的实体如果有租户,则不能缓存
Expand All @@ -500,7 +501,7 @@ private boolean isDynamicRelation(IEntityRelationModel rel) {
}

private boolean isRefColAligned(List<? extends IEntityJoinConditionModel> join, List<? extends IColumnModel> cols) {
if(join.size() != cols.size())
if (join.size() != cols.size())
return false;

for (int i = 0, n = join.size(); i < n; i++) {
Expand Down Expand Up @@ -540,7 +541,11 @@ private void initTopoMap() {

if (!it.getRemaining().isEmpty()) {
Set<String> names = it.getRemaining().stream().map(IEntityModel::getName).collect(Collectors.toSet());
throw new NopException(ERR_ORM_MODEL_REF_DEPENDS_CONTAINS_LOOP).param(ARG_LOOP_ENTITY_NAMES, names);
if (OrmModelConfigs.CFG_ORM_CHECK_ENTITY_LOOP_DEPENDENCY.get()) {
throw new NopException(ERR_ORM_MODEL_REF_DEPENDS_CONTAINS_LOOP).param(ARG_LOOP_ENTITY_NAMES, names);
} else {
LOG.warn("nop.orm.entity-dependency-contains-loop:model={},loopEntityNames={}", ormModel.getLocation(), names);
}
}
}

Expand Down

0 comments on commit 308f42f

Please sign in to comment.