Simplify TableJoin to only allow the distinction between inner and left joins
This commit is contained in:
parent
1988ffa310
commit
ab954925e4
|
@ -1356,7 +1356,7 @@ public abstract class AbstractEntityPersister
|
||||||
);
|
);
|
||||||
|
|
||||||
return new TableReferenceJoin(
|
return new TableReferenceJoin(
|
||||||
determineSubclassTableJoinType(
|
shouldInnerJoinSubclassTable(
|
||||||
i,
|
i,
|
||||||
Collections.emptySet()
|
Collections.emptySet()
|
||||||
),
|
),
|
||||||
|
@ -1404,7 +1404,7 @@ public abstract class AbstractEntityPersister
|
||||||
lhs,
|
lhs,
|
||||||
joinTableExpression,
|
joinTableExpression,
|
||||||
sqlAliasBase,
|
sqlAliasBase,
|
||||||
determineSubclassTableJoinType( i, Collections.emptySet() ),
|
shouldInnerJoinSubclassTable( i, Collections.emptySet() ),
|
||||||
getSubclassTableKeyColumns( i ),
|
getSubclassTableKeyColumns( i ),
|
||||||
sqlExpressionResolver
|
sqlExpressionResolver
|
||||||
);
|
);
|
||||||
|
@ -1418,18 +1418,18 @@ public abstract class AbstractEntityPersister
|
||||||
TableReference lhs,
|
TableReference lhs,
|
||||||
String joinTableExpression,
|
String joinTableExpression,
|
||||||
SqlAliasBase sqlAliasBase,
|
SqlAliasBase sqlAliasBase,
|
||||||
SqlAstJoinType joinType,
|
boolean innerJoin,
|
||||||
String[] targetColumns,
|
String[] targetColumns,
|
||||||
SqlExpressionResolver sqlExpressionResolver) {
|
SqlExpressionResolver sqlExpressionResolver) {
|
||||||
final NamedTableReference joinedTableReference = new NamedTableReference(
|
final NamedTableReference joinedTableReference = new NamedTableReference(
|
||||||
joinTableExpression,
|
joinTableExpression,
|
||||||
sqlAliasBase.generateNewAlias(),
|
sqlAliasBase.generateNewAlias(),
|
||||||
joinType != SqlAstJoinType.INNER,
|
!innerJoin,
|
||||||
getFactory()
|
getFactory()
|
||||||
);
|
);
|
||||||
|
|
||||||
return new TableReferenceJoin(
|
return new TableReferenceJoin(
|
||||||
joinType,
|
innerJoin,
|
||||||
joinedTableReference,
|
joinedTableReference,
|
||||||
generateJoinPredicate(
|
generateJoinPredicate(
|
||||||
lhs,
|
lhs,
|
||||||
|
@ -4062,7 +4062,7 @@ public abstract class AbstractEntityPersister
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected SqlAstJoinType determineSubclassTableJoinType(
|
protected boolean shouldInnerJoinSubclassTable(
|
||||||
int subclassTableNumber,
|
int subclassTableNumber,
|
||||||
Set<String> treatAsDeclarations) {
|
Set<String> treatAsDeclarations) {
|
||||||
if ( isClassOrSuperclassJoin( subclassTableNumber ) ) {
|
if ( isClassOrSuperclassJoin( subclassTableNumber ) ) {
|
||||||
|
@ -4070,7 +4070,7 @@ public abstract class AbstractEntityPersister
|
||||||
&& !isNullableTable( subclassTableNumber );
|
&& !isNullableTable( subclassTableNumber );
|
||||||
// the table is either this persister's driving table or (one of) its super class persister's driving
|
// the table is either this persister's driving table or (one of) its super class persister's driving
|
||||||
// tables which can be inner joined as long as the `shouldInnerJoin` condition resolves to true
|
// tables which can be inner joined as long as the `shouldInnerJoin` condition resolves to true
|
||||||
return shouldInnerJoin ? SqlAstJoinType.INNER : SqlAstJoinType.LEFT;
|
return shouldInnerJoin;
|
||||||
}
|
}
|
||||||
|
|
||||||
// otherwise we have a subclass table and need to look a little deeper...
|
// otherwise we have a subclass table and need to look a little deeper...
|
||||||
|
@ -4080,10 +4080,10 @@ public abstract class AbstractEntityPersister
|
||||||
// so we give TREAT-AS higher precedence...
|
// so we give TREAT-AS higher precedence...
|
||||||
|
|
||||||
if ( isSubclassTableIndicatedByTreatAsDeclarations( subclassTableNumber, treatAsDeclarations ) ) {
|
if ( isSubclassTableIndicatedByTreatAsDeclarations( subclassTableNumber, treatAsDeclarations ) ) {
|
||||||
return SqlAstJoinType.INNER;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return SqlAstJoinType.LEFT;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isSubclassTableIndicatedByTreatAsDeclarations(
|
protected boolean isSubclassTableIndicatedByTreatAsDeclarations(
|
||||||
|
|
|
@ -1346,7 +1346,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
|
||||||
&& sharedSuperclassTables.contains( joinedTableReference.getTableExpression() ) ) {
|
&& sharedSuperclassTables.contains( joinedTableReference.getTableExpression() ) ) {
|
||||||
tableReferenceJoins.add(
|
tableReferenceJoins.add(
|
||||||
new TableReferenceJoin(
|
new TableReferenceJoin(
|
||||||
SqlAstJoinType.INNER,
|
true,
|
||||||
joinedTableReference,
|
joinedTableReference,
|
||||||
oldJoin.getPredicate()
|
oldJoin.getPredicate()
|
||||||
)
|
)
|
||||||
|
|
|
@ -19,25 +19,19 @@ import org.hibernate.sql.ast.tree.predicate.PredicateContainer;
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class TableReferenceJoin implements TableJoin, PredicateContainer {
|
public class TableReferenceJoin implements TableJoin, PredicateContainer {
|
||||||
private final SqlAstJoinType sqlAstJoinType;
|
private final boolean innerJoin;
|
||||||
private final NamedTableReference joinedTableBinding;
|
private final NamedTableReference joinedTableBinding;
|
||||||
private Predicate predicate;
|
private Predicate predicate;
|
||||||
|
|
||||||
public TableReferenceJoin(SqlAstJoinType sqlAstJoinType, NamedTableReference joinedTableBinding, Predicate predicate) {
|
public TableReferenceJoin(boolean innerJoin, NamedTableReference joinedTableBinding, Predicate predicate) {
|
||||||
this.sqlAstJoinType = sqlAstJoinType == null ? SqlAstJoinType.LEFT : sqlAstJoinType;
|
this.innerJoin = innerJoin;
|
||||||
this.joinedTableBinding = joinedTableBinding;
|
this.joinedTableBinding = joinedTableBinding;
|
||||||
this.predicate = predicate;
|
this.predicate = predicate;
|
||||||
|
|
||||||
// if ( joinType == JoinType.CROSS ) {
|
|
||||||
// if ( predicate != null ) {
|
|
||||||
// throw new IllegalJoinSpecificationException( "Cross join cannot include join predicate" );
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SqlAstJoinType getJoinType() {
|
public SqlAstJoinType getJoinType() {
|
||||||
return sqlAstJoinType;
|
return innerJoin ? SqlAstJoinType.INNER : SqlAstJoinType.LEFT;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NamedTableReference getJoinedTableReference() {
|
public NamedTableReference getJoinedTableReference() {
|
||||||
|
|
Loading…
Reference in New Issue