use of org.jooq.Clause.TABLE in project jOOQ by jOOQ.
the class Alias method acceptDeclareAliasStandard.
private final void acceptDeclareAliasStandard(Context<?> context) {
if (wrapped instanceof TableImpl)
context.scopeMarkStart(wrapping);
SQLDialect dialect = context.dialect();
SQLDialect family = context.family();
boolean emulatedDerivedColumnList = false;
// Hence, wrap the table reference in a subselect
if (fieldAliases != null && (SUPPORT_DERIVED_COLUMN_NAMES_SPECIAL1.contains(dialect)) && (wrapped instanceof TableImpl || wrapped instanceof CommonTableExpressionImpl)) {
visitSubquery(context, select(asterisk()).from(((Table<?>) wrapped).as(alias)), true, false, false);
} else // results using UNION ALL
if (fieldAliases != null && (emulatedDerivedColumnList || SUPPORT_DERIVED_COLUMN_NAMES_SPECIAL2.contains(dialect))) {
emulatedDerivedColumnList = true;
if (wrapped instanceof Values && NO_SUPPORT_VALUES.contains(dialect)) {
context.data(DATA_SELECT_ALIASES, fieldAliases, t -> toSQLWrapped(t));
} else {
// [#3156] Do not SELECT * from derived tables to prevent ambiguously defined columns
// in those derived tables
Select<?> wrappedAsSelect = wrapped instanceof Select ? (Select<?>) wrapped : wrapped instanceof DerivedTable ? ((DerivedTable<?>) wrapped).query() : select(asterisk()).from(((Table<?>) wrapped).as(alias));
List<Field<?>> select = wrappedAsSelect.getSelect();
if (emulatedDerivedColumnList) {
SelectFieldList<Field<?>> fields = new SelectFieldList<>();
for (int i = 0; i < fieldAliases.length; i++) {
switch(family) {
default:
fields.add(field("null").as(fieldAliases[i]));
break;
}
}
visitSubquery(context, select(fields).where(falseCondition()).unionAll(wrappedAsSelect), true, false, false);
}
}
} else
// The default behaviour
toSQLWrapped(context);
// [#291] some aliases cause trouble, if they are not explicitly marked using "as"
toSQLAs(context);
context.sql(' ').qualify(false, c -> c.visit(alias));
// [#1801] Add field aliases to the table alias, if applicable
if (fieldAliases != null && !emulatedDerivedColumnList) {
toSQLDerivedColumnList(context);
} else {
// TODO: Is this still needed?
switch(family) {
case HSQLDB:
case POSTGRES:
case YUGABYTEDB:
{
// The javac compiler doesn't like casting of generics
Object o = wrapped;
if (context.declareTables() && o instanceof ArrayTable)
context.sql('(').visit(wrap(((ArrayTable) o).fields()).qualify(false)).sql(')');
break;
}
}
}
if (wrapped instanceof TableImpl)
context.scopeMarkEnd(wrapping);
}
Aggregations