fix up lots of warnings, esp. unused parameters
This commit is contained in:
parent
b4e26b3e32
commit
25d0922ff9
|
@ -91,7 +91,7 @@ public class BeanValidationIntegrator implements Integrator {
|
|||
Metadata metadata,
|
||||
BootstrapContext bootstrapContext,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
ServiceRegistryImplementor serviceRegistry = sessionFactory.getServiceRegistry();
|
||||
final ServiceRegistryImplementor serviceRegistry = sessionFactory.getServiceRegistry();
|
||||
final ConfigurationService cfgService = serviceRegistry.requireService( ConfigurationService.class );
|
||||
// IMPL NOTE : see the comments on ActivationContext.getValidationModes() as to why this is multi-valued...
|
||||
Object modeSetting = cfgService.getSettings().get( JAKARTA_MODE_PROPERTY );
|
||||
|
|
|
@ -46,7 +46,6 @@ import org.hibernate.engine.spi.SessionFactoryImplementor;
|
|||
import org.hibernate.event.service.spi.EventListenerGroup;
|
||||
import org.hibernate.event.service.spi.EventListenerRegistry;
|
||||
import org.hibernate.event.spi.EventType;
|
||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||
import org.hibernate.mapping.Collection;
|
||||
import org.hibernate.mapping.Column;
|
||||
import org.hibernate.mapping.Component;
|
||||
|
|
|
@ -37,7 +37,7 @@ import org.jboss.logging.Logger;
|
|||
/**
|
||||
* Allows the collection cache to be automatically evicted if an element is inserted/removed/updated *without* properly
|
||||
* managing both sides of the association (ie, the ManyToOne collection is changed w/o properly managing the OneToMany).
|
||||
*
|
||||
* <p>
|
||||
* For this functionality to be used, {@value org.hibernate.cfg.AvailableSettings#AUTO_EVICT_COLLECTION_CACHE} must be
|
||||
* enabled. For performance reasons, it's disabled by default.
|
||||
*
|
||||
|
@ -90,7 +90,8 @@ public class CollectionCacheInvalidator
|
|||
// Nothing to do, if caching is disabled
|
||||
return;
|
||||
}
|
||||
final EventListenerRegistry eventListenerRegistry = sessionFactory.getServiceRegistry().requireService( EventListenerRegistry.class );
|
||||
final EventListenerRegistry eventListenerRegistry =
|
||||
sessionFactory.getServiceRegistry().requireService( EventListenerRegistry.class );
|
||||
eventListenerRegistry.appendListeners( EventType.POST_INSERT, this );
|
||||
eventListenerRegistry.appendListeners( EventType.POST_DELETE, this );
|
||||
eventListenerRegistry.appendListeners( EventType.POST_UPDATE, this );
|
||||
|
|
|
@ -30,7 +30,6 @@ import org.hibernate.metamodel.CollectionClassification;
|
|||
import org.hibernate.metamodel.mapping.AttributeMapping;
|
||||
import org.hibernate.metamodel.mapping.CollectionPart;
|
||||
import org.hibernate.metamodel.mapping.EntityIdentifierMapping;
|
||||
import org.hibernate.metamodel.mapping.EntityMappingType;
|
||||
import org.hibernate.metamodel.mapping.EntityValuedModelPart;
|
||||
import org.hibernate.metamodel.mapping.ForeignKeyDescriptor;
|
||||
import org.hibernate.metamodel.mapping.ModelPart;
|
||||
|
|
|
@ -202,11 +202,11 @@ public interface MappingMetamodel {
|
|||
<T> void addNamedEntityGraph(String graphName, RootGraphImplementor<T> entityGraph);
|
||||
void forEachNamedGraph(Consumer<RootGraph<?>> action);
|
||||
RootGraph<?> defaultGraph(String entityName);
|
||||
RootGraph<?> defaultGraph(Class entityJavaType);
|
||||
RootGraph<?> defaultGraph(Class<?> entityJavaType);
|
||||
RootGraph<?> defaultGraph(EntityPersister entityDescriptor);
|
||||
RootGraph<?> defaultGraph(EntityDomainType<?> entityDomainType);
|
||||
|
||||
List<RootGraph<?>> findRootGraphsForType(Class baseEntityJavaType);
|
||||
List<RootGraph<?>> findRootGraphsForType(Class<?> baseEntityJavaType);
|
||||
List<RootGraph<?>> findRootGraphsForType(String baseEntityName);
|
||||
List<RootGraph<?>> findRootGraphsForType(EntityPersister baseEntityDescriptor);
|
||||
}
|
||||
|
|
|
@ -11,14 +11,14 @@ import org.hibernate.graph.internal.SubGraphImpl;
|
|||
import org.hibernate.graph.spi.SubGraphImplementor;
|
||||
import org.hibernate.metamodel.MappingMetamodel;
|
||||
import org.hibernate.metamodel.mapping.EntityMappingType;
|
||||
import org.hibernate.metamodel.mapping.MappingModelHelper;
|
||||
import org.hibernate.metamodel.mapping.ModelPart;
|
||||
import org.hibernate.metamodel.model.domain.EmbeddableDomainType;
|
||||
import org.hibernate.metamodel.model.domain.EntityDomainType;
|
||||
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.spi.JpaMetamodelImplementor;
|
||||
|
||||
import static org.hibernate.metamodel.mapping.MappingModelHelper.isCompatibleModelPart;
|
||||
|
||||
/**
|
||||
* Helper containing utilities useful for domain model handling
|
||||
|
@ -38,16 +38,16 @@ public class DomainModelHelper {
|
|||
}
|
||||
|
||||
// first, try to find it by name directly
|
||||
ManagedDomainType<S> subManagedType = jpaMetamodel.resolveHqlEntityReference( subTypeName );
|
||||
final ManagedDomainType<S> subManagedType = jpaMetamodel.resolveHqlEntityReference( subTypeName );
|
||||
if ( subManagedType != null ) {
|
||||
return subManagedType;
|
||||
}
|
||||
|
||||
// it could still be a mapped-superclass
|
||||
try {
|
||||
final Class<?> javaType = jpaMetamodel.getServiceRegistry()
|
||||
.requireService( ClassLoaderService.class )
|
||||
.classForName( subTypeName );
|
||||
final Class<?> javaType =
|
||||
jpaMetamodel.getServiceRegistry().requireService( ClassLoaderService.class )
|
||||
.classForName( subTypeName );
|
||||
return (ManagedDomainType<S>) jpaMetamodel.managedType( javaType );
|
||||
}
|
||||
catch (Exception ignore) {
|
||||
|
@ -59,27 +59,19 @@ public class DomainModelHelper {
|
|||
static boolean isCompatible(
|
||||
PersistentAttribute<?, ?> attribute1,
|
||||
PersistentAttribute<?, ?> attribute2,
|
||||
JpaMetamodel jpaMetamodel) {
|
||||
MappingMetamodel mappingMetamodel) {
|
||||
if ( attribute1 == attribute2 ) {
|
||||
return true;
|
||||
}
|
||||
final MappingMetamodel runtimeMetamodels =
|
||||
//TODO: eliminate this cast!
|
||||
((JpaMetamodelImplementor) jpaMetamodel).getMappingMetamodel();
|
||||
final ModelPart modelPart1 = getEntityAttributeModelPart(
|
||||
attribute1,
|
||||
attribute1.getDeclaringType(),
|
||||
runtimeMetamodels
|
||||
);
|
||||
final ModelPart modelPart2 = getEntityAttributeModelPart(
|
||||
attribute2,
|
||||
attribute2.getDeclaringType(),
|
||||
runtimeMetamodels
|
||||
);
|
||||
return modelPart1 != null && modelPart2 != null && MappingModelHelper.isCompatibleModelPart(
|
||||
modelPart1,
|
||||
modelPart2
|
||||
);
|
||||
else {
|
||||
final ModelPart modelPart1 =
|
||||
getEntityAttributeModelPart( attribute1, attribute1.getDeclaringType(), mappingMetamodel );
|
||||
final ModelPart modelPart2 =
|
||||
getEntityAttributeModelPart( attribute2, attribute2.getDeclaringType(), mappingMetamodel );
|
||||
return modelPart1 != null
|
||||
&& modelPart2 != null
|
||||
&& isCompatibleModelPart( modelPart1, modelPart2 );
|
||||
}
|
||||
}
|
||||
|
||||
static ModelPart getEntityAttributeModelPart(
|
||||
|
@ -95,7 +87,7 @@ public class DomainModelHelper {
|
|||
for ( ManagedDomainType<?> subType : domainType.getSubTypes() ) {
|
||||
final ModelPart modelPart = getEntityAttributeModelPart( attribute, subType, mappingMetamodel );
|
||||
if ( modelPart != null ) {
|
||||
if ( candidate != null && !MappingModelHelper.isCompatibleModelPart( candidate, modelPart ) ) {
|
||||
if ( candidate != null && !isCompatibleModelPart( candidate, modelPart ) ) {
|
||||
return null;
|
||||
}
|
||||
candidate = modelPart;
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
package org.hibernate.metamodel.model.domain.internal;
|
||||
|
||||
import java.io.ObjectStreamException;
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.Locale;
|
||||
|
@ -75,16 +76,13 @@ public class EntityTypeImpl<J>
|
|||
metamodel.getMappingMetamodel()
|
||||
.getEntityDescriptor( getHibernateEntityName() );
|
||||
final DiscriminatorMetadata discriminatorMetadata = entityDescriptor.getTypeDiscriminatorMetadata();
|
||||
final DomainType discriminatorType =
|
||||
final DomainType<?> discriminatorType =
|
||||
discriminatorMetadata != null
|
||||
? (DomainType) discriminatorMetadata.getResolutionType()
|
||||
? (DomainType<?>) discriminatorMetadata.getResolutionType()
|
||||
: metamodel.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.STRING );
|
||||
|
||||
this.discriminatorPathSource = discriminatorType == null ? null : new EntityDiscriminatorSqmPathSource(
|
||||
discriminatorType,
|
||||
this,
|
||||
entityDescriptor
|
||||
);
|
||||
this.discriminatorPathSource = discriminatorType == null ? null
|
||||
: new EntityDiscriminatorSqmPathSource<>( discriminatorType, this, entityDescriptor );
|
||||
}
|
||||
|
||||
public EntityTypeImpl(
|
||||
|
@ -147,16 +145,16 @@ public class EntityTypeImpl<J>
|
|||
if ( attribute != null ) {
|
||||
return (SqmPathSource<?>) attribute;
|
||||
}
|
||||
|
||||
if ( EntityIdentifierMapping.matchesRoleName( name ) ) {
|
||||
else if ( EntityIdentifierMapping.matchesRoleName( name ) ) {
|
||||
return hasSingleIdAttribute() ? findIdAttribute() : getIdentifierDescriptor();
|
||||
}
|
||||
|
||||
if ( EntityDiscriminatorMapping.matchesRoleName( name ) ) {
|
||||
else if ( EntityDiscriminatorMapping.matchesRoleName( name ) ) {
|
||||
return discriminatorPathSource;
|
||||
}
|
||||
|
||||
return null;
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -165,29 +163,31 @@ public class EntityTypeImpl<J>
|
|||
if ( attribute != null ) {
|
||||
return (SqmPathSource<?>) attribute;
|
||||
}
|
||||
|
||||
PersistentAttribute<?, ?> subtypeAttribute = findSubtypeAttribute( name, metamodel );
|
||||
if ( subtypeAttribute != null ) {
|
||||
return (SqmPathSource<?>) subtypeAttribute;
|
||||
else {
|
||||
//TODO: eliminate this cast!
|
||||
final PersistentAttribute<?, ?> subtypeAttribute = findSubtypeAttribute( name );
|
||||
if ( subtypeAttribute != null ) {
|
||||
return (SqmPathSource<?>) subtypeAttribute;
|
||||
}
|
||||
else if ( EntityIdentifierMapping.matchesRoleName( name ) ) {
|
||||
return hasSingleIdAttribute() ? findIdAttribute() : getIdentifierDescriptor();
|
||||
}
|
||||
else if ( EntityDiscriminatorMapping.matchesRoleName( name ) ) {
|
||||
return discriminatorPathSource;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if ( EntityIdentifierMapping.matchesRoleName( name ) ) {
|
||||
return hasSingleIdAttribute() ? findIdAttribute() : getIdentifierDescriptor();
|
||||
}
|
||||
|
||||
if ( EntityDiscriminatorMapping.matchesRoleName( name ) ) {
|
||||
return discriminatorPathSource;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private PersistentAttribute<?, ?> findSubtypeAttribute(String name, JpaMetamodel metamodel) {
|
||||
private PersistentAttribute<?, ?> findSubtypeAttribute(String name) {
|
||||
PersistentAttribute<?,?> subtypeAttribute = null;
|
||||
for ( ManagedDomainType<?> subtype : getSubTypes() ) {
|
||||
final PersistentAttribute<?,?> candidate = subtype.findSubTypesAttribute( name );
|
||||
if ( candidate != null ) {
|
||||
if ( subtypeAttribute != null && !isCompatible( subtypeAttribute, candidate, metamodel ) ) {
|
||||
if ( subtypeAttribute != null
|
||||
&& !isCompatible( subtypeAttribute, candidate, metamodel.getMappingMetamodel() ) ) {
|
||||
throw new PathException(
|
||||
String.format(
|
||||
Locale.ROOT,
|
||||
|
@ -211,12 +211,12 @@ public class EntityTypeImpl<J>
|
|||
if ( attribute != null ) {
|
||||
return attribute;
|
||||
}
|
||||
|
||||
if ( EntityIdentifierMapping.matchesRoleName( name ) ) {
|
||||
else if ( EntityIdentifierMapping.matchesRoleName( name ) ) {
|
||||
return findIdAttribute();
|
||||
}
|
||||
|
||||
return null;
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -255,6 +255,7 @@ public class EntityTypeImpl<J>
|
|||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// Serialization
|
||||
|
||||
@Serial
|
||||
protected Object writeReplace() throws ObjectStreamException {
|
||||
return new SerialForm( metamodel, getHibernateEntityName() );
|
||||
}
|
||||
|
@ -268,6 +269,7 @@ public class EntityTypeImpl<J>
|
|||
this.hibernateEntityName = hibernateEntityName;
|
||||
}
|
||||
|
||||
@Serial
|
||||
private Object readResolve() {
|
||||
return jpaMetamodel.entity( hibernateEntityName );
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@ import java.io.Serializable;
|
|||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
@ -70,6 +69,8 @@ import jakarta.persistence.metamodel.EntityType;
|
|||
import jakarta.persistence.metamodel.ManagedType;
|
||||
import jakarta.persistence.metamodel.Type;
|
||||
|
||||
import static java.util.Collections.emptySet;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
|
@ -247,17 +248,12 @@ public class JpaMetamodelImpl implements JpaMetamodelImplementor, Serializable {
|
|||
}
|
||||
|
||||
private Collection<ManagedDomainType<?>> getAllManagedTypes() {
|
||||
switch ( jpaMetaModelPopulationSetting ) {
|
||||
case IGNORE_UNSUPPORTED:
|
||||
return managedTypeByClass.values();
|
||||
case ENABLED:
|
||||
return managedTypeByName.values();
|
||||
case DISABLED:
|
||||
return Collections.emptySet();
|
||||
default:
|
||||
// should never happen
|
||||
throw new AssertionError();
|
||||
}
|
||||
// should never happen
|
||||
return switch (jpaMetaModelPopulationSetting) {
|
||||
case IGNORE_UNSUPPORTED -> managedTypeByClass.values();
|
||||
case ENABLED -> managedTypeByName.values();
|
||||
case DISABLED -> emptySet();
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -649,9 +645,8 @@ public class JpaMetamodelImpl implements JpaMetamodelImplementor, Serializable {
|
|||
}
|
||||
}
|
||||
|
||||
typeConfiguration.getJavaTypeRegistry().forEachDescriptor( (descriptor) -> {
|
||||
if ( descriptor instanceof EnumJavaType ) {
|
||||
final EnumJavaType<? extends Enum<?>> enumJavaType = (EnumJavaType<? extends Enum<?>>) descriptor;
|
||||
typeConfiguration.getJavaTypeRegistry().forEachDescriptor( descriptor -> {
|
||||
if ( descriptor instanceof EnumJavaType<? extends Enum<?>> enumJavaType ) {
|
||||
final Class<? extends Enum<?>> enumJavaClass = enumJavaType.getJavaTypeClass();
|
||||
final Enum<?>[] enumConstants = enumJavaClass.getEnumConstants();
|
||||
for ( Enum<?> enumConstant : enumConstants ) {
|
||||
|
|
|
@ -70,7 +70,6 @@ import org.hibernate.spi.NavigablePath;
|
|||
import org.hibernate.sql.ast.tree.from.TableGroup;
|
||||
import org.hibernate.type.BasicType;
|
||||
import org.hibernate.type.ComponentType;
|
||||
import org.hibernate.type.Type;
|
||||
import org.hibernate.type.descriptor.java.EnumJavaType;
|
||||
import org.hibernate.type.descriptor.java.JavaType;
|
||||
import org.hibernate.type.descriptor.java.spi.JavaTypeRegistry;
|
||||
|
@ -315,38 +314,32 @@ public class MappingMetamodelImpl extends QueryParameterBindingTypeResolverImpl
|
|||
modelCreationContext
|
||||
);
|
||||
collectionPersisterMap.put( model.getRole(), persister );
|
||||
final Type indexType = persister.getIndexType();
|
||||
if ( indexType instanceof org.hibernate.type.EntityType ) {
|
||||
final String entityName = ( (org.hibernate.type.EntityType) indexType ).getAssociatedEntityName();
|
||||
Set<String> roles = collectionRolesByEntityParticipant.get( entityName );
|
||||
//noinspection Java8MapApi
|
||||
if ( roles == null ) {
|
||||
roles = new HashSet<>();
|
||||
collectionRolesByEntityParticipant.put( entityName, roles );
|
||||
}
|
||||
roles.add( persister.getRole() );
|
||||
if ( persister.getIndexType() instanceof org.hibernate.type.EntityType entityType ) {
|
||||
registerEntityParticipant( entityType, persister );
|
||||
}
|
||||
final Type elementType = persister.getElementType();
|
||||
if ( elementType instanceof org.hibernate.type.EntityType ) {
|
||||
final String entityName = ( (org.hibernate.type.EntityType) elementType ).getAssociatedEntityName();
|
||||
Set<String> roles = collectionRolesByEntityParticipant.get( entityName );
|
||||
//noinspection Java8MapApi
|
||||
if ( roles == null ) {
|
||||
roles = new HashSet<>();
|
||||
collectionRolesByEntityParticipant.put( entityName, roles );
|
||||
}
|
||||
roles.add( persister.getRole() );
|
||||
if ( persister.getElementType() instanceof org.hibernate.type.EntityType entityType ) {
|
||||
registerEntityParticipant( entityType, persister );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void registerEntityParticipant(org.hibernate.type.EntityType entityType, CollectionPersister persister) {
|
||||
final String entityName = entityType.getAssociatedEntityName();
|
||||
Set<String> roles = collectionRolesByEntityParticipant.get( entityName );
|
||||
//noinspection Java8MapApi
|
||||
if ( roles == null ) {
|
||||
roles = new HashSet<>();
|
||||
collectionRolesByEntityParticipant.put( entityName, roles );
|
||||
}
|
||||
roles.add( persister.getRole() );
|
||||
}
|
||||
|
||||
private static void registerEntityNameResolvers(
|
||||
EntityPersister persister,
|
||||
Set<EntityNameResolver> entityNameResolvers) {
|
||||
if ( persister.getRepresentationStrategy() == null ) {
|
||||
return;
|
||||
if ( persister.getRepresentationStrategy() != null ) {
|
||||
registerEntityNameResolvers( persister.getRepresentationStrategy(), entityNameResolvers );
|
||||
}
|
||||
registerEntityNameResolvers( persister.getRepresentationStrategy(), entityNameResolvers );
|
||||
}
|
||||
|
||||
private static void registerEntityNameResolvers(
|
||||
|
@ -607,7 +600,7 @@ public class MappingMetamodelImpl extends QueryParameterBindingTypeResolverImpl
|
|||
|
||||
@Override @SuppressWarnings("deprecation")
|
||||
public EntityPersister entityPersister(String entityName) throws MappingException {
|
||||
EntityPersister result = entityPersisterMap.get( entityName );
|
||||
final EntityPersister result = entityPersisterMap.get( entityName );
|
||||
if ( result == null ) {
|
||||
throw new MappingException( "Unknown entity: " + entityName );
|
||||
}
|
||||
|
@ -641,7 +634,7 @@ public class MappingMetamodelImpl extends QueryParameterBindingTypeResolverImpl
|
|||
|
||||
@Override
|
||||
public CollectionPersister getCollectionDescriptor(String role) {
|
||||
CollectionPersister collectionPersister = collectionPersisterMap.get( role );
|
||||
final CollectionPersister collectionPersister = collectionPersisterMap.get( role );
|
||||
if ( collectionPersister == null ) {
|
||||
throw new IllegalArgumentException( "Unable to locate persister: " + role );
|
||||
}
|
||||
|
@ -719,7 +712,7 @@ public class MappingMetamodelImpl extends QueryParameterBindingTypeResolverImpl
|
|||
}
|
||||
|
||||
@Override
|
||||
public RootGraph<?> defaultGraph(Class entityJavaType) {
|
||||
public RootGraph<?> defaultGraph(Class<?> entityJavaType) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
@ -734,7 +727,7 @@ public class MappingMetamodelImpl extends QueryParameterBindingTypeResolverImpl
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<RootGraph<?>> findRootGraphsForType(Class baseEntityJavaType) {
|
||||
public List<RootGraph<?>> findRootGraphsForType(Class<?> baseEntityJavaType) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
@ -782,8 +775,7 @@ public class MappingMetamodelImpl extends QueryParameterBindingTypeResolverImpl
|
|||
public MappingModelExpressible<?> resolveMappingExpressible(
|
||||
SqmExpressible<?> sqmExpressible,
|
||||
Function<NavigablePath, TableGroup> tableGroupLocator) {
|
||||
if ( sqmExpressible instanceof SqmPath ) {
|
||||
final SqmPath<?> sqmPath = (SqmPath<?>) sqmExpressible;
|
||||
if ( sqmExpressible instanceof SqmPath<?> sqmPath ) {
|
||||
final NavigablePath navigablePath = sqmPath.getNavigablePath();
|
||||
if ( navigablePath.getParent() != null ) {
|
||||
final TableGroup parentTableGroup = tableGroupLocator.apply( navigablePath.getParent() );
|
||||
|
@ -804,35 +796,34 @@ public class MappingMetamodelImpl extends QueryParameterBindingTypeResolverImpl
|
|||
return resolveMappingExpressible( sqmExpressible.getSqmType(), tableGroupLocator );
|
||||
}
|
||||
|
||||
if ( sqmExpressible instanceof SqmFieldLiteral ) {
|
||||
return getTypeConfiguration().getBasicTypeForJavaType( ( (SqmFieldLiteral<?>) sqmExpressible).getJavaType() );
|
||||
if ( sqmExpressible instanceof SqmFieldLiteral<?> sqmFieldLiteral ) {
|
||||
return getTypeConfiguration().getBasicTypeForJavaType( sqmFieldLiteral.getJavaType() );
|
||||
}
|
||||
|
||||
if ( sqmExpressible instanceof CompositeSqmPathSource ) {
|
||||
throw new UnsupportedOperationException( "Resolution of embedded-valued SqmExpressible nodes not yet implemented" );
|
||||
}
|
||||
|
||||
if ( sqmExpressible instanceof AnonymousTupleSqmPathSource<?> ) {
|
||||
if ( sqmExpressible instanceof AnonymousTupleSqmPathSource<?> anonymousTupleSqmPathSource ) {
|
||||
return resolveMappingExpressible(
|
||||
( (AnonymousTupleSqmPathSource<?>) sqmExpressible ).getSqmPathType(),
|
||||
anonymousTupleSqmPathSource.getSqmPathType(),
|
||||
tableGroupLocator
|
||||
);
|
||||
}
|
||||
|
||||
if ( sqmExpressible instanceof EmbeddableTypeImpl ) {
|
||||
if ( sqmExpressible instanceof EmbeddableTypeImpl<?> ) {
|
||||
return (MappingModelExpressible<?>) sqmExpressible;
|
||||
}
|
||||
|
||||
if ( sqmExpressible instanceof EntityDomainType<?> ) {
|
||||
return getEntityDescriptor( ( (EntityDomainType<?>) sqmExpressible).getHibernateEntityName() );
|
||||
if ( sqmExpressible instanceof EntityDomainType<?> entityDomainType ) {
|
||||
return getEntityDescriptor( entityDomainType.getHibernateEntityName() );
|
||||
}
|
||||
|
||||
if ( sqmExpressible instanceof TupleType<?> ) {
|
||||
if ( sqmExpressible instanceof TupleType<?> tupleType ) {
|
||||
final MappingModelExpressible<?> mappingModelExpressible = tupleTypeCache.get(sqmExpressible);
|
||||
if ( mappingModelExpressible != null ) {
|
||||
return mappingModelExpressible;
|
||||
}
|
||||
final TupleType<?> tupleType = (TupleType<?>) sqmExpressible;
|
||||
final MappingModelExpressible<?>[] components = new MappingModelExpressible<?>[tupleType.componentCount()];
|
||||
for ( int i = 0; i < components.length; i++ ) {
|
||||
components[i] = resolveMappingExpressible( tupleType.get( i ), tableGroupLocator );
|
||||
|
|
|
@ -30,10 +30,12 @@ public enum SortDirection {
|
|||
if ( value == null ) {
|
||||
return null;
|
||||
}
|
||||
else return switch ( value.toLowerCase(Locale.ROOT) ) {
|
||||
case "asc", "ascending" -> ASCENDING;
|
||||
case "desc", "descending" -> DESCENDING;
|
||||
default -> throw new IllegalArgumentException( "Unknown sort order: " + value );
|
||||
};
|
||||
else {
|
||||
return switch ( value.toLowerCase(Locale.ROOT) ) {
|
||||
case "asc", "ascending" -> ASCENDING;
|
||||
case "desc", "descending" -> DESCENDING;
|
||||
default -> throw new IllegalArgumentException( "Unknown sort order: " + value );
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3384,7 +3384,7 @@ public interface HibernateCriteriaBuilder extends CriteriaBuilder {
|
|||
* @since 6.4
|
||||
*/
|
||||
@Incubating
|
||||
<T> JpaExpression<String> collectionToString(Expression<? extends Collection<?>> collectionExpression, Expression<String> separatorExpression);
|
||||
JpaExpression<String> collectionToString(Expression<? extends Collection<?>> collectionExpression, Expression<String> separatorExpression);
|
||||
|
||||
/**
|
||||
* Concatenates the non-null basic collection elements with a separator, as specified by the arguments.
|
||||
|
@ -3392,7 +3392,7 @@ public interface HibernateCriteriaBuilder extends CriteriaBuilder {
|
|||
* @since 6.4
|
||||
*/
|
||||
@Incubating
|
||||
<T> JpaExpression<String> collectionToString(Expression<? extends Collection<?>> collectionExpression, String separator);
|
||||
JpaExpression<String> collectionToString(Expression<? extends Collection<?>> collectionExpression, String separator);
|
||||
|
||||
/**
|
||||
* Whether a basic collection contains an element.
|
||||
|
|
|
@ -3086,7 +3086,7 @@ public class HibernateCriteriaBuilderDelegate implements HibernateCriteriaBuilde
|
|||
|
||||
@Override
|
||||
@Incubating
|
||||
public <T> JpaExpression<String> collectionToString(
|
||||
public JpaExpression<String> collectionToString(
|
||||
Expression<? extends Collection<?>> collectionExpression,
|
||||
Expression<String> separatorExpression) {
|
||||
return criteriaBuilder.collectionToString( collectionExpression, separatorExpression );
|
||||
|
@ -3094,7 +3094,7 @@ public class HibernateCriteriaBuilderDelegate implements HibernateCriteriaBuilde
|
|||
|
||||
@Override
|
||||
@Incubating
|
||||
public <T> JpaExpression<String> collectionToString(
|
||||
public JpaExpression<String> collectionToString(
|
||||
Expression<? extends Collection<?>> collectionExpression,
|
||||
String separator) {
|
||||
return criteriaBuilder.collectionToString( collectionExpression, separator );
|
||||
|
|
|
@ -486,10 +486,10 @@ public interface NodeBuilder extends HibernateCriteriaBuilder, BindingContext {
|
|||
<T> SqmExpression<Collection<T>> collectionFill(T element, Integer elementCount);
|
||||
|
||||
@Override
|
||||
<T> SqmExpression<String> collectionToString(Expression<? extends Collection<?>> collectionExpression, Expression<String> separatorExpression);
|
||||
SqmExpression<String> collectionToString(Expression<? extends Collection<?>> collectionExpression, Expression<String> separatorExpression);
|
||||
|
||||
@Override
|
||||
<T> SqmExpression<String> collectionToString(Expression<? extends Collection<?>> collectionExpression, String separator);
|
||||
SqmExpression<String> collectionToString(Expression<? extends Collection<?>> collectionExpression, String separator);
|
||||
|
||||
@Override
|
||||
<E> SqmPredicate collectionContains(Expression<? extends Collection<E>> collectionExpression, Expression<? extends E> elementExpression);
|
||||
|
|
|
@ -443,13 +443,10 @@ public class ConcreteSqmSelectQueryPlan<R> implements SelectQueryPlan<R> {
|
|||
}
|
||||
|
||||
private JdbcParameterBindings createJdbcParameterBindings(CacheableSqmInterpretation sqmInterpretation, DomainQueryExecutionContext executionContext) {
|
||||
final SharedSessionContractImplementor session = executionContext.getSession();
|
||||
return SqmUtil.createJdbcParameterBindings(
|
||||
executionContext.getQueryParameterBindings(),
|
||||
domainParameterXref,
|
||||
sqmInterpretation.getJdbcParamsXref(),
|
||||
session.getFactory().getRuntimeMetamodels().getMappingMetamodel(),
|
||||
sqmInterpretation.getTableGroupAccess()::findTableGroup,
|
||||
new SqmParameterMappingModelResolutionAccess() {
|
||||
//this is pretty ugly!
|
||||
@Override @SuppressWarnings("unchecked")
|
||||
|
@ -457,7 +454,7 @@ public class ConcreteSqmSelectQueryPlan<R> implements SelectQueryPlan<R> {
|
|||
return (MappingModelExpressible<T>) sqmInterpretation.getSqmParameterMappingModelTypes().get(parameter);
|
||||
}
|
||||
},
|
||||
session
|
||||
executionContext.getSession()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -494,8 +491,6 @@ public class ConcreteSqmSelectQueryPlan<R> implements SelectQueryPlan<R> {
|
|||
executionContext.getQueryParameterBindings(),
|
||||
domainParameterXref,
|
||||
jdbcParamsXref,
|
||||
session.getFactory().getRuntimeMetamodels().getMappingMetamodel(),
|
||||
tableGroupAccess::findTableGroup,
|
||||
new SqmParameterMappingModelResolutionAccess() {
|
||||
@Override @SuppressWarnings("unchecked")
|
||||
public <T> MappingModelExpressible<T> getResolvedMappingModelType(SqmParameter<T> parameter) {
|
||||
|
|
|
@ -94,8 +94,6 @@ public class SimpleDeleteQueryPlan implements NonSelectQueryPlan {
|
|||
executionContext.getQueryParameterBindings(),
|
||||
domainParameterXref,
|
||||
jdbcParamsXref,
|
||||
factory.getRuntimeMetamodels().getMappingMetamodel(),
|
||||
sqmInterpretation.getFromClauseAccess()::findTableGroup,
|
||||
new SqmParameterMappingModelResolutionAccess() {
|
||||
@Override @SuppressWarnings("unchecked")
|
||||
public <T> MappingModelExpressible<T> getResolvedMappingModelType(SqmParameter<T> parameter) {
|
||||
|
|
|
@ -19,14 +19,10 @@ import org.hibernate.query.spi.NonSelectQueryPlan;
|
|||
import org.hibernate.query.spi.QueryParameterImplementor;
|
||||
import org.hibernate.query.sqm.spi.SqmParameterMappingModelResolutionAccess;
|
||||
import org.hibernate.query.sqm.sql.SqmTranslation;
|
||||
import org.hibernate.query.sqm.sql.SqmTranslator;
|
||||
import org.hibernate.query.sqm.tree.expression.SqmParameter;
|
||||
import org.hibernate.query.sqm.tree.insert.SqmInsertStatement;
|
||||
import org.hibernate.sql.ast.SqlAstTranslator;
|
||||
import org.hibernate.sql.ast.spi.FromClauseAccess;
|
||||
import org.hibernate.sql.ast.tree.MutationStatement;
|
||||
import org.hibernate.sql.ast.tree.insert.InsertStatement;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQueryInsert;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQueryMutation;
|
||||
import org.hibernate.sql.exec.spi.JdbcParameterBindings;
|
||||
import org.hibernate.sql.exec.spi.JdbcParametersList;
|
||||
|
@ -40,7 +36,6 @@ public class SimpleInsertQueryPlan implements NonSelectQueryPlan {
|
|||
private Map<SqmParameter<?>, MappingModelExpressible<?>> paramTypeResolutions;
|
||||
|
||||
private JdbcOperationQueryMutation jdbcInsert;
|
||||
private FromClauseAccess tableGroupAccess;
|
||||
private Map<QueryParameterImplementor<?>, Map<SqmParameter<?>, List<JdbcParametersList>>> jdbcParamsXref;
|
||||
|
||||
public SimpleInsertQueryPlan(
|
||||
|
@ -64,8 +59,6 @@ public class SimpleInsertQueryPlan implements NonSelectQueryPlan {
|
|||
)
|
||||
.translate();
|
||||
|
||||
tableGroupAccess = sqmInterpretation.getFromClauseAccess();
|
||||
|
||||
this.jdbcParamsXref = SqmUtil.generateJdbcParamsXref(
|
||||
domainParameterXref,
|
||||
sqmInterpretation::getJdbcParamsBySqmParam
|
||||
|
@ -94,8 +87,6 @@ public class SimpleInsertQueryPlan implements NonSelectQueryPlan {
|
|||
executionContext.getQueryParameterBindings(),
|
||||
domainParameterXref,
|
||||
jdbcParamsXref,
|
||||
factory.getRuntimeMetamodels().getMappingMetamodel(),
|
||||
tableGroupAccess::findTableGroup,
|
||||
new SqmParameterMappingModelResolutionAccess() {
|
||||
@Override @SuppressWarnings("unchecked")
|
||||
public <T> MappingModelExpressible<T> getResolvedMappingModelType(SqmParameter<T> parameter) {
|
||||
|
|
|
@ -22,11 +22,8 @@ import org.hibernate.query.sqm.sql.SqmTranslation;
|
|||
import org.hibernate.query.sqm.tree.expression.SqmParameter;
|
||||
import org.hibernate.query.sqm.tree.update.SqmUpdateStatement;
|
||||
import org.hibernate.sql.ast.SqlAstTranslator;
|
||||
import org.hibernate.sql.ast.spi.FromClauseAccess;
|
||||
import org.hibernate.sql.ast.tree.MutationStatement;
|
||||
import org.hibernate.sql.ast.tree.update.UpdateStatement;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQueryMutation;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQueryUpdate;
|
||||
import org.hibernate.sql.exec.spi.JdbcParameterBindings;
|
||||
import org.hibernate.sql.exec.spi.JdbcParametersList;
|
||||
|
||||
|
@ -38,7 +35,6 @@ public class SimpleUpdateQueryPlan implements NonSelectQueryPlan {
|
|||
private final DomainParameterXref domainParameterXref;
|
||||
|
||||
private JdbcOperationQueryMutation jdbcUpdate;
|
||||
private FromClauseAccess tableGroupAccess;
|
||||
private Map<QueryParameterImplementor<?>, Map<SqmParameter<?>, List<JdbcParametersList>>> jdbcParamsXref;
|
||||
private Map<SqmParameter<?>, MappingModelExpressible<?>> sqmParamMappingTypeResolutions;
|
||||
|
||||
|
@ -64,8 +60,6 @@ public class SimpleUpdateQueryPlan implements NonSelectQueryPlan {
|
|||
executionContext.getQueryParameterBindings(),
|
||||
domainParameterXref,
|
||||
jdbcParamsXref,
|
||||
factory.getRuntimeMetamodels().getMappingMetamodel(),
|
||||
tableGroupAccess::findTableGroup,
|
||||
new SqmParameterMappingModelResolutionAccess() {
|
||||
@Override @SuppressWarnings("unchecked")
|
||||
public <T> MappingModelExpressible<T> getResolvedMappingModelType(SqmParameter<T> parameter) {
|
||||
|
@ -113,8 +107,6 @@ public class SimpleUpdateQueryPlan implements NonSelectQueryPlan {
|
|||
)
|
||||
.translate();
|
||||
|
||||
tableGroupAccess = sqmInterpretation.getFromClauseAccess();
|
||||
|
||||
this.jdbcParamsXref = SqmUtil.generateJdbcParamsXref(
|
||||
domainParameterXref,
|
||||
sqmInterpretation::getJdbcParamsBySqmParam
|
||||
|
|
|
@ -47,7 +47,6 @@ import org.hibernate.metamodel.model.domain.DomainType;
|
|||
import org.hibernate.metamodel.model.domain.JpaMetamodel;
|
||||
import org.hibernate.metamodel.model.domain.SingularPersistentAttribute;
|
||||
import org.hibernate.metamodel.model.domain.internal.BasicTypeImpl;
|
||||
import org.hibernate.metamodel.model.domain.spi.JpaMetamodelImplementor;
|
||||
import org.hibernate.metamodel.spi.MappingMetamodelImplementor;
|
||||
import org.hibernate.query.BindableType;
|
||||
import org.hibernate.query.ImmutableEntityUpdateQueryHandlingMode;
|
||||
|
@ -91,7 +90,6 @@ import org.hibernate.query.sqm.function.SqmFunctionDescriptor;
|
|||
import org.hibernate.query.sqm.produce.function.FunctionArgumentException;
|
||||
import org.hibernate.query.sqm.produce.function.FunctionReturnTypeResolver;
|
||||
import org.hibernate.query.sqm.produce.function.StandardFunctionReturnTypeResolvers;
|
||||
import org.hibernate.query.sqm.spi.SqmCreationContext;
|
||||
import org.hibernate.query.sqm.tree.SqmQuery;
|
||||
import org.hibernate.query.sqm.tree.SqmStatement;
|
||||
import org.hibernate.query.sqm.tree.SqmTypedNode;
|
||||
|
@ -339,8 +337,8 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, Serializable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public JpaMetamodelImplementor getJpaMetamodel() {
|
||||
return (JpaMetamodelImplementor) bindingContext.getJpaMetamodel();
|
||||
public JpaMetamodel getJpaMetamodel() {
|
||||
return bindingContext.getJpaMetamodel();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1669,7 +1667,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, Serializable {
|
|||
|
||||
@Override
|
||||
public SqmExpression<String> concat(List<Expression<String>> expressions) {
|
||||
//noinspection unchecked
|
||||
//noinspection RedundantCast, unchecked
|
||||
return getFunctionDescriptor( "concat" ).generateSqmExpression(
|
||||
(List<? extends SqmTypedNode<?>>) (List<?>) expressions,
|
||||
null,
|
||||
|
@ -2073,8 +2071,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, Serializable {
|
|||
|
||||
@Override
|
||||
public <T> SqmExpression<T> value(T value) {
|
||||
if ( value instanceof Duration ) {
|
||||
final Duration duration = (Duration) value;
|
||||
if ( value instanceof Duration duration ) {
|
||||
final JpaExpression<Duration> expression = duration.getNano() == 0
|
||||
? duration( duration.getSeconds(), TemporalUnit.SECOND )
|
||||
: duration( duration.getNano() + duration.getSeconds() * 1_000_000_000, TemporalUnit.NANOSECOND );
|
||||
|
@ -2091,8 +2088,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, Serializable {
|
|||
}
|
||||
|
||||
private <T> boolean isInstance(BindableType<T> bindableType, T value) {
|
||||
if ( bindableType instanceof SqmExpressible<?> ) {
|
||||
final SqmExpressible<?> expressible = (SqmExpressible<?>) bindableType;
|
||||
if ( bindableType instanceof SqmExpressible<?> expressible ) {
|
||||
return expressible.getExpressibleJavaType().isInstance( value );
|
||||
}
|
||||
else {
|
||||
|
@ -2154,10 +2150,11 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, Serializable {
|
|||
BindableType<E> bindableType = null;
|
||||
if ( elementTypeInferenceSource != null ) {
|
||||
if ( elementTypeInferenceSource instanceof BindableType ) {
|
||||
//noinspection unchecked
|
||||
bindableType = (BindableType<E>) elementTypeInferenceSource;
|
||||
}
|
||||
else if ( elementTypeInferenceSource.getNodeType() != null ) {
|
||||
bindableType = (BindableType<E>) elementTypeInferenceSource.getNodeType();
|
||||
bindableType = elementTypeInferenceSource.getNodeType();
|
||||
}
|
||||
}
|
||||
DomainType<E> elementType = null;
|
||||
|
@ -2683,27 +2680,27 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, Serializable {
|
|||
|
||||
@Override
|
||||
public <E, C extends Collection<E>> SqmPredicate isMember(Expression<E> elem, Expression<C> collection) {
|
||||
return createSqmMemberOfPredicate( (SqmExpression<?>) elem, (SqmPath<?>) collection, false, this );
|
||||
return createSqmMemberOfPredicate( (SqmExpression<?>) elem, (SqmPath<?>) collection, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E, C extends Collection<E>> SqmPredicate isMember(E elem, Expression<C> collection) {
|
||||
return createSqmMemberOfPredicate( value( elem ), (SqmPath<?>) collection, false, this );
|
||||
return createSqmMemberOfPredicate( value( elem ), (SqmPath<?>) collection, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E, C extends Collection<E>> SqmPredicate isNotMember(Expression<E> elem, Expression<C> collection) {
|
||||
return createSqmMemberOfPredicate( (SqmExpression<?>) elem, (SqmPath<?>) collection, true, this );
|
||||
return createSqmMemberOfPredicate( (SqmExpression<?>) elem, (SqmPath<?>) collection, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E, C extends Collection<E>> SqmPredicate isNotMember(E elem, Expression<C> collection) {
|
||||
return createSqmMemberOfPredicate( value( elem ), (SqmPath<?>) collection, true, this );
|
||||
return createSqmMemberOfPredicate( value( elem ), (SqmPath<?>) collection, true);
|
||||
}
|
||||
|
||||
private SqmMemberOfPredicate createSqmMemberOfPredicate(SqmExpression<?> elem, SqmPath<?> collection, boolean negated, NodeBuilder nodeBuilder) {
|
||||
if ( collection instanceof SqmPluralValuedSimplePath ) {
|
||||
return new SqmMemberOfPredicate( elem, (SqmPluralValuedSimplePath) collection, negated, this );
|
||||
private SqmMemberOfPredicate createSqmMemberOfPredicate(SqmExpression<?> elem, SqmPath<?> collection, boolean negated) {
|
||||
if ( collection instanceof SqmPluralValuedSimplePath<?> pluralValuedSimplePath ) {
|
||||
return new SqmMemberOfPredicate( elem, pluralValuedSimplePath, negated, this );
|
||||
}
|
||||
else {
|
||||
throw new SemanticException( "Operand of 'member of' operator must be a plural path" );
|
||||
|
@ -5275,7 +5272,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, Serializable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public <T> SqmExpression<String> collectionToString(
|
||||
public SqmExpression<String> collectionToString(
|
||||
Expression<? extends Collection<?>> collectionExpression,
|
||||
Expression<String> separatorExpression) {
|
||||
return getFunctionDescriptor( "array_to_string" ).generateSqmExpression(
|
||||
|
@ -5286,7 +5283,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, Serializable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public <T> SqmExpression<String> collectionToString(
|
||||
public SqmExpression<String> collectionToString(
|
||||
Expression<? extends Collection<?>> collectionExpression,
|
||||
String separator) {
|
||||
return getFunctionDescriptor( "array_to_string" ).generateSqmExpression(
|
||||
|
|
|
@ -19,13 +19,11 @@ import java.util.Locale;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||
import org.hibernate.jpa.spi.JpaCompliance;
|
||||
import org.hibernate.metamodel.MappingMetamodel;
|
||||
import org.hibernate.metamodel.mapping.BasicValuedMapping;
|
||||
import org.hibernate.metamodel.mapping.Bindable;
|
||||
import org.hibernate.metamodel.mapping.CollectionPart;
|
||||
|
@ -91,7 +89,6 @@ import org.hibernate.spi.NavigablePath;
|
|||
import org.hibernate.sql.ast.Clause;
|
||||
import org.hibernate.sql.ast.SqlTreeCreationException;
|
||||
import org.hibernate.sql.ast.tree.expression.JdbcParameter;
|
||||
import org.hibernate.sql.ast.tree.from.TableGroup;
|
||||
import org.hibernate.sql.exec.internal.JdbcParameterBindingImpl;
|
||||
import org.hibernate.sql.exec.internal.JdbcParameterBindingsImpl;
|
||||
import org.hibernate.sql.exec.spi.JdbcParameterBindings;
|
||||
|
@ -188,8 +185,7 @@ public class SqmUtil {
|
|||
else {
|
||||
modelPart = modelPartContainer;
|
||||
}
|
||||
if ( modelPart instanceof EntityAssociationMapping ) {
|
||||
final EntityAssociationMapping association = (EntityAssociationMapping) modelPart;
|
||||
if ( modelPart instanceof EntityAssociationMapping association ) {
|
||||
// If the path is one of the association's target key properties,
|
||||
// we need to render the target side if in group/order by
|
||||
if ( association.getTargetKeyPropertyNames().contains( sqmPath.getReferencedPathSource().getPathName() )
|
||||
|
@ -228,8 +224,7 @@ public class SqmUtil {
|
|||
*/
|
||||
@Deprecated(forRemoval = true, since = "6.6.1")
|
||||
public static boolean isFkOptimizationAllowed(SqmPath<?> sqmPath) {
|
||||
if ( sqmPath instanceof SqmJoin<?, ?> ) {
|
||||
final SqmJoin<?, ?> sqmJoin = (SqmJoin<?, ?>) sqmPath;
|
||||
if ( sqmPath instanceof SqmJoin<?, ?> sqmJoin ) {
|
||||
switch ( sqmJoin.getSqmJoinType() ) {
|
||||
case LEFT:
|
||||
final EntityAssociationMapping associationMapping = resolveAssociationMapping( sqmJoin );
|
||||
|
@ -253,8 +248,7 @@ public class SqmUtil {
|
|||
* or one that has an explicit on clause predicate.
|
||||
*/
|
||||
public static boolean isFkOptimizationAllowed(SqmPath<?> sqmPath, EntityAssociationMapping associationMapping) {
|
||||
if ( sqmPath instanceof SqmJoin<?, ?> ) {
|
||||
final SqmJoin<?, ?> sqmJoin = (SqmJoin<?, ?>) sqmPath;
|
||||
if ( sqmPath instanceof SqmJoin<?, ?> sqmJoin ) {
|
||||
switch ( sqmJoin.getSqmJoinType() ) {
|
||||
case LEFT:
|
||||
if ( isFiltered( associationMapping ) ) {
|
||||
|
@ -279,8 +273,7 @@ public class SqmUtil {
|
|||
}
|
||||
|
||||
private static @Nullable EntityAssociationMapping resolveAssociationMapping(SqmJoin<?, ?> sqmJoin) {
|
||||
if ( sqmJoin instanceof SqmSingularJoin<?, ?> ) {
|
||||
final SqmSingularJoin<?, ?> singularJoin = (SqmSingularJoin<?, ?>) sqmJoin;
|
||||
if ( sqmJoin instanceof SqmSingularJoin<?, ?> singularJoin ) {
|
||||
if ( singularJoin.getAttribute().getSqmPathType() instanceof EntityDomainType<?> ) {
|
||||
return resolveAssociationMapping( singularJoin );
|
||||
}
|
||||
|
@ -294,7 +287,7 @@ public class SqmUtil {
|
|||
if ( declaringType.getPersistenceType() != Type.PersistenceType.ENTITY ) {
|
||||
final StringBuilder pathBuilder = new StringBuilder();
|
||||
do {
|
||||
if ( pathBuilder.length() > 0 ) {
|
||||
if ( !pathBuilder.isEmpty() ) {
|
||||
pathBuilder.insert(0, '.');
|
||||
}
|
||||
pathBuilder.insert( 0, attribute.getName() );
|
||||
|
@ -489,8 +482,6 @@ public class SqmUtil {
|
|||
QueryParameterBindings domainParamBindings,
|
||||
DomainParameterXref domainParameterXref,
|
||||
Map<QueryParameterImplementor<?>, Map<SqmParameter<?>, List<JdbcParametersList>>> jdbcParamXref,
|
||||
MappingMetamodel domainModel,
|
||||
Function<NavigablePath, TableGroup> tableGroupLocator,
|
||||
SqmParameterMappingModelResolutionAccess mappingModelResolutionAccess,
|
||||
SharedSessionContractImplementor session) {
|
||||
final JdbcParameterBindings jdbcParameterBindings = new JdbcParameterBindingsImpl(
|
||||
|
@ -506,8 +497,8 @@ public class SqmUtil {
|
|||
|
||||
final Map<SqmParameter<?>, List<JdbcParametersList>> jdbcParamMap = jdbcParamXref.get( queryParam );
|
||||
for ( SqmParameter<?> sqmParameter : sqmParameters ) {
|
||||
final MappingModelExpressible resolvedMappingModelType = mappingModelResolutionAccess
|
||||
.getResolvedMappingModelType( sqmParameter );
|
||||
final MappingModelExpressible resolvedMappingModelType =
|
||||
mappingModelResolutionAccess.getResolvedMappingModelType( sqmParameter );
|
||||
if ( resolvedMappingModelType != null ) {
|
||||
domainParamBinding.setType( resolvedMappingModelType );
|
||||
}
|
||||
|
@ -529,12 +520,9 @@ public class SqmUtil {
|
|||
for ( int i = 0; i < jdbcParamsBinds.size(); i++ ) {
|
||||
final JdbcParametersList jdbcParams = jdbcParamsBinds.get( i );
|
||||
parameterType.forEachJdbcType(
|
||||
(position, jdbcMapping) -> {
|
||||
jdbcParameterBindings.addBinding(
|
||||
jdbcParams.get( position ),
|
||||
new JdbcParameterBindingImpl( jdbcMapping, null )
|
||||
);
|
||||
}
|
||||
(position, jdbcMapping) ->
|
||||
jdbcParameterBindings.addBinding( jdbcParams.get( position ),
|
||||
new JdbcParameterBindingImpl( jdbcMapping, null ) )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -553,7 +541,6 @@ public class SqmUtil {
|
|||
parameterType,
|
||||
jdbcParams,
|
||||
firstValue,
|
||||
tableGroupLocator,
|
||||
session
|
||||
);
|
||||
}
|
||||
|
@ -578,7 +565,6 @@ public class SqmUtil {
|
|||
parameterType,
|
||||
expansionJdbcParams,
|
||||
expandedValue,
|
||||
tableGroupLocator,
|
||||
session
|
||||
);
|
||||
}
|
||||
|
@ -626,7 +612,6 @@ public class SqmUtil {
|
|||
}
|
||||
}
|
||||
else {
|
||||
|
||||
for ( int i = 0; i < jdbcParamsBinds.size(); i++ ) {
|
||||
final JdbcParametersList jdbcParams = jdbcParamsBinds.get( i );
|
||||
createValueBindings(
|
||||
|
@ -636,7 +621,6 @@ public class SqmUtil {
|
|||
parameterType,
|
||||
jdbcParams,
|
||||
bindValue,
|
||||
tableGroupLocator,
|
||||
session
|
||||
);
|
||||
}
|
||||
|
@ -656,7 +640,6 @@ public class SqmUtil {
|
|||
Bindable parameterType,
|
||||
JdbcParametersList jdbcParams,
|
||||
Object bindValue,
|
||||
Function<NavigablePath, TableGroup> tableGroupLocator,
|
||||
SharedSessionContractImplementor session) {
|
||||
if ( parameterType == null ) {
|
||||
throw new SqlTreeCreationException( "Unable to interpret mapping-model type for Query parameter : " + domainParam );
|
||||
|
@ -666,8 +649,7 @@ public class SqmUtil {
|
|||
parameterType = ( (PluralAttributeMapping) parameterType ).getElementDescriptor();
|
||||
}
|
||||
|
||||
if ( parameterType instanceof EntityIdentifierMapping ) {
|
||||
final EntityIdentifierMapping identifierMapping = (EntityIdentifierMapping) parameterType;
|
||||
if ( parameterType instanceof EntityIdentifierMapping identifierMapping ) {
|
||||
final EntityMappingType entityMapping = identifierMapping.findContainingEntityMapping();
|
||||
if ( entityMapping.getRepresentationStrategy().getInstantiator().isInstance( bindValue, session.getFactory() ) ) {
|
||||
bindValue = identifierMapping.getIdentifierIfNotUnsaved( bindValue, session );
|
||||
|
@ -681,8 +663,7 @@ public class SqmUtil {
|
|||
bindValue = identifierMapping.getIdentifierIfNotUnsaved( bindValue, session );
|
||||
}
|
||||
}
|
||||
else if ( parameterType instanceof EntityAssociationMapping ) {
|
||||
EntityAssociationMapping association = (EntityAssociationMapping) parameterType;
|
||||
else if ( parameterType instanceof EntityAssociationMapping association ) {
|
||||
if ( association.getSideNature() == ForeignKeyDescriptor.Nature.TARGET ) {
|
||||
// If the association is the target, we must use the identifier of the EntityMappingType
|
||||
bindValue = association.getAssociatedEntityMappingType().getIdentifierMapping()
|
||||
|
@ -763,12 +744,12 @@ public class SqmUtil {
|
|||
return null;
|
||||
}
|
||||
//There's a high chance that we're dealing with a BasicTypeImpl, or a subclass of it.
|
||||
else if ( o instanceof BasicTypeImpl ) {
|
||||
return (BasicTypeImpl) o;
|
||||
else if ( o instanceof BasicTypeImpl<?> basicType ) {
|
||||
return basicType;
|
||||
}
|
||||
//Alternatively, chances are good that we're dealing with an ConvertedBasicTypeImpl.
|
||||
else if ( o instanceof ConvertedBasicTypeImpl ) {
|
||||
return (ConvertedBasicTypeImpl) o;
|
||||
else if ( o instanceof ConvertedBasicTypeImpl<?> convertedBasicType ) {
|
||||
return convertedBasicType;
|
||||
}
|
||||
else {
|
||||
//Eventually fallback to the standard check for completeness:
|
||||
|
@ -826,8 +807,7 @@ public class SqmUtil {
|
|||
else {
|
||||
// ordering by an attribute of the returned entity
|
||||
if ( items.size() == 1) {
|
||||
if ( selected instanceof SqmRoot) {
|
||||
final SqmFrom<?,?> root = (SqmFrom<?,?>) selected;
|
||||
if ( selected instanceof SqmFrom<?, ?> root ) {
|
||||
if ( !order.getEntityClass().isAssignableFrom( root.getJavaType() ) ) {
|
||||
throw new IllegalQueryOperationException("Select item was of wrong entity type");
|
||||
}
|
||||
|
@ -884,12 +864,11 @@ public class SqmUtil {
|
|||
sqmParameters = new LinkedHashSet<>();
|
||||
}
|
||||
|
||||
if ( parameter instanceof SqmJpaCriteriaParameterWrapper<?> ) {
|
||||
if ( parameter instanceof SqmJpaCriteriaParameterWrapper<?> wrapper ) {
|
||||
if ( jpaCriteriaParamResolutions == null ) {
|
||||
jpaCriteriaParamResolutions = new IdentityHashMap<>();
|
||||
}
|
||||
|
||||
final SqmJpaCriteriaParameterWrapper<?> wrapper = (SqmJpaCriteriaParameterWrapper<?>) parameter;
|
||||
final JpaCriteriaParameter<?> criteriaParameter = wrapper.getJpaCriteriaParameter();
|
||||
|
||||
final List<SqmJpaCriteriaParameterWrapper<?>> sqmParametersForCriteriaParameter = jpaCriteriaParamResolutions.computeIfAbsent(
|
||||
|
@ -1059,9 +1038,8 @@ public class SqmUtil {
|
|||
// See if the selected type can be used to instantiate the expected-type
|
||||
final JavaType<?> javaTypeDescriptor = selectableNode.getJavaTypeDescriptor();
|
||||
if ( javaTypeDescriptor != null ) {
|
||||
final Class<?> selectedJavaType = javaTypeDescriptor.getJavaTypeClass();
|
||||
// ignore the exception if the expected type has a constructor accepting the selected item type
|
||||
if ( hasMatchingConstructor( expectedResultClass, selectedJavaType ) ) {
|
||||
if ( hasMatchingConstructor( expectedResultClass, javaTypeDescriptor.getJavaTypeClass() ) ) {
|
||||
// ignore it
|
||||
}
|
||||
else {
|
||||
|
@ -1086,8 +1064,7 @@ public class SqmUtil {
|
|||
JpaCompliance jpaCompliance,
|
||||
SqmSelectableNode<?> selection) {
|
||||
// special case for parameters in the select list
|
||||
if ( selection instanceof SqmParameter ) {
|
||||
final SqmParameter<?> sqmParameter = (SqmParameter<?>) selection;
|
||||
if ( selection instanceof SqmParameter<?> sqmParameter ) {
|
||||
final SqmExpressible<?> nodeType = sqmParameter.getExpressible();
|
||||
// we may not yet know a selection type
|
||||
if ( nodeType == null || nodeType.getExpressibleJavaType() == null ) {
|
||||
|
@ -1120,17 +1097,13 @@ public class SqmUtil {
|
|||
assert selectionExpressibleJavaType != null;
|
||||
|
||||
final Class<?> selectionExpressibleJavaTypeClass = selectionExpressibleJavaType.getJavaTypeClass();
|
||||
if ( selectionExpressibleJavaTypeClass == Object.class ) {
|
||||
|
||||
}
|
||||
if ( selectionExpressibleJavaTypeClass != Object.class ) {
|
||||
// performs a series of opt-out checks for validity... each if branch and return indicates a valid case
|
||||
if ( resultClass.isAssignableFrom( selectionExpressibleJavaTypeClass ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( selectionExpressibleJavaType instanceof PrimitiveJavaType ) {
|
||||
final PrimitiveJavaType<?> primitiveJavaType = (PrimitiveJavaType<?>) selectionExpressibleJavaType;
|
||||
if ( selectionExpressibleJavaType instanceof PrimitiveJavaType<?> primitiveJavaType ) {
|
||||
if ( primitiveJavaType.getPrimitiveClass() == resultClass ) {
|
||||
return;
|
||||
}
|
||||
|
@ -1149,13 +1122,11 @@ public class SqmUtil {
|
|||
}
|
||||
|
||||
private static boolean isEntityIdType(SqmExpressible<?> selectionExpressible, Class<?> resultClass) {
|
||||
if ( selectionExpressible instanceof IdentifiableDomainType ) {
|
||||
final IdentifiableDomainType<?> identifiableDomainType = (IdentifiableDomainType<?>) selectionExpressible;
|
||||
if ( selectionExpressible instanceof IdentifiableDomainType<?> identifiableDomainType ) {
|
||||
final SimpleDomainType<?> idType = identifiableDomainType.getIdType();
|
||||
return resultClass.isAssignableFrom( idType.getBindableJavaType() );
|
||||
}
|
||||
else if ( selectionExpressible instanceof EntitySqmPathSource ) {
|
||||
final EntitySqmPathSource<?> entityPath = (EntitySqmPathSource<?>) selectionExpressible;
|
||||
else if ( selectionExpressible instanceof EntitySqmPathSource<?> entityPath ) {
|
||||
final EntityDomainType<?> entityType = entityPath.getSqmPathType();
|
||||
final SimpleDomainType<?> idType = entityType.getIdType();
|
||||
return resultClass.isAssignableFrom( idType.getBindableJavaType() );
|
||||
|
@ -1178,8 +1149,7 @@ public class SqmUtil {
|
|||
if ( sqmExpressible instanceof BasicDomainType<?> ) {
|
||||
return ( (BasicDomainType<?>) sqmExpressible).getJdbcType();
|
||||
}
|
||||
else if ( sqmExpressible instanceof SqmPathSource<?> ) {
|
||||
final SqmPathSource<?> pathSource = (SqmPathSource<?>) sqmExpressible;
|
||||
else if ( sqmExpressible instanceof SqmPathSource<?> pathSource ) {
|
||||
final DomainType<?> domainType = pathSource.getSqmPathType();
|
||||
if ( domainType instanceof BasicDomainType<?> ) {
|
||||
return ( (BasicDomainType<?>) domainType ).getJdbcType();
|
||||
|
@ -1190,16 +1160,12 @@ public class SqmUtil {
|
|||
|
||||
private static boolean isMatchingDateJdbcType(Class<?> resultClass, JdbcType jdbcType) {
|
||||
if ( jdbcType != null ) {
|
||||
switch ( jdbcType.getDefaultSqlTypeCode() ) {
|
||||
case Types.DATE:
|
||||
return resultClass.isAssignableFrom( java.sql.Date.class );
|
||||
case Types.TIME:
|
||||
return resultClass.isAssignableFrom( java.sql.Time.class );
|
||||
case Types.TIMESTAMP:
|
||||
return resultClass.isAssignableFrom( java.sql.Timestamp.class );
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return switch ( jdbcType.getDefaultSqlTypeCode() ) {
|
||||
case Types.DATE -> resultClass.isAssignableFrom(java.sql.Date.class);
|
||||
case Types.TIME -> resultClass.isAssignableFrom(java.sql.Time.class);
|
||||
case Types.TIMESTAMP -> resultClass.isAssignableFrom(java.sql.Timestamp.class);
|
||||
default -> false;
|
||||
};
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
|
|
|
@ -38,9 +38,7 @@ import org.hibernate.query.sqm.tree.select.SqmSelectClause;
|
|||
import org.hibernate.query.sqm.tree.select.SqmSelectStatement;
|
||||
import org.hibernate.sql.ast.SqlAstJoinType;
|
||||
import org.hibernate.sql.ast.SqlAstTranslator;
|
||||
import org.hibernate.sql.ast.tree.expression.Expression;
|
||||
import org.hibernate.sql.ast.tree.from.TableGroup;
|
||||
import org.hibernate.sql.ast.tree.from.TableReference;
|
||||
import org.hibernate.sql.ast.tree.predicate.Predicate;
|
||||
import org.hibernate.sql.ast.tree.select.QuerySpec;
|
||||
import org.hibernate.sql.ast.tree.select.SelectStatement;
|
||||
|
@ -50,7 +48,6 @@ import org.hibernate.sql.results.graph.DomainResult;
|
|||
import org.hibernate.sql.results.graph.basic.BasicResult;
|
||||
import org.hibernate.sql.results.internal.RowTransformerArrayImpl;
|
||||
import org.hibernate.sql.results.internal.RowTransformerSingularReturnImpl;
|
||||
import org.hibernate.sql.results.internal.SqlSelectionImpl;
|
||||
import org.hibernate.sql.results.spi.ListResultsConsumer;
|
||||
import org.hibernate.sql.results.spi.RowTransformer;
|
||||
|
||||
|
@ -76,13 +73,12 @@ public class MatchingIdSelectionHelper {
|
|||
*/
|
||||
public static SelectStatement generateMatchingIdSelectStatement(
|
||||
EntityMappingType targetEntityDescriptor,
|
||||
SqmDeleteOrUpdateStatement sqmStatement,
|
||||
SqmDeleteOrUpdateStatement<?> sqmStatement,
|
||||
boolean queryRoot,
|
||||
Predicate restriction,
|
||||
MultiTableSqmMutationConverter sqmConverter,
|
||||
DomainQueryExecutionContext executionContext,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
final EntityDomainType entityDomainType = sqmStatement.getTarget().getModel();
|
||||
DomainQueryExecutionContext executionContext) {
|
||||
final EntityDomainType<?> entityDomainType = sqmStatement.getTarget().getModel();
|
||||
if ( log.isTraceEnabled() ) {
|
||||
log.tracef(
|
||||
"Starting generation of entity-id SQM selection - %s",
|
||||
|
@ -110,15 +106,14 @@ public class MatchingIdSelectionHelper {
|
|||
mutatingTableGroup.getNavigablePath(),
|
||||
mutatingTableGroup,
|
||||
sqmConverter,
|
||||
(selection, jdbcMapping) -> {
|
||||
domainResults.add(
|
||||
new BasicResult<>(
|
||||
selection.getValuesArrayPosition(),
|
||||
null,
|
||||
jdbcMapping
|
||||
)
|
||||
);
|
||||
}
|
||||
(selection, jdbcMapping) ->
|
||||
domainResults.add(
|
||||
new BasicResult<>(
|
||||
selection.getValuesArrayPosition(),
|
||||
null,
|
||||
jdbcMapping
|
||||
)
|
||||
)
|
||||
);
|
||||
sqmConverter.getProcessingStateStack().pop();
|
||||
|
||||
|
@ -152,14 +147,14 @@ public class MatchingIdSelectionHelper {
|
|||
sqmQuerySpec.setFromClause( new SqmFromClause( 1 ) );
|
||||
sqmQuerySpec.addRoot( sqmStatement.getTarget() );
|
||||
sqmQuerySpec.setSelectClause( new SqmSelectClause( false, 1, sqmQuerySpec.nodeBuilder() ) );
|
||||
entityDescriptor.getIdentifierMapping().forEachSelectable( 0, (selectionIndex, selectableMapping) -> {
|
||||
sqmQuerySpec.getSelectClause().addSelection(
|
||||
SelectableMappingExpressionConverter.forSelectableMapping(
|
||||
sqmStatement.getTarget(),
|
||||
selectableMapping
|
||||
)
|
||||
);
|
||||
} );
|
||||
entityDescriptor.getIdentifierMapping()
|
||||
.forEachSelectable( 0, (selectionIndex, selectableMapping) ->
|
||||
sqmQuerySpec.getSelectClause().addSelection(
|
||||
SelectableMappingExpressionConverter.forSelectableMapping(
|
||||
sqmStatement.getTarget(),
|
||||
selectableMapping
|
||||
)
|
||||
));
|
||||
sqmQuerySpec.setWhereClause( sqmStatement.getWhereClause() );
|
||||
|
||||
return new SqmSelectStatement<>(
|
||||
|
@ -169,59 +164,59 @@ public class MatchingIdSelectionHelper {
|
|||
nodeBuilder
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @asciidoc
|
||||
*
|
||||
* Generates a query-spec for selecting all ids matching the restriction defined as part
|
||||
* of the user's update/delete query. This query-spec is generally used:
|
||||
*
|
||||
* * to select all the matching ids via JDBC - see {@link MatchingIdSelectionHelper#selectMatchingIds}
|
||||
* * as a sub-query restriction to insert rows into an "id table"
|
||||
*/
|
||||
public static QuerySpec generateMatchingIdSelectQuery(
|
||||
EntityMappingType targetEntityDescriptor,
|
||||
SqmDeleteOrUpdateStatement sqmStatement,
|
||||
DomainParameterXref domainParameterXref,
|
||||
Predicate restriction,
|
||||
MultiTableSqmMutationConverter sqmConverter,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
final EntityDomainType entityDomainType = sqmStatement.getTarget().getModel();
|
||||
if ( log.isTraceEnabled() ) {
|
||||
log.tracef(
|
||||
"Starting generation of entity-id SQM selection - %s",
|
||||
entityDomainType.getHibernateEntityName()
|
||||
);
|
||||
}
|
||||
|
||||
final QuerySpec idSelectionQuery = new QuerySpec( true, 1 );
|
||||
|
||||
final TableGroup mutatingTableGroup = sqmConverter.getMutatingTableGroup();
|
||||
idSelectionQuery.getFromClause().addRoot( mutatingTableGroup );
|
||||
|
||||
targetEntityDescriptor.getIdentifierMapping().forEachSelectable(
|
||||
(position, selection) -> {
|
||||
final TableReference tableReference = mutatingTableGroup.resolveTableReference(
|
||||
mutatingTableGroup.getNavigablePath(),
|
||||
selection.getContainingTableExpression()
|
||||
);
|
||||
final Expression expression = sqmConverter.getSqlExpressionResolver().resolveSqlExpression(
|
||||
tableReference,
|
||||
selection
|
||||
);
|
||||
idSelectionQuery.getSelectClause().addSqlSelection(
|
||||
new SqlSelectionImpl(
|
||||
position,
|
||||
expression
|
||||
)
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
idSelectionQuery.applyPredicate( restriction );
|
||||
|
||||
return idSelectionQuery;
|
||||
}
|
||||
//
|
||||
// /**
|
||||
// * @asciidoc
|
||||
// *
|
||||
// * Generates a query-spec for selecting all ids matching the restriction defined as part
|
||||
// * of the user's update/delete query. This query-spec is generally used:
|
||||
// *
|
||||
// * * to select all the matching ids via JDBC - see {@link MatchingIdSelectionHelper#selectMatchingIds}
|
||||
// * * as a sub-query restriction to insert rows into an "id table"
|
||||
// */
|
||||
// public static QuerySpec generateMatchingIdSelectQuery(
|
||||
// EntityMappingType targetEntityDescriptor,
|
||||
// SqmDeleteOrUpdateStatement sqmStatement,
|
||||
// DomainParameterXref domainParameterXref,
|
||||
// Predicate restriction,
|
||||
// MultiTableSqmMutationConverter sqmConverter,
|
||||
// SessionFactoryImplementor sessionFactory) {
|
||||
// final EntityDomainType entityDomainType = sqmStatement.getTarget().getModel();
|
||||
// if ( log.isTraceEnabled() ) {
|
||||
// log.tracef(
|
||||
// "Starting generation of entity-id SQM selection - %s",
|
||||
// entityDomainType.getHibernateEntityName()
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// final QuerySpec idSelectionQuery = new QuerySpec( true, 1 );
|
||||
//
|
||||
// final TableGroup mutatingTableGroup = sqmConverter.getMutatingTableGroup();
|
||||
// idSelectionQuery.getFromClause().addRoot( mutatingTableGroup );
|
||||
//
|
||||
// targetEntityDescriptor.getIdentifierMapping().forEachSelectable(
|
||||
// (position, selection) -> {
|
||||
// final TableReference tableReference = mutatingTableGroup.resolveTableReference(
|
||||
// mutatingTableGroup.getNavigablePath(),
|
||||
// selection.getContainingTableExpression()
|
||||
// );
|
||||
// final Expression expression = sqmConverter.getSqlExpressionResolver().resolveSqlExpression(
|
||||
// tableReference,
|
||||
// selection
|
||||
// );
|
||||
// idSelectionQuery.getSelectClause().addSqlSelection(
|
||||
// new SqlSelectionImpl(
|
||||
// position,
|
||||
// expression
|
||||
// )
|
||||
// );
|
||||
// }
|
||||
// );
|
||||
//
|
||||
// idSelectionQuery.applyPredicate( restriction );
|
||||
//
|
||||
// return idSelectionQuery;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Centralized selection of ids matching the restriction of the DELETE
|
||||
|
@ -243,22 +238,20 @@ public class MatchingIdSelectionHelper {
|
|||
// For delete statements we also want to collect FK values to execute collection table cleanups
|
||||
entityDescriptor.visitSubTypeAttributeMappings(
|
||||
attribute -> {
|
||||
if ( attribute instanceof PluralAttributeMapping ) {
|
||||
final PluralAttributeMapping pluralAttribute = (PluralAttributeMapping) attribute;
|
||||
|
||||
if ( attribute instanceof PluralAttributeMapping pluralAttribute ) {
|
||||
if ( pluralAttribute.getSeparateCollectionTable() != null ) {
|
||||
// Ensure that the FK target columns are available
|
||||
final ValuedModelPart targetPart = pluralAttribute.getKeyDescriptor().getTargetPart();
|
||||
final boolean useFkTarget = !targetPart.isEntityIdentifierMapping();
|
||||
if ( useFkTarget ) {
|
||||
targetPart.forEachSelectable( 0, (selectionIndex, selectableMapping) -> {
|
||||
sqmQuerySpec.getSelectClause().addSelection(
|
||||
SelectableMappingExpressionConverter.forSelectableMapping(
|
||||
sqmMutationStatement.getTarget(),
|
||||
selectableMapping
|
||||
)
|
||||
);
|
||||
} );
|
||||
targetPart.forEachSelectable( 0, (selectionIndex, selectableMapping) ->
|
||||
sqmQuerySpec.getSelectClause().addSelection(
|
||||
SelectableMappingExpressionConverter.forSelectableMapping(
|
||||
sqmMutationStatement.getTarget(),
|
||||
selectableMapping
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -288,8 +281,6 @@ public class MatchingIdSelectionHelper {
|
|||
executionContext.getQueryParameterBindings(),
|
||||
domainParameterXref,
|
||||
SqmUtil.generateJdbcParamsXref( domainParameterXref, translator ),
|
||||
factory.getRuntimeMetamodels().getMappingMetamodel(),
|
||||
translation.getFromClauseAccess()::findTableGroup,
|
||||
new SqmParameterMappingModelResolutionAccess() {
|
||||
@Override @SuppressWarnings("unchecked")
|
||||
public <T> MappingModelExpressible<T> getResolvedMappingModelType(SqmParameter<T> parameter) {
|
||||
|
|
|
@ -9,7 +9,6 @@ package org.hibernate.query.sqm.mutation.internal.cte;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -101,8 +100,7 @@ public abstract class AbstractCteMutationHandler extends AbstractMutationHandler
|
|||
|
||||
@Override
|
||||
public int execute(DomainQueryExecutionContext executionContext) {
|
||||
//noinspection rawtypes
|
||||
final SqmDeleteOrUpdateStatement sqmMutationStatement = getSqmDeleteOrUpdateStatement();
|
||||
final SqmDeleteOrUpdateStatement<?> sqmMutationStatement = getSqmDeleteOrUpdateStatement();
|
||||
final SessionFactoryImplementor factory = executionContext.getSession().getFactory();
|
||||
final EntityMappingType entityDescriptor = getEntityDescriptor();
|
||||
final String explicitDmlTargetAlias;
|
||||
|
@ -144,8 +142,7 @@ public abstract class AbstractCteMutationHandler extends AbstractMutationHandler
|
|||
true,
|
||||
restriction,
|
||||
sqmConverter,
|
||||
executionContext,
|
||||
factory
|
||||
executionContext
|
||||
),
|
||||
// The id-select cte will be reused multiple times
|
||||
CteMaterialization.MATERIALIZED
|
||||
|
@ -186,8 +183,6 @@ public abstract class AbstractCteMutationHandler extends AbstractMutationHandler
|
|||
executionContext.getQueryParameterBindings(),
|
||||
domainParameterXref,
|
||||
SqmUtil.generateJdbcParamsXref( domainParameterXref, sqmConverter ),
|
||||
factory.getRuntimeMetamodels().getMappingMetamodel(),
|
||||
navigablePath -> sqmConverter.getMutatingTableGroup(),
|
||||
new SqmParameterMappingModelResolutionAccess() {
|
||||
@Override @SuppressWarnings("unchecked")
|
||||
public <T> MappingModelExpressible<T> getResolvedMappingModelType(SqmParameter<T> parameter) {
|
||||
|
|
|
@ -70,7 +70,6 @@ import org.hibernate.sql.ast.tree.cte.CteTableGroup;
|
|||
import org.hibernate.sql.ast.tree.expression.BinaryArithmeticExpression;
|
||||
import org.hibernate.sql.ast.tree.expression.ColumnReference;
|
||||
import org.hibernate.sql.ast.tree.expression.Expression;
|
||||
import org.hibernate.sql.ast.tree.expression.JdbcParameter;
|
||||
import org.hibernate.sql.ast.tree.expression.QueryLiteral;
|
||||
import org.hibernate.sql.ast.tree.expression.SelfRenderingSqlFragmentExpression;
|
||||
import org.hibernate.sql.ast.tree.expression.SqlTuple;
|
||||
|
@ -557,7 +556,6 @@ public class CteInsertHandler implements InsertHandler {
|
|||
targetPathColumns,
|
||||
assignsId,
|
||||
sqmConverter,
|
||||
sqmConverter.getJdbcParamsBySqmParam(),
|
||||
factory
|
||||
);
|
||||
|
||||
|
@ -588,9 +586,7 @@ public class CteInsertHandler implements InsertHandler {
|
|||
final JdbcParameterBindings jdbcParameterBindings = SqmUtil.createJdbcParameterBindings(
|
||||
executionContext.getQueryParameterBindings(),
|
||||
domainParameterXref,
|
||||
SqmUtil.generateJdbcParamsXref(domainParameterXref, sqmConverter),
|
||||
factory.getRuntimeMetamodels().getMappingMetamodel(),
|
||||
navigablePath -> sqmConverter.getMutatingTableGroup(),
|
||||
SqmUtil.generateJdbcParamsXref( domainParameterXref, sqmConverter ),
|
||||
new SqmParameterMappingModelResolutionAccess() {
|
||||
@Override @SuppressWarnings("unchecked")
|
||||
public <T> MappingModelExpressible<T> getResolvedMappingModelType(SqmParameter<T> parameter) {
|
||||
|
@ -631,7 +627,6 @@ public class CteInsertHandler implements InsertHandler {
|
|||
List<Map.Entry<List<CteColumn>, Assignment>> assignments,
|
||||
boolean assignsId,
|
||||
MultiTableSqmMutationConverter sqmConverter,
|
||||
Map<SqmParameter<?>, List<List<JdbcParameter>>> parameterResolutions,
|
||||
SessionFactoryImplementor factory) {
|
||||
final TableGroup updatingTableGroup = sqmConverter.getMutatingTableGroup();
|
||||
final EntityMappingType entityDescriptor = getEntityDescriptor();
|
||||
|
@ -672,11 +667,7 @@ public class CteInsertHandler implements InsertHandler {
|
|||
|
||||
for ( int c = 0; c < assignmentColumnRefs.size(); c++ ) {
|
||||
final ColumnReference columnReference = assignmentColumnRefs.get( c );
|
||||
final TableReference tableReference = resolveTableReference(
|
||||
columnReference,
|
||||
updatingTableGroup,
|
||||
tableReferenceByAlias
|
||||
);
|
||||
final TableReference tableReference = resolveTableReference( columnReference, tableReferenceByAlias );
|
||||
|
||||
// TODO: this could be fixed by introducing joins to DML statements
|
||||
if ( assignmentTableReference != null && !assignmentTableReference.equals( tableReference ) ) {
|
||||
|
@ -1372,7 +1363,6 @@ public class CteInsertHandler implements InsertHandler {
|
|||
|
||||
private TableReference resolveTableReference(
|
||||
ColumnReference columnReference,
|
||||
TableGroup updatingTableGroup,
|
||||
Map<String, TableReference> tableReferenceByAlias) {
|
||||
final TableReference tableReferenceByQualifier = tableReferenceByAlias.get( columnReference.getQualifier() );
|
||||
if ( tableReferenceByQualifier != null ) {
|
||||
|
|
|
@ -131,12 +131,7 @@ public class InlineUpdateHandler implements UpdateHandler {
|
|||
final JdbcParameterBindings jdbcParameterBindings = SqmUtil.createJdbcParameterBindings(
|
||||
executionContext.getQueryParameterBindings(),
|
||||
domainParameterXref,
|
||||
SqmUtil.generateJdbcParamsXref(
|
||||
domainParameterXref,
|
||||
translation::getJdbcParamsBySqmParam
|
||||
),
|
||||
sessionFactory.getRuntimeMetamodels().getMappingMetamodel(),
|
||||
navigablePath -> updatingTableGroup,
|
||||
SqmUtil.generateJdbcParamsXref( domainParameterXref, translation::getJdbcParamsBySqmParam ),
|
||||
new SqmParameterMappingModelResolutionAccess() {
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
|
@ -39,7 +39,6 @@ import org.hibernate.metamodel.mapping.JdbcMapping;
|
|||
import org.hibernate.metamodel.mapping.MappingModelExpressible;
|
||||
import org.hibernate.metamodel.mapping.ModelPartContainer;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.persister.entity.mutation.EntityMutationTarget;
|
||||
import org.hibernate.query.SemanticException;
|
||||
import org.hibernate.query.SortDirection;
|
||||
import org.hibernate.query.results.TableGroupImpl;
|
||||
|
@ -51,7 +50,6 @@ import org.hibernate.query.sqm.internal.SqmUtil;
|
|||
import org.hibernate.query.sqm.mutation.internal.MultiTableSqmMutationConverter;
|
||||
import org.hibernate.query.sqm.spi.SqmParameterMappingModelResolutionAccess;
|
||||
import org.hibernate.query.sqm.tree.expression.SqmParameter;
|
||||
import org.hibernate.query.sqm.tree.insert.SqmInsertStatement;
|
||||
import org.hibernate.sql.ast.tree.expression.ColumnReference;
|
||||
import org.hibernate.sql.ast.tree.expression.JdbcParameter;
|
||||
import org.hibernate.sql.ast.tree.expression.QueryLiteral;
|
||||
|
@ -77,7 +75,6 @@ import org.hibernate.sql.exec.spi.JdbcOperationQueryMutation;
|
|||
import org.hibernate.sql.exec.spi.JdbcOperationQuerySelect;
|
||||
import org.hibernate.sql.exec.spi.JdbcParameterBindings;
|
||||
import org.hibernate.sql.results.graph.basic.BasicFetch;
|
||||
import org.hibernate.sql.results.graph.basic.BasicResultAssembler;
|
||||
import org.hibernate.sql.results.internal.SqlSelectionImpl;
|
||||
import org.hibernate.sql.results.spi.ListResultsConsumer;
|
||||
import org.hibernate.type.descriptor.ValueBinder;
|
||||
|
@ -89,12 +86,9 @@ import static org.hibernate.generator.EventType.INSERT;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public class InsertExecutionDelegate implements TableBasedInsertHandler.ExecutionDelegate {
|
||||
private final SqmInsertStatement<?> sqmInsert;
|
||||
private final MultiTableSqmMutationConverter sqmConverter;
|
||||
private final TemporaryTable entityTable;
|
||||
private final AfterUseAction afterUseAction;
|
||||
private final Function<SharedSessionContractImplementor, String> sessionUidAccess;
|
||||
private final DomainParameterXref domainParameterXref;
|
||||
private final TableGroup updatingTableGroup;
|
||||
private final InsertSelectStatement insertStatement;
|
||||
private final ConflictClause conflictClause;
|
||||
|
@ -108,7 +102,6 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio
|
|||
private final SessionFactoryImplementor sessionFactory;
|
||||
|
||||
public InsertExecutionDelegate(
|
||||
SqmInsertStatement<?> sqmInsert,
|
||||
MultiTableSqmMutationConverter sqmConverter,
|
||||
TemporaryTable entityTable,
|
||||
AfterUseAction afterUseAction,
|
||||
|
@ -121,12 +114,9 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio
|
|||
ConflictClause conflictClause,
|
||||
JdbcParameter sessionUidParameter,
|
||||
DomainQueryExecutionContext executionContext) {
|
||||
this.sqmInsert = sqmInsert;
|
||||
this.sqmConverter = sqmConverter;
|
||||
this.entityTable = entityTable;
|
||||
this.afterUseAction = afterUseAction;
|
||||
this.sessionUidAccess = sessionUidAccess;
|
||||
this.domainParameterXref = domainParameterXref;
|
||||
this.updatingTableGroup = insertingTableGroup;
|
||||
this.conflictClause = conflictClause;
|
||||
this.sessionUidParameter = sessionUidParameter;
|
||||
|
@ -144,12 +134,7 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio
|
|||
jdbcParameterBindings = SqmUtil.createJdbcParameterBindings(
|
||||
executionContext.getQueryParameterBindings(),
|
||||
domainParameterXref,
|
||||
SqmUtil.generateJdbcParamsXref(
|
||||
domainParameterXref,
|
||||
sqmConverter::getJdbcParamsBySqmParam
|
||||
),
|
||||
sessionFactory.getRuntimeMetamodels().getMappingMetamodel(),
|
||||
navigablePath -> insertingTableGroup,
|
||||
SqmUtil.generateJdbcParamsXref( domainParameterXref, sqmConverter ),
|
||||
new SqmParameterMappingModelResolutionAccess() {
|
||||
@Override @SuppressWarnings("unchecked")
|
||||
public <T> MappingModelExpressible<T> getResolvedMappingModelType(SqmParameter<T> parameter) {
|
||||
|
@ -173,11 +158,7 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio
|
|||
|
||||
for ( int c = 0; c < assignmentColumnRefs.size(); c++ ) {
|
||||
final ColumnReference columnReference = assignmentColumnRefs.get( c );
|
||||
final TableReference tableReference = resolveTableReference(
|
||||
columnReference,
|
||||
insertingTableGroup,
|
||||
tableReferenceByAlias
|
||||
);
|
||||
final TableReference tableReference = resolveTableReference( columnReference, tableReferenceByAlias );
|
||||
|
||||
if ( assignmentTableReference != null && assignmentTableReference != tableReference ) {
|
||||
throw new SemanticException( "Assignment referred to columns from multiple tables: " + i );
|
||||
|
@ -274,7 +255,6 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio
|
|||
|
||||
private TableReference resolveTableReference(
|
||||
ColumnReference columnReference,
|
||||
TableGroup updatingTableGroup,
|
||||
Map<String, TableReference> tableReferenceByAlias) {
|
||||
if ( columnReference.getQualifier() == null ) {
|
||||
// This happens only for the special row_number column
|
||||
|
@ -566,9 +546,9 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio
|
|||
.translate( null, executionContext.getQueryOptions() );
|
||||
|
||||
if ( generator.generatedOnExecution() ) {
|
||||
final GeneratedValuesMutationDelegate insertDelegate = ( (EntityMutationTarget) entityDescriptor.getEntityPersister() ).getInsertDelegate();
|
||||
final GeneratedValuesMutationDelegate insertDelegate = entityDescriptor.getEntityPersister().getInsertDelegate();
|
||||
// todo 7.0 : InsertGeneratedIdentifierDelegate will be removed once we're going to handle
|
||||
// generated values within the jdbc insert operaetion itself
|
||||
// generated values within the jdbc insert operaetion itself
|
||||
final InsertGeneratedIdentifierDelegate identifierDelegate = (InsertGeneratedIdentifierDelegate) insertDelegate;
|
||||
final String finalSql = identifierDelegate.prepareIdentifierGeneratingInsert( jdbcInsert.getSqlString() );
|
||||
final BasicEntityIdentifierMapping identifierMapping =
|
||||
|
|
|
@ -140,7 +140,6 @@ public class RestrictedDeleteExecutionDelegate extends AbstractDeleteExecutionDe
|
|||
if ( needsIdTable ) {
|
||||
return executeWithIdTable(
|
||||
predicateCollector.getPredicate(),
|
||||
deletingTableGroup,
|
||||
getConverter().getJdbcParamsBySqmParam(),
|
||||
getConverter().getSqmParameterMappingModelExpressibleResolutions(),
|
||||
executionContextAdapter
|
||||
|
@ -190,8 +189,6 @@ public class RestrictedDeleteExecutionDelegate extends AbstractDeleteExecutionDe
|
|||
getDomainParameterXref(),
|
||||
() -> restrictionSqmParameterResolutions
|
||||
),
|
||||
getSessionFactory().getRuntimeMetamodels().getMappingMetamodel(),
|
||||
navigablePath -> tableGroup,
|
||||
new SqmParameterMappingModelResolutionAccess() {
|
||||
@Override @SuppressWarnings("unchecked")
|
||||
public <T> MappingModelExpressible<T> getResolvedMappingModelType(SqmParameter<T> parameter) {
|
||||
|
@ -425,7 +422,6 @@ public class RestrictedDeleteExecutionDelegate extends AbstractDeleteExecutionDe
|
|||
|
||||
private int executeWithIdTable(
|
||||
Predicate predicate,
|
||||
TableGroup deletingTableGroup,
|
||||
Map<SqmParameter<?>, List<List<JdbcParameter>>> restrictionSqmParameterResolutions,
|
||||
Map<SqmParameter<?>, MappingModelExpressible<?>> paramTypeResolutions,
|
||||
ExecutionContext executionContext) {
|
||||
|
@ -436,8 +432,6 @@ public class RestrictedDeleteExecutionDelegate extends AbstractDeleteExecutionDe
|
|||
getDomainParameterXref(),
|
||||
() -> restrictionSqmParameterResolutions
|
||||
),
|
||||
getSessionFactory().getRuntimeMetamodels().getMappingMetamodel(),
|
||||
navigablePath -> deletingTableGroup,
|
||||
new SqmParameterMappingModelResolutionAccess() {
|
||||
@Override @SuppressWarnings("unchecked")
|
||||
public <T> MappingModelExpressible<T> getResolvedMappingModelType(SqmParameter<T> parameter) {
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
package org.hibernate.query.sqm.mutation.internal.temptable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
|
@ -53,6 +52,7 @@ import org.hibernate.sql.exec.spi.JdbcOperationQueryMutation;
|
|||
import org.hibernate.sql.exec.spi.JdbcParameterBindings;
|
||||
import org.hibernate.sql.results.internal.SqlSelectionImpl;
|
||||
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.hibernate.query.sqm.internal.SqmJdbcExecutionContextAdapter.omittingLockingAndPaging;
|
||||
|
||||
/**
|
||||
|
@ -133,12 +133,7 @@ public class SoftDeleteExecutionDelegate extends AbstractDeleteExecutionDelegate
|
|||
final JdbcParameterBindings jdbcParameterBindings = SqmUtil.createJdbcParameterBindings(
|
||||
executionContext.getQueryParameterBindings(),
|
||||
getDomainParameterXref(),
|
||||
SqmUtil.generateJdbcParamsXref(
|
||||
getDomainParameterXref(),
|
||||
getConverter()::getJdbcParamsBySqmParam
|
||||
),
|
||||
getSessionFactory().getRuntimeMetamodels().getMappingMetamodel(),
|
||||
navigablePath -> deletingTableGroup,
|
||||
SqmUtil.generateJdbcParamsXref( getDomainParameterXref(), getConverter() ),
|
||||
new SqmParameterMappingModelResolutionAccess() {
|
||||
@Override @SuppressWarnings("unchecked")
|
||||
public <T> MappingModelExpressible<T> getResolvedMappingModelType(SqmParameter<T> parameter) {
|
||||
|
@ -153,7 +148,6 @@ public class SoftDeleteExecutionDelegate extends AbstractDeleteExecutionDelegate
|
|||
if ( needsSubQuery ) {
|
||||
if ( getSessionFactory().getJdbcServices().getDialect().supportsSubqueryOnMutatingTable() ) {
|
||||
return performDeleteWithSubQuery(
|
||||
targetEntityDescriptor,
|
||||
rootEntityDescriptor,
|
||||
deletingTableGroup,
|
||||
rootTableReference,
|
||||
|
@ -175,13 +169,10 @@ public class SoftDeleteExecutionDelegate extends AbstractDeleteExecutionDelegate
|
|||
}
|
||||
else {
|
||||
return performDirectDelete(
|
||||
targetEntityDescriptor,
|
||||
rootEntityDescriptor,
|
||||
deletingTableGroup,
|
||||
rootTableReference,
|
||||
predicateCollector,
|
||||
jdbcParameterBindings,
|
||||
getConverter(),
|
||||
executionContext
|
||||
);
|
||||
}
|
||||
|
@ -293,7 +284,7 @@ public class SoftDeleteExecutionDelegate extends AbstractDeleteExecutionDelegate
|
|||
|
||||
final UpdateStatement updateStatement = new UpdateStatement(
|
||||
targetTableReference,
|
||||
Collections.singletonList( softDeleteAssignment ),
|
||||
singletonList( softDeleteAssignment ),
|
||||
new InSubQueryPredicate( idExpression, idTableIdentifierSubQuery, false )
|
||||
);
|
||||
|
||||
|
@ -303,7 +294,6 @@ public class SoftDeleteExecutionDelegate extends AbstractDeleteExecutionDelegate
|
|||
}
|
||||
|
||||
private int performDeleteWithSubQuery(
|
||||
EntityMappingType targetEntityDescriptor,
|
||||
EntityMappingType rootEntityDescriptor,
|
||||
TableGroup deletingTableGroup,
|
||||
NamedTableReference rootTableReference,
|
||||
|
@ -347,7 +337,7 @@ public class SoftDeleteExecutionDelegate extends AbstractDeleteExecutionDelegate
|
|||
|
||||
final UpdateStatement updateStatement = new UpdateStatement(
|
||||
targetTable,
|
||||
Collections.singletonList( softDeleteAssignment ),
|
||||
singletonList( softDeleteAssignment ),
|
||||
new InSubQueryPredicate( idExpression, matchingIdSubQuery, false )
|
||||
);
|
||||
|
||||
|
@ -355,13 +345,10 @@ public class SoftDeleteExecutionDelegate extends AbstractDeleteExecutionDelegate
|
|||
}
|
||||
|
||||
private int performDirectDelete(
|
||||
EntityMappingType targetEntityDescriptor,
|
||||
EntityMappingType rootEntityDescriptor,
|
||||
TableGroup deletingTableGroup,
|
||||
NamedTableReference rootTableReference,
|
||||
PredicateCollector predicateCollector,
|
||||
JdbcParameterBindings jdbcParameterBindings,
|
||||
MultiTableSqmMutationConverter converter,
|
||||
SqmJdbcExecutionContextAdapter executionContext) {
|
||||
final Assignment softDeleteAssignment = SoftDeleteHelper.createSoftDeleteAssignment(
|
||||
rootTableReference,
|
||||
|
@ -370,7 +357,7 @@ public class SoftDeleteExecutionDelegate extends AbstractDeleteExecutionDelegate
|
|||
|
||||
final UpdateStatement updateStatement = new UpdateStatement(
|
||||
rootTableReference,
|
||||
Collections.singletonList( softDeleteAssignment ),
|
||||
singletonList( softDeleteAssignment ),
|
||||
predicateCollector.getPredicate()
|
||||
);
|
||||
|
||||
|
|
|
@ -334,7 +334,6 @@ public class TableBasedInsertHandler implements InsertHandler {
|
|||
JdbcParameter sessionUidParameter,
|
||||
DomainQueryExecutionContext executionContext) {
|
||||
return new InsertExecutionDelegate(
|
||||
sqmInsertStatement,
|
||||
sqmConverter,
|
||||
entityTable,
|
||||
afterUseAction,
|
||||
|
|
|
@ -19,7 +19,6 @@ import org.hibernate.dialect.temptable.TemporaryTable;
|
|||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||
import org.hibernate.metamodel.mapping.EntityMappingType;
|
||||
import org.hibernate.metamodel.mapping.MappingModelExpressible;
|
||||
import org.hibernate.metamodel.mapping.ModelPartContainer;
|
||||
|
@ -40,7 +39,6 @@ import org.hibernate.sql.ast.SqlAstTranslatorFactory;
|
|||
import org.hibernate.sql.ast.spi.SqlSelection;
|
||||
import org.hibernate.sql.ast.tree.expression.ColumnReference;
|
||||
import org.hibernate.sql.ast.tree.expression.Expression;
|
||||
import org.hibernate.sql.ast.tree.expression.JdbcParameter;
|
||||
import org.hibernate.sql.ast.tree.expression.QueryLiteral;
|
||||
import org.hibernate.sql.ast.tree.expression.SqlTuple;
|
||||
import org.hibernate.sql.ast.tree.from.NamedTableReference;
|
||||
|
@ -58,12 +56,12 @@ import org.hibernate.sql.ast.tree.update.Assignment;
|
|||
import org.hibernate.sql.ast.tree.update.UpdateStatement;
|
||||
import org.hibernate.sql.exec.spi.ExecutionContext;
|
||||
import org.hibernate.sql.exec.spi.JdbcMutationExecutor;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQueryInsert;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQueryMutation;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQueryUpdate;
|
||||
import org.hibernate.sql.exec.spi.JdbcParameterBindings;
|
||||
import org.hibernate.sql.results.internal.SqlSelectionImpl;
|
||||
|
||||
import static org.hibernate.internal.util.collections.CollectionHelper.mapOfSize;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
|
@ -121,17 +119,12 @@ public class UpdateExecutionDelegate implements TableBasedUpdateHandler.Executio
|
|||
|
||||
|
||||
|
||||
this.assignmentsByTable = CollectionHelper.mapOfSize( updatingTableGroup.getTableReferenceJoins().size() + 1 );
|
||||
this.assignmentsByTable = mapOfSize( updatingTableGroup.getTableReferenceJoins().size() + 1 );
|
||||
|
||||
jdbcParameterBindings = SqmUtil.createJdbcParameterBindings(
|
||||
executionContext.getQueryParameterBindings(),
|
||||
domainParameterXref,
|
||||
SqmUtil.generateJdbcParamsXref(
|
||||
domainParameterXref,
|
||||
sqmConverter::getJdbcParamsBySqmParam
|
||||
),
|
||||
sessionFactory.getRuntimeMetamodels().getMappingMetamodel(),
|
||||
navigablePath -> updatingTableGroup,
|
||||
SqmUtil.generateJdbcParamsXref( domainParameterXref, sqmConverter ),
|
||||
new SqmParameterMappingModelResolutionAccess() {
|
||||
@Override @SuppressWarnings("unchecked")
|
||||
public <T> MappingModelExpressible<T> getResolvedMappingModelType(SqmParameter<T> parameter) {
|
||||
|
|
|
@ -13,7 +13,6 @@ import org.hibernate.Internal;
|
|||
import org.hibernate.metamodel.MappingMetamodel;
|
||||
import org.hibernate.metamodel.mapping.JdbcMapping;
|
||||
import org.hibernate.metamodel.mapping.JdbcMappingContainer;
|
||||
import org.hibernate.metamodel.model.domain.DomainType;
|
||||
import org.hibernate.query.sqm.SqmExpressible;
|
||||
import org.hibernate.query.sqm.tree.SqmTypedNode;
|
||||
import org.hibernate.query.sqm.tree.expression.SqmCollation;
|
||||
|
@ -132,9 +131,7 @@ public class ArgumentTypesValidator implements ArgumentsValidator {
|
|||
FunctionParameterType type,
|
||||
JavaType<?> javaType) {
|
||||
if ( !isUnknown( javaType ) ) {
|
||||
DomainType<?> domainType = argument.getExpressible().getSqmType();
|
||||
if ( domainType instanceof JdbcMapping ) {
|
||||
JdbcMapping jdbcMapping = (JdbcMapping) domainType;
|
||||
if ( argument.getExpressible().getSqmType() instanceof JdbcMapping jdbcMapping ) {
|
||||
checkArgumentType(
|
||||
count, functionName, type,
|
||||
jdbcMapping.getJdbcType(),
|
||||
|
@ -181,8 +178,7 @@ public class ArgumentTypesValidator implements ArgumentsValidator {
|
|||
public void validateSqlTypes(List<? extends SqlAstNode> arguments, String functionName) {
|
||||
int count = 0;
|
||||
for ( SqlAstNode argument : arguments ) {
|
||||
if ( argument instanceof Expression ) {
|
||||
final Expression expression = (Expression) argument;
|
||||
if ( argument instanceof Expression expression ) {
|
||||
final JdbcMappingContainer expressionType = expression.getExpressionType();
|
||||
if (expressionType != null) {
|
||||
if ( isUnknownExpressionType( expressionType ) ) {
|
||||
|
@ -240,34 +236,22 @@ public class ArgumentTypesValidator implements ArgumentsValidator {
|
|||
|
||||
@Internal
|
||||
private static boolean isCompatible(FunctionParameterType type, JdbcType jdbcType) {
|
||||
switch ( type ) {
|
||||
case COMPARABLE:
|
||||
return jdbcType.isComparable();
|
||||
case STRING:
|
||||
return jdbcType.isStringLikeExcludingClob();
|
||||
case STRING_OR_CLOB:
|
||||
return jdbcType.isString(); // should it be isStringLike()
|
||||
case NUMERIC:
|
||||
return jdbcType.isNumber();
|
||||
case INTEGER:
|
||||
return jdbcType.isInteger();
|
||||
case BOOLEAN:
|
||||
return jdbcType.isBoolean()
|
||||
return switch (type) {
|
||||
case COMPARABLE -> jdbcType.isComparable();
|
||||
case STRING -> jdbcType.isStringLikeExcludingClob();
|
||||
case STRING_OR_CLOB -> jdbcType.isString(); // should it be isStringLike()
|
||||
case NUMERIC -> jdbcType.isNumber();
|
||||
case INTEGER -> jdbcType.isInteger();
|
||||
case BOOLEAN -> jdbcType.isBoolean()
|
||||
// some Dialects map Boolean to SMALLINT or TINYINT
|
||||
// TODO: check with Dialect.getPreferredSqlTypeCodeForBoolean
|
||||
|| jdbcType.isSmallInteger();
|
||||
case TEMPORAL:
|
||||
return jdbcType.isTemporal();
|
||||
case DATE:
|
||||
return jdbcType.hasDatePart();
|
||||
case TIME:
|
||||
return jdbcType.hasTimePart();
|
||||
case SPATIAL:
|
||||
return jdbcType.isSpatial();
|
||||
default:
|
||||
// TODO: should we throw here?
|
||||
return true;
|
||||
}
|
||||
case TEMPORAL -> jdbcType.isTemporal();
|
||||
case DATE -> jdbcType.hasDatePart();
|
||||
case TIME -> jdbcType.hasTimePart();
|
||||
case SPATIAL -> jdbcType.isSpatial();
|
||||
default -> true; // TODO: should we throw here?
|
||||
};
|
||||
}
|
||||
|
||||
private static void throwError(
|
||||
|
|
Loading…
Reference in New Issue