API changes for query-validator

This commit is contained in:
Gavin 2023-06-08 16:15:36 +02:00 committed by Gavin King
parent 67f737f4ab
commit 3dff3fb20e
10 changed files with 57 additions and 41 deletions

View File

@ -187,9 +187,9 @@ public abstract class AbstractManagedType<J>
Locale.ROOT,
"Could not resolve attribute '%s' of '%s' due to the attribute being declared in multiple sub types: ['%s', '%s']",
name,
getExpressibleJavaType().getJavaType().getTypeName(),
attribute.getDeclaringType().getExpressibleJavaType().getJavaType().getTypeName(),
subTypeAttribute.getDeclaringType().getExpressibleJavaType().getJavaType().getTypeName()
getTypeName(),
attribute.getDeclaringType().getTypeName(),
subTypeAttribute.getDeclaringType().getTypeName()
)
)
);

View File

@ -26,23 +26,4 @@ import org.hibernate.type.descriptor.java.JavaType;
* @author Steve Ebersole
*/
public interface DomainType<J> extends SqmExpressible<J> {
/**
* The name of the type.
*
* @apiNote This is the Hibernate notion of the type name. For most types
* this will simply be the Java type (i.e. {@link Class}) name. However
* using the String allows for Hibernate's dynamic model feature.
*/
default String getTypeName() {
// default impl to handle the general case returning the Java type name
return getExpressibleJavaType().getJavaType().getTypeName();
}
/**
* The descriptor for the Java type (i.e. {@link Class}) represented by this
* DomainType.
*
* @see #getTypeName
*/
JavaType<J> getExpressibleJavaType();
}

View File

