extract two methods / code style

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-05-27 10:09:05 +02:00 committed by Steve Ebersole
parent e96741cfa6
commit a5f1925b69
2 changed files with 16 additions and 64 deletions

View File

@ -552,53 +552,15 @@ public class GeneratorBinder {
final Class<? extends Generator> generatorClass = idGeneratorType.value(); final Class<? extends Generator> generatorClass = idGeneratorType.value();
return creationContext -> { return creationContext -> {
checkGeneratorClass( generatorClass ); checkGeneratorClass( generatorClass );
Generator generator; final Generator generator =
if ( beanContainer != null ) { instantiateGenerator(
final ContainedBean<? extends Generator> bean = beanContainer.getBean( annotation,
generatorClass, beanContainer,
new BeanContainer.LifecycleOptions() { creationContext,
@Override generatorClass,
public boolean canUseCachedReferences() { idAttributeMember,
return false; annotationType
} );
@Override
public boolean useJpaCompliantCreation() {
return true;
}
},
new BeanInstanceProducer() {
@SuppressWarnings("unchecked")
@Override
public <B> B produceBeanInstance(Class<B> beanType) {
return (B) instantiateGenerator(
annotation,
idAttributeMember,
annotationType,
CustomIdGeneratorCreationContext.class,
generatorClass,
creationContext
);
}
@Override
public <B> B produceBeanInstance(String name, Class<B> beanType) {
return produceBeanInstance( beanType );
}
}
);
generator = bean.getBeanInstance();
}
else {
generator = instantiateGenerator(
annotation,
beanContainer,
creationContext,
generatorClass,
idAttributeMember,
annotationType
);
}
callInitialize( annotation, idAttributeMember, creationContext, generator ); callInitialize( annotation, idAttributeMember, creationContext, generator );
callConfigure( creationContext, generator ); callConfigure( creationContext, generator );
checkIdGeneratorTiming( annotationType, generator ); checkIdGeneratorTiming( annotationType, generator );
@ -611,7 +573,7 @@ public class GeneratorBinder {
BeanContainer beanContainer, BeanContainer beanContainer,
CustomIdGeneratorCreationContext creationContext, CustomIdGeneratorCreationContext creationContext,
Class<? extends Generator> generatorClass, Class<? extends Generator> generatorClass,
MemberDetails memberDetails, MemberDetails idAttributeMember,
Class<? extends Annotation> annotationType) { Class<? extends Annotation> annotationType) {
if ( beanContainer != null ) { if ( beanContainer != null ) {
return instantiateGeneratorAsBean( return instantiateGeneratorAsBean(
@ -619,14 +581,14 @@ public class GeneratorBinder {
beanContainer, beanContainer,
creationContext, creationContext,
generatorClass, generatorClass,
memberDetails, idAttributeMember,
annotationType annotationType
); );
} }
else { else {
return instantiateGenerator( return instantiateGenerator(
annotation, annotation,
memberDetails, idAttributeMember,
annotationType, annotationType,
CustomIdGeneratorCreationContext.class, CustomIdGeneratorCreationContext.class,
generatorClass, generatorClass,
@ -640,7 +602,7 @@ public class GeneratorBinder {
BeanContainer beanContainer, BeanContainer beanContainer,
CustomIdGeneratorCreationContext creationContext, CustomIdGeneratorCreationContext creationContext,
Class<? extends Generator> generatorClass, Class<? extends Generator> generatorClass,
MemberDetails memberDetails, MemberDetails idAttributeMember,
Class<? extends Annotation> annotationType) { Class<? extends Annotation> annotationType) {
return beanContainer.getBean( generatorClass, return beanContainer.getBean( generatorClass,
new BeanContainer.LifecycleOptions() { new BeanContainer.LifecycleOptions() {
@ -659,7 +621,7 @@ public class GeneratorBinder {
public <B> B produceBeanInstance(Class<B> beanType) { public <B> B produceBeanInstance(Class<B> beanType) {
return (B) instantiateGenerator( return (B) instantiateGenerator(
annotation, annotation,
memberDetails, idAttributeMember,
annotationType, annotationType,
CustomIdGeneratorCreationContext.class, CustomIdGeneratorCreationContext.class,
generatorClass, generatorClass,
@ -670,8 +632,7 @@ public class GeneratorBinder {
public <B> B produceBeanInstance(String name, Class<B> beanType) { public <B> B produceBeanInstance(String name, Class<B> beanType) {
return produceBeanInstance( beanType ); return produceBeanInstance( beanType );
} }
} ) } ).getBeanInstance();
.getBeanInstance();
} }
private static <C, G extends Generator> G instantiateGenerator( private static <C, G extends Generator> G instantiateGenerator(

View File

@ -7,7 +7,6 @@
package org.hibernate.boot.model.internal; package org.hibernate.boot.model.internal;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -64,10 +63,8 @@ import org.hibernate.service.ServiceRegistry;
import org.hibernate.usertype.CompositeUserType; import org.hibernate.usertype.CompositeUserType;
import org.hibernate.resource.beans.container.spi.BeanContainer; import org.hibernate.resource.beans.container.spi.BeanContainer;
import org.hibernate.resource.beans.internal.Helper;
import org.hibernate.resource.beans.spi.ManagedBeanRegistry; import org.hibernate.resource.beans.spi.ManagedBeanRegistry;
import org.hibernate.service.ServiceRegistry; import org.hibernate.service.ServiceRegistry;
import org.hibernate.usertype.CompositeUserType;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import jakarta.persistence.Basic; import jakarta.persistence.Basic;
@ -1476,13 +1473,7 @@ public class PropertyBinder {
List<AnnotationUsage<? extends Annotation>> generatorAnnotations, List<AnnotationUsage<? extends Annotation>> generatorAnnotations,
List<AnnotationUsage<? extends Annotation>> idGeneratorAnnotations) { List<AnnotationUsage<? extends Annotation>> idGeneratorAnnotations) {
for ( AnnotationUsage<? extends Annotation> id : idGeneratorAnnotations ) { for ( AnnotationUsage<? extends Annotation> id : idGeneratorAnnotations ) {
final Iterator<AnnotationUsage<? extends Annotation>> iterator = generatorAnnotations.iterator(); generatorAnnotations.removeIf( gen -> gen.getAnnotationType().equals( id.getAnnotationType() ) );
while ( iterator.hasNext() ) {
final AnnotationUsage<? extends Annotation> gen = iterator.next();
if ( gen.getAnnotationType().equals( id.getAnnotationType() ) ) {
iterator.remove();
}
}
} }
} }
} }