[jOOQ/jOOQ#10023] Add Table.with(SQL) to allow for plain SQL templating in T-SQL style table hints

This commit is contained in:
Lukas Eder 2020-04-01 12:59:18 +02:00
parent c790c84d99
commit db13cee6d3
3 changed files with 174 additions and 48 deletions

View File

@ -2613,6 +2613,109 @@ public interface Table<R extends Record> extends TableLike<R>, Named {

View File

@ -57,6 +57,7 @@ import static org.jooq.impl.DSL.exists;
// ...
import static org.jooq.impl.DSL.notExists;
import static org.jooq.impl.DSL.selectFrom;
import static org.jooq.impl.DSL.sql;
import static org.jooq.impl.DSL.table;
import static org.jooq.impl.DSL.val;
import static org.jooq.impl.Tools.EMPTY_FIELD;
@ -1012,6 +1013,22 @@ abstract class AbstractTable<R extends Record> extends AbstractNamed implements

View File

@ -37,63 +37,69 @@
*/
package org.jooq.impl;
import static org.jooq.impl.Keywords.K_WITH;
import org.jooq.Context;
import org.jooq.Name;
import org.jooq.Record;
import org.jooq.Table;
/**
* @author Lukas Eder
*/
final class WithTable<R extends Record> extends AbstractTable<R> {
/**
* Generated UID
*/
private static final long serialVersionUID = -3905775637768497535L;
private final AbstractTable<R> delegate;
private final String hint;
WithTable(AbstractTable<R> delegate, String hint) {
super(delegate.getOptions(), delegate.getQualifiedName(), delegate.getSchema());
this.delegate = delegate;
this.hint = hint;
}
@Override
public final boolean declaresTables() {
return true;
}
@Override
public final void accept(Context<?> ctx) {
ctx.visit(delegate)
.sql(' ').visit(K_WITH)
.sql(" (").sql(hint)
.sql(')');
}
@Override
public final Class<? extends R> getRecordType() {
return delegate.getRecordType();
}
@Override
public final Table<R> as(Name alias) {
return new WithTable<>(new TableAlias<>(delegate, alias), hint);
}
@Override
public final Table<R> as(Name alias, Name... fieldAliases) {
return new WithTable<>(new TableAlias<>(delegate, alias, fieldAliases), hint);
}
@Override
final Fields<R> fields0() {
return delegate.fields0();
}
}