actually remove EntityTuplizer and friends

This commit is contained in:
Gavin King 2022-01-25 08:02:32 +01:00
parent 56973f5da4
commit 766d519ddd
19 changed files with 5 additions and 898 deletions

View File

@ -18,14 +18,11 @@ import org.hibernate.cache.spi.TimestampsCacheFactory;
import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
import org.hibernate.jpa.spi.JpaCompliance;
import org.hibernate.loader.BatchFetchStyle;
import org.hibernate.metamodel.RepresentationMode;
import org.hibernate.proxy.EntityNotFoundDelegate;
import org.hibernate.query.sqm.NullPrecedence;
import org.hibernate.query.sqm.function.SqmFunctionDescriptor;
import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode;
import org.hibernate.resource.jdbc.spi.StatementInspector;
import org.hibernate.tuple.entity.EntityTuplizer;
import org.hibernate.tuple.entity.EntityTuplizerFactory;
/**
* The contract for building a {@link SessionFactory} given a number of options.
@ -241,27 +238,6 @@ public interface SessionFactoryBuilder {
*/
SessionFactoryBuilder applyLazyInitializationOutsideTransaction(boolean enabled);
/**
* Specify the EntityTuplizerFactory to use.
*
* @param entityTuplizerFactory The EntityTuplizerFactory to use.
*
* @return {@code this}, for method chaining
*/
SessionFactoryBuilder applyEntityTuplizerFactory(EntityTuplizerFactory entityTuplizerFactory);
/**
* Register the default {@link EntityTuplizer} to be applied to the SessionFactory.
*
* @param entityMode The entity mode that which this tuplizer will be applied.
* @param tuplizerClass The custom tuplizer class.
*
* @return {@code this}, for method chaining
*/
SessionFactoryBuilder applyEntityTuplizer(
RepresentationMode entityMode,
Class<? extends EntityTuplizer> tuplizerClass);
SessionFactoryBuilder applyTempTableDdlTransactionHandling(TempTableDdlTransactionHandling handling);
/**

View File

@ -27,14 +27,11 @@ import org.hibernate.cache.spi.TimestampsCacheFactory;
import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
import org.hibernate.internal.SessionFactoryImpl;
import org.hibernate.loader.BatchFetchStyle;
import org.hibernate.metamodel.RepresentationMode;
import org.hibernate.proxy.EntityNotFoundDelegate;
import org.hibernate.query.sqm.NullPrecedence;
import org.hibernate.query.sqm.function.SqmFunctionDescriptor;
import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode;
import org.hibernate.resource.jdbc.spi.StatementInspector;
import org.hibernate.tuple.entity.EntityTuplizer;
import org.hibernate.tuple.entity.EntityTuplizerFactory;
/**
* @author Gail Badner
@ -184,20 +181,6 @@ public class SessionFactoryBuilderImpl implements SessionFactoryBuilderImplement
return this;
}
@Override
public SessionFactoryBuilder applyEntityTuplizerFactory(EntityTuplizerFactory entityTuplizerFactory) {
this.optionsBuilder.applyEntityTuplizerFactory( entityTuplizerFactory );
return this;
}
@Override
public SessionFactoryBuilder applyEntityTuplizer(
RepresentationMode entityMode,
Class<? extends EntityTuplizer> tuplizerClass) {
this.optionsBuilder.applyEntityTuplizer( entityMode, tuplizerClass );
return this;
}
@Override
public SessionFactoryBuilder applyTempTableDdlTransactionHandling(TempTableDdlTransactionHandling handling) {
this.optionsBuilder.applyTempTableDdlTransactionHandling( handling );

View File

@ -55,7 +55,6 @@ import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.jpa.spi.JpaCompliance;
import org.hibernate.jpa.spi.MutableJpaCompliance;
import org.hibernate.loader.BatchFetchStyle;
import org.hibernate.metamodel.RepresentationMode;
import org.hibernate.proxy.EntityNotFoundDelegate;
import org.hibernate.query.ImmutableEntityUpdateQueryHandlingMode;
import org.hibernate.query.sqm.NullPrecedence;
@ -71,8 +70,6 @@ import org.hibernate.resource.jdbc.spi.StatementInspector;
import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder;
import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.hibernate.stat.Statistics;
import org.hibernate.tuple.entity.EntityTuplizer;
import org.hibernate.tuple.entity.EntityTuplizerFactory;
import org.hibernate.type.FormatMapper;
import org.hibernate.type.JacksonJsonFormatMapper;
import org.hibernate.type.JsonBJsonFormatMapper;
@ -186,7 +183,6 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
private final List<EntityNameResolver> entityNameResolvers = new ArrayList<>();
private EntityNotFoundDelegate entityNotFoundDelegate;
private boolean identifierRollbackEnabled;
private EntityTuplizerFactory entityTuplizerFactory = new EntityTuplizerFactory();
private boolean checkNullability;
private boolean initializeLazyStateOutsideTransactions;
private TempTableDdlTransactionHandling tempTableDdlTransactionHandling;
@ -941,11 +937,6 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
return identifierRollbackEnabled;
}
@Override
public EntityTuplizerFactory getEntityTuplizerFactory() {
return entityTuplizerFactory;
}
@Override
public boolean isCheckNullability() {
return checkNullability;
@ -1287,14 +1278,6 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
this.initializeLazyStateOutsideTransactions = enabled;
}
public void applyEntityTuplizerFactory(EntityTuplizerFactory entityTuplizerFactory) {
this.entityTuplizerFactory = entityTuplizerFactory;
}
public void applyEntityTuplizer(RepresentationMode entityMode, Class<? extends EntityTuplizer> tuplizerClass) {
this.entityTuplizerFactory.registerDefaultTuplizerClass( entityMode, tuplizerClass );
}
public void applyTempTableDdlTransactionHandling(TempTableDdlTransactionHandling handling) {
this.tempTableDdlTransactionHandling = handling;
}

View File

@ -18,14 +18,11 @@ import org.hibernate.boot.TempTableDdlTransactionHandling;
import org.hibernate.cache.spi.TimestampsCacheFactory;
import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
import org.hibernate.loader.BatchFetchStyle;
import org.hibernate.metamodel.RepresentationMode;
import org.hibernate.proxy.EntityNotFoundDelegate;
import org.hibernate.query.sqm.NullPrecedence;
import org.hibernate.query.sqm.function.SqmFunctionDescriptor;
import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode;
import org.hibernate.resource.jdbc.spi.StatementInspector;
import org.hibernate.tuple.entity.EntityTuplizer;
import org.hibernate.tuple.entity.EntityTuplizerFactory;
/**
* Convenience base class for custom implementors of SessionFactoryBuilder, using delegation
@ -150,20 +147,6 @@ public abstract class AbstractDelegatingSessionFactoryBuilder<T extends SessionF
return getThis();
}
@Override
public T applyEntityTuplizerFactory(EntityTuplizerFactory entityTuplizerFactory) {
delegate.applyEntityTuplizerFactory( entityTuplizerFactory );
return getThis();
}
@Override
public T applyEntityTuplizer(
RepresentationMode entityMode,
Class<? extends EntityTuplizer> tuplizerClass) {
delegate.applyEntityTuplizer( entityMode, tuplizerClass );
return getThis();
}
@Override
public T applyTempTableDdlTransactionHandling(TempTableDdlTransactionHandling handling) {
delegate.applyTempTableDdlTransactionHandling( handling );

View File

@ -36,7 +36,6 @@ import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
import org.hibernate.query.sqm.sql.SqmTranslatorFactory;
import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode;
import org.hibernate.resource.jdbc.spi.StatementInspector;
import org.hibernate.tuple.entity.EntityTuplizerFactory;
import org.hibernate.type.FormatMapper;
/**
@ -154,11 +153,6 @@ public class AbstractDelegatingSessionFactoryOptions implements SessionFactoryOp
return delegate.isIdentifierRollbackEnabled();
}
@Override
public EntityTuplizerFactory getEntityTuplizerFactory() {
return delegate.getEntityTuplizerFactory();
}
@Override
public boolean isCheckNullability() {
return delegate.isCheckNullability();

View File

@ -32,7 +32,6 @@ import org.hibernate.query.spi.QueryEngineOptions;
import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode;
import org.hibernate.resource.jdbc.spi.StatementInspector;
import org.hibernate.stat.Statistics;
import org.hibernate.tuple.entity.EntityTuplizerFactory;
import org.hibernate.type.FormatMapper;
/**
@ -145,8 +144,6 @@ public interface SessionFactoryOptions extends QueryEngineOptions {
boolean isIdentifierRollbackEnabled();
EntityTuplizerFactory getEntityTuplizerFactory();
boolean isCheckNullability();
boolean isInitializeLazyStateOutsideTransactionsEnabled();

View File

@ -56,7 +56,6 @@ import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.proxy.EntityNotFoundDelegate;
import org.hibernate.query.sqm.function.SqmFunctionDescriptor;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.tuple.entity.EntityTuplizerFactory;
import org.hibernate.type.BasicType;
import org.hibernate.type.SerializationException;
import org.hibernate.usertype.UserType;
@ -111,7 +110,6 @@ public class Configuration {
// used to build SF
private StandardServiceRegistryBuilder standardServiceRegistryBuilder;
private EntityNotFoundDelegate entityNotFoundDelegate;
private EntityTuplizerFactory entityTuplizerFactory;
private Interceptor interceptor;
private SessionFactoryObserver sessionFactoryObserver;
private CurrentTenantIdentifierResolver currentTenantIdentifierResolver;
@ -162,7 +160,6 @@ public class Configuration {
namedProcedureCallMap = new HashMap<>();
standardServiceRegistryBuilder = new StandardServiceRegistryBuilder( bootstrapServiceRegistry );
entityTuplizerFactory = new EntityTuplizerFactory();
interceptor = EmptyInterceptor.INSTANCE;
properties = new Properties( );
properties.putAll( standardServiceRegistryBuilder.getSettings() );
@ -572,10 +569,6 @@ public class Configuration {
return this;
}
public EntityTuplizerFactory getEntityTuplizerFactory() {
return entityTuplizerFactory;
}
/**
* Retrieve the user-supplied delegate to handle non-existent entity
* scenarios. May be null.
@ -687,10 +680,6 @@ public class Configuration {
sessionFactoryBuilder.applyEntityNotFoundDelegate( getEntityNotFoundDelegate() );
}
if ( getEntityTuplizerFactory() != null ) {
sessionFactoryBuilder.applyEntityTuplizerFactory( getEntityTuplizerFactory() );
}
if ( getCurrentTenantIdentifierResolver() != null ) {
sessionFactoryBuilder.applyCurrentTenantIdentifierResolver( getCurrentTenantIdentifierResolver() );
}

View File

@ -47,7 +47,6 @@ import org.hibernate.sql.ast.spi.SqlAliasStemHelper;
import org.hibernate.sql.ast.tree.from.RootTableGroupProducer;
import org.hibernate.sql.ast.tree.from.TableGroup;
import org.hibernate.tuple.entity.EntityMetamodel;
import org.hibernate.tuple.entity.EntityTuplizer;
import org.hibernate.type.BasicType;
import org.hibernate.type.Type;
import org.hibernate.type.descriptor.java.VersionJavaType;
@ -920,16 +919,6 @@ public interface EntityPersister
return this;
}
/**
* Throws {@link UnsupportedOperationException}.
*
* @deprecated Use {@link #getRepresentationStrategy()}
*/
@Deprecated(since = "6.0") @Remove
default EntityTuplizer getEntityTuplizer() {
throw new UnsupportedOperationException("Support for EntityTuplizer has been removed");
}
BytecodeEnhancementMetadata getInstrumentationMetadata();
default BytecodeEnhancementMetadata getBytecodeEnhancementMetadata() {

View File

@ -20,10 +20,9 @@ import org.hibernate.mapping.Subclass;
import org.hibernate.property.access.spi.Getter;
import org.hibernate.property.access.spi.Setter;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.tuple.entity.PojoEntityTuplizer;
/**
* Most of this code was originally an internal detail of {@link PojoEntityTuplizer},
* Most of this code was originally an internal detail of {@code PojoEntityTuplizer},
* then extracted to make it easier for integrators to initialize a custom
* {@link org.hibernate.proxy.ProxyFactory}.
*/

View File

@ -1,235 +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.tuple.entity;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.bytecode.spi.BytecodeEnhancementMetadata;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
import org.hibernate.metamodel.mapping.EntityIdentifierMapping;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.property.access.spi.Getter;
import org.hibernate.property.access.spi.Setter;
import org.hibernate.proxy.ProxyFactory;
import org.hibernate.type.ComponentType;
/**
* Support for tuplizers relating to entities.
*
* @author Steve Ebersole
* @author Gavin King
*
* @deprecated like its supertypes
*/
@Deprecated(since = "6.0")
public abstract class AbstractEntityTuplizer implements EntityTuplizer {
private final EntityMetamodel entityMetamodel;
protected final Getter[] getters;
protected final Setter[] setters;
protected final int propertySpan;
protected final boolean hasCustomAccessors;
private EntityPersister entityDescriptor;
private EntityIdentifierMapping identifierMapping;
/**
* Build an appropriate Getter for the given property.
*
* @param mappedProperty The property to be accessed via the built Getter.
* @param mappedEntity The entity information regarding the mapped entity owning this property.
*
* @return An appropriate Getter instance.
*/
protected abstract Getter buildPropertyGetter(Property mappedProperty, PersistentClass mappedEntity);
/**
* Build an appropriate Setter for the given property.
*
* @param mappedProperty The property to be accessed via the built Setter.
* @param mappedEntity The entity information regarding the mapped entity owning this property.
*
* @return An appropriate Setter instance.
*/
protected abstract Setter buildPropertySetter(Property mappedProperty, PersistentClass mappedEntity);
/**
* Build an appropriate ProxyFactory for the given mapped entity.
*
* @param mappingInfo The mapping information regarding the mapped entity.
* @param idGetter The constructed Getter relating to the entity's id property.
* @param idSetter The constructed Setter relating to the entity's id property.
*
* @return An appropriate ProxyFactory instance.
*/
protected abstract ProxyFactory buildProxyFactory(PersistentClass mappingInfo, Getter idGetter, Setter idSetter);
/**
* Constructs a new AbstractEntityTuplizer instance.
*
* @param entityMetamodel The "interpreted" information relating to the mapped entity.
* @param mappingInfo The parsed "raw" mapping data relating to the given entity.
*/
public AbstractEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappingInfo) {
this.entityMetamodel = entityMetamodel;
propertySpan = entityMetamodel.getPropertySpan();
getters = new Getter[propertySpan];
setters = new Setter[propertySpan];
final Iterator<Property> itr = mappingInfo.getPropertyClosureIterator();
boolean foundCustomAccessor = false;
int i = 0;
while ( itr.hasNext() ) {
//TODO: redesign how PropertyAccessors are acquired...
Property property = itr.next();
getters[i] = buildPropertyGetter( property, mappingInfo );
setters[i] = buildPropertySetter( property, mappingInfo );
if ( !property.isBasicPropertyAccessor() ) {
foundCustomAccessor = true;
}
i++;
}
hasCustomAccessors = foundCustomAccessor;
}
/**
* Retrieves the defined entity-name for the tuplized entity.
*
* @return The entity-name.
*/
protected String getEntityName() {
return entityMetamodel.getName();
}
/**
* Retrieves the defined entity-names for any subclasses defined for this
* entity.
*
* @return Any subclass entity-names.
*/
protected Set<String> getSubclassEntityNames() {
return entityMetamodel.getSubclassEntityNames();
}
@Override
public Object getIdentifier(Object entity, SharedSessionContractImplementor session) {
final EntityIdentifierMapping identifierMapping = resolveIdentifierDescriptor();
return identifierMapping.getIdentifier( entity, session );
}
protected EntityIdentifierMapping resolveIdentifierDescriptor() {
if ( identifierMapping == null ) {
identifierMapping = resolveEntityDescriptor().getIdentifierMapping();
}
return identifierMapping;
}
private EntityPersister resolveEntityDescriptor() {
if ( entityDescriptor == null ) {
entityDescriptor = getFactory()
.getRuntimeMetamodels()
.getMappingMetamodel()
.findEntityDescriptor( getEntityName() );
}
return entityDescriptor;
}
protected boolean shouldGetAllProperties(Object entity) {
final BytecodeEnhancementMetadata bytecodeEnhancementMetadata = getEntityMetamodel().getBytecodeEnhancementMetadata();
if ( !bytecodeEnhancementMetadata.isEnhancedForLazyLoading() ) {
return true;
}
return !bytecodeEnhancementMetadata.hasUnFetchedAttributes( entity );
}
@Override
public Object[] getPropertyValuesToInsert(Object entity, Map mergeMap, SharedSessionContractImplementor session) {
final EntityPersister entityDescriptor = resolveEntityDescriptor();
return entityDescriptor.getPropertyValuesToInsert( entity, mergeMap, session );
}
@Override
public Object getPropertyValue(Object entity, int i) throws HibernateException {
final EntityPersister entityDescriptor = resolveEntityDescriptor();
return entityDescriptor.getPropertyValue( entity, i );
}
/**
* Extract a component property value.
*
* @param type The component property types.
* @param component The component instance itself.
* @param propertyPath The property path for the property to be extracted.
*
* @return The property value extracted.
*/
protected Object getComponentValue(ComponentType type, Object component, String propertyPath) {
final int loc = propertyPath.indexOf( '.' );
final String basePropertyName = loc > 0
? propertyPath.substring( 0, loc )
: propertyPath;
final int index = findSubPropertyIndex( type, basePropertyName );
final Object baseValue = type.getPropertyValue( component, index );
if ( loc > 0 ) {
if ( baseValue == null ) {
return null;
}
return getComponentValue(
(ComponentType) type.getSubtypes()[index],
baseValue,
propertyPath.substring( loc + 1 )
);
}
else {
return baseValue;
}
}
private int findSubPropertyIndex(ComponentType type, String subPropertyName) {
final String[] propertyNames = type.getPropertyNames();
for ( int index = 0; index < propertyNames.length; index++ ) {
if ( subPropertyName.equals( propertyNames[index] ) ) {
return index;
}
}
throw new MappingException( "component property not found: " + subPropertyName );
}
protected final EntityMetamodel getEntityMetamodel() {
return entityMetamodel;
}
protected final SessionFactoryImplementor getFactory() {
return entityMetamodel.getSessionFactory();
}
@Override
public String toString() {
return getClass().getName() + '(' + getEntityMetamodel().getName() + ')';
}
@Override
public Getter getGetter(int i) {
return getters[i];
}
}

