use of com.qlangtech.tis.sql.parser.er.ERRules.$ in project tis by qlangtech.
the class OfflineDatasourceAction method doGetErRule.
/**
* 取得ER关系规则
*
* @param context
* @throws Exception
*/
public void doGetErRule(Context context) throws Exception {
String topology = this.getString("topology");
// 强制同步,时间长了,toplolog上会新加一些数据表,导致ER规则和现有topology不同步,需要同步一下
boolean forceSync = this.getBoolean("sync");
if (StringUtils.isEmpty(topology)) {
throw new IllegalArgumentException("param 'topology' can not be null");
}
ERRules erRule = null;
if (!ERRules.ruleExist(topology)) {
// 还没有创建ER规则
erRule = new ERRules();
for (DependencyNode node : getDumpNodesFromTopology(topology)) {
erRule.addDumpNode(node);
}
} else {
erRule = ERRules.getErRule(topology).get();
final List<DependencyNode> oldErRules = erRule.getDumpNodes();
if (forceSync) {
List<DependencyNode> dumpNodes = getDumpNodesFromTopology(topology);
/**
* *************************************
* 需要添加的节点
* ***************************************
*/
List<DependencyNode> shallBeAdd = dumpNodes.stream().filter((n) -> !oldErRules.stream().filter((old) -> StringUtils.equals(n.getTabid(), old.getTabid())).findAny().isPresent()).collect(Collectors.toList());
/**
* *************************************
* 需要删除的节点
* ***************************************
*/
Iterator<DependencyNode> it = oldErRules.iterator();
while (it.hasNext()) {
DependencyNode old = it.next();
if (!dumpNodes.stream().filter((n) -> StringUtils.equals(n.getTabid(), old.getTabid())).findAny().isPresent()) {
it.remove();
}
}
oldErRules.addAll(shallBeAdd);
}
}
this.setBizResult(context, erRule);
}
use of com.qlangtech.tis.sql.parser.er.ERRules.$ in project tis by qlangtech.
the class TestCoreAction method createMockErRules.
public ERRules createMockErRules(TableMeta totalpayMeta) {
ERRules erRules = mock("erRules", ERRules.class);
if (totalpayMeta != null) {
TabExtraMeta extraMeta = new TabExtraMeta();
extraMeta.setSharedKey(totalpayMeta.getSharedKey());
PrimaryTableMeta tabMeta = new PrimaryTableMeta(totalpayMeta.getTabName(), extraMeta);
EasyMock.expect(erRules.getPrimaryTabs()).andReturn(Lists.newArrayList(tabMeta)).anyTimes();
} else {
EasyMock.expect(erRules.getPrimaryTabs()).andReturn(Collections.emptyList()).anyTimes();
}
MockERRulesGetter.erRules = erRules;
return erRules;
}
Aggregations