Remove few NotYetImplementedFor6Exception

This commit is contained in:
Andrea Boriero 2021-12-23 12:01:25 +01:00 committed by Christian Beikov
parent 67f73f20ef
commit 313bc2666c
12 changed files with 76 additions and 167 deletions

View File

@ -9,7 +9,6 @@ package org.hibernate.query.sqm.function;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.metamodel.MappingMetamodel;
import org.hibernate.metamodel.mapping.BasicValuedMapping;
import org.hibernate.metamodel.mapping.MappingModelExpressable;
@ -22,8 +21,6 @@ import org.hibernate.query.sqm.tree.SqmTypedNode;
import org.hibernate.query.sqm.tree.SqmVisitableNode;
import org.hibernate.query.sqm.tree.expression.SqmFunction;
import org.hibernate.sql.ast.tree.SqlAstNode;
import org.hibernate.sql.results.graph.DomainResult;
import org.hibernate.sql.results.graph.DomainResultCreationState;
import org.hibernate.type.spi.TypeConfiguration;
import static java.util.Collections.emptyList;
@ -135,15 +132,4 @@ public class SelfRenderingSqmFunction<T> extends SqmFunction<T> {
return mapping;
}
@Override
public DomainResult<T> createDomainResult(
String resultVariable,
DomainResultCreationState creationState) {
throw new NotYetImplementedFor6Exception( getClass() );
}
@Override
public void applySqlSelections(DomainResultCreationState creationState) {
//implemented on SelfRenderingFunctionSqlAstExpression
}
}

View File

@ -35,7 +35,6 @@ import org.hibernate.QueryException;
import org.hibernate.boot.model.process.internal.InferredBasicValueResolver;
import org.hibernate.dialect.function.TimestampaddFunction;
import org.hibernate.dialect.function.TimestampdiffFunction;
import org.hibernate.engine.FetchStyle;
import org.hibernate.engine.FetchTiming;
import org.hibernate.engine.profile.FetchProfile;
import org.hibernate.engine.spi.LoadQueryInfluencers;
@ -3043,7 +3042,6 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
final Expression result;
if ( resultPart instanceof EntityValuedModelPart ) {
final EntityValuedModelPart mapping = (EntityValuedModelPart) resultPart;
final boolean expandToAllColumns;
if ( currentClauseStack.getCurrent() == Clause.GROUP ) {
// When the table group is known to be fetched i.e. a fetch join
@ -3054,11 +3052,23 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
else {
expandToAllColumns = false;
}
final EntityValuedModelPart mapping = (EntityValuedModelPart) resultPart;
EntityMappingType mappingType;
if ( path instanceof SqmTreatedPath ) {
mappingType = creationContext.getDomainModel()
.findEntityDescriptor( ( (SqmTreatedPath) path ).getTreatTarget().getHibernateEntityName() );
}
else {
mappingType = mapping.getEntityMappingType();
}
final TableGroup parentGroupToUse = findTableGroup( navigablePath.getParent() );
result = EntityValuedPathInterpretation.from(
navigablePath,
parentGroupToUse == null ? tableGroup : parentGroupToUse,
mapping,
(EntityValuedModelPart) resultPart,
mappingType,
expandToAllColumns,
this
);
@ -3307,6 +3317,28 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
return createMinOrMaxIndexOrElement( path, true, false );
}
@Override
public Expression visitCorrelation(SqmCorrelation<?, ?> correlation) {
final TableGroup resolved = getFromClauseAccess().findTableGroup( correlation.getNavigablePath() );
if ( resolved != null ) {
log.tracef( "SqmCorrelation [%s] resolved to existing TableGroup [%s]", correlation, resolved );
return visitTableGroup( resolved, correlation );
}
throw new InterpretationException( "SqmCorrelation not yet resolved to TableGroup" );
}
@Override
public Expression visitTreatedPath(SqmTreatedPath<?, ?> sqmTreatedPath) {
final TableGroup resolved = getFromClauseAccess().findTableGroup( sqmTreatedPath.getNavigablePath() );
if ( resolved != null ) {
log.tracef( "SqmTreatedPath [%s] resolved to existing TableGroup [%s]", sqmTreatedPath, resolved );
return visitTableGroup( resolved, (SqmFrom<?, ?>) sqmTreatedPath );
}
throw new InterpretationException( "SqmTreatedPath not yet resolved to TableGroup" );
}
@Override
public Expression visitPluralAttributeSizeFunction(SqmCollectionSize function) {
final SqmPath<?> pluralPath = function.getPluralPath();
@ -3456,7 +3488,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
@Override
public void applySqlSelections(DomainResultCreationState creationState) {
throw new NotYetImplementedFor6Exception( getClass() );
throw new UnsupportedOperationException();
}
};
}