View File

@ -1,127 +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.tuple.entity;
import java.util.Map;
import org.hibernate.EntityNameResolver;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
import org.hibernate.property.access.internal.PropertyAccessStrategyMapImpl;
import org.hibernate.property.access.spi.Getter;
import org.hibernate.property.access.spi.PropertyAccess;
import org.hibernate.property.access.spi.Setter;
import org.hibernate.proxy.ProxyFactory;
import org.hibernate.proxy.map.MapProxyFactory;
import org.hibernate.tuple.DynamicMapInstantiator;
/**
* An {@link EntityTuplizer} specific to the dynamic-map entity mode.
*
* @author Steve Ebersole
* @author Gavin King
*
* @deprecated like its supertypes
*/
@Deprecated(since = "6.0")
public class DynamicMapEntityTuplizer extends AbstractEntityTuplizer {
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( DynamicMapEntityTuplizer.class );
DynamicMapEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappedEntity) {
super( entityMetamodel, mappedEntity );
}
private PropertyAccess buildPropertyAccess(Property mappedProperty) {
if ( mappedProperty.isBackRef() ) {
return mappedProperty.getPropertyAccessStrategy( null ).buildPropertyAccess( null, mappedProperty.getName(), true );
}
else {
return PropertyAccessStrategyMapImpl.INSTANCE.buildPropertyAccess( null, mappedProperty.getName(), true );
}
}
@Override
protected Getter buildPropertyGetter(Property mappedProperty, PersistentClass mappedEntity) {
return buildPropertyAccess( mappedProperty ).getGetter();
}
@Override
protected Setter buildPropertySetter(Property mappedProperty, PersistentClass mappedEntity) {
return buildPropertyAccess( mappedProperty ).getSetter();
}
@Override
protected ProxyFactory buildProxyFactory(PersistentClass mappingInfo, Getter idGetter, Setter idSetter) {
ProxyFactory pf = new MapProxyFactory();
try {
//TODO: design new lifecycle for ProxyFactory
pf.postInstantiate(
getEntityName(),
null,
null,
null,
null,
null
);
}
catch (HibernateException he) {
LOG.unableToCreateProxyFactory( getEntityName(), he );
pf = null;
}
return pf;
}
@Override
public Class<?> getMappedClass() {
return Map.class;
}
@Override
public EntityNameResolver[] getEntityNameResolvers() {
return new EntityNameResolver[] {BasicEntityNameResolver.INSTANCE};
}
@Override
public String determineConcreteSubclassEntityName(Object entityInstance, SessionFactoryImplementor factory) {
return extractEmbeddedEntityName( (Map<?,?>) entityInstance );
}
public static String extractEmbeddedEntityName(Map<?,?> entity) {
return (String) entity.get( DynamicMapInstantiator.KEY );
}
public static class BasicEntityNameResolver implements EntityNameResolver {
public static final BasicEntityNameResolver INSTANCE = new BasicEntityNameResolver();
@Override
public String resolveEntityName(Object entity) {
if ( !(entity instanceof Map) ) {
return null;
}
final String entityName = extractEmbeddedEntityName( (Map<?,?>) entity );
if ( entityName == null ) {
throw new HibernateException( "Could not determine type of dynamic map entity" );
}
return entityName;
}
@Override
public boolean equals(Object obj) {
return obj != null && getClass().equals( obj.getClass() );
}
@Override
public int hashCode() {
return getClass().hashCode();
}
}
}

