HHH-18863 change the way enum types -> values are cached to avoid lookups
This commit is contained in:
parent
ece2981ae8
commit
de3408662c
|
@ -504,12 +504,25 @@ public final class Context {
|
|||
return enumTypesByValue;
|
||||
}
|
||||
|
||||
public void addEnumValue(String type, String value) {
|
||||
enumTypesByValue.computeIfAbsent( value, s -> new TreeSet<>() ).add( type );
|
||||
public void addEnumValue(
|
||||
String qualifiedTypeName, String shortTypeName,
|
||||
@Nullable String outerTypeQualifiedName, @Nullable String outerShortTypeName,
|
||||
String value) {
|
||||
addEnumValue( qualifiedTypeName, value );
|
||||
addEnumValue( qualifiedTypeName, qualifiedTypeName + '.' + value );
|
||||
addEnumValue( qualifiedTypeName, shortTypeName + '.' + value );
|
||||
if ( outerShortTypeName != null ) {
|
||||
addEnumValue( qualifiedTypeName, outerShortTypeName + '.' + shortTypeName + '.' + value );
|
||||
addEnumValue( qualifiedTypeName, outerShortTypeName + '$' + shortTypeName + '.' + value );
|
||||
addEnumValue( qualifiedTypeName, outerTypeQualifiedName + '$' + shortTypeName + '.' + value );
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public TypeElement entityType(String entityName) {
|
||||
private void addEnumValue(String qualifiedTypeName, String value) {
|
||||
enumTypesByValue.computeIfAbsent( value, s -> new TreeSet<>() ).add( qualifiedTypeName );
|
||||
}
|
||||
|
||||
public @Nullable TypeElement entityType(String entityName) {
|
||||
final Elements elementUtils = getElementUtils();
|
||||
final String qualifiedName = qualifiedNameForEntityName(entityName);
|
||||
if ( qualifiedName != null ) {
|
||||
|
|
|
@ -645,7 +645,13 @@ public class HibernateProcessor extends AbstractProcessor {
|
|||
if ( fieldType.getKind() == ElementKind.ENUM ) {
|
||||
for ( Element enumMember : fieldType.getEnclosedElements() ) {
|
||||
if ( enumMember.getKind() == ElementKind.ENUM_CONSTANT ) {
|
||||
final Element enclosingElement = fieldType.getEnclosingElement();
|
||||
final boolean hasOuterType =
|
||||
enclosingElement.getKind().isClass() || enclosingElement.getKind().isInterface();
|
||||
context.addEnumValue( fieldType.getQualifiedName().toString(),
|
||||
fieldType.getSimpleName().toString(),
|
||||
hasOuterType ? ((TypeElement) enclosingElement).getQualifiedName().toString() : null,
|
||||
hasOuterType ? enclosingElement.getSimpleName().toString() : null,
|
||||
enumMember.getSimpleName().toString() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,7 +57,6 @@ import static org.hibernate.internal.util.StringHelper.qualify;
|
|||
import static org.hibernate.internal.util.StringHelper.root;
|
||||
import static org.hibernate.internal.util.StringHelper.split;
|
||||
import static org.hibernate.internal.util.StringHelper.unroot;
|
||||
import static org.hibernate.metamodel.model.domain.internal.JpaMetamodelImpl.addAllowedEnumLiteralsToEnumTypesMap;
|
||||
import static org.hibernate.processor.util.Constants.JAVA_OBJECT;
|
||||
|
||||
/**
|
||||
|
@ -90,7 +89,7 @@ public abstract class ProcessorSessionFactory extends MockSessionFactory {
|
|||
private final Types typeUtil;
|
||||
private final Filer filer;
|
||||
private final Map<String, String> entityNameMappings;
|
||||
private final Map<String, Set<String>> allowedEnumLiteralsToEnumTypeNames;
|
||||
private final Map<String, Set<String>> enumTypesByValue;
|
||||
|
||||
public ProcessorSessionFactory(
|
||||
ProcessingEnvironment processingEnvironment,
|
||||
|
@ -100,23 +99,7 @@ public abstract class ProcessorSessionFactory extends MockSessionFactory {
|
|||
typeUtil = processingEnvironment.getTypeUtils();
|
||||
filer = processingEnvironment.getFiler();
|
||||
this.entityNameMappings = entityNameMappings;
|
||||
final Map<String, Set<String>> allowedEnumLiteralsToEnumTypeNames = new HashMap<>( enumTypesByValue.size() << 2 );
|
||||
for ( Map.Entry<String, Set<String>> entry : enumTypesByValue.entrySet() ) {
|
||||
final String enumConstantName = entry.getKey();
|
||||
for ( String enumClassName : entry.getValue() ) {
|
||||
final TypeElement enumTypeElement = elementUtil.getTypeElement( enumClassName );
|
||||
if ( enumTypeElement != null ) {
|
||||
addAllowedEnumLiteralsToEnumTypesMap(
|
||||
allowedEnumLiteralsToEnumTypeNames,
|
||||
enumConstantName,
|
||||
enumTypeElement.getSimpleName().toString(),
|
||||
elementUtil.getBinaryName( enumTypeElement ).toString(),
|
||||
enumClassName
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.allowedEnumLiteralsToEnumTypeNames = allowedEnumLiteralsToEnumTypeNames;
|
||||
this.enumTypesByValue = enumTypesByValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -233,7 +216,7 @@ public abstract class ProcessorSessionFactory extends MockSessionFactory {
|
|||
|
||||
@Override @Nullable
|
||||
Set<String> getEnumTypesForValue(String value) {
|
||||
final Set<String> result = allowedEnumLiteralsToEnumTypeNames.get( value);
|
||||
final Set<String> result = enumTypesByValue.get(value);
|
||||
if ( result != null ) {
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue