6 - SQM based on JPA type system
This commit is contained in:
parent
84a481a3c2
commit
70334e44e1
|
@ -40,7 +40,7 @@ public class QueryEngine {
|
||||||
SessionFactoryImplementor sessionFactory,
|
SessionFactoryImplementor sessionFactory,
|
||||||
NamedQueryRepository namedQueryRepository) {
|
NamedQueryRepository namedQueryRepository) {
|
||||||
return new QueryEngine(
|
return new QueryEngine(
|
||||||
sessionFactory.getDomainModel(),
|
sessionFactory.getMetamodel(),
|
||||||
sessionFactory.getServiceRegistry(),
|
sessionFactory.getServiceRegistry(),
|
||||||
sessionFactory.getSessionFactoryOptions(),
|
sessionFactory.getSessionFactoryOptions(),
|
||||||
sessionFactory,
|
sessionFactory,
|
||||||
|
|
|
@ -12,7 +12,8 @@ import java.util.Map;
|
||||||
import org.hibernate.NotYetImplementedFor6Exception;
|
import org.hibernate.NotYetImplementedFor6Exception;
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.internal.util.collections.Stack;
|
import org.hibernate.internal.util.collections.Stack;
|
||||||
import org.hibernate.metamodel.model.mapping.EntityTypeDescriptor;
|
import org.hibernate.metamodel.model.domain.EntityDomainType;
|
||||||
|
import org.hibernate.metamodel.model.domain.SingularPersistentAttribute;
|
||||||
import org.hibernate.query.NavigablePath;
|
import org.hibernate.query.NavigablePath;
|
||||||
import org.hibernate.query.sqm.produce.SqmCreationProcessingState;
|
import org.hibernate.query.sqm.produce.SqmCreationProcessingState;
|
||||||
import org.hibernate.query.sqm.produce.SqmPathRegistry;
|
import org.hibernate.query.sqm.produce.SqmPathRegistry;
|
||||||
|
@ -100,7 +101,7 @@ public class QuerySplitter {
|
||||||
final SqmSelectStatement[] expanded = new SqmSelectStatement[ unmappedPolymorphicDescriptor.getImplementors().size() ];
|
final SqmSelectStatement[] expanded = new SqmSelectStatement[ unmappedPolymorphicDescriptor.getImplementors().size() ];
|
||||||
|
|
||||||
int i = -1;
|
int i = -1;
|
||||||
for ( EntityTypeDescriptor<?> mappedDescriptor : unmappedPolymorphicDescriptor.getImplementors() ) {
|
for ( EntityDomainType<?> mappedDescriptor : unmappedPolymorphicDescriptor.getImplementors() ) {
|
||||||
i++;
|
i++;
|
||||||
final UnmappedPolymorphismReplacer replacer = new UnmappedPolymorphismReplacer(
|
final UnmappedPolymorphismReplacer replacer = new UnmappedPolymorphismReplacer(
|
||||||
unmappedPolymorphicReference,
|
unmappedPolymorphicReference,
|
||||||
|
@ -116,14 +117,14 @@ public class QuerySplitter {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private static class UnmappedPolymorphismReplacer extends BaseSemanticQueryWalker implements SqmCreationState {
|
private static class UnmappedPolymorphismReplacer extends BaseSemanticQueryWalker implements SqmCreationState {
|
||||||
private final SqmRoot unmappedPolymorphicFromElement;
|
private final SqmRoot unmappedPolymorphicFromElement;
|
||||||
private final EntityTypeDescriptor mappedDescriptor;
|
private final EntityDomainType mappedDescriptor;
|
||||||
|
|
||||||
private Map<NavigablePath, SqmPath> sqmPathCopyMap = new HashMap<>();
|
private Map<NavigablePath, SqmPath> sqmPathCopyMap = new HashMap<>();
|
||||||
private Map<SqmFrom,SqmFrom> sqmFromCopyMap = new HashMap<>();
|
private Map<SqmFrom,SqmFrom> sqmFromCopyMap = new HashMap<>();
|
||||||
|
|
||||||
private UnmappedPolymorphismReplacer(
|
private UnmappedPolymorphismReplacer(
|
||||||
SqmRoot unmappedPolymorphicFromElement,
|
SqmRoot unmappedPolymorphicFromElement,
|
||||||
EntityTypeDescriptor mappedDescriptor,
|
EntityDomainType mappedDescriptor,
|
||||||
SessionFactoryImplementor sessionFactory) {
|
SessionFactoryImplementor sessionFactory) {
|
||||||
super( sessionFactory.getServiceRegistry() );
|
super( sessionFactory.getServiceRegistry() );
|
||||||
this.unmappedPolymorphicFromElement = unmappedPolymorphicFromElement;
|
this.unmappedPolymorphicFromElement = unmappedPolymorphicFromElement;
|
||||||
|
@ -231,7 +232,7 @@ public class QuerySplitter {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
copy = new SqmRoot(
|
copy = new SqmRoot(
|
||||||
sqmRoot.getReferencedPathSource().getEntityDescriptor(),
|
sqmRoot.getReferencedPathSource(),
|
||||||
sqmRoot.getExplicitAlias(),
|
sqmRoot.getExplicitAlias(),
|
||||||
sqmRoot.nodeBuilder()
|
sqmRoot.nodeBuilder()
|
||||||
);
|
);
|
||||||
|
@ -249,7 +250,7 @@ public class QuerySplitter {
|
||||||
join.getNavigablePath(),
|
join.getNavigablePath(),
|
||||||
navigablePath -> {
|
navigablePath -> {
|
||||||
final SqmCrossJoin copy = new SqmCrossJoin(
|
final SqmCrossJoin copy = new SqmCrossJoin(
|
||||||
join.getReferencedPathSource().getEntityDescriptor(),
|
join.getReferencedPathSource(),
|
||||||
join.getExplicitAlias(),
|
join.getExplicitAlias(),
|
||||||
(SqmRoot) sqmFromCopyMap.get( join.findRoot() )
|
(SqmRoot) sqmFromCopyMap.get( join.findRoot() )
|
||||||
);
|
);
|
||||||
|
@ -266,7 +267,8 @@ public class QuerySplitter {
|
||||||
join.getNavigablePath(),
|
join.getNavigablePath(),
|
||||||
navigablePath -> {
|
navigablePath -> {
|
||||||
final SqmEntityJoin copy = new SqmEntityJoin(
|
final SqmEntityJoin copy = new SqmEntityJoin(
|
||||||
join.getReferencedPathSource().getEntityDescriptor(), join.getExplicitAlias(),
|
join.getReferencedPathSource(),
|
||||||
|
join.getExplicitAlias(),
|
||||||
join.getSqmJoinType(),
|
join.getSqmJoinType(),
|
||||||
(SqmRoot) sqmFromCopyMap.get( join.findRoot() )
|
(SqmRoot) sqmFromCopyMap.get( join.findRoot() )
|
||||||
);
|
);
|
||||||
|
@ -282,16 +284,17 @@ public class QuerySplitter {
|
||||||
return (SqmAttributeJoin) getProcessingStateStack().getCurrent().getPathRegistry().resolvePath(
|
return (SqmAttributeJoin) getProcessingStateStack().getCurrent().getPathRegistry().resolvePath(
|
||||||
join.getNavigablePath(),
|
join.getNavigablePath(),
|
||||||
navigablePath -> {
|
navigablePath -> {
|
||||||
final SqmAttributeJoin copy = new SqmSingularJoin(
|
SqmAttributeJoin copy = join.makeCopy(getProcessingStateStack().getCurrent());
|
||||||
getProcessingStateStack().getCurrent()
|
// final SqmAttributeJoin copy = new SqmSingularJoin(
|
||||||
.getPathRegistry()
|
// getProcessingStateStack().getCurrent()
|
||||||
.findFromByPath( join.getLhs().getNavigablePath() ),
|
// .getPathRegistry()
|
||||||
join.getReferencedPathSource(),
|
// .findFromByPath( join.getLhs().getNavigablePath() ),
|
||||||
join.getExplicitAlias(),
|
// (SingularPersistentAttribute) join.getReferencedPathSource(),
|
||||||
join.getSqmJoinType(),
|
// join.getExplicitAlias(),
|
||||||
join.isFetched(),
|
// join.getSqmJoinType(),
|
||||||
join.nodeBuilder()
|
// join.isFetched(),
|
||||||
);
|
// join.nodeBuilder()
|
||||||
|
// );
|
||||||
sqmFromCopyMap.put( join, copy );
|
sqmFromCopyMap.put( join, copy );
|
||||||
sqmPathCopyMap.put( join.getNavigablePath(), copy );
|
sqmPathCopyMap.put( join.getNavigablePath(), copy );
|
||||||
return copy;
|
return copy;
|
||||||
|
|
|
@ -10,6 +10,7 @@ import org.hibernate.HibernateException;
|
||||||
import org.hibernate.query.criteria.JpaFetch;
|
import org.hibernate.query.criteria.JpaFetch;
|
||||||
import org.hibernate.query.criteria.JpaJoin;
|
import org.hibernate.query.criteria.JpaJoin;
|
||||||
import org.hibernate.query.sqm.SqmPathSource;
|
import org.hibernate.query.sqm.SqmPathSource;
|
||||||
|
import org.hibernate.query.sqm.produce.SqmCreationProcessingState;
|
||||||
import org.hibernate.query.sqm.tree.predicate.SqmPredicate;
|
import org.hibernate.query.sqm.tree.predicate.SqmPredicate;
|
||||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||||
|
|
||||||
|
@ -35,6 +36,8 @@ public interface SqmAttributeJoin<O,T> extends SqmQualifiedJoin<O,T>, JpaFetch<O
|
||||||
|
|
||||||
void setJoinPredicate(SqmPredicate predicate);
|
void setJoinPredicate(SqmPredicate predicate);
|
||||||
|
|
||||||
|
SqmAttributeJoin makeCopy(SqmCreationProcessingState creationProcessingState);
|
||||||
|
|
||||||
class NotJoinableException extends HibernateException {
|
class NotJoinableException extends HibernateException {
|
||||||
public NotJoinableException(String message) {
|
public NotJoinableException(String message) {
|
||||||
super( message );
|
super( message );
|
||||||
|
|
Loading…
Reference in New Issue