View File

@ -1,90 +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.tuple.entity;
import java.util.Map;
import org.hibernate.EntityNameResolver;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.tuple.Tuplizer;
/**
* Defines further responsibilities regarding tuplization based on
* a mapped entity.
* <p/>
* EntityTuplizer implementations should have the following constructor signatures:
* (org.hibernate.tuple.entity.EntityMetamodel, org.hibernate.mapping.PersistentClass)
* (org.hibernate.tuple.entity.EntityMetamodel, org.hibernate.metamodel.binding.EntityBinding)
*
* @author Gavin King
* @author Steve Ebersole
*
* @deprecated See {@link org.hibernate.metamodel.spi.EntityRepresentationStrategy}
*/
@Deprecated(since = "6.0")
public interface EntityTuplizer extends Tuplizer {
/**
* Extract the identifier value from the given entity.
*
* @param entity The entity from which to extract the identifier value.
* @param session The session from which is requests originates
*
* @return The identifier value.
*
* @deprecated no longer used internally and to be removed.
* Use {@link org.hibernate.metamodel.mapping.EntityIdentifierMapping#getIdentifier}
* instead
*/
@Deprecated(since = "6.0")
Object getIdentifier(Object entity, SharedSessionContractImplementor session);
/**
* Extract the values of the insertable properties of the entity (including backrefs)
*
* @param entity The entity from which to extract.
* @param mergeMap a map of instances being merged to merged instances
* @param session The session in which the result set is being made.
* @return The insertable property values.
* @throws HibernateException Indicates a problem access the properties
*/
Object[] getPropertyValuesToInsert(Object entity, Map mergeMap, SharedSessionContractImplementor session);
/**
* Get any {@link EntityNameResolver}s associated with this {@link Tuplizer}.
*
* @return The associated resolvers. May be null or empty.
*/
EntityNameResolver[] getEntityNameResolvers();
/**
* Given an entity instance, determine the most appropriate (most targeted) entity-name which represents it.
* This is called in situations where we already know an entity name for the given entityInstance; we are being
* asked to determine if there is a more appropriate entity-name to use, specifically within an inheritance
* hierarchy.
* <p/>
* For example, consider a case where a user calls {@code session.update( "Animal", cat );}. Here, the
* user has explicitly provided {@code Animal} as the entity-name. However, they have passed in an instance
* of {@code Cat} which is a subclass of {@code Animal}. In this case, we would return {@code Cat} as the
* entity-name.
* <p/>
* {@code null} may be returned from calls to this method. The meaning of {@code null} in that case is assumed
* to be that we should use whatever explicit entity-name the user provided ({@code Animal} rather than {@code Cat}
* in the example above).
*
* @param entityInstance The entity instance.
* @param factory Reference to the SessionFactory.
*
* @return The most appropriate entity name to use.
*
* @throws HibernateException If we are unable to determine an entity-name within the inheritance hierarchy.
*/
String determineConcreteSubclassEntityName(Object entityInstance, SessionFactoryImplementor factory);
}

