6 - SQM based on JPA type system

This commit is contained in:
Andrea Boriero 2019-05-23 18:02:10 +01:00
parent 70334e44e1
commit 2748b34a11
14 changed files with 134 additions and 21 deletions

View File

@ -26,4 +26,6 @@ public interface SqmJoinable {
String alias,
boolean fetched,
SqmCreationState creationState);
String getName();
}

View File

@ -13,7 +13,6 @@ import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.internal.util.collections.Stack;
import org.hibernate.metamodel.model.domain.EntityDomainType;
import org.hibernate.metamodel.model.domain.SingularPersistentAttribute;
import org.hibernate.query.NavigablePath;
import org.hibernate.query.sqm.produce.SqmCreationProcessingState;
import org.hibernate.query.sqm.produce.SqmPathRegistry;
@ -29,7 +28,6 @@ import org.hibernate.query.sqm.tree.domain.SqmEntityValuedSimplePath;
import org.hibernate.query.sqm.tree.domain.SqmPath;
import org.hibernate.query.sqm.tree.domain.SqmPluralValuedSimplePath;
import org.hibernate.query.sqm.tree.domain.SqmPolymorphicRootDescriptor;
import org.hibernate.query.sqm.tree.domain.SqmSingularJoin;
import org.hibernate.query.sqm.tree.expression.SqmBinaryArithmetic;
import org.hibernate.query.sqm.tree.expression.SqmExpression;
import org.hibernate.query.sqm.tree.expression.SqmLiteral;
@ -37,22 +35,23 @@ import org.hibernate.query.sqm.tree.expression.SqmLiteralEntityType;
import org.hibernate.query.sqm.tree.expression.SqmNamedParameter;
import org.hibernate.query.sqm.tree.expression.SqmPositionalParameter;
import org.hibernate.query.sqm.tree.expression.SqmUnaryOperation;
import org.hibernate.query.sqm.tree.expression.function.SqmFunction;
import org.hibernate.query.sqm.tree.from.SqmAttributeJoin;
import org.hibernate.query.sqm.tree.from.SqmCrossJoin;
import org.hibernate.query.sqm.tree.from.SqmEntityJoin;
import org.hibernate.query.sqm.tree.from.SqmFrom;
import org.hibernate.query.sqm.tree.from.SqmFromClause;
import org.hibernate.query.sqm.tree.from.SqmRoot;
import org.hibernate.query.sqm.tree.predicate.SqmAndPredicate;
import org.hibernate.query.sqm.tree.predicate.SqmBetweenPredicate;
import org.hibernate.query.sqm.tree.predicate.SqmComparisonPredicate;
import org.hibernate.query.sqm.tree.predicate.SqmEmptinessPredicate;
import org.hibernate.query.sqm.tree.predicate.SqmGroupedPredicate;
import org.hibernate.query.sqm.tree.predicate.SqmInSubQueryPredicate;
import org.hibernate.query.sqm.tree.predicate.SqmLikePredicate;
import org.hibernate.query.sqm.tree.predicate.SqmMemberOfPredicate;
import org.hibernate.query.sqm.tree.predicate.SqmNegatedPredicate;
import org.hibernate.query.sqm.tree.predicate.SqmNullnessPredicate;
import org.hibernate.query.sqm.tree.predicate.SqmAndPredicate;
import org.hibernate.query.sqm.tree.predicate.SqmBetweenPredicate;
import org.hibernate.query.sqm.tree.predicate.SqmComparisonPredicate;
import org.hibernate.query.sqm.tree.predicate.SqmGroupedPredicate;
import org.hibernate.query.sqm.tree.predicate.SqmInSubQueryPredicate;
import org.hibernate.query.sqm.tree.predicate.SqmOrPredicate;
import org.hibernate.query.sqm.tree.predicate.SqmPredicate;
import org.hibernate.query.sqm.tree.predicate.SqmWhereClause;
@ -72,7 +71,6 @@ import org.hibernate.query.sqm.tree.select.SqmSubQuery;
import org.hibernate.query.sqm.tree.update.SqmAssignment;
import org.hibernate.query.sqm.tree.update.SqmSetClause;
import org.hibernate.query.sqm.tree.update.SqmUpdateStatement;
import org.hibernate.query.sqm.tree.expression.function.SqmFunction;
/**
* Handles splitting queries containing unmapped polymorphic references.
@ -285,16 +283,6 @@ public class QuerySplitter {
join.getNavigablePath(),
navigablePath -> {
SqmAttributeJoin copy = join.makeCopy(getProcessingStateStack().getCurrent());
// final SqmAttributeJoin copy = new SqmSingularJoin(
// getProcessingStateStack().getCurrent()
// .getPathRegistry()
// .findFromByPath( join.getLhs().getNavigablePath() ),
// (SingularPersistentAttribute) join.getReferencedPathSource(),
// join.getExplicitAlias(),
// join.getSqmJoinType(),
// join.isFetched(),
// join.nodeBuilder()
// );
sqmFromCopyMap.put( join, copy );
sqmPathCopyMap.put( join.getNavigablePath(), copy );
return copy;

View File

@ -53,7 +53,7 @@ public abstract class AbstractSqmAttributeJoin<O,T>
//noinspection unchecked
super(
SqmCreationHelper.buildSubNavigablePath( lhs, joinedNavigable.getName(), alias ),
(SqmPathSource<O>) joinedNavigable,
(SqmPathSource<T>) joinedNavigable,
lhs,
alias,
joinType,

View File

@ -31,7 +31,7 @@ public abstract class AbstractSqmPluralJoin<O,C,E> extends AbstractSqmAttributeJ
//noinspection unchecked
super(
lhs,
(SqmJoinable<O, E>) joinedNavigable,
joinedNavigable,
alias,
joinType,
fetched,

View File

@ -21,6 +21,7 @@ import org.hibernate.query.criteria.JpaExpression;
import org.hibernate.query.criteria.JpaPredicate;
import org.hibernate.query.criteria.JpaSubQuery;
import org.hibernate.query.sqm.NodeBuilder;
import org.hibernate.query.sqm.produce.SqmCreationProcessingState;
import org.hibernate.query.sqm.tree.SqmJoinType;
import org.hibernate.query.sqm.tree.from.SqmAttributeJoin;
import org.hibernate.query.sqm.tree.from.SqmFrom;
@ -41,6 +42,12 @@ public class SqmBagJoin<O, E> extends AbstractSqmPluralJoin<O,Collection<E>, E>
super( lhs, attribute, alias, sqmJoinType, fetched, nodeBuilder );
}
@Override
public BagPersistentAttribute<O,E> getReferencedPathSource() {
//noinspection unchecked
return (BagPersistentAttribute) super.getReferencedPathSource();
}
@Override
public JavaTypeDescriptor<E> getJavaTypeDescriptor() {
return getModel().getExpressableJavaTypeDescriptor();
@ -120,4 +127,16 @@ public class SqmBagJoin<O, E> extends AbstractSqmPluralJoin<O,Collection<E>, E>
//noinspection unchecked
return new SqmTreatedBagJoin( this, entityTypeDescriptor, null );
}
@Override
public SqmAttributeJoin makeCopy(SqmCreationProcessingState creationProcessingState) {
return new SqmBagJoin(
creationProcessingState.getPathRegistry().findFromByPath( getLhs().getNavigablePath() ),
getReferencedPathSource(),
getExplicitAlias(),
getSqmJoinType(),
isFetched(),
nodeBuilder()
);
}
}

View File

@ -22,6 +22,7 @@ import org.hibernate.query.criteria.JpaListJoin;
import org.hibernate.query.criteria.JpaPredicate;
import org.hibernate.query.criteria.JpaSubQuery;
import org.hibernate.query.sqm.NodeBuilder;
import org.hibernate.query.sqm.produce.SqmCreationProcessingState;
import org.hibernate.query.sqm.tree.SqmJoinType;
import org.hibernate.query.sqm.tree.from.SqmAttributeJoin;
import org.hibernate.query.sqm.tree.from.SqmFrom;
@ -47,6 +48,12 @@ public class SqmListJoin<O,E> extends AbstractSqmPluralJoin<O,List<E>, E> implem
return (ListPersistentAttribute<O, E>) super.getModel();
}
@Override
public ListPersistentAttribute<O,E> getReferencedPathSource() {
//noinspection unchecked
return (ListPersistentAttribute) super.getReferencedPathSource();
}
@Override
public JavaTypeDescriptor<E> getJavaTypeDescriptor() {
return getNodeJavaTypeDescriptor();
@ -128,4 +135,16 @@ public class SqmListJoin<O,E> extends AbstractSqmPluralJoin<O,List<E>, E> implem
public <X,Y> SqmAttributeJoin<X,Y> fetch(String attributeName, JoinType jt) {
throw new NotYetImplementedFor6Exception();
}
@Override
public SqmAttributeJoin makeCopy(SqmCreationProcessingState creationProcessingState) {
return new SqmListJoin(
creationProcessingState.getPathRegistry().findFromByPath( getLhs().getNavigablePath() ),
getReferencedPathSource(),
getExplicitAlias(),
getSqmJoinType(),
isFetched(),
nodeBuilder()
);
}
}

View File

@ -23,7 +23,9 @@ import org.hibernate.query.criteria.JpaSubQuery;
import org.hibernate.query.criteria.PathException;
import org.hibernate.query.sqm.NodeBuilder;
import org.hibernate.query.sqm.SqmPathSource;
import org.hibernate.query.sqm.produce.SqmCreationProcessingState;
import org.hibernate.query.sqm.tree.SqmJoinType;
import org.hibernate.query.sqm.tree.from.SqmAttributeJoin;
import org.hibernate.query.sqm.tree.from.SqmFrom;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
@ -171,4 +173,16 @@ public class SqmMapJoin<O,K,V> extends AbstractSqmPluralJoin<O,Map<K,V>,V> imple
final EntityDomainType<S> targetDescriptor = nodeBuilder().getDomainModel().entity( treatJavaType );
return new SqmTreatedMapJoin( this, targetDescriptor, null );
}
@Override
public SqmAttributeJoin makeCopy(SqmCreationProcessingState creationProcessingState) {
return new SqmMapJoin(
creationProcessingState.getPathRegistry().findFromByPath( getLhs().getNavigablePath() ),
getReferencedPathSource(),
getExplicitAlias(),
getSqmJoinType(),
isFetched(),
nodeBuilder()
);
}
}

View File

@ -21,6 +21,7 @@ import org.hibernate.query.criteria.JpaPredicate;
import org.hibernate.query.criteria.JpaSetJoin;
import org.hibernate.query.criteria.JpaSubQuery;
import org.hibernate.query.sqm.NodeBuilder;
import org.hibernate.query.sqm.produce.SqmCreationProcessingState;
import org.hibernate.query.sqm.tree.SqmJoinType;
import org.hibernate.query.sqm.tree.from.SqmAttributeJoin;
import org.hibernate.query.sqm.tree.from.SqmFrom;
@ -126,4 +127,16 @@ public class SqmSetJoin<O, E>
public <X,Y> SqmAttributeJoin<X,Y> fetch(String attributeName, JoinType jt) {
throw new NotYetImplementedFor6Exception();
}
@Override
public SqmAttributeJoin makeCopy(SqmCreationProcessingState creationProcessingState) {
return new SqmSetJoin(
creationProcessingState.getPathRegistry().findFromByPath( getLhs().getNavigablePath() ),
getReferencedPathSource(),
getExplicitAlias(),
getSqmJoinType(),
isFetched(),
nodeBuilder()
);
}
}

View File

@ -12,7 +12,9 @@ import org.hibernate.metamodel.model.domain.EntityDomainType;
import org.hibernate.metamodel.model.domain.SingularPersistentAttribute;
import org.hibernate.query.criteria.PathException;
import org.hibernate.query.sqm.NodeBuilder;
import org.hibernate.query.sqm.produce.SqmCreationProcessingState;
import org.hibernate.query.sqm.tree.SqmJoinType;
import org.hibernate.query.sqm.tree.from.SqmAttributeJoin;
import org.hibernate.query.sqm.tree.from.SqmFrom;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
@ -30,6 +32,11 @@ public class SqmSingularJoin<O,T> extends AbstractSqmAttributeJoin<O,T> {
super( lhs, joinedNavigable, alias, joinType, fetched, nodeBuilder );
}
@Override
public SingularPersistentAttribute<O, T> getReferencedPathSource() {
return (SingularPersistentAttribute<O, T>) super.getReferencedPathSource();
}
@Override
public JavaTypeDescriptor<T> getJavaTypeDescriptor() {
return getNodeJavaTypeDescriptor();
@ -51,4 +58,16 @@ public class SqmSingularJoin<O,T> extends AbstractSqmAttributeJoin<O,T> {
getReferencedPathSource().getPathName()
);
}
@Override
public SqmAttributeJoin makeCopy(SqmCreationProcessingState creationProcessingState) {
return new SqmSingularJoin(
creationProcessingState.getPathRegistry().findFromByPath( getLhs().getNavigablePath() ),
getReferencedPathSource(),
getExplicitAlias(),
getSqmJoinType(),
isFetched(),
nodeBuilder()
);
}
}

View File

@ -8,6 +8,8 @@ package org.hibernate.query.sqm.tree.domain;
import org.hibernate.metamodel.model.domain.BagPersistentAttribute;
import org.hibernate.metamodel.model.domain.EntityDomainType;
import org.hibernate.query.sqm.produce.SqmCreationProcessingState;
import org.hibernate.query.sqm.tree.from.SqmAttributeJoin;
/**
* @author Steve Ebersole
@ -42,4 +44,9 @@ public class SqmTreatedBagJoin<O,T, S extends T> extends SqmBagJoin<O,S> impleme
public EntityDomainType<S> getTreatTarget() {
return treatTarget;
}
@Override
public SqmAttributeJoin makeCopy(SqmCreationProcessingState creationProcessingState) {
return new SqmTreatedBagJoin( wrappedPath, treatTarget, getAlias() );
}
}

View File

@ -8,8 +8,10 @@ package org.hibernate.query.sqm.tree.domain;
import org.hibernate.metamodel.model.domain.EntityDomainType;
import org.hibernate.metamodel.model.domain.ListPersistentAttribute;
import org.hibernate.query.sqm.produce.SqmCreationProcessingState;
import org.hibernate.query.sqm.produce.spi.SqmCreationState;
import org.hibernate.query.sqm.tree.expression.SqmExpression;
import org.hibernate.query.sqm.tree.from.SqmAttributeJoin;
/**
* @author Steve Ebersole
@ -58,4 +60,9 @@ public class SqmTreatedListJoin<O,T, S extends T> extends SqmListJoin<O,S> imple
SqmCreationState creationState) {
return getWrappedPath().resolveIndexedAccess( selector, currentContextKey, isTerminal, creationState );
}
@Override
public SqmAttributeJoin makeCopy(SqmCreationProcessingState creationProcessingState) {
return new SqmTreatedListJoin( wrappedPath, treatTarget, getAlias() );
}
}

View File

@ -7,6 +7,8 @@
package org.hibernate.query.sqm.tree.domain;
import org.hibernate.metamodel.model.domain.EntityDomainType;
import org.hibernate.query.sqm.produce.SqmCreationProcessingState;
import org.hibernate.query.sqm.tree.from.SqmAttributeJoin;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
/**
@ -47,4 +49,13 @@ public class SqmTreatedMapJoin<O,K,V, S extends V> extends SqmMapJoin<O,K,S> imp
public JavaTypeDescriptor<S> getJavaTypeDescriptor() {
return null;
}
@Override
public SqmAttributeJoin makeCopy(SqmCreationProcessingState creationProcessingState) {
return new SqmTreatedMapJoin(
wrappedPath,
treatTarget,
getAlias()
);
}
}

View File

@ -8,6 +8,8 @@ package org.hibernate.query.sqm.tree.domain;
import org.hibernate.metamodel.model.domain.EntityDomainType;
import org.hibernate.metamodel.model.domain.SetPersistentAttribute;
import org.hibernate.query.sqm.produce.SqmCreationProcessingState;
import org.hibernate.query.sqm.tree.from.SqmAttributeJoin;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
/**
@ -59,4 +61,9 @@ public class SqmTreatedSetJoin<O,T, S extends T> extends SqmSetJoin<O,S> impleme
//noinspection unchecked
return (JavaTypeDescriptor) wrappedPath.getJavaTypeDescriptor();
}
@Override
public SqmAttributeJoin makeCopy(SqmCreationProcessingState creationProcessingState) {
return new SqmTreatedSetJoin( wrappedPath, treatTarget, getAlias() );
}
}

View File

@ -8,6 +8,8 @@ package org.hibernate.query.sqm.tree.domain;
import org.hibernate.metamodel.model.domain.EntityDomainType;
import org.hibernate.metamodel.model.domain.SingularPersistentAttribute;
import org.hibernate.query.sqm.produce.SqmCreationProcessingState;
import org.hibernate.query.sqm.tree.from.SqmAttributeJoin;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
/**
@ -48,11 +50,16 @@ public class SqmTreatedSingularJoin<O,T, S extends T> extends SqmSingularJoin<O,
@Override
@SuppressWarnings("unchecked")
public SingularPersistentAttribute getReferencedPathSource() {
return (SingularPersistentAttribute) super.getReferencedPathSource();
return super.getReferencedPathSource();
}
@Override
public JavaTypeDescriptor<S> getJavaTypeDescriptor() {
return treatTarget.getExpressableJavaTypeDescriptor();
}
@Override
public SqmAttributeJoin makeCopy(SqmCreationProcessingState creationProcessingState) {
return new SqmTreatedSingularJoin( wrappedPath, treatTarget, getAlias() );
}
}