use of org.jooq.impl.ScopeMarker.ScopeContent in project jOOQ by jOOQ.
the class DefaultRenderContext method scopeEnd0.
@Override
void scopeEnd0() {
ScopeMarker[] markers = ScopeMarker.values();
ScopeStackElement[] beforeFirst = new ScopeStackElement[markers.length];
ScopeStackElement[] afterLast = new ScopeStackElement[markers.length];
ScopeContent[] content = new ScopeContent[markers.length];
for (ScopeMarker marker : markers) {
if (!marker.topLevelOnly || subqueryLevel() == 0) {
int i = marker.ordinal();
ScopeContent o = content[i] = (ScopeContent) data(marker.key);
if (o != null && !o.isEmpty()) {
beforeFirst[i] = scopeStack.get(marker.beforeFirst);
afterLast[i] = scopeStack.get(marker.afterLast);
}
}
}
outer: for (ScopeStackElement e1 : scopeStack.iterable(e -> e.scopeLevel == scopeStack.scopeLevel())) {
String replacedSQL = null;
QueryPartList<Param<?>> insertedBindValues = null;
if (e1.positions == null) {
continue outer;
} else // TODO: subqueryLevel() is lower than scopeLevel if we use implicit join in procedural logic
if (e1.joinNode != null && !e1.joinNode.children.isEmpty()) {
replacedSQL = configuration.dsl().renderContext().declareTables(true).sql('(').formatIndentStart(e1.indent).formatIndentStart().formatNewLine().visit(e1.joinNode.joinTree()).formatNewLine().sql(')').render();
} else {
elementLoop: for (int i = 0; i < beforeFirst.length; i++) {
ScopeStackElement e = beforeFirst[i];
ScopeContent c = content[i];
if (e1 == e && c != null) {
DefaultRenderContext ctx = new DefaultRenderContext(this, false);
markers[i].renderer.render((DefaultRenderContext) ctx.formatIndentStart(e.indent), e, afterLast[i], c);
replacedSQL = ctx.render();
insertedBindValues = ctx.bindValues();
break elementLoop;
}
}
}
if (replacedSQL != null) {
sql.replace(e1.positions[0], e1.positions[1], replacedSQL);
int shift = replacedSQL.length() - (e1.positions[1] - e1.positions[0]);
inner: for (ScopeStackElement e2 : scopeStack) {
if (e2.positions == null)
continue inner;
if (e2.positions[0] > e1.positions[0]) {
e2.positions[0] = e2.positions[0] + shift;
e2.positions[1] = e2.positions[1] + shift;
}
}
if (insertedBindValues != null) {
bindValues.addAll(e1.bindIndex - 1, insertedBindValues);
inner: for (ScopeStackElement e2 : scopeStack) {
if (e2.positions == null)
continue inner;
if (e2.bindIndex > e1.bindIndex)
e2.bindIndex = e2.bindIndex + insertedBindValues.size();
}
}
}
}
}
Aggregations