View File

@ -1,132 +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.tuple.entity;
import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.hibernate.HibernateException;
import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.metamodel.RepresentationMode;
/**
* A registry allowing users to define the default {@link EntityTuplizer} class to use per {@link RepresentationMode}.
*
* @author Steve Ebersole
*
* @deprecated like its supertypes
*/
@Deprecated(since = "6.0")
public class EntityTuplizerFactory implements Serializable {
public static final Class<?>[] ENTITY_TUP_CTOR_SIG = new Class[] { EntityMetamodel.class, PersistentClass.class };
private final Map<RepresentationMode,Class<? extends EntityTuplizer>> defaultImplClassByMode = buildBaseMapping();
/**
* Method allowing registration of the tuplizer class to use as default for a particular entity-mode.
*
* @param entityMode The entity-mode for which to register the tuplizer class
* @param tuplizerClass The class to use as the default tuplizer for the given entity-mode.
*/
public void registerDefaultTuplizerClass(RepresentationMode entityMode, Class<? extends EntityTuplizer> tuplizerClass) {
assert isEntityTuplizerImplementor( tuplizerClass )
: "Specified tuplizer class [" + tuplizerClass.getName() + "] does not implement " + EntityTuplizer.class.getName();
// TODO: for now we need constructors for both PersistentClass and EntityBinding
assert hasProperConstructor( tuplizerClass, ENTITY_TUP_CTOR_SIG )
: "Specified tuplizer class [" + tuplizerClass.getName() + "] is not properly instantiatable";
defaultImplClassByMode.put( entityMode, tuplizerClass );
}
/**
* Construct an instance of the given tuplizer class.
*
* @param tuplizerClassName The name of the tuplizer class to instantiate
* @param metamodel The metadata for the entity.
* @param persistentClass The mapping info for the entity.
*
* @return The instantiated tuplizer
*
* @throws HibernateException If class name cannot be resolved to a class reference, or if the
* {@link Constructor#newInstance} call fails.
*/
@SuppressWarnings("unchecked")
public EntityTuplizer constructTuplizer(
String tuplizerClassName,
EntityMetamodel metamodel,
PersistentClass persistentClass) {
try {
Class<? extends EntityTuplizer> tuplizerClass = ReflectHelper.classForName( tuplizerClassName );
return constructTuplizer( tuplizerClass, metamodel, persistentClass );
}
catch ( ClassNotFoundException e ) {
throw new HibernateException( "Could not locate specified tuplizer class [" + tuplizerClassName + "]" );
}
}
/**
* Construct an instance of the given tuplizer class.
*
* @param tuplizerClass The tuplizer class to instantiate
* @param metamodel The metadata for the entity.
* @param persistentClass The mapping info for the entity.
*
* @return The instantiated tuplizer
*
* @throws HibernateException if the {@link Constructor#newInstance} call fails.
*/
public EntityTuplizer constructTuplizer(
Class<? extends EntityTuplizer> tuplizerClass,
EntityMetamodel metamodel,
PersistentClass persistentClass) {
Constructor<? extends EntityTuplizer> constructor = getProperConstructor( tuplizerClass, ENTITY_TUP_CTOR_SIG );
assert constructor != null : "Unable to locate proper constructor for tuplizer [" + tuplizerClass.getName() + "]";
try {
return constructor.newInstance( metamodel, persistentClass );
}
catch ( Throwable t ) {
throw new HibernateException( "Unable to instantiate default tuplizer [" + tuplizerClass.getName() + "]", t );
}
}
private boolean isEntityTuplizerImplementor(Class<?> tuplizerClass) {
return ReflectHelper.implementsInterface( tuplizerClass, EntityTuplizer.class );
}
private boolean hasProperConstructor(Class<? extends EntityTuplizer> tuplizerClass, Class<?>[] constructorArgs) {
return getProperConstructor( tuplizerClass, constructorArgs ) != null
&& ! ReflectHelper.isAbstractClass( tuplizerClass );
}
private Constructor<? extends EntityTuplizer> getProperConstructor(
Class<? extends EntityTuplizer> clazz,
Class<?>[] constructorArgs) {
Constructor<? extends EntityTuplizer> constructor = null;
try {
constructor = clazz.getDeclaredConstructor( constructorArgs );
try {
ReflectHelper.ensureAccessibility( constructor );
}
catch ( SecurityException e ) {
constructor = null;
}
}
catch ( NoSuchMethodException ignore ) {
}
return constructor;
}
private static Map<RepresentationMode,Class<? extends EntityTuplizer>> buildBaseMapping() {
Map<RepresentationMode,Class<? extends EntityTuplizer>> map = new ConcurrentHashMap<>();
map.put( RepresentationMode.POJO, PojoEntityTuplizer.class );
map.put( RepresentationMode.MAP, DynamicMapEntityTuplizer.class );
return map;
}
}