@ -19,11 +19,11 @@ import org.hibernate.query.sqm.tree.from.SqmFrom;
/**
* @author Steve Ebersole
*/
class BagAttributeImpl<X, E>
public class BagAttributeImpl<X, E>
extends AbstractPluralAttribute<X, Collection<E>, E>
implements BagPersistentAttribute<X, E> {
BagAttributeImpl(PluralAttributeBuilder<X, Collection<E>, E, ?> xceBuilder, MetadataContext metadataContext) {
public BagAttributeImpl(PluralAttributeBuilder<X, Collection<E>, E, ?> xceBuilder, MetadataContext metadataContext) {
super( xceBuilder, metadataContext );
}

View File

@ -23,7 +23,6 @@ import org.hibernate.metamodel.model.domain.DomainType;
import org.hibernate.metamodel.model.domain.EntityDomainType;
import org.hibernate.metamodel.model.domain.IdentifiableDomainType;
import org.hibernate.metamodel.model.domain.JpaMetamodel;
import org.hibernate.metamodel.model.domain.ManagedDomainType;
import org.hibernate.metamodel.model.domain.PersistentAttribute;
import org.hibernate.metamodel.model.domain.SingularPersistentAttribute;
import org.hibernate.metamodel.model.domain.spi.JpaMetamodelImplementor;
@ -47,22 +46,25 @@ public class EntityTypeImpl<J>
private final SqmPathSource<?> discriminatorPathSource;
public EntityTypeImpl(
String entityName,
String jpaEntityName,
boolean hasIdClass,
boolean hasIdProperty,
boolean hasVersion,
JavaType<J> javaType,
IdentifiableDomainType<? super J> superType,
PersistentClass persistentClass,
JpaMetamodelImplementor jpaMetamodel) {
super(
persistentClass.getEntityName(),
entityName,
javaType,
superType,
persistentClass.getDeclaredIdentifierMapper() != null
|| superType != null && superType.hasIdClass(),
persistentClass.hasIdentifierProperty(),
persistentClass.isVersioned(),
hasIdClass,
hasIdProperty,
hasVersion,
jpaMetamodel
);
this.jpaEntityName = persistentClass.getJpaEntityName();
this.jpaEntityName = jpaEntityName;
final Queryable entityDescriptor = (Queryable)
jpaMetamodel.getMappingMetamodel()
@ -84,6 +86,25 @@ public class EntityTypeImpl<J>
entityDescriptor
);
}
public EntityTypeImpl(
JavaType<J> javaType,
IdentifiableDomainType<? super J> superType,
PersistentClass persistentClass,
JpaMetamodelImplementor jpaMetamodel) {
this(
persistentClass.getEntityName(),
persistentClass.getJpaEntityName(),
persistentClass.getDeclaredIdentifierMapper() != null
|| superType != null && superType.hasIdClass(),
persistentClass.hasIdentifierProperty(),
persistentClass.isVersioned(),
javaType,
superType,
jpaMetamodel
);
}
public EntityTypeImpl(JavaType<J> javaTypeDescriptor, JpaMetamodelImplementor jpaMetamodel) {
super(
javaTypeDescriptor.getJavaTypeClass().getName(),

View File

@ -22,10 +22,10 @@ import org.hibernate.query.sqm.tree.from.SqmFrom;
/**
* @author Steve Ebersole
*/
class ListAttributeImpl<X, E> extends AbstractPluralAttribute<X, List<E>, E> implements ListPersistentAttribute<X, E> {
public class ListAttributeImpl<X, E> extends AbstractPluralAttribute<X, List<E>, E> implements ListPersistentAttribute<X, E> {
private final SqmPathSource<Integer> indexPathSource;
ListAttributeImpl(PluralAttributeBuilder<X, List<E>, E, ?> builder, MetadataContext metadataContext) {
public ListAttributeImpl(PluralAttributeBuilder<X, List<E>, E, ?> builder, MetadataContext metadataContext) {
super( builder, metadataContext );
//noinspection unchecked

View File

@ -23,10 +23,10 @@ import org.hibernate.query.sqm.tree.from.SqmFrom;
/**
* @author Steve Ebersole
*/
class MapAttributeImpl<X, K, V> extends AbstractPluralAttribute<X, Map<K, V>, V> implements MapPersistentAttribute<X, K, V> {
public class MapAttributeImpl<X, K, V> extends AbstractPluralAttribute<X, Map<K, V>, V> implements MapPersistentAttribute<X, K, V> {
private final SqmPathSource<K> keyPathSource;
MapAttributeImpl(PluralAttributeBuilder<X, Map<K, V>, V, K> xceBuilder, MetadataContext metadataContext) {
public MapAttributeImpl(PluralAttributeBuilder<X, Map<K, V>, V, K> xceBuilder, MetadataContext metadataContext) {
super( xceBuilder, metadataContext );
this.keyPathSource = SqmMappingModelHelper.resolveSqmKeyPathSource(

View File

@ -410,7 +410,7 @@ public abstract class AbstractSelectionQuery<R>
final String errorMessage = String.format(
"Specified result type [%s] did not match Query selection type [%s] - multiple selections: use Tuple or array",
resultClass.getName(),
sqmExpressible.getExpressibleJavaType().getJavaType().getTypeName()
sqmExpressible.getTypeName()
);
throw new QueryTypeMismatchException( errorMessage );
}

View File

@ -38,4 +38,17 @@ public interface SqmExpressible<J> extends BindableType<J> {
default SqmExpressible<J> resolveExpressible(SessionFactoryImplementor sessionFactory) {
return this;
}
/**
* The name of the type.
*
* @apiNote This is the Hibernate notion of the type name. For most types
* this will simply be the Java type (i.e. {@link Class}) name. However
* using the String allows for Hibernate's dynamic model feature.
*/
default String getTypeName() {
// default impl to handle the general case returning the Java type name
JavaType<J> expressibleJavaType = getExpressibleJavaType();
return expressibleJavaType == null ? "unknown" : expressibleJavaType.getJavaType().getTypeName();
}
}

View File

@ -62,7 +62,7 @@ public interface SqmPathSource<J> extends SqmExpressible<J>, Bindable<J>, SqmExp
Locale.ROOT,
"Could not resolve attribute '%s' of '%s'",
name,
getExpressible().getExpressibleJavaType().getJavaType().getTypeName()
getExpressible().getTypeName()
)
)
);

View File

@ -52,7 +52,6 @@ import org.hibernate.query.sqm.tree.from.SqmJoin;
import org.hibernate.query.sqm.tree.from.SqmRoot;
import org.hibernate.query.sqm.tree.predicate.SqmInPredicate;
import org.hibernate.query.sqm.tree.predicate.SqmPredicate;
import org.hibernate.type.BasicType;
import org.hibernate.type.descriptor.java.JavaType;
import jakarta.persistence.Tuple;
@ -579,8 +578,10 @@ public class SqmSubQuery<T> extends AbstractSqmSelectQuery<T> implements SqmSele
@Override
public void applyInferableType(SqmExpressible<?> type) {
//noinspection unchecked
this.expressibleType = (SqmExpressible<T>) type;
setResultType( type == null ? null : expressibleType.getExpressibleJavaType().getJavaTypeClass() );
expressibleType = (SqmExpressible<T>) type;
if ( expressibleType != null && expressibleType.getExpressibleJavaType() != null ) {
setResultType( expressibleType.getExpressibleJavaType().getJavaTypeClass() );
}
}
private void applyInferableType(Class<T> type) {