Clean up various legacy "read path" contracts

- clean-up unused Type methods
    * Type#nullSafeGet
    * Type#hydrate
    * Type#resolve
    * Type#getSemiResolvedType
    * Type#semiResolve
    * related
- start removing usage of Tuplizer
- start removing usage of legacy Tuplizer-based Instantiator
This commit is contained in:
Steve Ebersole 2021-10-20 15:48:36 -05:00
parent cf36d17fac
commit 62f761732d
24 changed files with 323 additions and 783 deletions

View File

@ -7,11 +7,14 @@
package org.hibernate.engine.internal;
import java.lang.reflect.Constructor;
import java.util.function.Supplier;
import org.hibernate.InstantiationException;
import org.hibernate.MappingException;
import org.hibernate.engine.spi.IdentifierValue;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.VersionValue;
import org.hibernate.mapping.KeyValue;
import org.hibernate.property.access.spi.Getter;
import org.hibernate.type.BasicType;
import org.hibernate.type.Type;
@ -27,51 +30,28 @@ import org.hibernate.type.descriptor.java.spi.PrimitiveJavaType;
public class UnsavedValueFactory {
/**
* Instantiate a class using the provided Constructor
*
* @param constructor The constructor
*
* @return The instantiated object
*
* @throws InstantiationException if something went wrong
*/
private static Object instantiate(Constructor constructor) {
try {
return constructor.newInstance();
}
catch (Exception e) {
throw new InstantiationException( "could not instantiate test object", constructor.getDeclaringClass(), e );
}
}
/**
* Return an IdentifierValue for the specified unsaved-value. If none is specified,
* guess the unsaved value by instantiating a test instance of the class and
* reading it's id property, or if that is not possible, using the java default
* value for the type
*
* @param unsavedValue The mapping defined unsaved value
* @param identifierGetter The getter for the entity identifier attribute
* @param identifierType The mapping type for the identifier
* @param constructor The constructor for the entity
*
* @return The appropriate IdentifierValue
* Return the UnsavedValueStrategy for determining whether an entity instance is
* unsaved based on the identifier. If an explicit strategy is not specified, determine
* the unsaved value by instantiating an instance of the entity and reading the value of
* its id property, or if that is not possible, using the java default value for the type
*/
public static IdentifierValue getUnsavedIdentifierValue(
String unsavedValue,
Getter identifierGetter,
Type identifierType,
Constructor constructor) {
KeyValue bootIdMapping,
JavaType<?> idJtd,
Getter getter,
Supplier<?> templateInstanceAccess,
SessionFactoryImplementor sessionFactory) {
final String unsavedValue = bootIdMapping.getNullValue();
if ( unsavedValue == null ) {
if ( identifierGetter != null && constructor != null ) {
if ( getter != null && templateInstanceAccess != null ) {
// use the id value of a newly instantiated instance as the unsaved-value
final Object defaultValue = identifierGetter.get( instantiate( constructor ) );
final Object templateInstance = templateInstanceAccess.get();
final Object defaultValue = getter.get( templateInstance );
return new IdentifierValue( defaultValue );
}
final JavaType<?> jtd;
if ( identifierGetter != null && ( identifierType instanceof BasicType<?> ) && ( jtd = ( (BasicType<?>) identifierType ).getJavaTypeDescriptor() ) instanceof PrimitiveJavaType ) {
final Object defaultValue = ( (PrimitiveJavaType<?>) jtd ).getDefaultValue();
return new IdentifierValue( defaultValue );
else if ( idJtd instanceof PrimitiveJavaType ) {
return new IdentifierValue( ( (PrimitiveJavaType<?>) idJtd ).getDefaultValue() );
}
else {
return IdentifierValue.NULL;
@ -90,16 +70,71 @@ public class UnsavedValueFactory {
return IdentifierValue.ANY;
}
else {
try {
return new IdentifierValue( ( (BasicType<?>) identifierType ).getJavaTypeDescriptor().fromString( unsavedValue ) );
return new IdentifierValue( idJtd.fromString( unsavedValue ) );
}
}
/**
* Return the UnsavedValueStrategy for determining whether an entity instance is
* unsaved based on the version. If an explicit strategy is not specified, determine the
* unsaved value by instantiating an instance of the entity and reading the value of its
* version property, or if that is not possible, using the java default value for the type
*/
public static VersionValue getUnsavedVersionValue(
KeyValue bootVersionMapping,
VersionJavaType jtd,
Getter getter,
Supplier<?> templateInstanceAccess,
SessionFactoryImplementor sessionFactory) {
final String unsavedValue = bootVersionMapping.getNullValue();
if ( unsavedValue == null ) {
if ( getter != null && templateInstanceAccess != null ) {
final Object templateInstance = templateInstanceAccess.get();
final Object defaultValue = getter.get( templateInstance );
// if the version of a newly instantiated object is not the same
// as the version seed value, use that as the unsaved-value
final Object seedValue = jtd.seed( null );
return jtd.areEqual( seedValue, defaultValue )
? VersionValue.UNDEFINED
: new VersionValue( defaultValue );
}
catch ( ClassCastException cce ) {
throw new MappingException( "Bad identifier type: " + identifierType.getName() );
}
catch ( Exception e ) {
throw new MappingException( "Could not parse identifier unsaved-value: " + unsavedValue );
else {
return VersionValue.UNDEFINED;
}
}
else if ( "undefined".equals( unsavedValue ) ) {
return VersionValue.UNDEFINED;
}
else if ( "null".equals( unsavedValue ) ) {
return VersionValue.NULL;
}
else if ( "negative".equals( unsavedValue ) ) {
return VersionValue.NEGATIVE;
}
else {
// this should not happen since the DTD prevents it
throw new MappingException( "Could not parse version unsaved-value: " + unsavedValue );
}
}
/**
* Instantiate a class using the provided Constructor
*
* @param constructor The constructor
*
* @return The instantiated object
*
* @throws InstantiationException if something went wrong
*/
private static Object instantiate(Constructor constructor) {
try {
return constructor.newInstance();
}
catch (Exception e) {
throw new InstantiationException( "could not instantiate test object", constructor.getDeclaringClass(), e );
}
}
/**

View File

@ -0,0 +1,40 @@
/*
* 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;
import java.util.function.Supplier;
/**
* A lazily accessible object reference. Useful for cases where final references
* are needed (anon inner class, lambdas, etc).
*
* @param <T> The type of object referenced
*/
public class LazyValue<T> {
public static final Object NULL = new Object();
private final Supplier<T> supplier;
private Object value;
public LazyValue(Supplier<T> supplier) {
this.supplier = supplier;
}
public Object getValue() {
if ( value == null ) {
final T obtainedValue = supplier.get();
if ( obtainedValue == null ) {
value = NULL;
}
else {
value = obtainedValue;
}
}
return value == NULL ? null : value;
}
}

View File

@ -61,6 +61,11 @@ public class EntityInstantiatorPojoStandard extends AbstractEntityInstantiatorPo
return null;
}
@Override
public boolean canBeInstantiated() {
return constructor != null;
}
@Override
protected Object applyInterception(Object entity) {
if ( !applyBytecodeInterception ) {

View File

@ -9,6 +9,7 @@ package org.hibernate.metamodel.mapping;
import java.util.List;
import org.hibernate.engine.spi.IdentifierValue;
import org.hibernate.mapping.IndexedConsumer;
/**
@ -33,4 +34,9 @@ public interface CompositeIdentifierMapping extends EntityIdentifierMapping {
consumer.accept( i, attributes.get( i ) );
}
}
@Override
default IdentifierValue getUnsavedStrategy() {
return IdentifierValue.UNDEFINED;
}
}

View File

@ -6,20 +6,30 @@
*/
package org.hibernate.metamodel.mapping;
import org.hibernate.engine.spi.IdentifierValue;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
/**
* @author Steve Ebersole
* Describes the mapping of an entity's identifier.
*
* @see jakarta.persistence.Id
* @see jakarta.persistence.EmbeddedId
*/
public interface EntityIdentifierMapping extends ValueMapping, ModelPart {
String ROLE_LOCAL_NAME = "{id}";
Object getIdentifier(Object entity, SharedSessionContractImplementor session);
void setIdentifier(Object entity, Object id, SharedSessionContractImplementor session);
Object instantiate();
@Override
default String getPartName() {
return ROLE_LOCAL_NAME;
}
/**
* The strategy for distinguishing between detached and transient
* state based on the identifier mapping
*/
IdentifierValue getUnsavedStrategy();
Object getIdentifier(Object entity, SharedSessionContractImplementor session);
void setIdentifier(Object entity, Object id, SharedSessionContractImplementor session);
Object instantiate();
}

View File

@ -6,11 +6,23 @@
*/
package org.hibernate.metamodel.mapping;
import org.hibernate.engine.spi.VersionValue;
import org.hibernate.metamodel.mapping.internal.BasicAttributeMapping;
/**
* @author Steve Ebersole
* Describes the mapping of an entity's version
*
* @see jakarta.persistence.Version
*/
public interface EntityVersionMapping extends BasicValuedModelPart {
/**
* The attribute marked as the version
*/
BasicAttributeMapping getVersionAttribute();
/**
* The strategy for distinguishing between detached and transient
* state based on the version mapping
*/
VersionValue getUnsavedStrategy();
}

View File

@ -7,20 +7,23 @@
package org.hibernate.metamodel.mapping.internal;
import java.util.Locale;
import java.util.function.Supplier;
import org.hibernate.engine.FetchStyle;
import org.hibernate.engine.FetchTiming;
import org.hibernate.engine.internal.UnsavedValueFactory;
import org.hibernate.engine.spi.IdentifierValue;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.mapping.IndexedConsumer;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.metamodel.mapping.BasicEntityIdentifierMapping;
import org.hibernate.metamodel.mapping.BasicValuedMapping;
import org.hibernate.metamodel.mapping.SelectableConsumer;
import org.hibernate.metamodel.mapping.EntityIdentifierMapping;
import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.metamodel.mapping.JdbcMapping;
import org.hibernate.metamodel.mapping.MappingType;
import org.hibernate.metamodel.mapping.SelectableConsumer;
import org.hibernate.metamodel.model.domain.NavigableRole;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.property.access.spi.PropertyAccess;
@ -51,6 +54,8 @@ public class BasicEntityIdentifierMappingImpl implements BasicEntityIdentifierMa
private final NavigableRole idRole;
private final String attributeName;
private final IdentifierValue unsavedStrategy;
private final PropertyAccess propertyAccess;
private final EntityPersister entityPersister;
@ -63,6 +68,7 @@ public class BasicEntityIdentifierMappingImpl implements BasicEntityIdentifierMa
public BasicEntityIdentifierMappingImpl(
EntityPersister entityPersister,
Supplier<?> instanceCreator,
String attributeName,
String rootTable,
String pkColumnName,
@ -84,6 +90,14 @@ public class BasicEntityIdentifierMappingImpl implements BasicEntityIdentifierMa
idRole = entityPersister.getNavigableRole().append( EntityIdentifierMapping.ROLE_LOCAL_NAME );
sessionFactory = creationProcess.getCreationContext().getSessionFactory();
unsavedStrategy = UnsavedValueFactory.getUnsavedIdentifierValue(
bootEntityDescriptor.getIdentifier(),
getJavaTypeDescriptor(),
propertyAccess.getGetter(),
instanceCreator,
sessionFactory
);
}
@Override
@ -96,6 +110,11 @@ public class BasicEntityIdentifierMappingImpl implements BasicEntityIdentifierMa
return attributeName;
}
@Override
public IdentifierValue getUnsavedStrategy() {
return unsavedStrategy;
}
@Override
public Object getIdentifier(Object entity, SharedSessionContractImplementor session) {
if ( entity instanceof HibernateProxy ) {

View File

@ -7,10 +7,15 @@
package org.hibernate.metamodel.mapping.internal;
import java.util.function.BiConsumer;
import java.util.function.Supplier;
import org.hibernate.engine.FetchStyle;
import org.hibernate.engine.FetchTiming;
import org.hibernate.engine.internal.UnsavedValueFactory;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.engine.spi.VersionValue;
import org.hibernate.mapping.KeyValue;
import org.hibernate.mapping.RootClass;
import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.metamodel.mapping.EntityVersionMapping;
import org.hibernate.metamodel.mapping.JdbcMapping;
@ -32,6 +37,7 @@ import org.hibernate.sql.results.graph.basic.BasicFetch;
import org.hibernate.sql.results.graph.basic.BasicResult;
import org.hibernate.type.BasicType;
import org.hibernate.type.descriptor.java.JavaType;
import org.hibernate.type.descriptor.java.VersionJavaType;
/**
* @author Steve Ebersole
@ -45,12 +51,19 @@ public class EntityVersionMappingImpl implements EntityVersionMapping, FetchOpti
private final BasicType versionBasicType;
private final VersionValue unsavedValueStrategy;
private BasicAttributeMapping attributeMapping;
public EntityVersionMappingImpl(
RootClass bootEntityDescriptor,
Supplier<?> templateInstanceAccess,
String attributeName,
String columnTableExpression,
String columnExpression,
BasicType versionBasicType,
EntityMappingType declaringType) {
EntityMappingType declaringType,
MappingModelCreationProcess creationProcess) {
this.attributeName = attributeName;
this.declaringType = declaringType;
@ -58,6 +71,17 @@ public class EntityVersionMappingImpl implements EntityVersionMapping, FetchOpti
this.columnExpression = columnExpression;
this.versionBasicType = versionBasicType;
unsavedValueStrategy = UnsavedValueFactory.getUnsavedVersionValue(
(KeyValue) bootEntityDescriptor.getVersion().getValue(),
(VersionJavaType) versionBasicType.getJavaTypeDescriptor(),
declaringType
.getRepresentationStrategy()
.resolvePropertyAccess( bootEntityDescriptor.getVersion() )
.getGetter(),
templateInstanceAccess,
creationProcess.getCreationContext().getSessionFactory()
);
}
@Override
@ -65,6 +89,11 @@ public class EntityVersionMappingImpl implements EntityVersionMapping, FetchOpti
return (BasicAttributeMapping) declaringType.findAttributeMapping( attributeName );
}
@Override
public VersionValue getUnsavedStrategy() {
return unsavedValueStrategy;
}
@Override
public String getContainingTableExpression() {
return columnTableExpression;

View File

@ -10,12 +10,17 @@ import org.hibernate.engine.spi.SessionFactoryImplementor;
/**
* Contract for instantiating entity values
*
* @author Steve Ebersole
*/
public interface EntityInstantiator extends Instantiator {
/**
* Create an instance of managed entity
*/
Object instantiate(SessionFactoryImplementor sessionFactory);
/**
* Can this entity be instantiated?
*/
default boolean canBeInstantiated() {
return true;
}
}

View File

@ -108,6 +108,7 @@ import org.hibernate.id.insert.InsertGeneratedIdentifierDelegate;
import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.FilterHelper;
import org.hibernate.internal.util.LazyValue;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.internal.util.collections.CollectionHelper;
@ -183,6 +184,7 @@ import org.hibernate.metamodel.mapping.internal.MappingModelCreationProcess;
import org.hibernate.metamodel.mapping.internal.NonAggregatedIdentifierMappingImpl;
import org.hibernate.metamodel.mapping.internal.SimpleNaturalIdMapping;
import org.hibernate.metamodel.model.domain.NavigableRole;
import org.hibernate.metamodel.spi.EntityInstantiator;
import org.hibernate.metamodel.spi.EntityRepresentationStrategy;
import org.hibernate.metamodel.spi.RuntimeModelCreationContext;
import org.hibernate.persister.collection.CollectionPersister;
@ -240,7 +242,6 @@ import org.hibernate.sql.results.graph.entity.internal.EntityResultImpl;
import org.hibernate.sql.results.internal.SqlSelectionImpl;
import org.hibernate.stat.spi.StatisticsImplementor;
import org.hibernate.tuple.GenerationTiming;
import org.hibernate.tuple.IdentifierProperty;
import org.hibernate.tuple.InDatabaseValueGenerationStrategy;
import org.hibernate.tuple.InMemoryValueGenerationStrategy;
import org.hibernate.tuple.NonIdentifierAttribute;
@ -248,7 +249,6 @@ import org.hibernate.tuple.ValueGeneration;
import org.hibernate.tuple.entity.EntityBasedAssociationAttribute;
import org.hibernate.tuple.entity.EntityMetamodel;
import org.hibernate.tuple.entity.EntityTuplizer;
import org.hibernate.tuple.entity.VersionProperty;
import org.hibernate.type.AnyType;
import org.hibernate.type.AssociationType;
import org.hibernate.type.BasicType;
@ -4627,16 +4627,14 @@ public abstract class AbstractEntityPersister
if ( isVersioned() ) {
// let this take precedence if defined, since it works for
// assigned identifiers
Boolean result = entityMetamodel.getVersionProperty()
.getUnsavedValue().isUnsaved( version );
Boolean result = versionMapping.getUnsavedStrategy().isUnsaved( version );
if ( result != null ) {
return result;
}
}
// check the id unsaved-value
Boolean result = entityMetamodel.getIdentifierProperty()
.getUnsavedValue().isUnsaved( id );
Boolean result = identifierMapping.getUnsavedStrategy().isUnsaved( id );
if ( result != null ) {
return result;
}
@ -5088,22 +5086,24 @@ public abstract class AbstractEntityPersister
Object currentId,
Object currentVersion,
SharedSessionContractImplementor session) {
final IdentifierProperty identifierProperty = entityMetamodel.getIdentifierProperty();
if ( !(identifierProperty.getIdentifierGenerator() instanceof Assigned) ) {
//reset the id
Object result = identifierProperty
.getUnsavedValue()
.getDefaultValue( currentId );
setIdentifier( entity, result, session );
//reset the version
VersionProperty versionProperty = entityMetamodel.getVersionProperty();
if ( entityMetamodel.isVersioned() ) {
setPropertyValue(
entity,
entityMetamodel.getVersionPropertyIndex(),
versionProperty.getUnsavedValue().getDefaultValue( currentVersion )
);
}
if ( entityMetamodel.getIdentifierProperty().getIdentifierGenerator() instanceof Assigned ) {
return;
}
// reset the identifier
setIdentifier(
entity,
identifierMapping.getUnsavedStrategy().getDefaultValue( currentId ),
session
);
// reset the version
if ( versionMapping != null ) {
versionMapping.getVersionAttribute().getPropertyAccess().getSetter().set(
entity,
versionMapping.getUnsavedStrategy().getDefaultValue( currentVersion ),
getFactory()
);
}
}
@ -5579,14 +5579,25 @@ public abstract class AbstractEntityPersister
}
}
private void prepareMappingModel(MappingModelCreationProcess creationProcess, PersistentClass bootEntityDescriptor) {
private void prepareMappingModel(MappingModelCreationProcess creationProcess, PersistentClass bootEntityDescriptor) { final EntityInstantiator instantiator = getRepresentationStrategy().getInstantiator();
final Supplier<?> templateInstanceCreator;
if ( ! instantiator.canBeInstantiated() ) {
templateInstanceCreator = null;
}
else {
final LazyValue<?> templateCreator = new LazyValue<>(
() -> instantiator.instantiate( creationProcess.getCreationContext().getSessionFactory() )
);
templateInstanceCreator = templateCreator::getValue;
}
identifierMapping = creationProcess.processSubPart(
EntityIdentifierMapping.ROLE_LOCAL_NAME,
(role, process) ->
generateIdentifierMapping( process, bootEntityDescriptor )
generateIdentifierMapping( templateInstanceCreator, bootEntityDescriptor, process )
);
versionMapping = generateVersionMapping( creationProcess, bootEntityDescriptor );
versionMapping = generateVersionMapping( templateInstanceCreator, bootEntityDescriptor, creationProcess );
if ( rowIdName == null ) {
rowIdMapping = null;
@ -5735,8 +5746,9 @@ public abstract class AbstractEntityPersister
}
protected EntityVersionMapping generateVersionMapping(
MappingModelCreationProcess creationProcess,
PersistentClass bootEntityDescriptor) {
Supplier<?> templateInstanceCreator,
PersistentClass bootEntityDescriptor,
MappingModelCreationProcess creationProcess) {
if ( getVersionType() == null ) {
return null;
}
@ -5748,6 +5760,7 @@ public abstract class AbstractEntityPersister
versionPropertyName,
(role, creationProcess1) -> generateVersionMapping(
this,
templateInstanceCreator,
bootEntityDescriptor,
creationProcess
)
@ -5836,7 +5849,10 @@ public abstract class AbstractEntityPersister
}
protected EntityIdentifierMapping generateIdentifierMapping(MappingModelCreationProcess creationProcess, PersistentClass bootEntityDescriptor) {
protected EntityIdentifierMapping generateIdentifierMapping(
Supplier<?> templateInstanceCreator,
PersistentClass bootEntityDescriptor,
MappingModelCreationProcess creationProcess) {
final Type idType = getIdentifierType();
if ( idType instanceof CompositeType ) {
@ -5866,6 +5882,7 @@ public abstract class AbstractEntityPersister
return new BasicEntityIdentifierMappingImpl(
this,
templateInstanceCreator,
bootEntityDescriptor.getIdentifierProperty().getName(),
getTableName(),
rootTableKeyColumnNames[0],
@ -5898,25 +5915,25 @@ public abstract class AbstractEntityPersister
*/
protected static EntityVersionMapping generateVersionMapping(
AbstractEntityPersister entityPersister,
Supplier<?> templateInstanceCreator,
PersistentClass bootModelRootEntityDescriptor,
MappingModelCreationProcess creationProcess) {
final BasicValue bootModelVersionValue = (BasicValue) bootModelRootEntityDescriptor.getVersion().getValue();
final Property versionProperty = bootModelRootEntityDescriptor.getVersion();
final BasicValue bootModelVersionValue = (BasicValue) versionProperty.getValue();
final BasicValue.Resolution<?> basicTypeResolution = bootModelVersionValue.resolve();
final Iterator<Selectable> versionColumnIterator = bootModelRootEntityDescriptor.getVersion().getColumnIterator();
assert versionColumnIterator.hasNext();
final Selectable column = bootModelVersionValue.getColumn();
final Dialect dialect = creationProcess.getCreationContext().getSessionFactory().getJdbcServices().getDialect();
final Selectable column = versionColumnIterator.next();
assert !versionColumnIterator.hasNext();
assert !column.isFormula();
return new EntityVersionMappingImpl(
bootModelRootEntityDescriptor.getRootClass(),
templateInstanceCreator,
bootModelRootEntityDescriptor.getVersion().getName(),
entityPersister.getTableName(),
column.getText( dialect ),
basicTypeResolution.getLegacyResolvedBasicType(),
entityPersister
entityPersister,
creationProcess
);
}

View File

@ -14,6 +14,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Supplier;
import org.hibernate.AssertionFailure;
import org.hibernate.HibernateException;
@ -1154,7 +1155,9 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
@Override
protected EntityVersionMapping generateVersionMapping(
MappingModelCreationProcess creationProcess, PersistentClass bootEntityDescriptor) {
Supplier<?> templateInstanceCreator,
PersistentClass bootEntityDescriptor,
MappingModelCreationProcess creationProcess) {
if ( getVersionType() == null ) {
return null;
}
@ -1166,6 +1169,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
versionPropertyName,
(role, process) -> generateVersionMapping(
this,
templateInstanceCreator,
bootEntityDescriptor,
process
)
@ -1179,7 +1183,10 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
}
@Override
protected EntityIdentifierMapping generateIdentifierMapping(MappingModelCreationProcess creationProcess, PersistentClass bootEntityDescriptor) {
protected EntityIdentifierMapping generateIdentifierMapping(
Supplier<?> templateInstanceCreator,
PersistentClass bootEntityDescriptor,
MappingModelCreationProcess creationProcess) {
final Type idType = getIdentifierType();
if ( idType instanceof CompositeType ) {
@ -1209,6 +1216,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
return new BasicEntityIdentifierMappingImpl(
this,
templateInstanceCreator,
bootEntityDescriptor.getIdentifierProperty().getName(),
getTableName(),
tableKeyColumns[0][0],

View File

@ -6,7 +6,6 @@
*/
package org.hibernate.tuple;
import org.hibernate.engine.spi.IdentifierValue;
import org.hibernate.id.IdentifierGenerator;
/**
@ -17,8 +16,6 @@ public interface IdentifierAttribute extends Attribute, Property {
boolean isEmbedded();
IdentifierValue getUnsavedValue();
IdentifierGenerator getIdentifierGenerator();
boolean isIdentifierAssignedByInsert();

View File

@ -21,7 +21,6 @@ public class IdentifierProperty extends AbstractAttribute implements IdentifierA
private final boolean virtual;
private final boolean embedded;
private final IdentifierValue unsavedValue;
private final IdentifierGenerator identifierGenerator;
private final boolean identifierAssignedByInsert;
private final boolean hasIdentifierMapper;
@ -33,7 +32,6 @@ public class IdentifierProperty extends AbstractAttribute implements IdentifierA
* its owning entity.
* @param type The Hibernate Type for the identifier property.
* @param embedded Is this an embedded identifier.
* @param unsavedValue The value which, if found as the value on the identifier
* property, represents new (i.e., un-saved) instances of the owning entity.
* @param identifierGenerator The generator to use for id value generation.
*/
@ -41,13 +39,11 @@ public class IdentifierProperty extends AbstractAttribute implements IdentifierA
String name,
Type type,
boolean embedded,
IdentifierValue unsavedValue,
IdentifierGenerator identifierGenerator) {
super( name, type );
this.virtual = false;
this.embedded = embedded;
this.hasIdentifierMapper = false;
this.unsavedValue = unsavedValue;
this.identifierGenerator = identifierGenerator;
this.identifierAssignedByInsert = identifierGenerator instanceof PostInsertIdentifierGenerator;
}
@ -57,7 +53,6 @@ public class IdentifierProperty extends AbstractAttribute implements IdentifierA
*
* @param type The Hibernate Type for the identifier property.
* @param embedded Is this an embedded identifier.
* @param unsavedValue The value which, if found as the value on the identifier
* property, represents new (i.e., un-saved) instances of the owning entity.
* @param identifierGenerator The generator to use for id value generation.
*/
@ -65,13 +60,11 @@ public class IdentifierProperty extends AbstractAttribute implements IdentifierA
Type type,
boolean embedded,
boolean hasIdentifierMapper,
IdentifierValue unsavedValue,
IdentifierGenerator identifierGenerator) {
super( null, type );
this.virtual = true;
this.embedded = embedded;
this.hasIdentifierMapper = hasIdentifierMapper;
this.unsavedValue = unsavedValue;
this.identifierGenerator = identifierGenerator;
this.identifierAssignedByInsert = identifierGenerator instanceof PostInsertIdentifierGenerator;
}
@ -86,11 +79,6 @@ public class IdentifierProperty extends AbstractAttribute implements IdentifierA
return embedded;
}
@Override
public IdentifierValue getUnsavedValue() {
return unsavedValue;
}
@Override
public IdentifierGenerator getIdentifierGenerator() {
return identifierGenerator;

View File

@ -63,20 +63,12 @@ public final class PropertyFactory {
Type type = mappedEntity.getIdentifier().getType();
Property property = mappedEntity.getIdentifierProperty();
IdentifierValue unsavedValue = UnsavedValueFactory.getUnsavedIdentifierValue(
mappedUnsavedValue,
getGetter( property ),
type,
getConstructor( mappedEntity )
);
if ( property == null ) {
// this is a virtual id property...
return new IdentifierProperty(
type,
mappedEntity.hasEmbeddedIdentifier(),
mappedEntity.hasIdentifierMapper(),
unsavedValue,
generator
);
}
@ -85,7 +77,6 @@ public final class PropertyFactory {
property.getName(),
type,
mappedEntity.hasEmbeddedIdentifier(),
unsavedValue,
generator
);
}
@ -108,14 +99,6 @@ public final class PropertyFactory {
boolean lazyAvailable) {
String mappedUnsavedValue = ( (KeyValue) property.getValue() ).getNullValue();
//noinspection unchecked
VersionValue unsavedValue = UnsavedValueFactory.getUnsavedVersionValue(
mappedUnsavedValue,
getGetter( property ),
(VersionJavaType<Object>) ((BasicType<?>) property.getType()).getJavaTypeDescriptor(),
getConstructor( property.getPersistentClass() )
);
boolean lazy = lazyAvailable && property.isLazy();
return new VersionProperty(
@ -133,8 +116,7 @@ public final class PropertyFactory {
.setDirtyCheckable( property.isUpdateable() && !lazy )
.setVersionable( property.isOptimisticLocked() )
.setCascadeStyle( property.getCascadeStyle() )
.createInformation(),
unsavedValue
.createInformation()
);
}

View File

@ -37,21 +37,6 @@ import org.hibernate.property.access.spi.Getter;
*/
@Deprecated
public interface Tuplizer {
/**
* Extract the current values contained on the given entity.
*
* @param entity The entity from which to extract values.
* @return The current property values.
*/
public Object[] getPropertyValues(Object entity);
/**
* Inject the given values into the given entity.
*
* @param entity The entity.
* @param values The values to be injected.
*/
public void setPropertyValues(Object entity, Object[] values);
/**
* Extract the value of a particular property from the given entity.
@ -62,23 +47,6 @@ public interface Tuplizer {
*/
public Object getPropertyValue(Object entity, int i);
/**
* Generate a new, empty entity.
*
* @return The new, empty entity instance.
*/
public Object instantiate();
/**
* Is the given object considered an instance of the the entity (accounting
* for entity-mode) managed by this tuplizer.
*
* @param object The object to be checked.
* @return True if the object is considered as an instance of this entity
* within the given mode.
*/
public boolean isInstance(Object object);
/**
* Return the pojo class managed by this tuplizer.
* </p>

View File

@ -67,10 +67,6 @@ public abstract class AbstractComponentTuplizer implements ComponentTuplizer {
return values;
}
public boolean isInstance(Object object) {
return instantiator.isInstance(object);
}
public void setPropertyValues(Object component, Object[] values) throws HibernateException {
for ( int i = 0; i < propertySpan; i++ ) {
setters[i].set( component, values[i], null );

View File

@ -13,7 +13,6 @@ import java.util.Map;
import org.hibernate.EntityMode;
import org.hibernate.HibernateException;
import org.hibernate.boot.spi.BootstrapContext;
import org.hibernate.boot.spi.MetadataBuildingOptions;
import org.hibernate.cfg.Environment;
import org.hibernate.engine.config.spi.ConfigurationService;
@ -44,18 +43,11 @@ public class ComponentMetamodel implements Serializable {
private final Map propertyIndexes = new HashMap();
private final boolean createEmptyCompositesEnabled;
/**
* @deprecated Use {@link ComponentMetamodel#ComponentMetamodel(Component, BootstrapContext)} instead.
*/
@Deprecated
public ComponentMetamodel(Component component, MetadataBuildingOptions metadataBuildingOptions) {
this( component, new ComponentTuplizerFactory( metadataBuildingOptions ) );
}
public ComponentMetamodel(Component component, BootstrapContext bootstrapContext) {
this( component, new ComponentTuplizerFactory( bootstrapContext ) );
}
private ComponentMetamodel(Component component, ComponentTuplizerFactory componentTuplizerFactory){
this.role = component.getRoleName();
this.isKey = component.isKey();

View File

@ -54,4 +54,27 @@ public interface ComponentTuplizer extends Tuplizer, Serializable {
* @return True if the managed component is available from the managed component; else false.
*/
public boolean isMethodOf(Method method);
/**
* Generate a new, empty entity.
*
* @return The new, empty entity instance.
*/
public Object instantiate();
/**
* Extract the current values contained on the given entity.
*
* @param entity The entity from which to extract values.
* @return The current property values.
*/
public Object[] getPropertyValues(Object entity);
/**
* Inject the given values into the given entity.
*
* @param entity The entity.
* @param values The values to be injected.
*/
public void setPropertyValues(Object entity, Object[] values);
}

View File

@ -6,7 +6,6 @@
*/
package org.hibernate.tuple.entity;
import java.io.Serializable;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
@ -15,9 +14,7 @@ import org.hibernate.EntityMode;
import org.hibernate.EntityNameResolver;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer;
import org.hibernate.bytecode.enhance.spi.interceptor.BytecodeLazyAttributeInterceptor;
import org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributesMetadata;
import org.hibernate.bytecode.spi.BytecodeEnhancementMetadata;
import org.hibernate.engine.spi.EntityEntry;
import org.hibernate.engine.spi.EntityKey;
@ -25,7 +22,6 @@ import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.engine.spi.PersistentAttributeInterceptable;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.Assigned;
import org.hibernate.loader.PropertyPath;
import org.hibernate.mapping.Component;
import org.hibernate.mapping.KeyValue;
@ -38,7 +34,6 @@ import org.hibernate.property.access.spi.Getter;
import org.hibernate.property.access.spi.Setter;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.ProxyFactory;
import org.hibernate.tuple.IdentifierProperty;
import org.hibernate.tuple.Instantiator;
import org.hibernate.type.AssociationType;
import org.hibernate.type.ComponentType;
@ -245,13 +240,6 @@ public abstract class AbstractEntityTuplizer implements EntityTuplizer {
}
}
@Override
public void setIdentifier(Object entity, Object id) throws HibernateException {
// 99% of the time the session is not needed. It's only needed for certain brain-dead
// interpretations of JPA 2 "derived identity" support
setIdentifier( entity, id, null );
}
@Override
public void setIdentifier(Object entity, Object id, SharedSessionContractImplementor session) {
if ( entityMetamodel.getIdentifierProperty().isEmbedded() ) {
@ -502,41 +490,6 @@ public abstract class AbstractEntityTuplizer implements EntityTuplizer {
return metamodel.entityPersister( entityName );
}
@Override
public void resetIdentifier(Object entity, Object currentId, Object currentVersion) {
// 99% of the time the session is not needed. It's only needed for certain brain-dead
// interpretations of JPA 2 "derived identity" support
resetIdentifier( entity, currentId, currentVersion, null );
}
@Override
public void resetIdentifier(
Object entity,
Object currentId,
Object currentVersion,
SharedSessionContractImplementor session) {
//noinspection StatementWithEmptyBody
final IdentifierProperty identifierProperty = entityMetamodel.getIdentifierProperty();
if ( identifierProperty.getIdentifierGenerator() instanceof Assigned ) {
}
else {
//reset the id
Object result = identifierProperty
.getUnsavedValue()
.getDefaultValue( currentId );
setIdentifier( entity, result, session );
//reset the version
VersionProperty versionProperty = entityMetamodel.getVersionProperty();
if ( entityMetamodel.isVersioned() ) {
setPropertyValue(
entity,
entityMetamodel.getVersionPropertyIndex(),
versionProperty.getUnsavedValue().getDefaultValue( currentVersion )
);
}
}
}
@Override
public Object getVersion(Object entity) throws HibernateException {
if ( !entityMetamodel.isVersioned() ) {
@ -554,32 +507,6 @@ public abstract class AbstractEntityTuplizer implements EntityTuplizer {
return !bytecodeEnhancementMetadata.hasUnFetchedAttributes( entity );
}
@Override
public Object[] getPropertyValues(Object entity) {
final BytecodeEnhancementMetadata enhancementMetadata = entityMetamodel.getBytecodeEnhancementMetadata();
final LazyAttributesMetadata lazyAttributesMetadata = enhancementMetadata.getLazyAttributesMetadata();
final int span = entityMetamodel.getPropertySpan();
final String[] propertyNames = entityMetamodel.getPropertyNames();
final Object[] result = new Object[span];
for ( int j = 0; j < span; j++ ) {
final String propertyName = propertyNames[j];
// if the attribute is not lazy (bytecode sense), we can just use the value from the instance
// if the attribute is lazy but has been initialized we can just use the value from the instance
// todo : there should be a third case here when we merge transient instances
if ( ! lazyAttributesMetadata.isLazyAttribute( propertyName )
|| enhancementMetadata.isAttributeLoaded( entity, propertyName) ) {
result[j] = getters[j].get( entity );
}
else {
result[j] = LazyPropertyInitializer.UNFETCHED_PROPERTY;
}
}
return result;
}
@Override
public Object[] getPropertyValuesToInsert(Object entity, Map mergeMap, SharedSessionContractImplementor session) {
final int span = entityMetamodel.getPropertySpan();
@ -670,18 +597,6 @@ public abstract class AbstractEntityTuplizer implements EntityTuplizer {
throw new MappingException( "component property not found: " + subPropertyName );
}
@Override
public void setPropertyValues(Object entity, Object[] values) throws HibernateException {
boolean setAll = !entityMetamodel.hasLazyProperties();
final SessionFactoryImplementor factory = getFactory();
for ( int j = 0; j < entityMetamodel.getPropertySpan(); j++ ) {
if ( setAll || values[j] != LazyPropertyInitializer.UNFETCHED_PROPERTY ) {
setters[j].set( entity, values[j], factory );
}
}
}
@Override
public void setPropertyValue(Object entity, int i, Object value) throws HibernateException {
setters[i].set( entity, value, getFactory() );
@ -692,23 +607,6 @@ public abstract class AbstractEntityTuplizer implements EntityTuplizer {
setters[entityMetamodel.getPropertyIndex( propertyName )].set( entity, value, getFactory() );
}
@Override
public final Object instantiate(Object id) throws HibernateException {
// 99% of the time the session is not needed. It's only needed for certain brain-dead
// interpretations of JPA 2 "derived identity" support
return instantiate( id, null );
}
@Override
public final Object instantiate(Object id, SharedSessionContractImplementor session) {
Object result = getInstantiator().instantiate( id );
linkToSession( result, session );
if ( id != null ) {
setIdentifier( result, id, session );
}
return result;
}
protected void linkToSession(Object entity, SharedSessionContractImplementor session) {
if ( session == null ) {
return;
@ -721,20 +619,10 @@ public abstract class AbstractEntityTuplizer implements EntityTuplizer {
}
}
@Override
public final Object instantiate() throws HibernateException {
return instantiate( null, null );
}
@Override
public void afterInitialize(Object entity, SharedSessionContractImplementor session) {
}
@Override
public final boolean isInstance(Object object) {
return getInstantiator().isInstance( object );
}
@Override
public boolean hasProxy() {
return entityMetamodel.isLazy() && !entityMetamodel.getBytecodeEnhancementMetadata().isEnhancedForLazyLoading();
@ -777,15 +665,6 @@ public abstract class AbstractEntityTuplizer implements EntityTuplizer {
return idGetter;
}
@Override
public Getter getVersionGetter() {
final EntityMetamodel entityMetamodel = getEntityMetamodel();
if ( entityMetamodel.isVersioned() ) {
return getGetter( entityMetamodel.getVersionPropertyIndex() );
}
return null;
}
@Override
public Getter getGetter(int i) {
return getters[i];

View File

@ -39,30 +39,7 @@ public interface EntityTuplizer extends Tuplizer {
*/
EntityMode getEntityMode();
/**
* Create an entity instance initialized with the given identifier.
*
* @param id The identifier value for the entity to be instantiated.
* @return The instantiated entity.
* @throws HibernateException
*
* @deprecated Use {@link #instantiate(Object, SharedSessionContractImplementor)} instead.
*/
@Deprecated
@SuppressWarnings( {"JavaDoc"})
Object instantiate(Object id) throws HibernateException;
/**
* Create an entity instance initialized with the given identifier.
*
* @param id The identifier value for the entity to be instantiated.
* @param session The session from which is requests originates
*
* @return The instantiated entity.
*/
Object instantiate(Object id, SharedSessionContractImplementor session);
/**
/**
* Extract the identifier value from the given entity.
*
* @param entity The entity from which to extract the identifier value.
@ -87,21 +64,7 @@ public interface EntityTuplizer extends Tuplizer {
*/
Object getIdentifier(Object entity, SharedSessionContractImplementor session);
/**
* Inject the identifier value into the given entity.
* </p>
* Has no effect if the entity does not define an identifier property
*
* @param entity The entity to inject with the identifier value.
* @param id The value to be injected as the identifier.
*
* @deprecated Use {@link #setIdentifier(Object, Object, SharedSessionContractImplementor)} instead.
*/
@Deprecated
@SuppressWarnings( {"JavaDoc"})
void setIdentifier(Object entity, Object id) throws HibernateException;
/**
/**
* Inject the identifier value into the given entity.
* </p>
* Has no effect if the entity does not define an identifier property
@ -113,30 +76,6 @@ public interface EntityTuplizer extends Tuplizer {
void setIdentifier(Object entity, Object id, SharedSessionContractImplementor session);
/**
* Inject the given identifier and version into the entity, in order to
* "roll back" to their original values.
*
* @param entity The entity for which to reset the id/version values
* @param currentId The identifier value to inject into the entity.
* @param currentVersion The version value to inject into the entity.
*
* @deprecated Use {@link #resetIdentifier(Object, Object, Object, SharedSessionContractImplementor)} instead
*/
@Deprecated
@SuppressWarnings( {"UnusedDeclaration"})
void resetIdentifier(Object entity, Object currentId, Object currentVersion);
/**
* Inject the given identifier and version into the entity, in order to
* "roll back" to their original values.
* @param entity The entity for which to reset the id/version values
* @param currentId The identifier value to inject into the entity.
* @param currentVersion The version value to inject into the entity.
* @param session The session from which the request originated
*/
void resetIdentifier(Object entity, Object currentId, Object currentVersion, SharedSessionContractImplementor session);
/**
* Extract the value of the version property from the given entity.
*
* @param entity The entity from which to extract the version value.
@ -269,13 +208,6 @@ public interface EntityTuplizer extends Tuplizer {
*/
Getter getIdentifierGetter();
/**
* Retrieve the getter for the version property. May return null.
*
* @return The getter for the version property.
*/
Getter getVersionGetter();
default ProxyFactory getProxyFactory() {
return null;
}

View File

@ -135,26 +135,6 @@ public class PojoEntityTuplizer extends AbstractEntityTuplizer {
}
}
@Override
public void setPropertyValues(Object entity, Object[] values) throws HibernateException {
if ( !getEntityMetamodel().hasLazyProperties() && optimizer != null && optimizer.getAccessOptimizer() != null ) {
setPropertyValuesWithOptimizer( entity, values );
}
else {
super.setPropertyValues( entity, values );
}
}
@Override
public Object[] getPropertyValues(Object entity) throws HibernateException {
if ( shouldGetAllProperties( entity ) && optimizer != null && optimizer.getAccessOptimizer() != null ) {
return getPropertyValuesWithOptimizer( entity );
}
else {
return super.getPropertyValues( entity );
}
}
@Override
public Object[] getPropertyValuesToInsert(Object entity, Map mergeMap, SharedSessionContractImplementor session) {
if ( shouldGetAllProperties( entity ) && optimizer != null && optimizer.getAccessOptimizer() != null ) {
@ -165,10 +145,6 @@ public class PojoEntityTuplizer extends AbstractEntityTuplizer {
}
}
protected void setPropertyValuesWithOptimizer(Object object, Object[] values) {
optimizer.getAccessOptimizer().setPropertyValues( object, values );
}
protected Object[] getPropertyValuesWithOptimizer(Object object) {
return optimizer.getAccessOptimizer().getPropertyValues( object );
}

View File

@ -19,8 +19,6 @@ import org.hibernate.type.Type;
* @author Steve Ebersole
*/
public class VersionProperty extends AbstractNonIdentifierAttribute {
private final VersionValue unsavedValue;
/**
* Constructs VersionProperty instances.
*
@ -31,7 +29,6 @@ public class VersionProperty extends AbstractNonIdentifierAttribute {
* its owner.
* @param attributeType The Hibernate Type of this property.
* @param attributeInformation The basic attribute information.
* @param unsavedValue The value which, if found as the value of
* this (i.e., the version) property, represents new (i.e., un-saved)
* instances of the owning entity.
*/
@ -41,13 +38,7 @@ public class VersionProperty extends AbstractNonIdentifierAttribute {
int attributeNumber,
String attributeName,
Type attributeType,
BaselineAttributeInformation attributeInformation,
VersionValue unsavedValue) {
BaselineAttributeInformation attributeInformation) {
super( source, sessionFactory, attributeNumber, attributeName, attributeType, attributeInformation );
this.unsavedValue = unsavedValue;
}
public VersionValue getUnsavedValue() {
return unsavedValue;
}
}

View File

@ -6,31 +6,11 @@
*/
package org.hibernate.orm.test.bytecode.enhancement.lazy.proxy;
import java.util.Map;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.Id;
import jakarta.persistence.Inheritance;
import jakarta.persistence.InheritanceType;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import org.hibernate.EntityMode;
import org.hibernate.EntityNameResolver;
import org.hibernate.Hibernate;
import org.hibernate.HibernateException;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.SessionFactoryBuilder;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.property.access.spi.Getter;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.ProxyFactory;
import org.hibernate.stat.Statistics;
import org.hibernate.tuple.entity.EntityMetamodel;
import org.hibernate.tuple.entity.EntityTuplizer;
import org.hibernate.tuple.entity.PojoEntityTuplizer;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
@ -39,6 +19,14 @@ import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.Id;
import jakarta.persistence.Inheritance;
import jakarta.persistence.InheritanceType;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
@ -305,177 +293,4 @@ public class LazyToOnesNoProxyFactoryWithSubclassesStatefulTest extends BaseNonC
}
}
public static class NoProxyFactoryPojoEntityTuplizer implements EntityTuplizer {
private final PojoEntityTuplizer pojoEntityTuplizer;
public NoProxyFactoryPojoEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappedEntity) {
pojoEntityTuplizer = new PojoEntityTuplizer( entityMetamodel, mappedEntity );
}
@Override
public EntityMode getEntityMode() {
return pojoEntityTuplizer.getEntityMode();
}
@Override
public Object instantiate(Object id) throws HibernateException {
return pojoEntityTuplizer.instantiate( id );
}
@Override
public Object instantiate(Object id, SharedSessionContractImplementor session) {
return pojoEntityTuplizer.instantiate( id, session );
}
@Override
public Object getIdentifier(Object entity) throws HibernateException {
return pojoEntityTuplizer.getIdentifier( entity );
}
@Override
public Object getIdentifier(Object entity, SharedSessionContractImplementor session) {
return pojoEntityTuplizer.getIdentifier( entity, session );
}
@Override
public void setIdentifier(Object entity, Object id) throws HibernateException {
pojoEntityTuplizer.setIdentifier( entity, id );
}
@Override
public void setIdentifier(Object entity, Object id, SharedSessionContractImplementor session) {
pojoEntityTuplizer.setIdentifier( entity, id, session );
}
@Override
public void resetIdentifier(Object entity, Object currentId, Object currentVersion) {
pojoEntityTuplizer.resetIdentifier( entity, currentId, currentVersion );
}
@Override
public void resetIdentifier(
Object entity,
Object currentId,
Object currentVersion,
SharedSessionContractImplementor session) {
pojoEntityTuplizer.resetIdentifier( entity, currentId, currentVersion, session );
}
@Override
public Object getVersion(Object entity) throws HibernateException {
return pojoEntityTuplizer.getVersion( entity );
}
@Override
public void setPropertyValue(Object entity, int i, Object value) throws HibernateException {
pojoEntityTuplizer. setPropertyValue( entity, i, value );
}
@Override
public void setPropertyValue(Object entity, String propertyName, Object value) throws HibernateException {
pojoEntityTuplizer.setPropertyValue( entity, propertyName, value );
}
@Override
public Object[] getPropertyValuesToInsert(
Object entity,
Map mergeMap,
SharedSessionContractImplementor session) throws HibernateException {
return pojoEntityTuplizer.getPropertyValuesToInsert( entity, mergeMap, session );
}
@Override
public Object getPropertyValue(Object entity, String propertyName) throws HibernateException {
return pojoEntityTuplizer.getPropertyValue( entity, propertyName );
}
@Override
public void afterInitialize(Object entity, SharedSessionContractImplementor session) {
pojoEntityTuplizer.afterInitialize( entity, session );
}
@Override
public boolean hasProxy() {
return pojoEntityTuplizer.hasProxy();
}
@Override
public Object createProxy(Object id, SharedSessionContractImplementor session) throws HibernateException {
return pojoEntityTuplizer.createProxy( id, session );
}
@Override
public boolean isLifecycleImplementor() {
return pojoEntityTuplizer.isLifecycleImplementor();
}
@Override
public Class getConcreteProxyClass() {
return pojoEntityTuplizer.getConcreteProxyClass();
}
@Override
public EntityNameResolver[] getEntityNameResolvers() {
return pojoEntityTuplizer.getEntityNameResolvers();
}
@Override
public String determineConcreteSubclassEntityName(
Object entityInstance, SessionFactoryImplementor factory) {
return pojoEntityTuplizer.determineConcreteSubclassEntityName( entityInstance, factory );
}
@Override
public Getter getIdentifierGetter() {
return pojoEntityTuplizer.getIdentifierGetter();
}
@Override
public Getter getVersionGetter() {
return pojoEntityTuplizer.getVersionGetter();
}
@Override
public ProxyFactory getProxyFactory() {
return null;
}
@Override
public Object[] getPropertyValues(Object entity) {
return pojoEntityTuplizer.getPropertyValues( entity );
}
@Override
public void setPropertyValues(Object entity, Object[] values) {
pojoEntityTuplizer.setPropertyValues( entity, values );
}
@Override
public Object getPropertyValue(Object entity, int i) {
return pojoEntityTuplizer.getPropertyValue( entity, i );
}
@Override
public Object instantiate() {
return pojoEntityTuplizer.instantiate();
}
@Override
public boolean isInstance(Object object) {
return pojoEntityTuplizer.isInstance( object );
}
@Override
public Class getMappedClass() {
return pojoEntityTuplizer.getMappedClass();
}
@Override
public Getter getGetter(int i) {
return pojoEntityTuplizer.getGetter( i );
}
}
}

View File

@ -6,31 +6,11 @@
*/
package org.hibernate.orm.test.bytecode.enhancement.lazy.proxy;
import java.util.Map;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.Id;
import jakarta.persistence.Inheritance;
import jakarta.persistence.InheritanceType;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import org.hibernate.EntityMode;
import org.hibernate.EntityNameResolver;
import org.hibernate.Hibernate;
import org.hibernate.HibernateException;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.SessionFactoryBuilder;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.property.access.spi.Getter;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.ProxyFactory;
import org.hibernate.stat.Statistics;
import org.hibernate.tuple.entity.EntityMetamodel;
import org.hibernate.tuple.entity.EntityTuplizer;
import org.hibernate.tuple.entity.PojoEntityTuplizer;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
@ -39,6 +19,14 @@ import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.Id;
import jakarta.persistence.Inheritance;
import jakarta.persistence.InheritanceType;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
@ -306,177 +294,4 @@ public class LazyToOnesNoProxyFactoryWithSubclassesStatelessTest extends BaseNon
}
}
public static class NoProxyFactoryPojoEntityTuplizer implements EntityTuplizer {
private final PojoEntityTuplizer pojoEntityTuplizer;
public NoProxyFactoryPojoEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappedEntity) {
pojoEntityTuplizer = new PojoEntityTuplizer( entityMetamodel, mappedEntity );
}
@Override
public EntityMode getEntityMode() {
return pojoEntityTuplizer.getEntityMode();
}
@Override
public Object instantiate(Object id) throws HibernateException {
return pojoEntityTuplizer.instantiate( id );
}
@Override
public Object instantiate(Object id, SharedSessionContractImplementor session) {
return pojoEntityTuplizer.instantiate( id, session );
}
@Override
public Object getIdentifier(Object entity) throws HibernateException {
return pojoEntityTuplizer.getIdentifier( entity );
}
@Override
public Object getIdentifier(Object entity, SharedSessionContractImplementor session) {
return pojoEntityTuplizer.getIdentifier( entity, session );
}
@Override
public void setIdentifier(Object entity, Object id) throws HibernateException {
pojoEntityTuplizer.setIdentifier( entity, id );
}
@Override
public void setIdentifier(Object entity, Object id, SharedSessionContractImplementor session) {
pojoEntityTuplizer.setIdentifier( entity, id, session );
}
@Override
public void resetIdentifier(Object entity, Object currentId, Object currentVersion) {
pojoEntityTuplizer.resetIdentifier( entity, currentId, currentVersion );
}
@Override
public void resetIdentifier(
Object entity,
Object currentId,
Object currentVersion,
SharedSessionContractImplementor session) {
pojoEntityTuplizer.resetIdentifier( entity, currentId, currentVersion, session );
}
@Override
public Object getVersion(Object entity) throws HibernateException {
return pojoEntityTuplizer.getVersion( entity );
}
@Override
public void setPropertyValue(Object entity, int i, Object value) throws HibernateException {
pojoEntityTuplizer. setPropertyValue( entity, i, value );
}
@Override
public void setPropertyValue(Object entity, String propertyName, Object value) throws HibernateException {
pojoEntityTuplizer.setPropertyValue( entity, propertyName, value );
}
@Override
public Object[] getPropertyValuesToInsert(
Object entity,
Map mergeMap,
SharedSessionContractImplementor session) throws HibernateException {
return pojoEntityTuplizer.getPropertyValuesToInsert( entity, mergeMap, session );
}
@Override
public Object getPropertyValue(Object entity, String propertyName) throws HibernateException {
return pojoEntityTuplizer.getPropertyValue( entity, propertyName );
}
@Override
public void afterInitialize(Object entity, SharedSessionContractImplementor session) {
pojoEntityTuplizer.afterInitialize( entity, session );
}
@Override
public boolean hasProxy() {
return pojoEntityTuplizer.hasProxy();
}
@Override
public Object createProxy(Object id, SharedSessionContractImplementor session) throws HibernateException {
return pojoEntityTuplizer.createProxy( id, session );
}
@Override
public boolean isLifecycleImplementor() {
return pojoEntityTuplizer.isLifecycleImplementor();
}
@Override
public Class getConcreteProxyClass() {
return pojoEntityTuplizer.getConcreteProxyClass();
}
@Override
public EntityNameResolver[] getEntityNameResolvers() {
return pojoEntityTuplizer.getEntityNameResolvers();
}
@Override
public String determineConcreteSubclassEntityName(
Object entityInstance, SessionFactoryImplementor factory) {
return pojoEntityTuplizer.determineConcreteSubclassEntityName( entityInstance, factory );
}
@Override
public Getter getIdentifierGetter() {
return pojoEntityTuplizer.getIdentifierGetter();
}
@Override
public Getter getVersionGetter() {
return pojoEntityTuplizer.getVersionGetter();
}
@Override
public ProxyFactory getProxyFactory() {
return null;
}
@Override
public Object[] getPropertyValues(Object entity) {
return pojoEntityTuplizer.getPropertyValues( entity );
}
@Override
public void setPropertyValues(Object entity, Object[] values) {
pojoEntityTuplizer.setPropertyValues( entity, values );
}
@Override
public Object getPropertyValue(Object entity, int i) {
return pojoEntityTuplizer.getPropertyValue( entity, i );
}
@Override
public Object instantiate() {
return pojoEntityTuplizer.instantiate();
}
@Override
public boolean isInstance(Object object) {
return pojoEntityTuplizer.isInstance( object );
}
@Override
public Class getMappedClass() {
return pojoEntityTuplizer.getMappedClass();
}
@Override
public Getter getGetter(int i) {
return pojoEntityTuplizer.getGetter( i );
}
}
}