View File

@ -56,13 +56,21 @@ public class EntityValuedPathInterpretation<T> extends AbstractSqmPathInterpreta
.findTableGroup( sqmPath.getLhs().getNavigablePath() )
.getModelPart()
.findSubPart( sqmPath.getReferencedPathSource().getPathName(), null );
return from( sqmPath.getNavigablePath(), tableGroup, mapping, false, sqlAstCreationState );
return from(
sqmPath.getNavigablePath(),
tableGroup,
mapping,
mapping,
false,
sqlAstCreationState
);
}
public static <T> EntityValuedPathInterpretation<T> from(
NavigablePath navigablePath,
TableGroup tableGroup,
EntityValuedModelPart mapping,
EntityValuedModelPart treatedMapping,
boolean expandToAllColumns,
SqmToSqlAstConverter sqlAstCreationState) {
final SqlExpressionResolver sqlExprResolver = sqlAstCreationState.getSqlExpressionResolver();
@ -211,7 +219,7 @@ public class EntityValuedPathInterpretation<T> extends AbstractSqmPathInterpreta
sqlExpression,
navigablePath,
tableGroup,
mapping
treatedMapping
);
}

View File

@ -8,25 +8,21 @@ package org.hibernate.query.sqm.tree.domain;
import java.util.Locale;
import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.metamodel.model.domain.EntityDomainType;
import org.hibernate.query.NavigablePath;
import org.hibernate.query.sqm.NodeBuilder;
import org.hibernate.query.sqm.SemanticQueryWalker;
import org.hibernate.query.sqm.SqmPathSource;
import org.hibernate.query.sqm.spi.SqmCreationHelper;
import org.hibernate.query.sqm.sql.internal.DomainResultProducer;
import org.hibernate.query.sqm.tree.SqmJoinType;
import org.hibernate.query.sqm.tree.from.SqmFrom;
import org.hibernate.query.sqm.tree.from.SqmQualifiedJoin;
import org.hibernate.query.sqm.tree.predicate.SqmPredicate;
import org.hibernate.sql.results.graph.DomainResult;
import org.hibernate.sql.results.graph.DomainResultCreationState;
/**
* @author Christian Beikov
*/
public class SqmPluralPartJoin<O,T> extends AbstractSqmJoin<O,T> implements DomainResultProducer<T>, SqmQualifiedJoin<O, T> {
public class SqmPluralPartJoin<O,T> extends AbstractSqmJoin<O,T> implements SqmQualifiedJoin<O, T> {
public SqmPluralPartJoin(
SqmFrom<?,O> lhs,
@ -114,15 +110,4 @@ public class SqmPluralPartJoin<O,T> extends AbstractSqmJoin<O,T> implements Doma
getReferencedPathSource().getPathName()
);
}
@Override
public DomainResult<T> createDomainResult(
String resultVariable, DomainResultCreationState creationState) {
throw new NotYetImplementedFor6Exception( getClass() );
}
@Override
public void applySqlSelections(DomainResultCreationState creationState) {
throw new NotYetImplementedFor6Exception( getClass() );
}
}

View File

