rewrite EntityBinder

This commit is contained in:
Gavin King 2022-11-02 13:56:31 +01:00
parent 3cd90d7615
commit bb0edab332
5 changed files with 499 additions and 635 deletions

View File

@ -448,8 +448,7 @@ public final class AnnotationBinder {
return null;
}
IdentifierGeneratorDefinition.Builder definitionBuilder = new IdentifierGeneratorDefinition.Builder();
final IdentifierGeneratorDefinition.Builder definitionBuilder = new IdentifierGeneratorDefinition.Builder();
if ( generatorAnn instanceof TableGenerator ) {
context.getBuildingOptions().getIdGenerationTypeInterpreter().interpretTableGenerator(
(TableGenerator) generatorAnn,
@ -469,11 +468,10 @@ public final class AnnotationBinder {
}
}
else if ( generatorAnn instanceof GenericGenerator ) {
GenericGenerator genGen = ( GenericGenerator ) generatorAnn;
final GenericGenerator genGen = ( GenericGenerator ) generatorAnn;
definitionBuilder.setName( genGen.name() );
definitionBuilder.setStrategy( genGen.strategy() );
Parameter[] params = genGen.parameters();
for ( Parameter parameter : params ) {
for ( Parameter parameter : genGen.parameters() ) {
definitionBuilder.addParam( parameter.name(), parameter.value() );
}
if ( LOG.isTraceEnabled() ) {
@ -483,7 +481,6 @@ public final class AnnotationBinder {
else {
throw new AssertionFailure( "Unknown Generator annotation: " + generatorAnn );
}
return definitionBuilder.build();
}
@ -514,7 +511,7 @@ public final class AnnotationBinder {
}
// try to find class level generators
HashMap<String, IdentifierGeneratorDefinition> classGenerators = AnnotationBinder.buildGenerators( clazzToProcess, context );
final HashMap<String, IdentifierGeneratorDefinition> classGenerators = AnnotationBinder.buildGenerators( clazzToProcess, context );
handleTypeDescriptorRegistrations( clazzToProcess, context );
bindEmbeddableInstantiatorRegistrations( clazzToProcess, context );
bindCompositeUserTypeRegistrations( clazzToProcess, context );
@ -2347,7 +2344,7 @@ public final class AnnotationBinder {
//the classes are ordered thus preventing an NPE
//FIXME if an entity has subclasses annotated @MappedSuperclass wo sub @Entity this is wrong
superclassState.setHasSiblings( true );
InheritanceState superEntityState = getInheritanceStateOfSuperEntity( clazz, inheritanceStatePerClass );
final InheritanceState superEntityState = getInheritanceStateOfSuperEntity( clazz, inheritanceStatePerClass );
state.setHasParents( superEntityState != null );
logMixedInheritance( clazz, superclassState, state );
if ( superclassState.getType() != null ) {

View File

@ -83,13 +83,11 @@ public class InheritanceState {
return hasParents() && InheritanceType.TABLE_PER_CLASS.equals( getType() );
}
public static InheritanceState getInheritanceStateOfSuperEntity(
XClass clazz, Map<XClass, InheritanceState> states
) {
public static InheritanceState getInheritanceStateOfSuperEntity(XClass clazz, Map<XClass, InheritanceState> states) {
XClass superclass = clazz;
do {
superclass = superclass.getSuperclass();
InheritanceState currentState = states.get( superclass );
final InheritanceState currentState = states.get( superclass );
if ( currentState != null && !currentState.isEmbeddableSuperclass() ) {
return currentState;
}
@ -151,18 +149,19 @@ public class InheritanceState {
isEmbeddableSuperclass = embeddableSuperclass;
}
public void postProcess(PersistentClass persistenceClass, EntityBinder entityBinder) {
public ElementsToProcess postProcess(PersistentClass persistenceClass, EntityBinder entityBinder) {
//make sure we run elements to process
getElementsToProcess();
addMappedSuperClassInMetadata( persistenceClass );
entityBinder.setPropertyAccessType( accessType );
return elementsToProcess;
}
public XClass getClassWithIdClass(boolean evenIfSubclass) {
if ( !evenIfSubclass && hasParents() ) {
return null;
}
if ( clazz.isAnnotationPresent( IdClass.class ) ) {
else if ( clazz.isAnnotationPresent( IdClass.class ) ) {
return clazz;
}
else {
@ -200,7 +199,7 @@ public class InheritanceState {
* guessing from @Id or @EmbeddedId presence if not specified.
* Change EntityBinder by side effect
*/
public ElementsToProcess getElementsToProcess() {
private ElementsToProcess getElementsToProcess() {
if ( elementsToProcess == null ) {
InheritanceState inheritanceState = inheritanceStatePerClass.get( clazz );
assert !inheritanceState.isEmbeddableSuperclass();
@ -274,7 +273,6 @@ public class InheritanceState {
}
private void getMappedSuperclassesTillNextEntityOrdered() {
//ordered to allow proper messages on properties subclassing
XClass currentClassInHierarchy = clazz;
InheritanceState superclassState;
@ -297,14 +295,13 @@ public class InheritanceState {
private void addMappedSuperClassInMetadata(PersistentClass persistentClass) {
//add @MappedSuperclass in the metadata
// classes from 0 to n-1 are @MappedSuperclass and should be linked
org.hibernate.mapping.MappedSuperclass mappedSuperclass = null;
final InheritanceState superEntityState =
InheritanceState.getInheritanceStateOfSuperEntity( clazz, inheritanceStatePerClass );
PersistentClass superEntity =
final InheritanceState superEntityState = getInheritanceStateOfSuperEntity( clazz, inheritanceStatePerClass );
final PersistentClass superEntity =
superEntityState != null ?
buildingContext.getMetadataCollector().getEntityBinding( superEntityState.getClazz().getName() ) :
null;
final int lastMappedSuperclass = classesToProcessForMappedSuperclass.size() - 1;
org.hibernate.mapping.MappedSuperclass mappedSuperclass = null;
for ( int index = 0; index < lastMappedSuperclass; index++ ) {
org.hibernate.mapping.MappedSuperclass parentSuperclass = mappedSuperclass;
final Class<?> type = buildingContext.getBootstrapContext().getReflectionManager()

View File

@ -168,8 +168,10 @@ public final class CallbackDefinitionResolverLegacyImpl {
return callbackDefinitions;
}
public static List<CallbackDefinition> resolveEmbeddableCallbacks(ReflectionManager reflectionManager,
Class<?> entityClass, Property embeddableProperty,
public static List<CallbackDefinition> resolveEmbeddableCallbacks(
ReflectionManager reflectionManager,
Class<?> entityClass,
Property embeddableProperty,
CallbackType callbackType) {
final Class<?> embeddableClass = embeddableProperty.getType().getReturnedClass();
final XClass embeddableXClass = reflectionManager.toXClass( embeddableClass );

View File

@ -148,7 +148,8 @@ public abstract class AbstractIdentifiableType<J>
private void checkType(SingularPersistentAttribute<?, ?> attribute, Class<?> javaType) {
if ( !javaType.isAssignableFrom( attribute.getType().getJavaType() ) ) {
final JavaType<?> attributeJavaType = attribute.getAttributeJavaType();
if ( !( attributeJavaType instanceof PrimitiveJavaType ) || ( (PrimitiveJavaType) attributeJavaType ).getPrimitiveClass() != javaType ) {
if ( !( attributeJavaType instanceof PrimitiveJavaType )
|| ( (PrimitiveJavaType) attributeJavaType ).getPrimitiveClass() != javaType ) {
throw new IllegalArgumentException(
String.format(
"Attribute [%s#%s : %s] not castable to requested type [%s]",