View File

@ -1,180 +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.tuple.entity;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.Set;
import org.hibernate.EntityNameResolver;
import org.hibernate.HibernateException;
import org.hibernate.bytecode.spi.BytecodeProvider;
import org.hibernate.bytecode.spi.ProxyFactoryFactory;
import org.hibernate.bytecode.spi.ReflectionOptimizer;
import org.hibernate.cfg.Environment;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
import org.hibernate.property.access.spi.Getter;
import org.hibernate.property.access.spi.Setter;
import org.hibernate.proxy.ProxyFactory;
import org.hibernate.proxy.pojo.ProxyFactoryHelper;
import org.hibernate.type.CompositeType;
/**
* An {@link EntityTuplizer} specific to the pojo entity mode.
*
* @author Steve Ebersole
* @author Gavin King
*
* @deprecated like its supertypes
*/
@Deprecated(since = "6.0")
public class PojoEntityTuplizer extends AbstractEntityTuplizer {
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( PojoEntityTuplizer.class );
private final Class<?> mappedClass;
private final Class<?> proxyInterface;
private final ReflectionOptimizer optimizer;
public PojoEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappedEntity) {
super( entityMetamodel, mappedEntity );
this.mappedClass = mappedEntity.getMappedClass();
this.proxyInterface = mappedEntity.getProxyInterface();
String[] getterNames = new String[propertySpan];
String[] setterNames = new String[propertySpan];
Class<?>[] propTypes = new Class[propertySpan];
for ( int i = 0; i < propertySpan; i++ ) {
getterNames[i] = getters[i].getMethodName();
setterNames[i] = setters[i].getMethodName();
propTypes[i] = getters[i].getReturnTypeClass();
}
if ( hasCustomAccessors || !Environment.useReflectionOptimizer() ) {
optimizer = null;
}
else {
final BytecodeProvider bytecodeProvider = entityMetamodel.getSessionFactory().getServiceRegistry().getService( BytecodeProvider.class );
optimizer = bytecodeProvider.getReflectionOptimizer(
mappedClass,
getterNames,
setterNames,
propTypes
);
}
}
@Override
protected ProxyFactory buildProxyFactory(PersistentClass persistentClass, Getter idGetter, Setter idSetter) {
// determine the id getter and setter methods from the proxy interface (if any)
// determine all interfaces needed by the resulting proxy
final String entityName = getEntityName();
final Class<?> mappedClass = persistentClass.getMappedClass();
final Class<?> proxyInterface = persistentClass.getProxyInterface();
final Set<Class<?>> proxyInterfaces = ProxyFactoryHelper.extractProxyInterfaces( persistentClass, entityName );
Method proxyGetIdentifierMethod = ProxyFactoryHelper.extractProxyGetIdentifierMethod( idGetter, proxyInterface );
Method proxySetIdentifierMethod = ProxyFactoryHelper.extractProxySetIdentifierMethod( idSetter, proxyInterface );
ProxyFactory pf = buildProxyFactoryInternal( persistentClass, idGetter, idSetter );
try {
ProxyFactoryHelper.validateGetterSetterMethodProxyability( "Getter", proxyGetIdentifierMethod );
ProxyFactoryHelper.validateGetterSetterMethodProxyability( "Setter", proxySetIdentifierMethod );
ProxyFactoryHelper.validateProxyability( persistentClass );
pf.postInstantiate(
entityName,
mappedClass,
proxyInterfaces,
proxyGetIdentifierMethod,
proxySetIdentifierMethod,
persistentClass.hasEmbeddedIdentifier() ?
(CompositeType) persistentClass.getIdentifier().getType() :
null
);
}
catch (HibernateException he) {
LOG.unableToCreateProxyFactory( entityName, he );
pf = null;
}
return pf;
}
protected ProxyFactory buildProxyFactoryInternal(
PersistentClass persistentClass,
Getter idGetter,
Setter idSetter) {
ProxyFactoryFactory proxyFactory = getFactory().getServiceRegistry().getService( ProxyFactoryFactory.class );
return proxyFactory.buildProxyFactory( getFactory() );
}
@Override
public Object[] getPropertyValuesToInsert(Object entity, Map mergeMap, SharedSessionContractImplementor session) {
if ( shouldGetAllProperties( entity ) && optimizer != null && optimizer.getAccessOptimizer() != null ) {
return getPropertyValuesWithOptimizer( entity );
}
else {
return super.getPropertyValuesToInsert( entity, mergeMap, session );
}
}
protected Object[] getPropertyValuesWithOptimizer(Object object) {
return optimizer.getAccessOptimizer().getPropertyValues( object );
}
@Override
public Class<?> getMappedClass() {
return mappedClass;
}
@Override
protected Getter buildPropertyGetter(Property mappedProperty, PersistentClass mappedEntity) {
return mappedProperty.getGetter( mappedEntity.getMappedClass() );
}
@Override
protected Setter buildPropertySetter(Property mappedProperty, PersistentClass mappedEntity) {
return mappedProperty.getSetter( mappedEntity.getMappedClass() );
}
//TODO: need to make the majority of this functionality into a top-level support class for custom impl support
@Override
public String determineConcreteSubclassEntityName(Object entityInstance, SessionFactoryImplementor factory) {
if ( entityInstance == null ) {
return getEntityName();
}
final Class<?> concreteEntityClass = entityInstance.getClass();
if ( concreteEntityClass == getMappedClass() ) {
return getEntityName();
}
else {
String entityName = getEntityMetamodel().findEntityNameByEntityClass( concreteEntityClass );
if ( entityName == null ) {
throw new HibernateException(
"Unable to resolve entity name from Class [" + concreteEntityClass.getName() + "]"
+ " expected instance/subclass of [" + getEntityName() + "]"
);
}
return entityName;
}
}
@Override
public EntityNameResolver[] getEntityNameResolvers() {
// the fallback is to check class name which is exactly what we'd do here
return null;
}
}

