6 - SQM based on JPA type system

This commit is contained in:
Andrea Boriero 2019-08-19 09:47:43 +01:00
parent 7a82dcf22b
commit 00d3abba13
21 changed files with 72 additions and 40 deletions

View File

@ -30,7 +30,9 @@ public interface MappingModelExpressable<T> {
//
// todo (6.0) : IMO `Bindable` should be consumed here and `Bindable` go away
void visitJdbcTypes(Consumer<SqlExpressableType> action, TypeConfiguration typeConfiguration);
default void visitJdbcTypes(Consumer<SqlExpressableType> action, TypeConfiguration typeConfiguration){
throw new NotYetImplementedFor6Exception( getClass() );
}
default Bindable getBindable() {
throw new NotYetImplementedFor6Exception( getClass() );

View File

@ -269,18 +269,18 @@ public abstract class AbstractIdentifiableType<J>
}
}
@Override
public void visitJdbcTypes(Consumer action, TypeConfiguration typeConfiguration) {
id.visitJdbcTypes( action, typeConfiguration );
if ( versionAttribute != null ) {
versionAttribute.visitJdbcTypes( action, typeConfiguration );
}
visitAttributes(
attribute -> attribute.visitJdbcTypes( action, typeConfiguration )
);
}
// @Override
// public void visitJdbcTypes(Consumer action, TypeConfiguration typeConfiguration) {
// id.visitJdbcTypes( action, typeConfiguration );
//
// if ( versionAttribute != null ) {
// versionAttribute.visitJdbcTypes( action, typeConfiguration );
// }
//
// visitAttributes(
// attribute -> attribute.visitJdbcTypes( action, typeConfiguration )
// );
// }
/**
* For used to retrieve the declared version when populating the static metamodel.

View File

@ -53,6 +53,7 @@ public abstract class AbstractPluralAttribute<D,C,E>
this.elementPathSource = DomainModelHelper.resolveSqmPathSource(
getName(),
getMappingRole(),
builder.getValueType(),
BindableType.PLURAL_ATTRIBUTE
);

View File

@ -19,9 +19,10 @@ public class AnyMappingSqmPathSource<J> extends AbstractSqmPathSource<J> {
@SuppressWarnings("WeakerAccess")
public AnyMappingSqmPathSource(
String localPathName,
String roleName,
AnyMappingDomainType<J> domainType,
BindableType jpaBindableType) {
super( localPathName, domainType, jpaBindableType );
super( localPathName, roleName, domainType, jpaBindableType );
}
@Override

View File

@ -9,6 +9,7 @@ package org.hibernate.metamodel.model.domain.internal;
import java.util.Collection;
import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.metamodel.internal.MetadataContext;
import org.hibernate.metamodel.model.domain.BagPersistentAttribute;
import org.hibernate.query.sqm.SqmPathSource;
import org.hibernate.query.hql.spi.SqmCreationState;
@ -24,8 +25,8 @@ class BagAttributeImpl<X, E>
extends AbstractPluralAttribute<X, Collection<E>, E>
implements BagPersistentAttribute<X, E> {
BagAttributeImpl(PluralAttributeBuilder<X, Collection<E>, E, ?> xceBuilder) {
super( xceBuilder );
BagAttributeImpl(PluralAttributeBuilder<X, Collection<E>, E, ?> xceBuilder, MetadataContext metadataContext) {
super( xceBuilder, metadataContext );
}
@Override

View File

@ -80,12 +80,14 @@ public class DomainModelHelper {
public static <J> SqmPathSource<J> resolveSqmPathSource(
String name,
String roleName,
DomainType<J> valueDomainType,
Bindable.BindableType jpaBindableType) {
if ( valueDomainType instanceof BasicDomainType ) {
return new BasicSqmPathSource<>(
name,
roleName,
(BasicDomainType<J>) valueDomainType,
jpaBindableType
);
@ -94,6 +96,7 @@ public class DomainModelHelper {
if ( valueDomainType instanceof AnyMappingDomainType ) {
return new AnyMappingSqmPathSource<>(
name,
roleName,
(AnyMappingDomainType<J>) valueDomainType,
jpaBindableType
);
@ -102,6 +105,7 @@ public class DomainModelHelper {
if ( valueDomainType instanceof EmbeddableDomainType ) {
return new EmbeddedSqmPathSource<>(
name,
roleName,
(EmbeddableDomainType<J>) valueDomainType,
jpaBindableType
);
@ -110,6 +114,7 @@ public class DomainModelHelper {
if ( valueDomainType instanceof EntityDomainType ) {
return new EntitySqmPathSource<>(
name,
roleName,
(EntityDomainType<J>) valueDomainType,
jpaBindableType
);

View File

@ -8,6 +8,7 @@ package org.hibernate.metamodel.model.domain.internal;
import java.util.List;
import org.hibernate.metamodel.internal.MetadataContext;
import org.hibernate.metamodel.model.domain.ListPersistentAttribute;
import org.hibernate.query.sqm.SqmPathSource;
import org.hibernate.query.hql.spi.SqmCreationState;
@ -22,12 +23,13 @@ import org.hibernate.query.sqm.tree.from.SqmFrom;
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) {
super( builder );
ListAttributeImpl(PluralAttributeBuilder<X, List<E>, E, ?> builder, MetadataContext metadataContext) {
super( builder, metadataContext );
//noinspection unchecked
this.indexPathSource = (SqmPathSource) DomainModelHelper.resolveSqmPathSource(
getName(),
getMappingRole(),
builder.getListIndexOrMapKeyType(),
BindableType.PLURAL_ATTRIBUTE
);

View File

@ -9,6 +9,7 @@ package org.hibernate.metamodel.model.domain.internal;
import java.util.Map;
import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.metamodel.internal.MetadataContext;
import org.hibernate.metamodel.model.domain.MapPersistentAttribute;
import org.hibernate.metamodel.model.domain.SimpleDomainType;
import org.hibernate.query.sqm.SqmPathSource;
@ -24,11 +25,12 @@ import org.hibernate.query.sqm.tree.from.SqmFrom;
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) {
super( xceBuilder );
MapAttributeImpl(PluralAttributeBuilder<X, Map<K, V>, V, K> xceBuilder, MetadataContext metadataContext) {
super( xceBuilder, metadataContext );
this.keyPathSource = DomainModelHelper.resolveSqmPathSource(
getName(),
getMappingRole(),
xceBuilder.getListIndexOrMapKeyType(),
BindableType.PLURAL_ATTRIBUTE
);

View File

@ -86,42 +86,42 @@ public class PluralAttributeBuilder<D, C, E, K> {
if ( Map.class.equals( attributeJtd.getJavaType() ) ) {
//noinspection unchecked
return new MapAttributeImpl<>( builder );
return new MapAttributeImpl<>( builder, metadataContext );
}
else if ( Set.class.equals( attributeJtd.getJavaType() ) ) {
//noinspection unchecked
return new SetAttributeImpl<>( builder );
return new SetAttributeImpl<>( builder, metadataContext );
}
else if ( List.class.equals( attributeJtd.getJavaType() ) ) {
//noinspection unchecked
return new ListAttributeImpl<>( builder );
return new ListAttributeImpl<>( builder, metadataContext );
}
else if ( Collection.class.equals( attributeJtd.getJavaType() ) ) {
//noinspection unchecked
return new BagAttributeImpl<>( builder );
return new BagAttributeImpl<>( builder, metadataContext );
}
//apply loose rules
if ( attributeJtd.getJavaType().isArray() ) {
//noinspection unchecked
return new ListAttributeImpl<>( builder );
return new ListAttributeImpl<>( builder, metadataContext );
}
if ( Map.class.isAssignableFrom( attributeJtd.getJavaType() ) ) {
//noinspection unchecked
return new MapAttributeImpl<>( builder );
return new MapAttributeImpl<>( builder, metadataContext );
}
else if ( Set.class.isAssignableFrom( attributeJtd.getJavaType() ) ) {
//noinspection unchecked
return new SetAttributeImpl<>( builder );
return new SetAttributeImpl<>( builder, metadataContext );
}
else if ( List.class.isAssignableFrom( attributeJtd.getJavaType() ) ) {
//noinspection unchecked
return new ListAttributeImpl<>( builder );
return new ListAttributeImpl<>( builder, metadataContext );
}
else if ( Collection.class.isAssignableFrom( attributeJtd.getJavaType() ) ) {
//noinspection unchecked
return new BagAttributeImpl<>( builder );
return new BagAttributeImpl<>( builder, metadataContext );
}
throw new UnsupportedOperationException( "Unknown collection: " + attributeJtd.getJavaType() );

View File

@ -8,6 +8,7 @@ package org.hibernate.metamodel.model.domain.internal;
import java.util.Set;
import org.hibernate.metamodel.internal.MetadataContext;
import org.hibernate.metamodel.model.domain.SetPersistentAttribute;
import org.hibernate.query.hql.spi.SqmCreationState;
import org.hibernate.query.sqm.tree.SqmJoinType;
@ -20,8 +21,8 @@ import org.hibernate.query.sqm.tree.from.SqmFrom;
*/
public class SetAttributeImpl<X, E> extends AbstractPluralAttribute<X, Set<E>, E>
implements SetPersistentAttribute<X, E> {
public SetAttributeImpl(PluralAttributeBuilder<X, Set<E>, E, ?> xceBuilder) {
super( xceBuilder );
public SetAttributeImpl(PluralAttributeBuilder<X, Set<E>, E, ?> xceBuilder, MetadataContext metadataContext) {
super( xceBuilder, metadataContext );
}
@Override

View File

@ -67,6 +67,7 @@ public class SingularAttributeImpl<D,J>
this.sqmPathSource = DomainModelHelper.resolveSqmPathSource(
name,
getMappingRole(),
attributeType,
BindableType.SINGULAR_ATTRIBUTE
);

View File

@ -9,6 +9,7 @@ package org.hibernate.persister.entity;
import org.hibernate.AssertionFailure;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.QueryException;
import org.hibernate.boot.model.relational.Database;
import org.hibernate.cache.spi.access.EntityDataAccess;
@ -41,6 +42,8 @@ import org.hibernate.sql.SelectFragment;
import org.hibernate.type.DiscriminatorType;
import org.hibernate.type.StandardBasicTypes;
import org.hibernate.type.Type;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.jboss.logging.Logger;
import java.io.Serializable;

View File

@ -17,6 +17,7 @@ import java.util.Set;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.boot.model.relational.Database;
import org.hibernate.cache.spi.access.EntityDataAccess;
import org.hibernate.cache.spi.access.NaturalIdDataAccess;
@ -43,6 +44,7 @@ import org.hibernate.sql.SelectFragment;
import org.hibernate.type.AssociationType;
import org.hibernate.type.DiscriminatorType;
import org.hibernate.type.Type;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
/**
* The default implementation of the <tt>EntityPersister</tt> interface.

View File

@ -19,6 +19,7 @@ import org.hibernate.AssertionFailure;
import org.hibernate.HibernateException;
import org.hibernate.LockMode;
import org.hibernate.MappingException;
import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.boot.model.relational.Database;
import org.hibernate.cache.spi.access.EntityDataAccess;
import org.hibernate.cache.spi.access.NaturalIdDataAccess;
@ -43,6 +44,7 @@ import org.hibernate.sql.SelectFragment;
import org.hibernate.sql.SimpleSelect;
import org.hibernate.type.StandardBasicTypes;
import org.hibernate.type.Type;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
/**
* Implementation of the "table-per-concrete-class" or "roll-down" mapping

View File

@ -140,10 +140,6 @@ public final class CompositionSingularSubAttributesHelper {
if ( type.isAssociationType() ) {
final AssociationType aType = (AssociationType) type;
return new AssociationAttributeDefinition() {
@Override
public JavaTypeDescriptor getExpressableJavaTypeDescriptor() {
return ;
}
@Override
public void visitJdbcTypes(

View File

@ -6,6 +6,7 @@
*/
package org.hibernate.persister.walking.internal;
import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.persister.entity.AbstractEntityPersister;
import org.hibernate.persister.walking.spi.AttributeDefinition;
import org.hibernate.persister.walking.spi.AttributeSource;
@ -16,6 +17,7 @@ import org.hibernate.persister.walking.spi.EntityIdentifierDefinition;
import org.hibernate.persister.walking.spi.NonEncapsulatedEntityIdentifierDefinition;
import org.hibernate.type.CompositeType;
import org.hibernate.type.Type;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
/**
* @author Gail Badner

View File

@ -239,4 +239,8 @@ public class FullyQualifiedReflectivePathTerminal
return null;
}
@Override
public SqmExpressable getExpressableType() {
return expressableType;
}
}

View File

@ -673,7 +673,7 @@ public abstract class BaseSqmToSqlAstConverter
private final Stack<Supplier<MappingModelExpressable>> inferableTypeAccessStack = new StandardStack<>(
() -> () -> null
() -> null
);
private void resolveSqmParameter(SqmParameter expression, MappingModelExpressable valueMapping, Consumer<JdbcParameter> jdbcParameterConsumer) {

View File

@ -31,9 +31,9 @@ public interface SqmPathInterpretation<T> extends SqmExpressionInterpretation<T>
SqmPathSource<T> getSqmPathSource();
@Override
default Expression toSqlExpression(SqlAstCreationState sqlAstCreationState) {
throw new NotYetImplementedFor6Exception( getClass() );
// @Override
// default Expression toSqlExpression(SqlAstCreationState sqlAstCreationState) {
// throw new NotYetImplementedFor6Exception( getClass() );
// final TableGroup tableGroup;
//
// if ( getSqmPathSource() instanceof BasicSqmPathSource ) {
@ -65,5 +65,5 @@ public interface SqmPathInterpretation<T> extends SqmExpressionInterpretation<T>
// }
//
// return new SqlTuple( list, sqlAstCreationState.getExpressableType() );
}
// }
}

View File

@ -106,6 +106,11 @@ public class SqmPolymorphicRootDescriptor<T> implements EntityDomainType<T> {
return getName();
}
@Override
public String getMappingRole() {
return getHibernateEntityName();
}
@Override
public String getPathName() {
return getName();

View File

@ -6,6 +6,7 @@
*/
package org.hibernate.tuple.entity;
import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.engine.FetchStrategy;
import org.hibernate.engine.FetchStyle;
import org.hibernate.engine.internal.JoinHelper;
@ -30,6 +31,7 @@ import org.hibernate.tuple.BaselineAttributeInformation;
import org.hibernate.type.AnyType;
import org.hibernate.type.AssociationType;
import org.hibernate.type.ForeignKeyDirection;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import static org.hibernate.engine.internal.JoinHelper.getLHSColumnNames;
import static org.hibernate.engine.internal.JoinHelper.getLHSTableName;