Change `@ParamDef#type` associated with a `@FilterDef` from `String` to `Class` in keeping with the general move away from String-based type usage in annotations

This commit is contained in:
Steve Ebersole 2022-01-24 07:15:42 -06:00
parent 596317da0b
commit d6c4f90f4c
38 changed files with 308 additions and 255 deletions

View File

@ -112,7 +112,7 @@ public class FilterJoinTableTest extends BaseEntityManagerFunctionalTestCase {
name="firstAccounts", name="firstAccounts",
parameters=@ParamDef( parameters=@ParamDef(
name="maxOrderId", name="maxOrderId",
type="int" type=int.class
) )
) )
public static class Client { public static class Client {

View File

@ -104,7 +104,7 @@ public class FilterSqlFragementAliasTest extends BaseEntityManagerFunctionalTest
name="activeAccount", name="activeAccount",
parameters = @ParamDef( parameters = @ParamDef(
name="active", name="active",
type="boolean" type=Boolean.class
) )
) )
@Filter( @Filter(

View File

@ -275,7 +275,7 @@ public class FilterTest extends BaseEntityManagerFunctionalTestCase {
name="activeAccount", name="activeAccount",
parameters = @ParamDef( parameters = @ParamDef(
name="active", name="active",
type="boolean" type=Boolean.class
) )
) )
@Filter( @Filter(

View File

@ -12,20 +12,44 @@ import java.lang.annotation.Target;
import static java.lang.annotation.RetentionPolicy.RUNTIME; import static java.lang.annotation.RetentionPolicy.RUNTIME;
/** /**
* A parameter definition. * Details about a parameter defined in a FilterDef.
* <p/>
* Mainly used to support cases where the proper {@link #type type}
* cannot be deduced by Hibernate.
* *
* @see FilterDef#parameters()
*
* @author Steve Ebersole
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
@Target({}) @Target({})
@Retention(RUNTIME) @Retention(RUNTIME)
public @interface ParamDef { public @interface ParamDef {
/** /**
* The name of the parameter definition. * The name of the parameter.
*/ */
String name(); String name();
/** /**
* The type of the parameter. * The type to use when binding the parameter value.
* <p/>
* Generally deduced from the bind value. Allows to
* specify a specific type to use.
* <p/>
* The supplied Class can be one of the following:<ul>
* <li>
* a {@link org.hibernate.usertype.UserType}
* </li>
* <li>
* an {@link jakarta.persistence.AttributeConverter}
* </li>
* <li>
* a {@link org.hibernate.type.descriptor.java.JavaType}
* </li>
* <li>
* any Java type resolvable from {@link org.hibernate.type.descriptor.java.spi.JavaTypeRegistry}
* </li>
* </ul>
*/ */
String type(); Class<?> type();
} }

View File

@ -9,17 +9,18 @@ package org.hibernate.boot.model.source.internal.hbm;
import java.io.Serializable; import java.io.Serializable;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import jakarta.xml.bind.JAXBElement;
import org.hibernate.boot.MappingException; import org.hibernate.boot.MappingException;
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmFilterDefinitionType; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmFilterDefinitionType;
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmFilterParameterType; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmFilterParameterType;
import org.hibernate.engine.spi.FilterDefinition; import org.hibernate.engine.spi.FilterDefinition;
import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.StringHelper;
import org.hibernate.type.Type; import org.hibernate.metamodel.mapping.JdbcMapping;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import jakarta.xml.bind.JAXBElement;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
*/ */
@ -36,7 +37,7 @@ class FilterDefinitionBinder {
static void processFilterDefinition( static void processFilterDefinition(
HbmLocalMetadataBuildingContext context, HbmLocalMetadataBuildingContext context,
JaxbHbmFilterDefinitionType jaxbFilterDefinitionMapping) { JaxbHbmFilterDefinitionType jaxbFilterDefinitionMapping) {
Map<String,Type> parameterMap = null; Map<String, JdbcMapping> parameterMap = null;
String condition = jaxbFilterDefinitionMapping.getCondition(); String condition = jaxbFilterDefinitionMapping.getCondition();
for ( Serializable content : jaxbFilterDefinitionMapping.getContent() ) { for ( Serializable content : jaxbFilterDefinitionMapping.getContent() ) {

View File

@ -58,26 +58,4 @@ public final class FilterKey implements Serializable {
return "FilterKey[" + filterName + filterParameters + ']'; return "FilterKey[" + filterName + filterParameters + ']';
} }
/**
* Constructs a number of FilterKey instances, given the currently enabled filters
*
* @param enabledFilters The currently enabled filters
*
* @return The filter keys, one per enabled filter
*/
public static Set<FilterKey> createFilterKeys(Map<String,Filter> enabledFilters) {
if ( enabledFilters.size() == 0 ) {
return null;
}
final Set<FilterKey> result = new HashSet<>();
for ( Filter filter : enabledFilters.values() ) {
final FilterKey key = new FilterKey(
filter.getName(),
( (FilterImpl) filter ).getParameters(),
filter.getFilterDefinition().getParameterTypes()
);
result.add( key );
}
return result;
}
} }

View File

@ -39,6 +39,7 @@ import org.hibernate.annotations.CollectionTypeRegistration;
import org.hibernate.annotations.CollectionTypeRegistrations; import org.hibernate.annotations.CollectionTypeRegistrations;
import org.hibernate.annotations.Columns; import org.hibernate.annotations.Columns;
import org.hibernate.annotations.Comment; import org.hibernate.annotations.Comment;
import org.hibernate.annotations.DialectOverride;
import org.hibernate.annotations.DialectOverride.OverridesAnnotation; import org.hibernate.annotations.DialectOverride.OverridesAnnotation;
import org.hibernate.annotations.DiscriminatorFormula; import org.hibernate.annotations.DiscriminatorFormula;
import org.hibernate.annotations.DiscriminatorOptions; import org.hibernate.annotations.DiscriminatorOptions;
@ -51,7 +52,6 @@ import org.hibernate.annotations.Filter;
import org.hibernate.annotations.FilterDef; import org.hibernate.annotations.FilterDef;
import org.hibernate.annotations.FilterDefs; import org.hibernate.annotations.FilterDefs;
import org.hibernate.annotations.Filters; import org.hibernate.annotations.Filters;
import org.hibernate.annotations.DialectOverride;
import org.hibernate.annotations.ForeignKey; import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.Formula; import org.hibernate.annotations.Formula;
import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.GenericGenerator;
@ -94,6 +94,7 @@ import org.hibernate.annotations.common.reflection.XPackage;
import org.hibernate.annotations.common.reflection.XProperty; import org.hibernate.annotations.common.reflection.XProperty;
import org.hibernate.boot.model.IdGeneratorStrategyInterpreter; import org.hibernate.boot.model.IdGeneratorStrategyInterpreter;
import org.hibernate.boot.model.IdentifierGeneratorDefinition; import org.hibernate.boot.model.IdentifierGeneratorDefinition;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.spi.InFlightMetadataCollector; import org.hibernate.boot.spi.InFlightMetadataCollector;
import org.hibernate.boot.spi.InFlightMetadataCollector.EntityTableXref; import org.hibernate.boot.spi.InFlightMetadataCollector.EntityTableXref;
@ -108,6 +109,7 @@ import org.hibernate.cfg.annotations.Nullability;
import org.hibernate.cfg.annotations.PropertyBinder; import org.hibernate.cfg.annotations.PropertyBinder;
import org.hibernate.cfg.annotations.QueryBinder; import org.hibernate.cfg.annotations.QueryBinder;
import org.hibernate.cfg.annotations.TableBinder; import org.hibernate.cfg.annotations.TableBinder;
import org.hibernate.cfg.internal.ConvertedJdbcMapping;
import org.hibernate.cfg.internal.NullableDiscriminatorColumnSecondPass; import org.hibernate.cfg.internal.NullableDiscriminatorColumnSecondPass;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.engine.OptimisticLockStyle; import org.hibernate.engine.OptimisticLockStyle;
@ -137,10 +139,18 @@ import org.hibernate.mapping.Subclass;
import org.hibernate.mapping.ToOne; import org.hibernate.mapping.ToOne;
import org.hibernate.mapping.UnionSubclass; import org.hibernate.mapping.UnionSubclass;
import org.hibernate.metamodel.EmbeddableInstantiator; import org.hibernate.metamodel.EmbeddableInstantiator;
import org.hibernate.metamodel.mapping.JdbcMapping;
import org.hibernate.resource.beans.spi.ManagedBean;
import org.hibernate.resource.beans.spi.ManagedBeanRegistry; import org.hibernate.resource.beans.spi.ManagedBeanRegistry;
import org.hibernate.type.CustomType;
import org.hibernate.type.descriptor.java.BasicJavaType; import org.hibernate.type.descriptor.java.BasicJavaType;
import org.hibernate.type.descriptor.java.JavaType;
import org.hibernate.type.descriptor.java.spi.JavaTypeRegistry;
import org.hibernate.type.descriptor.jdbc.JdbcType; import org.hibernate.type.descriptor.jdbc.JdbcType;
import org.hibernate.type.spi.TypeConfiguration;
import org.hibernate.usertype.UserType;
import jakarta.persistence.AttributeConverter;
import jakarta.persistence.AttributeOverride; import jakarta.persistence.AttributeOverride;
import jakarta.persistence.AttributeOverrides; import jakarta.persistence.AttributeOverrides;
import jakarta.persistence.Basic; import jakarta.persistence.Basic;
@ -1506,22 +1516,98 @@ public final class AnnotationBinder {
} }
private static void bindFilterDef(FilterDef defAnn, MetadataBuildingContext context) { private static void bindFilterDef(FilterDef defAnn, MetadataBuildingContext context) {
Map<String, org.hibernate.type.Type> params = new HashMap<>(); final Map<String, JdbcMapping> explicitParamJaMappings;
for ( ParamDef param : defAnn.parameters() ) { if ( defAnn.parameters().length == 0 ) {
params.put( explicitParamJaMappings = null;
param.name(), }
context.getMetadataCollector() else {
.getTypeConfiguration() explicitParamJaMappings = new HashMap<>();
.getBasicTypeRegistry()
.getRegisteredType( param.type() )
);
} }
final FilterDefinition def = new FilterDefinition( defAnn.name(), defAnn.defaultCondition(), params ); for ( ParamDef param : defAnn.parameters() ) {
final JdbcMapping jdbcMapping = resolveFilterParamType( param.type(), context );
if ( jdbcMapping == null ) {
throw new MappingException(
String.format(
Locale.ROOT,
"Unable to resolve type specified for parameter (%s) defined for @FilterDef (%s)",
param.name(),
defAnn.name()
)
);
}
explicitParamJaMappings.put( param.name(), jdbcMapping );
}
final FilterDefinition def = new FilterDefinition( defAnn.name(), defAnn.defaultCondition(), explicitParamJaMappings );
LOG.debugf( "Binding filter definition: %s", def.getFilterName() ); LOG.debugf( "Binding filter definition: %s", def.getFilterName() );
context.getMetadataCollector().addFilterDefinition( def ); context.getMetadataCollector().addFilterDefinition( def );
} }
private static JdbcMapping resolveFilterParamType(Class<?> type, MetadataBuildingContext context) {
if ( UserType.class.isAssignableFrom( type ) ) {
return resolveUserType( (Class<UserType<?>>) type, context );
}
if ( AttributeConverter.class.isAssignableFrom( type ) ) {
return resolveAttributeConverter( (Class<AttributeConverter<?,?>>) type, context );
}
if ( JavaType.class.isAssignableFrom( type ) ) {
return resolveJavaType( (Class<JavaType<?>>) type, context );
}
final TypeConfiguration typeConfiguration = context.getBootstrapContext().getTypeConfiguration();
final JavaType<Object> jtd = typeConfiguration.getJavaTypeRegistry().findDescriptor( type );
if ( jtd != null ) {
final JdbcType jdbcType = jtd.getRecommendedJdbcType( typeConfiguration.getCurrentBaseSqlTypeIndicators() );
return typeConfiguration.getBasicTypeRegistry().resolve( jtd, jdbcType );
}
return null;
}
private static JdbcMapping resolveUserType(Class<UserType<?>> type, MetadataBuildingContext context) {
final StandardServiceRegistry serviceRegistry = context.getBootstrapContext().getServiceRegistry();
final ManagedBeanRegistry beanRegistry = serviceRegistry.getService( ManagedBeanRegistry.class );
final ManagedBean<UserType<?>> bean = beanRegistry.getBean( type );
final UserType<?> userType = bean.getBeanInstance();
//noinspection rawtypes
return new CustomType( userType, context.getBootstrapContext().getTypeConfiguration() );
}
private static JdbcMapping resolveAttributeConverter(Class<AttributeConverter<?, ?>> type, MetadataBuildingContext context) {
final StandardServiceRegistry serviceRegistry = context.getBootstrapContext().getServiceRegistry();
final ManagedBeanRegistry beanRegistry = serviceRegistry.getService( ManagedBeanRegistry.class );
final ManagedBean<AttributeConverter<?, ?>> bean = beanRegistry.getBean( type );
return new ConvertedJdbcMapping<>( bean, context.getBootstrapContext().getTypeConfiguration() );
}
private static JdbcMapping resolveJavaType(Class<JavaType<?>> type, MetadataBuildingContext context) {
final TypeConfiguration typeConfiguration = context.getBootstrapContext().getTypeConfiguration();
final JavaTypeRegistry javaTypeRegistry = typeConfiguration.getJavaTypeRegistry();
final JavaType<?> registeredJtd = javaTypeRegistry.findDescriptor( type );
final JavaType<?> jtd;
if ( registeredJtd != null ) {
jtd = registeredJtd;
}
else {
final StandardServiceRegistry serviceRegistry = context.getBootstrapContext().getServiceRegistry();
final ManagedBeanRegistry beanRegistry = serviceRegistry.getService( ManagedBeanRegistry.class );
final ManagedBean<JavaType<?>> bean = beanRegistry.getBean( type );
jtd = bean.getBeanInstance();
}
final JdbcType jdbcType = jtd.getRecommendedJdbcType( typeConfiguration.getCurrentBaseSqlTypeIndicators() );
return typeConfiguration.getBasicTypeRegistry().resolve( jtd, jdbcType );
}
private static void bindCallbacks(XClass entityClass, PersistentClass persistentClass, private static void bindCallbacks(XClass entityClass, PersistentClass persistentClass,
MetadataBuildingContext context) { MetadataBuildingContext context) {
ReflectionManager reflectionManager = context.getBootstrapContext().getReflectionManager(); ReflectionManager reflectionManager = context.getBootstrapContext().getReflectionManager();

View File

@ -0,0 +1,86 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.cfg.internal;
import java.lang.reflect.ParameterizedType;
import org.hibernate.internal.util.GenericsHelper;
import org.hibernate.metamodel.mapping.JdbcMapping;
import org.hibernate.metamodel.model.convert.internal.JpaAttributeConverterImpl;
import org.hibernate.resource.beans.spi.ManagedBean;
import org.hibernate.type.descriptor.ValueBinder;
import org.hibernate.type.descriptor.ValueExtractor;
import org.hibernate.type.descriptor.converter.AttributeConverterJdbcTypeAdapter;
import org.hibernate.type.descriptor.java.JavaType;
import org.hibernate.type.descriptor.java.spi.JavaTypeRegistry;
import org.hibernate.type.descriptor.jdbc.JdbcType;
import org.hibernate.type.spi.TypeConfiguration;
import jakarta.persistence.AttributeConverter;
/**
* Ad-hoc JdbcMapping implementation for cases where we only have a converter
*
* @author Steve Ebersole
*/
public class ConvertedJdbcMapping<T> implements JdbcMapping {
private final ManagedBean<AttributeConverter<?, ?>> converterBean;
private final JavaType<T> domainJtd;
private final JavaType<?> relationalJtd;
private final JdbcType jdbcType;
@SuppressWarnings({ "unchecked", "rawtypes" })
public ConvertedJdbcMapping(
ManagedBean<AttributeConverter<?, ?>> converterBean,
TypeConfiguration typeConfiguration) {
this.converterBean = converterBean;
final JavaTypeRegistry jtdRegistry = typeConfiguration.getJavaTypeRegistry();
final JavaType<? extends AttributeConverter<?,?>> converterJtd = jtdRegistry.resolveDescriptor( converterBean.getBeanClass() );
final ParameterizedType converterParameterizedType = GenericsHelper.extractParameterizedType( converterBean.getBeanClass() );
final Class<?> domainJavaClass = GenericsHelper.extractClass( converterParameterizedType.getActualTypeArguments()[0] );
final Class<?> relationalJavaClass = GenericsHelper.extractClass( converterParameterizedType.getActualTypeArguments()[1] );
this.domainJtd = jtdRegistry.resolveDescriptor( domainJavaClass );
this.relationalJtd = jtdRegistry.resolveDescriptor( relationalJavaClass );
final JpaAttributeConverterImpl converterDescriptor = new JpaAttributeConverterImpl(
converterBean,
converterJtd,
domainJtd,
relationalJtd
);
this.jdbcType = new AttributeConverterJdbcTypeAdapter(
converterDescriptor,
relationalJtd.getRecommendedJdbcType( typeConfiguration.getCurrentBaseSqlTypeIndicators() ),
relationalJtd
);
}
@Override
public JavaType<T> getJavaTypeDescriptor() {
return domainJtd;
}
@Override
public JdbcType getJdbcType() {
return jdbcType;
}
@Override
public ValueExtractor<?> getJdbcValueExtractor() {
return jdbcType.getExtractor( domainJtd );
}
@Override
public ValueBinder<T> getJdbcValueBinder() {
return jdbcType.getBinder( domainJtd );
}
}

View File

@ -11,7 +11,7 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.hibernate.type.Type; import org.hibernate.metamodel.mapping.JdbcMapping;
/** /**
* Represents the definition of a {@link org.hibernate.Filter filter}. * Represents the definition of a {@link org.hibernate.Filter filter}.
@ -28,18 +28,18 @@ import org.hibernate.type.Type;
public class FilterDefinition implements Serializable { public class FilterDefinition implements Serializable {
private final String filterName; private final String filterName;
private final String defaultFilterCondition; private final String defaultFilterCondition;
private final Map<String, Type> parameterTypes = new HashMap<>(); private final Map<String, JdbcMapping> explicitParamJaMappings = new HashMap<>();
/** /**
* Construct a new FilterDefinition instance. * Construct a new FilterDefinition instance.
* *
* @param name The name of the filter for which this configuration is in effect. * @param name The name of the filter for which this configuration is in effect.
*/ */
public FilterDefinition(String name, String defaultCondition, Map<String, Type> parameterTypes) { public FilterDefinition(String name, String defaultCondition, Map<String, JdbcMapping> explicitParamJaMappings) {
this.filterName = name; this.filterName = name;
this.defaultFilterCondition = defaultCondition; this.defaultFilterCondition = defaultCondition;
if ( parameterTypes != null ) { if ( explicitParamJaMappings != null ) {
this.parameterTypes.putAll( parameterTypes ); this.explicitParamJaMappings.putAll( explicitParamJaMappings );
} }
} }
@ -58,7 +58,7 @@ public class FilterDefinition implements Serializable {
* @return The parameters named by this configuration. * @return The parameters named by this configuration.
*/ */
public Set<String> getParameterNames() { public Set<String> getParameterNames() {
return parameterTypes.keySet(); return explicitParamJaMappings.keySet();
} }
/** /**
@ -68,16 +68,12 @@ public class FilterDefinition implements Serializable {
* *
* @return The type of the named parameter. * @return The type of the named parameter.
*/ */
public Type getParameterType(String parameterName) { public JdbcMapping getParameterJdbcMapping(String parameterName) {
return parameterTypes.get( parameterName ); return explicitParamJaMappings.get( parameterName );
} }
public String getDefaultFilterCondition() { public String getDefaultFilterCondition() {
return defaultFilterCondition; return defaultFilterCondition;
} }
public Map<String, Type> getParameterTypes() {
return parameterTypes;
}
} }

View File

@ -11,18 +11,14 @@ import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.function.Supplier; import java.util.function.Supplier;
import jakarta.persistence.EntityGraph;
import org.hibernate.Filter; import org.hibernate.Filter;
import org.hibernate.UnknownProfileException; import org.hibernate.UnknownProfileException;
import org.hibernate.graph.GraphSemantic;
import org.hibernate.graph.spi.RootGraphImplementor;
import org.hibernate.internal.FilterImpl; import org.hibernate.internal.FilterImpl;
import org.hibernate.loader.ast.spi.CascadingFetchProfile; import org.hibernate.loader.ast.spi.CascadingFetchProfile;
import org.hibernate.type.Type;
/** /**
* Centralize all options which can influence the SQL query needed to load an * Centralize all options which can influence the SQL query needed to load an
@ -76,13 +72,6 @@ public class LoadQueryInfluencers implements Serializable {
// internal fetch profile support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // internal fetch profile support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public void withInternalFetchProfile(CascadingFetchProfile profile, InternalFetchProfileAction action) {
final CascadingFetchProfile previous = this.enabledCascadingFetchProfile;
this.enabledCascadingFetchProfile = profile;
action.performAction();
this.enabledCascadingFetchProfile = previous;
}
public <T> T fromInternalFetchProfile(CascadingFetchProfile profile, Supplier<T> supplier) { public <T> T fromInternalFetchProfile(CascadingFetchProfile profile, Supplier<T> supplier) {
final CascadingFetchProfile previous = this.enabledCascadingFetchProfile; final CascadingFetchProfile previous = this.enabledCascadingFetchProfile;
this.enabledCascadingFetchProfile = profile; this.enabledCascadingFetchProfile = profile;
@ -94,11 +83,6 @@ public class LoadQueryInfluencers implements Serializable {
} }
} }
@FunctionalInterface
public interface InternalFetchProfileAction {
void performAction();
}
public CascadingFetchProfile getEnabledCascadingFetchProfile() { public CascadingFetchProfile getEnabledCascadingFetchProfile() {
return enabledCascadingFetchProfile; return enabledCascadingFetchProfile;
} }
@ -116,7 +100,7 @@ public class LoadQueryInfluencers implements Serializable {
/** /**
* @deprecated Use {@link #getEnabledCascadingFetchProfile} instead * @deprecated Use {@link #getEnabledCascadingFetchProfile} instead
*/ */
@Deprecated @Deprecated( since = "6.0" )
public String getInternalFetchProfile() { public String getInternalFetchProfile() {
return getEnabledCascadingFetchProfile().getLegacyName(); return getEnabledCascadingFetchProfile().getLegacyName();
} }
@ -124,7 +108,7 @@ public class LoadQueryInfluencers implements Serializable {
/** /**
* @deprecated Use {@link #setEnabledCascadingFetchProfile} instead * @deprecated Use {@link #setEnabledCascadingFetchProfile} instead
*/ */
@Deprecated @Deprecated( since = "6.0" )
public void setInternalFetchProfile(String internalFetchProfile) { public void setInternalFetchProfile(String internalFetchProfile) {
setEnabledCascadingFetchProfile( CascadingFetchProfile.fromLegacyName( internalFetchProfile ) ); setEnabledCascadingFetchProfile( CascadingFetchProfile.fromLegacyName( internalFetchProfile ) );
} }
@ -138,7 +122,7 @@ public class LoadQueryInfluencers implements Serializable {
public Map<String,Filter> getEnabledFilters() { public Map<String,Filter> getEnabledFilters() {
if ( enabledFilters == null ) { if ( enabledFilters == null ) {
return Collections.EMPTY_MAP; return Collections.emptyMap();
} }
else { else {
// First, validate all the enabled filters... // First, validate all the enabled filters...
@ -156,7 +140,7 @@ public class LoadQueryInfluencers implements Serializable {
*/ */
public Set<String> getEnabledFilterNames() { public Set<String> getEnabledFilterNames() {
if ( enabledFilters == null ) { if ( enabledFilters == null ) {
return Collections.EMPTY_SET; return Collections.emptySet();
} }
else { else {
return Collections.unmodifiableSet( enabledFilters.keySet() ); return Collections.unmodifiableSet( enabledFilters.keySet() );
@ -199,20 +183,6 @@ public class LoadQueryInfluencers implements Serializable {
return filter.getParameter( parsed[1] ); return filter.getParameter( parsed[1] );
} }
public Type getFilterParameterType(String filterParameterName) {
final String[] parsed = parseFilterParameterName( filterParameterName );
final FilterDefinition filterDef = sessionFactory.getFilterDefinition( parsed[0] );
if ( filterDef == null ) {
throw new IllegalArgumentException( "Filter [" + parsed[0] + "] not defined" );
}
final Type type = filterDef.getParameterType( parsed[1] );
if ( type == null ) {
// this is an internal error of some sort...
throw new InternalError( "Unable to locate type for filter parameter" );
}
return type;
}
public static String[] parseFilterParameterName(String filterParameterName) { public static String[] parseFilterParameterName(String filterParameterName) {
int dot = filterParameterName.lastIndexOf( '.' ); int dot = filterParameterName.lastIndexOf( '.' );
if ( dot <= 0 ) { if ( dot <= 0 ) {
@ -233,12 +203,7 @@ public class LoadQueryInfluencers implements Serializable {
} }
public Set<String> getEnabledFetchProfileNames() { public Set<String> getEnabledFetchProfileNames() {
if ( enabledFetchProfileNames == null ) { return Objects.requireNonNullElse( enabledFetchProfileNames, Collections.emptySet() );
return Collections.EMPTY_SET;
}
else {
return enabledFetchProfileNames;
}
} }
private void checkFetchProfileName(String name) { private void checkFetchProfileName(String name) {
@ -271,66 +236,6 @@ public class LoadQueryInfluencers implements Serializable {
return effectiveEntityGraph; return effectiveEntityGraph;
} }
/**
* @deprecated (since 5.4) {@link #getFetchGraph}, {@link #getLoadGraph}, {@link #setFetchGraph}
* and {@link #setLoadGraph} (as well as JPA itself honestly) all make it very unclear that
* there can be only one graph applied at any one time and that graph is *either* a load or
* a fetch graph. These have all been replaced with {@link #getEffectiveEntityGraph()}.
*
* @see EffectiveEntityGraph
*/
@Deprecated
public EntityGraph getFetchGraph() {
if ( effectiveEntityGraph.getSemantic() != GraphSemantic.FETCH ) {
return null;
}
return effectiveEntityGraph.getGraph();
}
/**
* @deprecated (since 5.4) {@link #getFetchGraph}, {@link #getLoadGraph}, {@link #setFetchGraph}
* and {@link #setLoadGraph} (as well as JPA itself honestly) all make it very unclear that
* there can be only one graph applied at any one time and that graph is *either* a load or
* a fetch graph. These have all been replaced with {@link #getEffectiveEntityGraph()}.
*
* @see EffectiveEntityGraph
*/
@Deprecated
public void setFetchGraph(EntityGraph fetchGraph) {
effectiveEntityGraph.applyGraph( (RootGraphImplementor<?>) fetchGraph, GraphSemantic.FETCH );
}
/**
* @deprecated (since 5.4) {@link #getFetchGraph}, {@link #getLoadGraph}, {@link #setFetchGraph}
* and {@link #setLoadGraph} (as well as JPA itself honestly) all make it very unclear that
* there can be only one graph applied at any one time and that graph is *either* a load or
* a fetch graph. These have all been replaced with {@link #getEffectiveEntityGraph()}.
*
* @see EffectiveEntityGraph
*/
@Deprecated
public EntityGraph getLoadGraph() {
if ( effectiveEntityGraph.getSemantic() != GraphSemantic.LOAD ) {
return null;
}
return effectiveEntityGraph.getGraph();
}
/**
* @deprecated (since 5.4) {@link #getFetchGraph}, {@link #getLoadGraph}, {@link #setFetchGraph}
* and {@link #setLoadGraph} (as well as JPA itself honestly) all make it very unclear that
* there can be only one graph applied at any one time and that that graph is *either* a load or
* a fetch graph. These have all been replaced with {@link #getEffectiveEntityGraph()}.
*
* @see EffectiveEntityGraph
*/
@Deprecated
public void setLoadGraph(final EntityGraph loadGraph) {
effectiveEntityGraph.applyGraph( (RootGraphImplementor<?>) loadGraph, GraphSemantic.LOAD );
}
public Boolean getReadOnly() { public Boolean getReadOnly() {
return readOnly; return readOnly;
} }

View File

@ -27,7 +27,6 @@ import org.hibernate.sql.ast.spi.SqlAstCreationState;
import org.hibernate.sql.ast.tree.from.TableGroup; import org.hibernate.sql.ast.tree.from.TableGroup;
import org.hibernate.sql.ast.tree.predicate.FilterPredicate; import org.hibernate.sql.ast.tree.predicate.FilterPredicate;
import org.hibernate.sql.ast.tree.predicate.Predicate; import org.hibernate.sql.ast.tree.predicate.Predicate;
import org.hibernate.type.Type;
import static org.hibernate.internal.util.StringHelper.safeInterning; import static org.hibernate.internal.util.StringHelper.safeInterning;
@ -167,12 +166,9 @@ public class FilterHelper {
if ( CollectionHelper.isNotEmpty( filterParameterNames ) ) { if ( CollectionHelper.isNotEmpty( filterParameterNames ) ) {
for ( int paramPos = 0; paramPos < filterParameterNames.size(); paramPos++ ) { for ( int paramPos = 0; paramPos < filterParameterNames.size(); paramPos++ ) {
final String parameterName = filterParameterNames.get( paramPos ); final String parameterName = filterParameterNames.get( paramPos );
final Type parameterType = enabledFilter.getFilterDefinition().getParameterType( parameterName ); final JdbcMapping jdbcMapping = enabledFilter
if ( ! (parameterType instanceof JdbcMapping) ) { .getFilterDefinition()
throw new MappingException( String.format( "parameter [%s] for filter [%s] is not of JdbcMapping type", parameterName, filterName ) ); .getParameterJdbcMapping( parameterName );
}
final JdbcMapping jdbcMapping = (JdbcMapping) parameterType;
final Object parameterValue = enabledFilter.getParameter( parameterName ); final Object parameterValue = enabledFilter.getParameter( parameterName );
if ( parameterValue == null ) { if ( parameterValue == null ) {
throw new MappingException( String.format( "unknown parameter [%s] for filter [%s]", parameterName, filterName ) ); throw new MappingException( String.format( "unknown parameter [%s] for filter [%s]", parameterName, filterName ) );

View File

@ -16,8 +16,7 @@ import org.hibernate.Filter;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.engine.spi.FilterDefinition; import org.hibernate.engine.spi.FilterDefinition;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.type.BasicType; import org.hibernate.metamodel.mapping.JdbcMapping;
import org.hibernate.type.Type;
/** /**
* Implementation of FilterImpl. FilterImpl implements the user's * Implementation of FilterImpl. FilterImpl implements the user's
@ -75,7 +74,7 @@ public class FilterImpl implements Filter, Serializable {
*/ */
public Filter setParameter(String name, Object value) throws IllegalArgumentException { public Filter setParameter(String name, Object value) throws IllegalArgumentException {
// Make sure this is a defined parameter and check the incoming value type // Make sure this is a defined parameter and check the incoming value type
BasicType<?> type = (BasicType<?>) definition.getParameterType( name ); JdbcMapping type = definition.getParameterJdbcMapping( name );
if ( type == null ) { if ( type == null ) {
throw new IllegalArgumentException( "Undefined filter parameter [" + name + "]" ); throw new IllegalArgumentException( "Undefined filter parameter [" + name + "]" );
} }
@ -99,13 +98,13 @@ public class FilterImpl implements Filter, Serializable {
if ( values == null ) { if ( values == null ) {
throw new IllegalArgumentException( "Collection must be not null!" ); throw new IllegalArgumentException( "Collection must be not null!" );
} }
Type type = definition.getParameterType( name ); JdbcMapping type = definition.getParameterJdbcMapping( name );
if ( type == null ) { if ( type == null ) {
throw new HibernateException( "Undefined filter parameter [" + name + "]" ); throw new HibernateException( "Undefined filter parameter [" + name + "]" );
} }
if ( !values.isEmpty() ) { if ( !values.isEmpty() ) {
Class<?> elementClass = values.iterator().next().getClass(); final Object element = values.iterator().next();
if ( !type.getReturnedClass().isAssignableFrom( elementClass ) ) { if ( !type.getJavaTypeDescriptor().isInstance( element ) ) {
throw new HibernateException( "Incorrect type for parameter [" + name + "]" ); throw new HibernateException( "Incorrect type for parameter [" + name + "]" );
} }
} }

View File

@ -16,6 +16,7 @@ import java.util.List;
import jakarta.persistence.AttributeConverter; import jakarta.persistence.AttributeConverter;
public class GenericsHelper { public class GenericsHelper {
public static ParameterizedType extractParameterizedType(Type base) { public static ParameterizedType extractParameterizedType(Type base) {
if ( base == null ) { if ( base == null ) {
return null; return null;

View File

@ -1,27 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.internal.util;
/**
* @author Steve Ebersole
*/
public class JavaHelper {
public static Package getPackageFor(String name) {
return getPackageFor( name, JavaHelper.class.getClassLoader() );
}
public static Package getPackageFor(String name, ClassLoader classLoader) {
// after Java 9 we can do -
//return classLoader.getDefinedPackage( name );
return Package.getPackage( name );
}
private JavaHelper() {
// disallow direct instantiation
}
}

View File

@ -11,13 +11,15 @@ import org.hibernate.annotations.TenantId;
import org.hibernate.boot.spi.InFlightMetadataCollector; import org.hibernate.boot.spi.InFlightMetadataCollector;
import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.engine.spi.FilterDefinition; import org.hibernate.engine.spi.FilterDefinition;
import org.hibernate.mapping.BasicValue;
import org.hibernate.mapping.Column; import org.hibernate.mapping.Column;
import org.hibernate.mapping.Formula; import org.hibernate.mapping.Formula;
import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property; import org.hibernate.mapping.Property;
import org.hibernate.mapping.Selectable; import org.hibernate.mapping.Selectable;
import org.hibernate.type.BasicType; import org.hibernate.type.BasicType;
import org.hibernate.type.Type; import org.hibernate.type.descriptor.java.JavaType;
import org.hibernate.type.spi.TypeConfiguration;
import static java.util.Collections.emptyMap; import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonMap; import static java.util.Collections.singletonMap;
@ -38,11 +40,15 @@ public class TenantIdBinder implements AttributeBinder<TenantId> {
MetadataBuildingContext buildingContext, MetadataBuildingContext buildingContext,
PersistentClass persistentClass, PersistentClass persistentClass,
Property property) { Property property) {
InFlightMetadataCollector collector = buildingContext.getMetadataCollector(); final InFlightMetadataCollector collector = buildingContext.getMetadataCollector();
BasicType<Object> tenantIdType = final TypeConfiguration typeConfiguration = collector.getTypeConfiguration();
collector.getTypeConfiguration().getBasicTypeRegistry()
.getRegisteredType( property.getReturnedClassName() ); final String returnedClassName = property.getReturnedClassName();
FilterDefinition filterDefinition = collector.getFilterDefinition(FILTER_NAME); final BasicType<Object> tenantIdType = typeConfiguration
.getBasicTypeRegistry()
.getRegisteredType( returnedClassName );
final FilterDefinition filterDefinition = collector.getFilterDefinition( FILTER_NAME );
if ( filterDefinition == null ) { if ( filterDefinition == null ) {
collector.addFilterDefinition( collector.addFilterDefinition(
new FilterDefinition( new FilterDefinition(
@ -53,13 +59,16 @@ public class TenantIdBinder implements AttributeBinder<TenantId> {
); );
} }
else { else {
Type parameterType = filterDefinition.getParameterTypes().get(PARAMETER_NAME); final JavaType<?> tenantIdTypeJtd = tenantIdType.getJavaTypeDescriptor();
if ( !parameterType.getName().equals( tenantIdType.getName() ) ) { final JavaType<?> parameterJtd = filterDefinition
.getParameterJdbcMapping( PARAMETER_NAME )
.getJavaTypeDescriptor();
if ( !parameterJtd.getJavaTypeClass().equals( tenantIdTypeJtd.getJavaTypeClass() ) ) {
throw new MappingException( throw new MappingException(
"all @TenantId fields must have the same type: " "all @TenantId fields must have the same type: "
+ parameterType.getName() + parameterJtd.getJavaType().getTypeName()
+ " differs from " + " differs from "
+ tenantIdType.getName() + tenantIdTypeJtd.getJavaType().getTypeName()
); );
} }
} }

View File

@ -23,7 +23,7 @@ import org.hibernate.type.descriptor.jdbc.JdbcType;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
/** /**
* Adapter for incorporating JPA {@link AttributeConverter} handling into the SqlTypeDescriptor contract. * Adapter for incorporating JPA {@link AttributeConverter} handling into the JdbcType contract.
* <p/> * <p/>
* Essentially this is responsible for mapping to/from the intermediate database type representation. Continuing the * Essentially this is responsible for mapping to/from the intermediate database type representation. Continuing the
* {@code AttributeConverter<Integer,String>} example from * {@code AttributeConverter<Integer,String>} example from

View File

@ -20,7 +20,7 @@ import org.hibernate.annotations.ParamDef;
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
@Entity @Entity
@FilterDef(name="selectedLocale", parameters={ @ParamDef( name="param", type="string" ) } ) @FilterDef(name="selectedLocale", parameters={ @ParamDef( name="param", type=String.class ) } )
public class TestCourse { public class TestCourse {
private Long testCourseId; private Long testCourseId;

View File

@ -46,7 +46,7 @@ import jakarta.persistence.Lob;
@OptimisticLocking(type = OptimisticLockType.ALL) @OptimisticLocking(type = OptimisticLockType.ALL)
@Polymorphism(type = PolymorphismType.EXPLICIT) @Polymorphism(type = PolymorphismType.EXPLICIT)
@Where(clause = "1=1") @Where(clause = "1=1")
@FilterDef(name = "minLength", parameters = {@ParamDef(name = "minLength", type = "integer")}) @FilterDef(name = "minLength", parameters = {@ParamDef(name = "minLength", type = Integer.class)})
@Filter(name = "betweenLength") @Filter(name = "betweenLength")
@Filter(name = "minLength", condition = ":minLength <= length") @Filter(name = "minLength", condition = ":minLength <= length")
@org.hibernate.annotations.Table(appliesTo = "Forest", @org.hibernate.annotations.Table(appliesTo = "Forest",

View File

@ -17,7 +17,7 @@ import org.hibernate.annotations.ParamDef;
/** /**
* @author Sharath Reddy * @author Sharath Reddy
*/ */
@FilterDef(name = "byCategory", parameters = {@ParamDef(name = "category", type = "string")}) @FilterDef(name = "byCategory", parameters = {@ParamDef(name = "category", type = String.class)})
@Filter(name = "byCategory", condition = ":category = `CATEGORY`") @Filter(name = "byCategory", condition = ":category = `CATEGORY`")
@MappedSuperclass @MappedSuperclass
public class Tool extends Widget { public class Tool extends Widget {

View File

@ -22,7 +22,7 @@ import org.hibernate.annotations.ParamDef;
* @author Sharath Reddy * @author Sharath Reddy
*/ */
@FilterDef(name="byState", defaultCondition=":state = state", @FilterDef(name="byState", defaultCondition=":state = state",
parameters=@ParamDef(name="state",type="string")) parameters=@ParamDef(name="state",type=String.class))
@Entity @Entity
public class Topic { public class Topic {

View File

@ -15,7 +15,7 @@ import org.hibernate.annotations.ParamDef;
/** /**
* @author Sharath Reddy * @author Sharath Reddy
*/ */
@FilterDef(name = "byName", parameters = {@ParamDef(name = "name", type = "string")}) @FilterDef(name = "byName", parameters = {@ParamDef(name = "name", type = String.class)})
@Filter(name = "byName", condition = ":name = name") @Filter(name = "byName", condition = ":name = name")
@MappedSuperclass @MappedSuperclass
public class Widget { public class Widget {

View File

@ -13,8 +13,8 @@
name = "betweenLength", name = "betweenLength",
defaultCondition = ":minLength <= length and :maxLength >= length", defaultCondition = ":minLength <= length and :maxLength >= length",
parameters = { parameters = {
@ParamDef(name = "minLength", type = "integer"), @ParamDef(name = "minLength", type = Integer.class),
@ParamDef(name = "maxLength", type = "integer") @ParamDef(name = "maxLength", type = Integer.class)
} }
) package org.hibernate.orm.test.annotations.entity; ) package org.hibernate.orm.test.annotations.entity;

View File

@ -243,7 +243,7 @@ public class CriteriaQueryWithAppliedFilterTest {
name = "statusFilter", name = "statusFilter",
parameters = { parameters = {
@ParamDef( @ParamDef(
name = "status", type = "string" name = "status", type = String.class
) )
} }
) )

View File

@ -9,12 +9,6 @@ package org.hibernate.orm.test.filter;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import org.hibernate.annotations.Filter; import org.hibernate.annotations.Filter;
import org.hibernate.annotations.FilterDef; import org.hibernate.annotations.FilterDef;
@ -26,13 +20,18 @@ import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.transaction.TransactionUtil;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
/** /**
@ -117,10 +116,10 @@ public class FilterDotNameTest {
@Entity(name = "PurchaseOrder") @Entity(name = "PurchaseOrder")
@FilterDefs({ @FilterDefs({
@FilterDef(name = "customerIdFilter", parameters = @ParamDef(name = "customerId", type = "long")), @FilterDef(name = "customerIdFilter", parameters = @ParamDef(name = "customerId", type = Long.class)),
@FilterDef(name = "PurchaseOrder.customerIdFilter", parameters = @ParamDef(name = "customerId", type = "long")), @FilterDef(name = "PurchaseOrder.customerIdFilter", parameters = @ParamDef(name = "customerId", type = Long.class)),
@FilterDef(name = "itemIdFilter", parameters = @ParamDef(name = "itemId", type = "long")), @FilterDef(name = "itemIdFilter", parameters = @ParamDef(name = "itemId", type = Long.class)),
@FilterDef(name = "PurchaseOrder.itemIdFilter", parameters = @ParamDef(name = "itemId", type = "long")) @FilterDef(name = "PurchaseOrder.itemIdFilter", parameters = @ParamDef(name = "itemId", type = Long.class))
}) })
@Filters({ @Filters({
@Filter(name = "customerIdFilter", condition = "customerId = :customerId"), @Filter(name = "customerIdFilter", condition = "customerId = :customerId"),

View File

@ -9,13 +9,6 @@ package org.hibernate.orm.test.filter;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import org.hibernate.annotations.Fetch; import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode; import org.hibernate.annotations.FetchMode;
@ -28,7 +21,6 @@ import org.hibernate.stat.Statistics;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.FailureExpected;
import org.hibernate.testing.orm.junit.ServiceRegistry; import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope; import org.hibernate.testing.orm.junit.SessionFactoryScope;
@ -37,9 +29,16 @@ import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
/** /**
@ -127,7 +126,7 @@ public class FilterWitSubSelectFetchModeTest {
name = "ID", name = "ID",
defaultCondition = "customerId >= :id", defaultCondition = "customerId >= :id",
parameters = { parameters = {
@ParamDef(type = "long", name = "id") @ParamDef(type = Long.class, name = "id")
} }
) )
@Filter(name = "ID") @Filter(name = "ID")

View File

@ -27,6 +27,7 @@ import org.hibernate.annotations.FilterDefs;
import org.hibernate.annotations.Filters; import org.hibernate.annotations.Filters;
import org.hibernate.annotations.ParamDef; import org.hibernate.annotations.ParamDef;
import org.hibernate.query.Query; import org.hibernate.query.Query;
import org.hibernate.type.YesNoConverter;
import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactory;
@ -100,8 +101,8 @@ public class OneToManyWithDynamicFilterTest {
@FilterDef( @FilterDef(
name = "aliveOnly", name = "aliveOnly",
parameters = { parameters = {
@ParamDef(name = "aliveTimestamp", type = "timestamp"), @ParamDef(name = "aliveTimestamp", type = Timestamp.class),
@ParamDef(name = "deleted", type = "boolean") @ParamDef(name = "deleted", type = YesNoConverter.class)
}, },
defaultCondition = "DELETION_TIMESTAMP = :aliveTimestamp and DELETED = :deleted") defaultCondition = "DELETION_TIMESTAMP = :aliveTimestamp and DELETED = :deleted")
}) })

View File

@ -74,7 +74,7 @@ public class BasicFilteredBulkManipulationTest {
name = "sex", name = "sex",
parameters = @ParamDef( parameters = @ParamDef(
name= "sexCode", name= "sexCode",
type = "char" type = Character.class
) )
) )
@Filter( name = "sex", condition = "SEX_CODE = :sexCode" ) @Filter( name = "sex", condition = "SEX_CODE = :sexCode" )

View File

@ -127,7 +127,7 @@ public class JoinedFilteredBulkManipulationTest {
name = "sex", name = "sex",
parameters = @ParamDef( parameters = @ParamDef(
name= "sexCode", name= "sexCode",
type = "char" type = Character.class
) )
) )
@Filter( name = "sex", condition = "SEX_CODE = :sexCode" ) @Filter( name = "sex", condition = "SEX_CODE = :sexCode" )

View File

@ -20,7 +20,7 @@ import org.hibernate.annotations.ParamDef;
* @author Steve Ebersole * @author Steve Ebersole
*/ */
@Entity @Entity
@FilterDef( name="byRegion", parameters = {@ParamDef(name = "region", type = "string")}) @FilterDef( name="byRegion", parameters = {@ParamDef(name = "region", type = String.class)})
@Filter( name = "byRegion", condition = "region_cd = :region" ) @Filter( name = "byRegion", condition = "region_cd = :region" )
public class Account { public class Account {
private Long id; private Long id;

View File

@ -23,7 +23,7 @@ import jakarta.persistence.Table;
@Entity @Entity
@Table(name="T_USER") @Table(name="T_USER")
@SecondaryTable(name="SECURITY_USER") @SecondaryTable(name="SECURITY_USER")
@FilterDef(name="ageFilter", parameters=@ParamDef(name="age", type="integer")) @FilterDef(name="ageFilter", parameters=@ParamDef(name="age", type=Integer.class))
@Filter(name="ageFilter", condition="{u}.AGE < :age AND {s}.LOCKED_OUT <> 1", @Filter(name="ageFilter", condition="{u}.AGE < :age AND {s}.LOCKED_OUT <> 1",
aliases={@SqlFragmentAlias(alias="u", table="T_USER"), @SqlFragmentAlias(alias="s", table="SECURITY_USER")}) aliases={@SqlFragmentAlias(alias="u", table="T_USER"), @SqlFragmentAlias(alias="s", table="SECURITY_USER")})
public class User { public class User {

View File

@ -16,7 +16,7 @@ import org.hibernate.annotations.FilterDef;
import org.hibernate.annotations.ParamDef; import org.hibernate.annotations.ParamDef;
@MappedSuperclass @MappedSuperclass
@FilterDef(name = "nameFilter", parameters = @ParamDef(name = "name", type = "string")) @FilterDef(name = "nameFilter", parameters = @ParamDef(name = "name", type = String.class))
@Filter(name = "nameFilter", condition = ":name = ANIMAL_NAME") @Filter(name = "nameFilter", condition = ":name = ANIMAL_NAME")
public abstract class Animal { public abstract class Animal {
@Id @Id

View File

@ -21,7 +21,7 @@ import org.hibernate.annotations.ParamDef;
@Entity @Entity
@Inheritance(strategy=InheritanceType.JOINED) @Inheritance(strategy=InheritanceType.JOINED)
@Table(name="ZOOLOGY_ANIMAL") @Table(name="ZOOLOGY_ANIMAL")
@FilterDef(name="ignoreSome", parameters={@ParamDef(name="name", type="string")}) @FilterDef(name="ignoreSome", parameters={@ParamDef(name="name", type=String.class)})
@Filter(name="ignoreSome", condition=":name <> ANIMAL_NAME") @Filter(name="ignoreSome", condition=":name <> ANIMAL_NAME")
public class Animal { public class Animal {
@Id @Id

View File

@ -20,7 +20,7 @@ import org.hibernate.annotations.ParamDef;
import org.hibernate.annotations.SqlFragmentAlias; import org.hibernate.annotations.SqlFragmentAlias;
@Entity @Entity
@FilterDef(name="iqMin", parameters={@ParamDef(name="min", type="integer")}) @FilterDef(name="iqMin", parameters={@ParamDef(name="min", type=Integer.class)})
@FilterDef(name="pregnantMembers") @FilterDef(name="pregnantMembers")
public class Club { public class Club {
@Id @Id

View File

@ -19,8 +19,8 @@ import org.hibernate.annotations.ParamDef;
@Table(name="ZOOLOGY_HUMAN") @Table(name="ZOOLOGY_HUMAN")
@FilterDef(name="iqRange", parameters= @FilterDef(name="iqRange", parameters=
{ {
@ParamDef(name="min", type="integer"), @ParamDef(name="min", type=Integer.class),
@ParamDef(name="max", type="integer") @ParamDef(name="max", type=Integer.class)
}) })
@Filter(name="iqRange", condition="HUMAN_IQ BETWEEN :min AND :max") @Filter(name="iqRange", condition="HUMAN_IQ BETWEEN :min AND :max")
public class Human extends Mammal { public class Human extends Mammal {

View File

@ -21,7 +21,7 @@ import org.hibernate.annotations.ParamDef;
@Entity @Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE) @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@Table(name="ZOOLOGY_ANIMAL") @Table(name="ZOOLOGY_ANIMAL")
@FilterDef(name="ignoreSome", parameters={@ParamDef(name="name", type="string")}) @FilterDef(name="ignoreSome", parameters={@ParamDef(name="name", type=String.class)})
@Filter(name="ignoreSome", deduceAliasInjectionPoints=false, condition=":name <> {alias}.ANIMAL_NAME") @Filter(name="ignoreSome", deduceAliasInjectionPoints=false, condition=":name <> {alias}.ANIMAL_NAME")
public class Animal { public class Animal {
@Id @Id

View File

@ -18,8 +18,8 @@ import org.hibernate.annotations.ParamDef;
@Table(name="ZOOLOGY_HUMAN") @Table(name="ZOOLOGY_HUMAN")
@FilterDef(name="iqRange", parameters= @FilterDef(name="iqRange", parameters=
{ {
@ParamDef(name="min", type="integer"), @ParamDef(name="min", type=Integer.class),
@ParamDef(name="max", type="integer") @ParamDef(name="max", type=Integer.class)
}) })
@Filter(name="iqRange", condition="HUMAN_IQ BETWEEN :min AND :max") @Filter(name="iqRange", condition="HUMAN_IQ BETWEEN :min AND :max")
public class Human extends Mammal { public class Human extends Mammal {

View File

@ -21,7 +21,7 @@ import org.hibernate.annotations.ParamDef;
@Entity @Entity
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS) @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
@Table(name="ZOOLOGY_ANIMAL") @Table(name="ZOOLOGY_ANIMAL")
@FilterDef(name="ignoreSome", parameters={@ParamDef(name="name", type="string")}) @FilterDef(name="ignoreSome", parameters={@ParamDef(name="name", type=String.class)})
@Filter(name="ignoreSome", condition=":name <> ANIMAL_NAME") @Filter(name="ignoreSome", condition=":name <> ANIMAL_NAME")
public class Animal { public class Animal {
@Id @Id

View File

@ -18,8 +18,8 @@ import org.hibernate.annotations.ParamDef;
@Table(name="ZOOLOGY_HUMAN") @Table(name="ZOOLOGY_HUMAN")
@FilterDef(name="iqRange", parameters= @FilterDef(name="iqRange", parameters=
{ {
@ParamDef(name="min", type="integer"), @ParamDef(name="min", type=Integer.class),
@ParamDef(name="max", type="integer") @ParamDef(name="max", type=Integer.class)
}) })
@Filter(name="iqRange", condition="HUMAN_IQ BETWEEN :min AND :max") @Filter(name="iqRange", condition="HUMAN_IQ BETWEEN :min AND :max")
public class Human extends Mammal { public class Human extends Mammal {