View File

@ -9,9 +9,6 @@ package org.hibernate.orm.test.boot.jaxb.hbm.internal;
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmHibernateMapping;
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmRootEntityType;
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmSimpleIdType;
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmTuplizerType;
import org.hibernate.metamodel.RepresentationMode;
import org.hibernate.tuple.entity.DynamicMapEntityTuplizer;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.junit.Test;
@ -23,24 +20,13 @@ public class RepresentationModeConverterTest extends BaseUnitTestCase {
@Test
public void testMashallNullEntityMode() throws Exception {
XmlBindingChecker.checkValidGeneration( generateXml( false ) );
XmlBindingChecker.checkValidGeneration( generateXml() );
}
@Test
public void testMashallNotNullEntityMode() throws Exception {
XmlBindingChecker.checkValidGeneration( generateXml( true ) );
}
private JaxbHbmHibernateMapping generateXml(boolean includeEntityMode)
throws Exception {
private JaxbHbmHibernateMapping generateXml() {
JaxbHbmHibernateMapping hm = new JaxbHbmHibernateMapping();
JaxbHbmRootEntityType clazz = new JaxbHbmRootEntityType();
JaxbHbmTuplizerType tuplizer = new JaxbHbmTuplizerType();
tuplizer.setClazz( DynamicMapEntityTuplizer.class.getCanonicalName() );
if ( includeEntityMode ) {
tuplizer.setEntityMode( RepresentationMode.MAP );
}
clazz.getTuplizer().add( tuplizer );
JaxbHbmSimpleIdType id = new JaxbHbmSimpleIdType();
clazz.setId( id );
hm.getClazz().add( clazz );

View File

@ -75,7 +75,6 @@ import org.hibernate.sql.results.graph.DomainResult;
import org.hibernate.sql.results.graph.DomainResultCreationState;
import org.hibernate.tuple.entity.BytecodeEnhancementMetadataNonPojoImpl;
import org.hibernate.tuple.entity.EntityMetamodel;
import org.hibernate.tuple.entity.EntityTuplizer;
import org.hibernate.type.BasicType;
import org.hibernate.type.CollectionType;
import org.hibernate.type.Type;

View File

@ -31,7 +31,6 @@ import org.hibernate.engine.spi.EntityEntryFactory;
import org.hibernate.engine.spi.LoadQueryInfluencers;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.engine.spi.ValueInclusion;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.internal.FilterAliasGenerator;
import org.hibernate.jpa.boot.spi.Bootstrap;
@ -69,7 +68,6 @@ import org.hibernate.sql.results.graph.DomainResult;
import org.hibernate.sql.results.graph.DomainResultCreationState;
import org.hibernate.tuple.entity.BytecodeEnhancementMetadataNonPojoImpl;
import org.hibernate.tuple.entity.EntityMetamodel;
import org.hibernate.tuple.entity.EntityTuplizer;
import org.hibernate.type.BasicType;
import org.hibernate.type.Type;
import org.hibernate.type.descriptor.java.JavaType;
@ -86,7 +84,6 @@ import jakarta.persistence.PersistenceException;
*/
public class PersisterClassProviderTest {
@Test
@SuppressWarnings("unchecked")
public void testPersisterClassProvider() {
Map settings = SettingsGenerator.generateSettings(
PersisterClassResolverInitiator.IMPL_NAME, GoofyPersisterClassProvider.class,

View File

@ -35,7 +35,6 @@ import org.hibernate.engine.spi.EntityEntryFactory;
import org.hibernate.engine.spi.LoadQueryInfluencers;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.engine.spi.ValueInclusion;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.id.UUIDHexGenerator;
import org.hibernate.internal.FilterAliasGenerator;
@ -69,7 +68,6 @@ import org.hibernate.sql.results.graph.DomainResult;
import org.hibernate.sql.results.graph.DomainResultCreationState;
import org.hibernate.tuple.entity.BytecodeEnhancementMetadataNonPojoImpl;
import org.hibernate.tuple.entity.EntityMetamodel;
import org.hibernate.tuple.entity.EntityTuplizer;
import org.hibernate.type.BasicType;
import org.hibernate.type.Type;
import org.hibernate.type.descriptor.java.JavaType;

View File

@ -12,8 +12,8 @@ import org.hibernate.type.EnumType;
/**
* The place to list all "static" types we know of that need to be possible to
* construct at runtime via reflection.
* This is useful for GraalVM native images - but is not intenteded to be an
* exhaustive list: take these as an helpful starting point.
* This is useful for GraalVM native images - but is not intended to be an
* exhaustive list: take these as a helpful starting point.
*/
final class StaticClassLists {
@ -22,13 +22,11 @@ final class StaticClassLists {
//The CoreMessageLogger is sometimes looked up without it necessarily being a field, so we're
//not processing it the same way as other Logger lookups.
org.hibernate.internal.CoreMessageLogger_$logger.class,
org.hibernate.tuple.entity.DynamicMapEntityTuplizer.class,
org.hibernate.persister.collection.OneToManyPersister.class,
org.hibernate.persister.collection.BasicCollectionPersister.class,
org.hibernate.persister.entity.JoinedSubclassEntityPersister.class,
org.hibernate.persister.entity.UnionSubclassEntityPersister.class,
org.hibernate.persister.entity.SingleTableEntityPersister.class,
org.hibernate.tuple.entity.PojoEntityTuplizer.class,
};
}