HHH-16733 Reuse correct navigable path for correlated and treated copy

This commit is contained in:
Marco Belladelli 2023-06-26 12:45:20 +02:00
parent c06d6053b3
commit c1c912d034
17 changed files with 206 additions and 16 deletions

View File

@ -47,7 +47,7 @@ public class SqmCorrelatedBagJoin<O, T> extends SqmBagJoin<O, T> implements SqmC
NodeBuilder nodeBuilder,
SqmCorrelatedRootJoin<O> correlatedRootJoin,
SqmBagJoin<O, T> correlationParent) {
super( lhs, attribute, alias, sqmJoinType, fetched, nodeBuilder );
super( lhs, correlationParent.getNavigablePath(), attribute, alias, sqmJoinType, fetched, nodeBuilder );
this.correlatedRootJoin = correlatedRootJoin;
this.correlationParent = correlationParent;
}

View File

@ -39,7 +39,7 @@ public class SqmCorrelatedCrossJoin<T> extends SqmCrossJoin<T> implements SqmCor
SqmRoot<?> sqmRoot,
SqmCorrelatedRootJoin<T> correlatedRootJoin,
SqmCrossJoin<T> correlationParent) {
super( joinedEntityDescriptor, alias, sqmRoot );
super( correlationParent.getNavigablePath(), joinedEntityDescriptor, alias, sqmRoot );
this.correlatedRootJoin = correlatedRootJoin;
this.correlationParent = correlationParent;
}

View File

@ -42,7 +42,7 @@ public class SqmCorrelatedEntityJoin<T> extends SqmEntityJoin<T> implements SqmC
SqmRoot<?> sqmRoot,
SqmCorrelatedRootJoin<T> correlatedRootJoin,
SqmEntityJoin<T> correlationParent) {
super( joinedEntityDescriptor, alias, joinType, sqmRoot );
super( correlationParent.getNavigablePath(), joinedEntityDescriptor, alias, joinType, sqmRoot );
this.correlatedRootJoin = correlatedRootJoin;
this.correlationParent = correlationParent;
}

View File

@ -47,7 +47,7 @@ public class SqmCorrelatedListJoin<O, T> extends SqmListJoin<O, T> implements Sq
NodeBuilder nodeBuilder,
SqmCorrelatedRootJoin<O> correlatedRootJoin,
SqmListJoin<O, T> correlationParent) {
super( lhs, attribute, alias, sqmJoinType, fetched, nodeBuilder );
super( lhs, correlationParent.getNavigablePath(), attribute, alias, sqmJoinType, fetched, nodeBuilder );
this.correlatedRootJoin = correlatedRootJoin;
this.correlationParent = correlationParent;
}

View File

@ -47,7 +47,7 @@ public class SqmCorrelatedMapJoin<O, K, V> extends SqmMapJoin<O, K, V> implement
NodeBuilder nodeBuilder,
SqmCorrelatedRootJoin<O> correlatedRootJoin,
SqmMapJoin<O, K, V> correlationParent) {
super( lhs, attribute, alias, sqmJoinType, fetched, nodeBuilder );
super( lhs, correlationParent.getNavigablePath(), attribute, alias, sqmJoinType, fetched, nodeBuilder );
this.correlatedRootJoin = correlatedRootJoin;
this.correlationParent = correlationParent;
}

View File

@ -47,7 +47,7 @@ public class SqmCorrelatedSetJoin<O, T> extends SqmSetJoin<O, T> implements SqmC
NodeBuilder nodeBuilder,
SqmCorrelatedRootJoin<O> correlatedRootJoin,
SqmSetJoin<O, T> correlationParent) {
super( lhs, attribute, alias, sqmJoinType, fetched, nodeBuilder );
super( lhs, correlationParent.getNavigablePath(), attribute, alias, sqmJoinType, fetched, nodeBuilder );
this.correlatedRootJoin = correlatedRootJoin;
this.correlationParent = correlationParent;
}

View File

@ -47,7 +47,7 @@ public class SqmCorrelatedSingularJoin<O, T> extends SqmSingularJoin<O, T> imple
NodeBuilder nodeBuilder,
SqmCorrelatedRootJoin<O> correlatedRootJoin,
SqmSingularJoin<O, T> correlationParent) {
super( lhs, joinedNavigable, alias, joinType, fetched, nodeBuilder );
super( lhs, correlationParent.getNavigablePath(), joinedNavigable, alias, joinType, fetched, nodeBuilder );
this.correlatedRootJoin = correlatedRootJoin;
this.correlationParent = correlationParent;
}

View File

@ -12,7 +12,7 @@ import org.hibernate.query.hql.spi.SqmCreationProcessingState;
import org.hibernate.query.sqm.SqmPathSource;
import org.hibernate.query.sqm.tree.SqmCopyContext;
import org.hibernate.query.sqm.tree.from.SqmAttributeJoin;
import org.hibernate.query.sqm.tree.from.SqmJoin;
import org.hibernate.spi.NavigablePath;
/**
* @author Steve Ebersole
@ -42,6 +42,28 @@ public class SqmTreatedBagJoin<O,T, S extends T> extends SqmBagJoin<O,S> impleme
this.wrappedPath = wrappedPath;
}
private SqmTreatedBagJoin(
NavigablePath navigablePath,
SqmBagJoin<O, T> wrappedPath,
EntityDomainType<S> treatTarget,
String alias) {
//noinspection unchecked
super(
wrappedPath.getLhs(),
wrappedPath.getNavigablePath().treatAs(
treatTarget.getHibernateEntityName(),
alias
),
(BagPersistentAttribute<O, S>) wrappedPath.getAttribute(),
alias,
wrappedPath.getSqmJoinType(),
wrappedPath.isFetched(),
wrappedPath.nodeBuilder()
);
this.treatTarget = treatTarget;
this.wrappedPath = wrappedPath;
}
@Override
public SqmTreatedBagJoin<O, T, S> copy(SqmCopyContext context) {
final SqmTreatedBagJoin<O, T, S> existing = context.getCopy( this );
@ -51,6 +73,7 @@ public class SqmTreatedBagJoin<O,T, S extends T> extends SqmBagJoin<O,S> impleme
final SqmTreatedBagJoin<O, T, S> path = context.registerCopy(
this,
new SqmTreatedBagJoin<>(
getNavigablePath(),
wrappedPath.copy( context ),
treatTarget,
getExplicitAlias()

View File

@ -10,7 +10,7 @@ import org.hibernate.metamodel.model.domain.EntityDomainType;
import org.hibernate.query.sqm.SqmPathSource;
import org.hibernate.query.sqm.tree.SqmCopyContext;
import org.hibernate.query.sqm.tree.from.SqmCrossJoin;
import org.hibernate.query.sqm.tree.from.SqmJoin;
import org.hibernate.spi.NavigablePath;
/**
* @author Steve Ebersole
@ -34,6 +34,22 @@ public class SqmTreatedCrossJoin<T, S extends T> extends SqmCrossJoin<S> impleme
this.treatTarget = treatTarget;
}
private SqmTreatedCrossJoin(
NavigablePath navigablePath,
SqmCrossJoin<T> wrappedPath,
EntityDomainType<S> treatTarget,
String alias) {
//noinspection unchecked
super(
navigablePath,
(EntityDomainType<S>) wrappedPath.getReferencedPathSource().getSqmPathType(),
alias,
wrappedPath.getRoot()
);
this.wrappedPath = wrappedPath;
this.treatTarget = treatTarget;
}
@Override
public SqmTreatedCrossJoin<T, S> copy(SqmCopyContext context) {
final SqmTreatedCrossJoin<T, S> existing = context.getCopy( this );
@ -43,6 +59,7 @@ public class SqmTreatedCrossJoin<T, S extends T> extends SqmCrossJoin<S> impleme
final SqmTreatedCrossJoin<T, S> path = context.registerCopy(
this,
new SqmTreatedCrossJoin<>(
getNavigablePath(),
wrappedPath.copy( context ),
treatTarget,
getExplicitAlias()

View File

@ -10,7 +10,7 @@ import org.hibernate.metamodel.model.domain.EntityDomainType;
import org.hibernate.query.sqm.SqmPathSource;
import org.hibernate.query.sqm.tree.SqmCopyContext;
import org.hibernate.query.sqm.tree.from.SqmEntityJoin;
import org.hibernate.query.sqm.tree.from.SqmJoin;
import org.hibernate.spi.NavigablePath;
/**
* @author Steve Ebersole
@ -37,6 +37,22 @@ public class SqmTreatedEntityJoin<T, S extends T> extends SqmEntityJoin<S> imple
this.treatTarget = treatTarget;
}
private SqmTreatedEntityJoin(
NavigablePath navigablePath,
SqmEntityJoin<T> wrappedPath,
EntityDomainType<S> treatTarget,
String alias) {
super(
navigablePath,
treatTarget,
alias,
wrappedPath.getSqmJoinType(),
wrappedPath.getRoot()
);
this.wrappedPath = wrappedPath;
this.treatTarget = treatTarget;
}
@Override
public SqmTreatedEntityJoin<T, S> copy(SqmCopyContext context) {
final SqmTreatedEntityJoin<T, S> existing = context.getCopy( this );
@ -46,6 +62,7 @@ public class SqmTreatedEntityJoin<T, S extends T> extends SqmEntityJoin<S> imple
final SqmTreatedEntityJoin<T, S> path = context.registerCopy(
this,
new SqmTreatedEntityJoin<>(
getNavigablePath(),
wrappedPath.copy( context ),
treatTarget,
getExplicitAlias()

View File

@ -14,7 +14,7 @@ import org.hibernate.query.sqm.SqmPathSource;
import org.hibernate.query.sqm.tree.SqmCopyContext;
import org.hibernate.query.sqm.tree.expression.SqmExpression;
import org.hibernate.query.sqm.tree.from.SqmAttributeJoin;
import org.hibernate.query.sqm.tree.from.SqmJoin;
import org.hibernate.spi.NavigablePath;
/**
* @author Steve Ebersole
@ -44,6 +44,25 @@ public class SqmTreatedListJoin<O,T, S extends T> extends SqmListJoin<O,S> imple
this.wrappedPath = wrappedPath;
}
private SqmTreatedListJoin(
NavigablePath navigablePath,
SqmListJoin<O, T> wrappedPath,
EntityDomainType<S> treatTarget,
String alias) {
//noinspection unchecked
super(
wrappedPath.getLhs(),
navigablePath,
(ListPersistentAttribute<O, S>) wrappedPath.getAttribute(),
alias,
wrappedPath.getSqmJoinType(),
wrappedPath.isFetched(),
wrappedPath.nodeBuilder()
);
this.treatTarget = treatTarget;
this.wrappedPath = wrappedPath;
}
@Override
public SqmTreatedListJoin<O, T, S> copy(SqmCopyContext context) {
final SqmTreatedListJoin<O, T, S> existing = context.getCopy( this );
@ -53,6 +72,7 @@ public class SqmTreatedListJoin<O,T, S extends T> extends SqmListJoin<O,S> imple
final SqmTreatedListJoin<O, T, S> path = context.registerCopy(
this,
new SqmTreatedListJoin<>(
getNavigablePath(),
wrappedPath.copy( context ),
treatTarget,
getExplicitAlias()

View File

@ -10,7 +10,7 @@ import org.hibernate.metamodel.model.domain.EntityDomainType;
import org.hibernate.query.hql.spi.SqmCreationProcessingState;
import org.hibernate.query.sqm.SqmPathSource;
import org.hibernate.query.sqm.tree.SqmCopyContext;
import org.hibernate.query.sqm.tree.from.SqmJoin;
import org.hibernate.spi.NavigablePath;
/**
* @author Steve Ebersole
@ -40,6 +40,25 @@ public class SqmTreatedMapJoin<O, K, V, S extends V> extends SqmMapJoin<O, K, S>
this.wrappedPath = wrappedPath;
}
private SqmTreatedMapJoin(
NavigablePath navigablePath,
SqmMapJoin<O, K, V> wrappedPath,
EntityDomainType<S> treatTarget,
String alias) {
//noinspection unchecked
super(
wrappedPath.getLhs(),
navigablePath,
( (SqmMapJoin<O, K, S>) wrappedPath ).getModel(),
alias,
wrappedPath.getSqmJoinType(),
wrappedPath.isFetched(),
wrappedPath.nodeBuilder()
);
this.treatTarget = treatTarget;
this.wrappedPath = wrappedPath;
}
@Override
public SqmTreatedMapJoin<O, K, V, S> copy(SqmCopyContext context) {
final SqmTreatedMapJoin<O, K, V, S> existing = context.getCopy( this );
@ -49,6 +68,7 @@ public class SqmTreatedMapJoin<O, K, V, S extends V> extends SqmMapJoin<O, K, S>
final SqmTreatedMapJoin<O, K, V, S> path = context.registerCopy(
this,
new SqmTreatedMapJoin<>(
getNavigablePath(),
wrappedPath.copy( context ),
treatTarget,
getExplicitAlias()

View File

@ -10,7 +10,7 @@ import org.hibernate.metamodel.model.domain.EntityDomainType;
import org.hibernate.query.sqm.SqmPathSource;
import org.hibernate.query.sqm.tree.SqmCopyContext;
import org.hibernate.query.sqm.tree.from.SqmFrom;
import org.hibernate.query.sqm.tree.from.SqmJoin;
import org.hibernate.spi.NavigablePath;
/**
* @author Steve Ebersole
@ -39,6 +39,24 @@ public class SqmTreatedPluralPartJoin<O,T, S extends T> extends SqmPluralPartJoi
this.wrappedPath = wrappedPath;
}
private SqmTreatedPluralPartJoin(
NavigablePath navigablePath,
SqmPluralPartJoin<O,T> wrappedPath,
EntityDomainType<S> treatTarget,
String alias) {
//noinspection unchecked
super(
(SqmFrom<?, O>) wrappedPath.getLhs(),
navigablePath,
(SqmPathSource<S>) wrappedPath.getReferencedPathSource(),
alias,
wrappedPath.getSqmJoinType(),
wrappedPath.nodeBuilder()
);
this.treatTarget = treatTarget;
this.wrappedPath = wrappedPath;
}
@Override
public SqmTreatedPluralPartJoin<O, T, S> copy(SqmCopyContext context) {
final SqmTreatedPluralPartJoin<O, T, S> existing = context.getCopy( this );
@ -48,6 +66,7 @@ public class SqmTreatedPluralPartJoin<O,T, S extends T> extends SqmPluralPartJoi
final SqmTreatedPluralPartJoin<O, T, S> path = context.registerCopy(
this,
new SqmTreatedPluralPartJoin<>(
getNavigablePath(),
wrappedPath.copy( context ),
treatTarget,
getExplicitAlias()

View File

@ -11,8 +11,8 @@ import org.hibernate.query.hql.spi.SqmCreationState;
import org.hibernate.query.sqm.SemanticQueryWalker;
import org.hibernate.query.sqm.SqmPathSource;
import org.hibernate.query.sqm.tree.SqmCopyContext;
import org.hibernate.query.sqm.tree.from.SqmJoin;
import org.hibernate.query.sqm.tree.from.SqmRoot;
import org.hibernate.spi.NavigablePath;
/**
* @author Steve Ebersole
@ -37,6 +37,21 @@ public class SqmTreatedRoot<T, S extends T> extends SqmRoot<S> implements SqmTre
this.treatTarget = treatTarget;
}
@SuppressWarnings({ "unchecked", "rawtypes" })
private SqmTreatedRoot(
NavigablePath navigablePath,
SqmRoot<T> wrappedPath,
EntityDomainType<S> treatTarget) {
super(
navigablePath,
(EntityDomainType) wrappedPath.getReferencedPathSource(),
null,
wrappedPath.nodeBuilder()
);
this.wrappedPath = wrappedPath;
this.treatTarget = treatTarget;
}
@Override
public SqmRoot<S> copy(SqmCopyContext context) {
final SqmTreatedRoot<T, S> existing = context.getCopy( this );
@ -46,6 +61,7 @@ public class SqmTreatedRoot<T, S extends T> extends SqmRoot<S> implements SqmTre
final SqmTreatedRoot<T, S> path = context.registerCopy(
this,
new SqmTreatedRoot<>(
getNavigablePath(),
wrappedPath.copy( context ),
treatTarget
)

View File

@ -12,7 +12,7 @@ import org.hibernate.query.hql.spi.SqmCreationProcessingState;
import org.hibernate.query.sqm.SqmPathSource;
import org.hibernate.query.sqm.tree.SqmCopyContext;
import org.hibernate.query.sqm.tree.from.SqmAttributeJoin;
import org.hibernate.query.sqm.tree.from.SqmJoin;
import org.hibernate.spi.NavigablePath;
/**
* @author Steve Ebersole
@ -42,6 +42,25 @@ public class SqmTreatedSetJoin<O,T, S extends T> extends SqmSetJoin<O,S> impleme
this.wrappedPath = wrappedPath;
}
private SqmTreatedSetJoin(
NavigablePath navigablePath,
SqmSetJoin<O, T> wrappedPath,
EntityDomainType<S> treatTarget,
String alias) {
//noinspection unchecked
super(
wrappedPath.getLhs(),
navigablePath,
(SetPersistentAttribute<O, S>) wrappedPath.getAttribute(),
alias,
wrappedPath.getSqmJoinType(),
wrappedPath.isFetched(),
wrappedPath.nodeBuilder()
);
this.treatTarget = treatTarget;
this.wrappedPath = wrappedPath;
}
@Override
public SqmTreatedSetJoin<O, T, S> copy(SqmCopyContext context) {
final SqmTreatedSetJoin<O, T, S> existing = context.getCopy( this );
@ -51,6 +70,7 @@ public class SqmTreatedSetJoin<O,T, S extends T> extends SqmSetJoin<O,S> impleme
final SqmTreatedSetJoin<O, T, S> path = context.registerCopy(
this,
new SqmTreatedSetJoin<>(
getNavigablePath(),
wrappedPath.copy( context ),
treatTarget,
getExplicitAlias()

View File

@ -12,6 +12,7 @@ import org.hibernate.query.sqm.NodeBuilder;
import org.hibernate.query.sqm.SemanticQueryWalker;
import org.hibernate.query.sqm.SqmPathSource;
import org.hibernate.query.sqm.tree.SqmCopyContext;
import org.hibernate.spi.NavigablePath;
/**
* @author Steve Ebersole
@ -57,6 +58,22 @@ public class SqmTreatedSimplePath<T, S extends T>
this.wrappedPath = wrappedPath;
}
private SqmTreatedSimplePath(
NavigablePath navigablePath,
SqmPath<T> wrappedPath,
EntityDomainType<S> treatTarget,
NodeBuilder nodeBuilder) {
//noinspection unchecked
super(
navigablePath,
(SqmPathSource<S>) wrappedPath.getReferencedPathSource(),
wrappedPath.getLhs(),
nodeBuilder
);
this.treatTarget = treatTarget;
this.wrappedPath = wrappedPath;
}
@Override
public SqmTreatedSimplePath<T, S> copy(SqmCopyContext context) {
final SqmTreatedSimplePath<T, S> existing = context.getCopy( this );
@ -67,6 +84,7 @@ public class SqmTreatedSimplePath<T, S extends T>
final SqmTreatedSimplePath<T, S> path = context.registerCopy(
this,
new SqmTreatedSimplePath<>(
getNavigablePath(),
wrappedPath.copy( context ),
getTreatTarget(),
nodeBuilder()

View File

@ -12,7 +12,7 @@ import org.hibernate.query.hql.spi.SqmCreationProcessingState;
import org.hibernate.query.sqm.SqmPathSource;
import org.hibernate.query.sqm.tree.SqmCopyContext;
import org.hibernate.query.sqm.tree.from.SqmAttributeJoin;
import org.hibernate.query.sqm.tree.from.SqmJoin;
import org.hibernate.spi.NavigablePath;
/**
* @author Steve Ebersole
@ -42,6 +42,25 @@ public class SqmTreatedSingularJoin<O,T, S extends T> extends SqmSingularJoin<O,
this.wrappedPath = wrappedPath;
}
private SqmTreatedSingularJoin(
NavigablePath navigablePath,
SqmSingularJoin<O,T> wrappedPath,
EntityDomainType<S> treatTarget,
String alias) {
//noinspection unchecked
super(
wrappedPath.getLhs(),
navigablePath,
(SingularPersistentAttribute<O, S>) wrappedPath.getAttribute(),
alias,
wrappedPath.getSqmJoinType(),
wrappedPath.isFetched(),
wrappedPath.nodeBuilder()
);
this.treatTarget = treatTarget;
this.wrappedPath = wrappedPath;
}
@Override
public SqmTreatedSingularJoin<O, T, S> copy(SqmCopyContext context) {
final SqmTreatedSingularJoin<O, T, S> existing = context.getCopy( this );
@ -51,6 +70,7 @@ public class SqmTreatedSingularJoin<O,T, S extends T> extends SqmSingularJoin<O,
final SqmTreatedSingularJoin<O, T, S> path = context.registerCopy(
this,
new SqmTreatedSingularJoin<>(
getNavigablePath(),
wrappedPath.copy( context ),
treatTarget,
getExplicitAlias()