@ -9,16 +9,12 @@ package org.hibernate.query.sqm.tree.expression;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.query.criteria.JpaSearchedCase;
import org.hibernate.query.internal.QueryHelper;
import org.hibernate.query.sqm.NodeBuilder;
import org.hibernate.query.sqm.SemanticQueryWalker;
import org.hibernate.query.sqm.SqmExpressable;
import org.hibernate.query.sqm.sql.internal.DomainResultProducer;
import org.hibernate.query.sqm.tree.predicate.SqmPredicate;
import org.hibernate.sql.results.graph.DomainResult;
import org.hibernate.sql.results.graph.DomainResultCreationState;
import jakarta.persistence.criteria.Expression;
@ -27,7 +23,7 @@ import jakarta.persistence.criteria.Expression;
*/
public class SqmCaseSearched<R>
extends AbstractSqmExpression<R>
implements JpaSearchedCase<R>, DomainResultProducer<R> {
implements JpaSearchedCase<R> {
private final List<WhenFragment<R>> whenFragments;
private SqmExpression<R> otherwise;
@ -103,18 +99,6 @@ public class SqmCaseSearched<R>
return "<searched-case>";
}
@Override
public DomainResult<R> createDomainResult(
String resultVariable,
DomainResultCreationState creationState) {
throw new NotYetImplementedFor6Exception( getClass() );
}
@Override
public void applySqlSelections(DomainResultCreationState creationState) {
throw new NotYetImplementedFor6Exception( getClass() );
}
public static class WhenFragment<R> {
private final SqmPredicate predicate;
private final SqmExpression<R> result;

View File

@ -6,15 +6,10 @@
*/
package org.hibernate.query.sqm.tree.expression;
import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.query.sqm.NodeBuilder;
import org.hibernate.query.sqm.SemanticQueryWalker;
import org.hibernate.query.sqm.SqmExpressable;
import org.hibernate.query.sqm.sql.internal.DomainResultProducer;
import org.hibernate.query.sqm.tree.domain.SqmPath;
import org.hibernate.sql.results.graph.DomainResult;
import org.hibernate.sql.results.graph.DomainResultCreationState;
import org.hibernate.type.StandardBasicTypes;
/**
* Represents the {@code SIZE()} function.
@ -22,7 +17,7 @@ import org.hibernate.type.StandardBasicTypes;
* @author Steve Ebersole
* @author Gunnar Morling
*/
public class SqmCollectionSize extends AbstractSqmExpression<Integer> implements DomainResultProducer<Integer> {
public class SqmCollectionSize extends AbstractSqmExpression<Integer> {
private final SqmPath<?> pluralPath;
public SqmCollectionSize(SqmPath<?> pluralPath, NodeBuilder nodeBuilder) {
@ -55,15 +50,4 @@ public class SqmCollectionSize extends AbstractSqmExpression<Integer> implements
sb.append( ')' );
}
@Override
public DomainResult<Integer> createDomainResult(
String resultVariable,
DomainResultCreationState creationState) {
throw new NotYetImplementedFor6Exception( getClass() );
}
@Override
public void applySqlSelections(DomainResultCreationState creationState) {
throw new NotYetImplementedFor6Exception( getClass() );
}
}

View File

@ -14,7 +14,6 @@ import org.hibernate.query.sqm.SemanticQueryWalker;
import org.hibernate.query.sqm.SqmExpressable;
import org.hibernate.query.sqm.function.SqmFunctionDescriptor;
import org.hibernate.query.sqm.sql.SqmToSqlAstConverter;
import org.hibernate.query.sqm.sql.internal.DomainResultProducer;
import org.hibernate.query.sqm.tree.SqmTypedNode;
import org.hibernate.query.sqm.tree.domain.SqmPath;
import org.hibernate.query.sqm.tree.select.SqmSelectableNode;
@ -28,7 +27,7 @@ import java.util.List;
* @author Steve Ebersole
*/
public abstract class SqmFunction<T> extends AbstractSqmExpression<T>
implements JpaFunction<T>, DomainResultProducer<T>, SemanticPathPart {
implements JpaFunction<T>, SemanticPathPart {
// this function-name is the one used to resolve the descriptor from
// the function registry (which may or may not be a db function name)
private final String functionName;

View File

@ -6,14 +6,10 @@
*/
package org.hibernate.query.sqm.tree.expression;
import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.query.internal.QueryLiteralHelper;
import org.hibernate.query.sqm.NodeBuilder;
import org.hibernate.query.sqm.SemanticQueryWalker;
import org.hibernate.query.sqm.SqmExpressable;
import org.hibernate.query.sqm.sql.internal.DomainResultProducer;
import org.hibernate.sql.results.graph.DomainResult;
import org.hibernate.sql.results.graph.DomainResultCreationState;
import org.hibernate.type.descriptor.java.JavaType;
/**
@ -26,9 +22,7 @@ import org.hibernate.type.descriptor.java.JavaType;
* </ul>
* @author Steve Ebersole
*/
public class SqmLiteral<T>
extends AbstractSqmExpression<T>
implements DomainResultProducer<T> {
public class SqmLiteral<T> extends AbstractSqmExpression<T> {
private final T value;
public SqmLiteral(T value, SqmExpressable<T> inherentType, NodeBuilder nodeBuilder) {
@ -71,16 +65,4 @@ public class SqmLiteral<T>
}
}
@Override
public DomainResult<T> createDomainResult(
String resultVariable,
DomainResultCreationState creationState) {
throw new NotYetImplementedFor6Exception( getClass() );
}
@Override
public void applySqlSelections(DomainResultCreationState creationState) {
throw new NotYetImplementedFor6Exception( getClass() );
}
}

View File

@ -10,26 +10,22 @@ import java.util.ArrayList;
import java.util.List;
import org.hibernate.metamodel.model.domain.EntityDomainType;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.query.NavigablePath;
import org.hibernate.query.PathException;
import org.hibernate.query.criteria.JpaRoot;
import org.hibernate.query.sqm.NodeBuilder;
import org.hibernate.query.sqm.SemanticQueryWalker;
import org.hibernate.query.sqm.SqmPathSource;
import org.hibernate.query.sqm.sql.internal.DomainResultProducer;
import org.hibernate.query.sqm.tree.SqmJoinType;
import org.hibernate.query.sqm.tree.domain.AbstractSqmFrom;
import org.hibernate.query.sqm.tree.domain.SqmCorrelatedRoot;
import org.hibernate.query.sqm.tree.domain.SqmPath;
import org.hibernate.query.sqm.tree.domain.SqmTreatedRoot;
import org.hibernate.sql.results.graph.DomainResult;
import org.hibernate.sql.results.graph.DomainResultCreationState;
/**
* @author Steve Ebersole
*/
public class SqmRoot<E> extends AbstractSqmFrom<E,E> implements JpaRoot<E>, DomainResultProducer<E> {
public class SqmRoot<E> extends AbstractSqmFrom<E,E> implements JpaRoot<E> {
private final boolean allowJoins;
private List<SqmJoin<?, ?>> orderedJoins;
@ -180,35 +176,4 @@ public class SqmRoot<E> extends AbstractSqmFrom<E,E> implements JpaRoot<E>, Doma
throw new UnsupportedOperationException( "Root treats can not be aliased" );
}
@Override
public DomainResult<E> createDomainResult(
String resultVariable,
DomainResultCreationState creationState) {
final String entityName = getReferencedPathSource().getHibernateEntityName();
final EntityPersister entityDescriptor = creationState.getSqlAstCreationState()
.getCreationContext()
.getDomainModel()
.getEntityDescriptor( entityName );
return entityDescriptor.createDomainResult(
getNavigablePath(),
creationState.getSqlAstCreationState().getFromClauseAccess().findTableGroup( getNavigablePath() ),
resultVariable,
creationState
);
}
@Override
public void applySqlSelections(DomainResultCreationState creationState) {
final String entityName = getReferencedPathSource().getHibernateEntityName();
final EntityPersister entityDescriptor = creationState.getSqlAstCreationState()
.getCreationContext()
.getDomainModel()
.getEntityDescriptor( entityName );
entityDescriptor.applySqlSelections(
getNavigablePath(),
creationState.getSqlAstCreationState().getFromClauseAccess().findTableGroup( getNavigablePath() ),
creationState
);
}
}

View File

@ -11,16 +11,12 @@ import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.query.DynamicInstantiationNature;
import org.hibernate.query.criteria.JpaCompoundSelection;
import org.hibernate.query.sqm.NodeBuilder;
import org.hibernate.query.sqm.SemanticQueryWalker;
import org.hibernate.query.sqm.sql.internal.DomainResultProducer;
import org.hibernate.query.sqm.tree.expression.SqmExpression;
import org.hibernate.query.sqm.tree.jpa.AbstractJpaSelection;
import org.hibernate.sql.results.graph.DomainResult;
import org.hibernate.sql.results.graph.DomainResultCreationState;
import org.hibernate.type.descriptor.java.JavaType;
import org.jboss.logging.Logger;
@ -38,8 +34,7 @@ public class SqmDynamicInstantiation<T>
extends AbstractJpaSelection<T>
implements SqmSelectableNode<T>,
SqmAliasedExpressionContainer<SqmDynamicInstantiationArgument<?>>,
JpaCompoundSelection<T>,
DomainResultProducer<T> {
JpaCompoundSelection<T> {
private static final Logger log = Logger.getLogger( SqmDynamicInstantiation.class );
@ -200,18 +195,6 @@ public class SqmDynamicInstantiation<T>
return new SqmDynamicInstantiation<>( getInstantiationTarget(), nodeBuilder() );
}
@Override
public DomainResult<T> createDomainResult(
String resultVariable,
DomainResultCreationState creationState) {
throw new NotYetImplementedFor6Exception( getClass() );
}
@Override
public void applySqlSelections(DomainResultCreationState creationState) {
throw new NotYetImplementedFor6Exception( getClass() );
}
private static class DynamicInstantiationTargetImpl<T> implements SqmDynamicInstantiationTarget<T> {
private final DynamicInstantiationNature nature;
private final JavaType<T> javaTypeDescriptor;

View File

@ -9,20 +9,16 @@ package org.hibernate.query.sqm.tree.select;
import java.util.List;
import java.util.function.Consumer;
import jakarta.persistence.criteria.Selection;
import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.query.criteria.JpaCompoundSelection;
import org.hibernate.query.criteria.JpaSelection;
import org.hibernate.query.sqm.NodeBuilder;
import org.hibernate.query.sqm.SqmExpressable;
import org.hibernate.query.sqm.SemanticQueryWalker;
import org.hibernate.query.sqm.SqmExpressable;
import org.hibernate.query.sqm.tree.expression.AbstractSqmExpression;
import org.hibernate.query.sqm.sql.internal.DomainResultProducer;
import org.hibernate.sql.results.graph.DomainResult;
import org.hibernate.sql.results.graph.DomainResultCreationState;
import org.hibernate.type.descriptor.java.JavaType;
import jakarta.persistence.criteria.Selection;
/**
* @asciidoctor
*
@ -41,7 +37,7 @@ import org.hibernate.type.descriptor.java.JavaType;
*/
public class SqmJpaCompoundSelection<T>
extends AbstractSqmExpression<T>
implements JpaCompoundSelection<T>, SqmExpressable<T>, DomainResultProducer<T> {
implements JpaCompoundSelection<T>, SqmExpressable<T> {
// todo (6.0) : should this really be SqmExpressable?
// - seems like it ought to be limited to just `SqmSelectableNode`.
@ -127,15 +123,4 @@ public class SqmJpaCompoundSelection<T>
selectableNodes.forEach( jpaSelectionConsumer );
}
@Override
public DomainResult<T> createDomainResult(
String resultVariable,
DomainResultCreationState creationState) {
throw new NotYetImplementedFor6Exception( getClass() );
}
@Override
public void applySqlSelections(DomainResultCreationState creationState) {
throw new NotYetImplementedFor6Exception( getClass() );
}
}

View File

@ -29,7 +29,9 @@ import org.junit.Before;
import org.junit.Test;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
/**
@ -48,6 +50,7 @@ public class TreatJoinTest extends BaseEntityManagerFunctionalTestCase {
Price price = new Price( 10, "EUR" );
Author author = new Author( "Andrea Camilleri" );
Book book = new Book( author, "Il nipote del Negus", price );
book.setDescription( "is a book" );
Bid bid = new Bid( book );
entityManager.persist( bid );
@ -130,7 +133,7 @@ public class TreatJoinTest extends BaseEntityManagerFunctionalTestCase {
assertThat(resultList.size(),is(1));
} );
}
@Test
@TestForIssue(jiraKey = "HHH-10561")
public void testJoinOnTreatedRoot() {
@ -143,7 +146,10 @@ public class TreatJoinTest extends BaseEntityManagerFunctionalTestCase {
cb.equal(
treatedRoot.<Book, Author>join("author").<String>get("name"),
"Andrea Camilleri"));
entityManager.createQuery(criteria.select(treatedRoot)).getResultList();
final List<Item> resultList = entityManager.createQuery( criteria.select( treatedRoot ) ).getResultList();
final Item item = resultList.get( 0 );
assertThat( item, instanceOf(Book.class) );
assertEquals( "is a book", item.getDescription() );
} );
}
@ -163,7 +169,7 @@ public class TreatJoinTest extends BaseEntityManagerFunctionalTestCase {
entityManager.createQuery(criteria.select(treatedRoot)).getResultList();
} );
}
@Test
@TestForIssue(jiraKey = "HHH-10767")
public void testJoinOnTreatedJoin() {
@ -186,6 +192,8 @@ public class TreatJoinTest extends BaseEntityManagerFunctionalTestCase {
@GeneratedValue
private Long id;
private String description;
@ManyToOne(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
private Price price;
@ -195,6 +203,14 @@ public class TreatJoinTest extends BaseEntityManagerFunctionalTestCase {
public Item(Price price) {
this.price = price;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
@Entity(name = "Price")