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

View File

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