use of com.qlangtech.tis.sql.parser.stream.generate.MergeData in project tis by qlangtech.
the class TableRelation method createSelectParentByChild.
/**
* 通过子记录查询父记录
*
* @param context
*/
public String createSelectParentByChild(MergeData context, FlatTableRelation currentTableRelation, FlatTableRelation nextRelation, PrimaryTableMeta primary) {
String methodToken = nextRelation.getJoinerKeysQueryMethodToken();
context.addGlobalScript(methodToken, nextRelation.buildQueryHeaderByTailerInfo(currentTableRelation.getTailerKeys().stream().map((rr) -> rr.getHeadLinkKey()).collect(Collectors.toSet())));
FuncFormat f = nextRelation.buildInvokeQueryHeaderByTailerInfo();
// 执行处理结果
FuncFormat p = nextRelation.buildInvokeQueryHeaderByTailerInfoResultProcess(primary, currentTableRelation);
f.appendLine(p);
return f.toString();
}
use of com.qlangtech.tis.sql.parser.stream.generate.MergeData in project tis by qlangtech.
the class TableRelation method createParentPKLiteria.
/**
* 生成主表的PK键 scala代码
*
* @param context
* @return
*/
public String createParentPKLiteria(MergeData context) {
Stack<FlatTableRelation> unprocessed = context.getUnprocessedTableRelations();
FlatTableRelation un = null;
try {
FlatTableRelation currentTableRelation = getCurrentTableRelation(true);
PrimaryTableMeta primary = getPrimaryTableMeta(context, currentTableRelation.getHeaderEntity());
LinkKeys pkJoinerKey = null;
for (LinkKeys lk : currentTableRelation.getHeaderKeys()) {
if (StringUtils.equals(lk.getHeadLinkKey(), primary.getDBPrimayKeyName().getName())) {
pkJoinerKey = lk;
}
}
if (!unprocessed.empty()) {
// 连接栈不为空
un = unprocessed.pop();
if (!unprocessed.empty()) {
// FIXME: 或许将来支持更加复杂的增量流式处理,可以支持外表连接
throw new IllegalStateException("un process rel can not exceed 2,but now size:" + unprocessed.size() + "pre:" + un.toString() + ",others:" + unprocessed.stream().map((r) -> r.toString()).collect(Collectors.joining(",")));
}
if (currentTableRelation.isLinkable(un)) {
return primary.createCompositePK(currentTableRelation, un) + "/*gencode1*/";
} else {
// SqlTaskNodeMeta.DependencyNode headerNode = un.getHeader();
return createSelectParentByChild(context, currentTableRelation, un, primary);
}
} else {
TableRelation.FinalLinkKey finalLinkKey = FlatTableRelation.getFinalLinkKey(primary.getDBPrimayKeyName().getName(), currentTableRelation);
if (finalLinkKey.success) {
// 连接栈为空
return "return " + primary.createCompositePK(currentTableRelation) + "/*gencode2*/";
} else {
// 例如:orderDetail是主表,以orderid作为pk,外表totalpayinfo 为外表(连接键为: totalpay_id -> totalpay_id,所以连接过程会中断
return createSelectParentByChild(context, currentTableRelation, currentTableRelation, primary);
}
}
} catch (Exception e) {
throw new RuntimeException("parent:" + this.getParent().parseEntityName() + ",child:" + this.getChild().parseEntityName(), e);
} finally {
context.getUnprocessedTableRelations().clear();
}
}
Aggregations