use of org.hibernate.sql.ast.tree.from.TableReferenceJoin in project hibernate-orm by hibernate.
the class AbstractSqlAstTranslator method renderTableReferenceJoins.
protected void renderTableReferenceJoins(TableGroup tableGroup) {
final List<TableReferenceJoin> joins = tableGroup.getTableReferenceJoins();
if (joins == null || joins.isEmpty()) {
return;
}
for (TableReferenceJoin tableJoin : joins) {
appendSql(WHITESPACE);
appendSql(tableJoin.getJoinType().getText());
appendSql("join ");
renderNamedTableReference(tableJoin.getJoinedTableReference(), LockMode.NONE);
if (tableJoin.getPredicate() != null && !tableJoin.getPredicate().isEmpty()) {
appendSql(" on ");
tableJoin.getPredicate().accept(this);
}
}
}
use of org.hibernate.sql.ast.tree.from.TableReferenceJoin in project hibernate-orm by hibernate.
the class JoinedSubclassEntityPersister method pruneForSubclasses.
@Override
public void pruneForSubclasses(TableGroup tableGroup, Set<String> treatedEntityNames) {
final Set<TableReference> retainedTableReferences = new HashSet<>(treatedEntityNames.size());
final Set<String> sharedSuperclassTables = new HashSet<>();
final MappingMetamodelImplementor metamodel = getFactory().getRuntimeMetamodels().getMappingMetamodel();
for (String treatedEntityName : treatedEntityNames) {
final JoinedSubclassEntityPersister subPersister = (JoinedSubclassEntityPersister) metamodel.findEntityDescriptor(treatedEntityName);
final String[] subclassTableNames = subPersister.getSubclassTableNames();
// In mathematical terms, sharedSuperclassTables will be the "intersection" of the table names of all treated entities
if (sharedSuperclassTables.isEmpty()) {
for (int i = 0; i < subclassTableNames.length; i++) {
if (subPersister.isClassOrSuperclassTable[i]) {
sharedSuperclassTables.add(subclassTableNames[i]);
}
}
} else {
sharedSuperclassTables.retainAll(Arrays.asList(subclassTableNames));
}
// todo (6.0): no need to resolve all table references, only the ones needed for cardinality
for (String subclassTableName : subclassTableNames) {
retainedTableReferences.add(tableGroup.resolveTableReference(null, subclassTableName, false));
}
}
final List<TableReferenceJoin> tableReferenceJoins = tableGroup.getTableReferenceJoins();
// i.e. with parenthesis around, as that means the table reference joins will be isolated
if (tableGroup.canUseInnerJoins() || tableGroup.isRealTableGroup()) {
final TableReferenceJoin[] oldJoins = tableReferenceJoins.toArray(new TableReferenceJoin[0]);
tableReferenceJoins.clear();
for (TableReferenceJoin oldJoin : oldJoins) {
final NamedTableReference joinedTableReference = oldJoin.getJoinedTableReference();
if (retainedTableReferences.contains(joinedTableReference)) {
if (oldJoin.getJoinType() != SqlAstJoinType.INNER && sharedSuperclassTables.contains(joinedTableReference.getTableExpression())) {
tableReferenceJoins.add(new TableReferenceJoin(true, joinedTableReference, oldJoin.getPredicate()));
} else {
tableReferenceJoins.add(oldJoin);
}
}
}
} else {
tableReferenceJoins.removeIf(join -> !retainedTableReferences.contains(join.getJoinedTableReference()));
}
}
use of org.hibernate.sql.ast.tree.from.TableReferenceJoin in project hibernate-orm by hibernate.
the class SqlTreePrinter method logTableGroupDetails.
private void logTableGroupDetails(TableGroup tableGroup) {
if (tableGroup instanceof LazyTableGroup) {
TableGroup underlyingTableGroup = ((LazyTableGroup) tableGroup).getUnderlyingTableGroup();
if (underlyingTableGroup != null) {
logTableGroupDetails(underlyingTableGroup);
}
return;
}
if (tableGroup.getPrimaryTableReference() instanceof NamedTableReference) {
logWithIndentation("primaryTableReference : %s as %s", tableGroup.getPrimaryTableReference().getTableId(), tableGroup.getPrimaryTableReference().getIdentificationVariable());
} else {
if (tableGroup.getPrimaryTableReference() instanceof ValuesTableReference) {
logWithIndentation("primaryTableReference : values (..) as %s", tableGroup.getPrimaryTableReference().getIdentificationVariable());
} else if (tableGroup.getPrimaryTableReference() instanceof FunctionTableReference) {
logWithIndentation("primaryTableReference : %s(...) as %s", ((FunctionTableReference) tableGroup.getPrimaryTableReference()).getFunctionExpression().getFunctionName(), tableGroup.getPrimaryTableReference().getIdentificationVariable());
} else {
logNode("PrimaryTableReference as " + tableGroup.getPrimaryTableReference().getIdentificationVariable(), () -> {
QueryPart queryPart = ((QueryPartTableReference) tableGroup.getPrimaryTableReference()).getQueryPart();
visitQueryPart(queryPart);
});
}
}
final List<TableReferenceJoin> tableReferenceJoins = tableGroup.getTableReferenceJoins();
if (!tableReferenceJoins.isEmpty()) {
logNode("TableReferenceJoins", () -> {
for (TableReferenceJoin join : tableReferenceJoins) {
logWithIndentation("%s join %s as %s", join.getJoinType().getText(), join.getJoinedTableReference().getTableExpression(), join.getJoinedTableReference().getIdentificationVariable());
}
});
}
final List<TableGroupJoin> nestedTableGroupJoins = tableGroup.getNestedTableGroupJoins();
if (!nestedTableGroupJoins.isEmpty()) {
logNode("NestedTableGroupJoins", () -> tableGroup.visitNestedTableGroupJoins(this::visitTableGroupJoin));
}
final List<TableGroupJoin> tableGroupJoins = tableGroup.getTableGroupJoins();
if (!tableGroupJoins.isEmpty()) {
logNode("TableGroupJoins", () -> tableGroup.visitTableGroupJoins(this::visitTableGroupJoin));
}
}
Aggregations