get rid of a class that was "being phased out"
and use some more correct generic types
This commit is contained in:
parent
6f2273d749
commit
3f073ae551
|
@ -433,7 +433,7 @@ public class SessionFactoryDelegatingImpl implements SessionFactoryImplementor,
|
|||
}
|
||||
|
||||
@Override
|
||||
public <T> BindableType<T> resolveParameterBindType(T bindValue) {
|
||||
public <T> BindableType<? extends T> resolveParameterBindType(T bindValue) {
|
||||
return delegate.resolveParameterBindType( bindValue );
|
||||
}
|
||||
|
||||
|
|
|
@ -109,7 +109,6 @@ import org.hibernate.persister.entity.SessionFactoryBasedWrapperOptions;
|
|||
import org.hibernate.procedure.spi.ProcedureCallImplementor;
|
||||
import org.hibernate.proxy.EntityNotFoundDelegate;
|
||||
import org.hibernate.proxy.HibernateProxy;
|
||||
import org.hibernate.proxy.HibernateProxyHelper;
|
||||
import org.hibernate.proxy.LazyInitializer;
|
||||
import org.hibernate.query.QueryLogging;
|
||||
import org.hibernate.query.hql.spi.SqmQueryImplementor;
|
||||
|
@ -1084,14 +1083,24 @@ public class SessionFactoryImpl implements SessionFactoryImplementor {
|
|||
return fetchProfiles.get( name );
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> BindableType<T> resolveParameterBindType(T bindValue) {
|
||||
@Override @SuppressWarnings("unchecked")
|
||||
public <T> BindableType<? extends T> resolveParameterBindType(T bindValue) {
|
||||
if ( bindValue == null ) {
|
||||
// we can't guess
|
||||
return null;
|
||||
}
|
||||
|
||||
return resolveParameterBindType( HibernateProxyHelper.getClassWithoutInitializingProxy( bindValue ) );
|
||||
Class<? extends T> clazz;
|
||||
if (bindValue instanceof HibernateProxy) {
|
||||
HibernateProxy proxy = (HibernateProxy) bindValue;
|
||||
LazyInitializer li = proxy.getHibernateLazyInitializer();
|
||||
clazz = li.getPersistentClass();
|
||||
}
|
||||
else {
|
||||
clazz = (Class<? extends T>) bindValue.getClass();
|
||||
}
|
||||
|
||||
return resolveParameterBindType( clazz );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -9,7 +9,6 @@ package org.hibernate.metamodel.model.domain;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
import jakarta.persistence.metamodel.EmbeddableType;
|
||||
import jakarta.persistence.metamodel.EntityType;
|
||||
import jakarta.persistence.metamodel.ManagedType;
|
||||
|
|
|
@ -1,37 +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.proxy;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Utility methods for working with proxies. (this class is being phased out)
|
||||
* @author Gavin King
|
||||
*/
|
||||
public final class HibernateProxyHelper {
|
||||
|
||||
/**
|
||||
* Get the class of an instance or the underlying class
|
||||
* of a proxy (without initializing the proxy!). It is
|
||||
* almost always better to use the entity name!
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> Class<T> getClassWithoutInitializingProxy(T object) {
|
||||
if (object instanceof HibernateProxy) {
|
||||
HibernateProxy proxy = (HibernateProxy) object;
|
||||
LazyInitializer li = proxy.getHibernateLazyInitializer();
|
||||
return li.getPersistentClass();
|
||||
}
|
||||
else {
|
||||
return (Class<T>) object.getClass();
|
||||
}
|
||||
}
|
||||
|
||||
private HibernateProxyHelper() {
|
||||
//cant instantiate
|
||||
}
|
||||
}
|
|
@ -9,10 +9,8 @@ package org.hibernate.query;
|
|||
import org.hibernate.QueryException;
|
||||
|
||||
/**
|
||||
* Indicates an attempt to call {@link QueryProducer#createSelectQuery(String)},
|
||||
* {@link QueryProducer#name(String)} or
|
||||
* {@link QueryProducer#createNativeMutationQuery(String)} with a non-mutation
|
||||
* query (generally a select query)
|
||||
* Indicates an attempt to call {@link QueryProducer#createSelectQuery(String)}
|
||||
* with a non-selection query (generally a mutation query)
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
|
|
|
@ -37,7 +37,7 @@ public class QueryParameterBindingImpl<T> implements QueryParameterBinding<T>, J
|
|||
private boolean isBound;
|
||||
private boolean isMultiValued;
|
||||
|
||||
private BindableType<T> bindType;
|
||||
private BindableType<? extends T> bindType;
|
||||
private MappingModelExpressable<T> type;
|
||||
private TemporalType explicitTemporalPrecision;
|
||||
|
||||
|
@ -68,7 +68,7 @@ public class QueryParameterBindingImpl<T> implements QueryParameterBinding<T>, J
|
|||
}
|
||||
|
||||
@Override
|
||||
public BindableType<T> getBindType() {
|
||||
public BindableType<? extends T> getBindType() {
|
||||
return bindType;
|
||||
}
|
||||
|
||||
|
@ -135,12 +135,12 @@ public class QueryParameterBindingImpl<T> implements QueryParameterBinding<T>, J
|
|||
bindValue( value );
|
||||
}
|
||||
|
||||
private T coerce(T value, BindableType<T> parameterType) {
|
||||
private T coerce(T value, BindableType<? extends T> parameterType) {
|
||||
if ( value == null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final SqmExpressable<T> sqmExpressable = parameterType.resolveExpressable( sessionFactory );
|
||||
final SqmExpressable<? extends T> sqmExpressable = parameterType.resolveExpressable( sessionFactory );
|
||||
assert sqmExpressable != null;
|
||||
|
||||
return sqmExpressable.getExpressableJavaType().coerce( value, this );
|
||||
|
@ -301,8 +301,8 @@ public class QueryParameterBindingImpl<T> implements QueryParameterBinding<T>, J
|
|||
this.explicitTemporalPrecision = temporalTypePrecision;
|
||||
}
|
||||
|
||||
private JavaType<T> determineJavaType(BindableType<T> bindType) {
|
||||
final SqmExpressable<T> sqmExpressable = bindType.resolveExpressable( sessionFactory );
|
||||
private JavaType<? extends T> determineJavaType(BindableType<? extends T> bindType) {
|
||||
final SqmExpressable<? extends T> sqmExpressable = bindType.resolveExpressable( sessionFactory );
|
||||
assert sqmExpressable != null;
|
||||
|
||||
return sqmExpressable.getExpressableJavaType();
|
||||
|
|
|
@ -39,7 +39,7 @@ public interface QueryParameterBinding<T> {
|
|||
*
|
||||
* @return The currently associated Type
|
||||
*/
|
||||
BindableType<T> getBindType();
|
||||
BindableType<? extends T> getBindType();
|
||||
|
||||
/**
|
||||
* If the parameter represents a temporal type, return the explicitly
|
||||
|
|
|
@ -16,7 +16,7 @@ import org.hibernate.type.spi.TypeConfiguration;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface QueryParameterBindingTypeResolver {
|
||||
<T> BindableType<T> resolveParameterBindType(T bindValue);
|
||||
<T> BindableType<? extends T> resolveParameterBindType(T bindValue);
|
||||
<T> BindableType<T> resolveParameterBindType(Class<T> clazz);
|
||||
TypeConfiguration getTypeConfiguration();
|
||||
}
|
||||
|
|
|
@ -714,7 +714,6 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext,
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public <N extends Number> SqmExpression<N> sum(Expression<? extends N> x, N y) {
|
||||
return createSqmArithmeticNode(
|
||||
BinaryArithmeticOperator.ADD,
|
||||
|
@ -724,7 +723,6 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext,
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public <N extends Number> SqmExpression<N> sum(N x, Expression<? extends N> y) {
|
||||
return createSqmArithmeticNode(
|
||||
BinaryArithmeticOperator.ADD,
|
||||
|
@ -770,11 +768,10 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext,
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public <N extends Number> SqmExpression<N> diff(Expression<? extends N> x, N y) {
|
||||
return createSqmArithmeticNode(
|
||||
BinaryArithmeticOperator.SUBTRACT,
|
||||
(SqmExpression) x,
|
||||
(SqmExpression<?>) x,
|
||||
value( y )
|
||||
);
|
||||
}
|
||||
|
@ -894,8 +891,8 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext,
|
|||
return new SqmLiteralNull<>( this );
|
||||
}
|
||||
|
||||
final SqmExpressable<T> expressable = resolveInferredType( value, typeInferenceSource, getTypeConfiguration() );
|
||||
return new SqmLiteral<>( value, expressable, this );
|
||||
final SqmExpressable<T> expressible = resolveInferredType( value, typeInferenceSource, getTypeConfiguration() );
|
||||
return new SqmLiteral<>( value, expressible, this );
|
||||
}
|
||||
|
||||
private static <T> SqmExpressable<T> resolveInferredType(
|
||||
|
@ -924,10 +921,10 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext,
|
|||
return new SqmLiteralNull<>( this );
|
||||
}
|
||||
|
||||
final BindableType<T> valueParamType = queryEngine.getTypeConfiguration()
|
||||
final BindableType<? extends T> valueParamType = queryEngine.getTypeConfiguration()
|
||||
.getSessionFactory()
|
||||
.resolveParameterBindType( value );
|
||||
final SqmExpressable<T> sqmExpressable = valueParamType == null
|
||||
final SqmExpressable<? extends T> sqmExpressable = valueParamType == null
|
||||
? null
|
||||
: valueParamType.resolveExpressable( getTypeConfiguration().getSessionFactory() );
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ import static org.hibernate.query.internal.QueryHelper.highestPrecedenceType;
|
|||
*/
|
||||
public abstract class AbstractSqmExpression<T> extends AbstractJpaSelection<T> implements SqmExpression<T> {
|
||||
|
||||
public AbstractSqmExpression(SqmExpressable<T> type, NodeBuilder criteriaBuilder) {
|
||||
public AbstractSqmExpression(SqmExpressable<? extends T> type, NodeBuilder criteriaBuilder) {
|
||||
super( type, criteriaBuilder );
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ import org.hibernate.type.descriptor.java.JavaType;
|
|||
public class SqmLiteral<T> extends AbstractSqmExpression<T> {
|
||||
private final T value;
|
||||
|
||||
public SqmLiteral(T value, SqmExpressable<T> inherentType, NodeBuilder nodeBuilder) {
|
||||
public SqmLiteral(T value, SqmExpressable<? extends T> inherentType, NodeBuilder nodeBuilder) {
|
||||
super( inherentType, nodeBuilder );
|
||||
assert value != null;
|
||||
this.value = value;
|
||||
|
|
|
@ -21,7 +21,7 @@ import org.hibernate.query.sqm.tree.select.SqmSelectableNode;
|
|||
public abstract class AbstractJpaSelection<T>
|
||||
extends AbstractJpaTupleElement<T>
|
||||
implements SqmSelectableNode<T>, JpaSelection<T> {
|
||||
protected AbstractJpaSelection(SqmExpressable<T> sqmExpressable, NodeBuilder criteriaBuilder) {
|
||||
protected AbstractJpaSelection(SqmExpressable<? extends T> sqmExpressable, NodeBuilder criteriaBuilder) {
|
||||
super( sqmExpressable, criteriaBuilder );
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ public abstract class AbstractJpaTupleElement<T>
|
|||
private String alias;
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
protected AbstractJpaTupleElement(SqmExpressable<T> expressableType, NodeBuilder criteriaBuilder) {
|
||||
protected AbstractJpaTupleElement(SqmExpressable<? extends T> expressableType, NodeBuilder criteriaBuilder) {
|
||||
super( criteriaBuilder );
|
||||
|
||||
setExpressableType( expressableType );
|
||||
|
|
|
@ -9,7 +9,6 @@ package org.hibernate.type;
|
|||
import java.io.Serializable;
|
||||
import java.lang.reflect.Method;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
@ -34,7 +33,6 @@ import org.hibernate.persister.entity.EntityPersister;
|
|||
import org.hibernate.persister.entity.Joinable;
|
||||
import org.hibernate.pretty.MessageHelper;
|
||||
import org.hibernate.proxy.HibernateProxy;
|
||||
import org.hibernate.proxy.HibernateProxyHelper;
|
||||
import org.hibernate.proxy.LazyInitializer;
|
||||
import org.hibernate.type.spi.TypeConfiguration;
|
||||
|
||||
|
@ -265,11 +263,13 @@ public class AnyType extends AbstractType implements CompositeType, AssociationT
|
|||
}
|
||||
|
||||
if ( value == LazyPropertyInitializer.UNFETCHED_PROPERTY || !Hibernate.isInitialized( value ) ) {
|
||||
return "<uninitialized>";
|
||||
return "<uninitialized>";
|
||||
}
|
||||
|
||||
final Class valueClass = HibernateProxyHelper.getClassWithoutInitializingProxy( value );
|
||||
final EntityPersister descriptor = factory.getDomainModel().getEntityDescriptor( valueClass );
|
||||
String entityName = factory.bestGuessEntityName(value);
|
||||
final EntityPersister descriptor = entityName == null
|
||||
? null
|
||||
: factory.getDomainModel().getEntityDescriptor( entityName );
|
||||
return MessageHelper.infoString( descriptor, value, factory );
|
||||
}
|
||||
|
||||
|
@ -309,10 +309,6 @@ public class AnyType extends AbstractType implements CompositeType, AssociationT
|
|||
}
|
||||
}
|
||||
|
||||
private Object nullSafeGet(ResultSet rs, String name, SharedSessionContractImplementor session, Object owner) {
|
||||
throw new UnsupportedOperationException( "object is a multicolumn type" );
|
||||
}
|
||||
|
||||
// CompositeType implementation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
@Override
|
||||
|
|
|
@ -16,8 +16,8 @@ import org.hibernate.orm.test.envers.Priority;
|
|||
import org.hibernate.orm.test.envers.entities.UnversionedStrTestEntity;
|
||||
import org.hibernate.orm.test.envers.entities.manytoone.unidirectional.TargetNotAuditedEntity;
|
||||
import org.hibernate.proxy.HibernateProxy;
|
||||
import org.hibernate.proxy.HibernateProxyHelper;
|
||||
|
||||
import org.hibernate.proxy.LazyInitializer;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
|
@ -113,6 +113,17 @@ public class RelationNotAuditedTarget extends BaseEnversJPAFunctionalTestCase {
|
|||
assert Arrays.asList( 1, 2, 3, 4 ).equals( revisions );
|
||||
}
|
||||
|
||||
static Class<?> getClassWithoutInitializingProxy(Object object) {
|
||||
if (object instanceof HibernateProxy) {
|
||||
HibernateProxy proxy = (HibernateProxy) object;
|
||||
LazyInitializer li = proxy.getHibernateLazyInitializer();
|
||||
return li.getPersistentClass();
|
||||
}
|
||||
else {
|
||||
return object.getClass();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHistoryOfTnae1_id() {
|
||||
// load original "tnae1" TargetNotAuditedEntity to force load "str1" UnversionedStrTestEntity as Proxy
|
||||
|
@ -133,7 +144,7 @@ public class RelationNotAuditedTarget extends BaseEnversJPAFunctionalTestCase {
|
|||
|
||||
assert original.getReference() instanceof HibernateProxy;
|
||||
assert UnversionedStrTestEntity.class.equals( Hibernate.getClass( original.getReference() ) );
|
||||
assert UnversionedStrTestEntity.class.equals( HibernateProxyHelper.getClassWithoutInitializingProxy( rev1.getReference() ) );
|
||||
assert UnversionedStrTestEntity.class.equals( getClassWithoutInitializingProxy( rev1.getReference() ) );
|
||||
assert UnversionedStrTestEntity.class.equals( Hibernate.getClass( rev1.getReference() ) );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue