fix some warnings

This commit is contained in:
Gavin King 2024-09-22 17:29:13 +02:00
parent ec0f78d8c7
commit c863838e72
4 changed files with 52 additions and 66 deletions

View File

@ -112,12 +112,9 @@ public abstract class AbstractGraph<J> extends AbstractGraphNode<J> implements G
@Override @Override
public void visitAttributeNodes(Consumer<AttributeNodeImplementor<?>> consumer) { public void visitAttributeNodes(Consumer<AttributeNodeImplementor<?>> consumer) {
if ( attrNodeMap == null ) { if ( attrNodeMap != null ) {
return; attrNodeMap.forEach( (attribute, nodeImplementor) -> consumer.accept( nodeImplementor ) );
} }
attrNodeMap.forEach( (persistentAttribute, attributeNodeImplementor) -> {
consumer.accept( attributeNodeImplementor );
} );
} }
@Override @Override
@ -125,9 +122,11 @@ public abstract class AbstractGraph<J> extends AbstractGraphNode<J> implements G
if ( attrNodeMap == null ) { if ( attrNodeMap == null ) {
return emptyList(); return emptyList();
} }
final List<AttributeNode<?>> result = new ArrayList<>(); else {
visitAttributeNodes( result::add ); final List<AttributeNode<?>> result = new ArrayList<>();
return result; visitAttributeNodes( result::add );
return result;
}
} }
@Override @Override
@ -209,8 +208,8 @@ public abstract class AbstractGraph<J> extends AbstractGraphNode<J> implements G
} }
} }
@Override @Override @SafeVarargs
public void addAttributeNodes(Attribute<? super J, ?>... attributes) { public final void addAttributeNodes(Attribute<? super J, ?>... attributes) {
for ( int i = 0; i < attributes.length; i++ ) { for ( int i = 0; i < attributes.length; i++ ) {
addAttributeNode( attributes[i] ); addAttributeNode( attributes[i] );
} }

View File

@ -231,16 +231,12 @@ public class AttributeFactory {
} }
public static <Y> DomainType<Y> determineSimpleType(ValueContext typeContext, MetadataContext context) { public static <Y> DomainType<Y> determineSimpleType(ValueContext typeContext, MetadataContext context) {
switch ( typeContext.getValueClassification() ) { return switch ( typeContext.getValueClassification() ) {
case BASIC: case BASIC -> basicDomainType( typeContext, context );
return basicDomainType( typeContext, context ); case ENTITY -> entityDomainType (typeContext, context );
case ENTITY: case EMBEDDABLE -> embeddableDomainType( typeContext, context );
return entityDomainType( typeContext, context ); default -> throw new AssertionFailure( "Unknown type : " + typeContext.getValueClassification() );
case EMBEDDABLE: };
return embeddableDomainType( typeContext, context );
default:
throw new AssertionFailure( "Unknown type : " + typeContext.getValueClassification() );
}
} }
private static <Y> EmbeddableDomainType<Y> embeddableDomainType(ValueContext typeContext, MetadataContext context) { private static <Y> EmbeddableDomainType<Y> embeddableDomainType(ValueContext typeContext, MetadataContext context) {
@ -339,8 +335,7 @@ public class AttributeFactory {
private static <Y> DomainType<Y> entityDomainType(ValueContext typeContext, MetadataContext context) { private static <Y> DomainType<Y> entityDomainType(ValueContext typeContext, MetadataContext context) {
final org.hibernate.type.Type type = typeContext.getHibernateValue().getType(); final org.hibernate.type.Type type = typeContext.getHibernateValue().getType();
if ( type instanceof EntityType ) { if ( type instanceof EntityType entityType ) {
final EntityType entityType = (EntityType) type;
final IdentifiableDomainType<Y> domainType = final IdentifiableDomainType<Y> domainType =
context.locateIdentifiableType( entityType.getAssociatedEntityName() ); context.locateIdentifiableType( entityType.getAssociatedEntityName() );
if ( domainType == null ) { if ( domainType == null ) {
@ -378,11 +373,11 @@ public class AttributeFactory {
} }
else { else {
final org.hibernate.type.Type type = hibernateValue.getType(); final org.hibernate.type.Type type = hibernateValue.getType();
if ( type instanceof BasicPluralType<?, ?> ) { if ( type instanceof BasicPluralType<?, ?> pluralType ) {
final JavaType<?> javaTypeDescriptor = ( (BasicPluralType<?, ?>) type ).getElementType() if ( pluralType.getElementType().getJavaTypeDescriptor()
.getJavaTypeDescriptor(); instanceof EmbeddableAggregateJavaType<?> ) {
if ( javaTypeDescriptor instanceof EmbeddableAggregateJavaType<?> ) { final AggregateColumn aggregateColumn =
final AggregateColumn aggregateColumn = (AggregateColumn) hibernateValue.getColumns().get( 0 ); (AggregateColumn) hibernateValue.getColumns().get( 0 );
classEmbeddableType( context, aggregateColumn.getComponent() ); classEmbeddableType( context, aggregateColumn.getComponent() );
} }
} }
@ -483,18 +478,15 @@ public class AttributeFactory {
} }
else if ( type instanceof CollectionType ) { else if ( type instanceof CollectionType ) {
// collection // collection
if ( value instanceof Collection ) { if ( value instanceof Collection collection ) {
final Collection collValue = (Collection) value; final org.hibernate.type.Type elementType = collection.getElement().getType();
final Value elementValue = collValue.getElement();
final org.hibernate.type.Type elementType = elementValue.getType();
final boolean isManyToMany = isManyToMany( member ); final boolean isManyToMany = isManyToMany( member );
return new PluralAttributeMetadataImpl<>( return new PluralAttributeMetadataImpl<>(
propertyMapping, propertyMapping,
attributeContext.getOwnerType(), attributeContext.getOwnerType(),
member, member,
collectionClassification( elementType, elementValue, isManyToMany ), collectionClassification( elementType, isManyToMany ),
elementClassification( elementType, elementValue, isManyToMany ), elementClassification( elementType, isManyToMany ),
indexClassification( value ), indexClassification( value ),
context context
); );
@ -544,9 +536,8 @@ public class AttributeFactory {
} }
private static AttributeClassification indexClassification(Value value) { private static AttributeClassification indexClassification(Value value) {
if ( value instanceof Map ) { if ( value instanceof Map map ) {
final Value keyValue = ( (Map) value).getIndex(); return keyClassification( map.getIndex().getType() );
return keyClassification( keyValue.getType(), keyValue );
} }
else if ( value instanceof List ) { else if ( value instanceof List ) {
return AttributeClassification.BASIC; return AttributeClassification.BASIC;
@ -557,7 +548,7 @@ public class AttributeFactory {
} }
private static AttributeClassification elementClassification( private static AttributeClassification elementClassification(
org.hibernate.type.Type elementType, Value elementValue, boolean isManyToMany) { org.hibernate.type.Type elementType, boolean isManyToMany) {
// First, determine the type of the elements and use that to help determine the // First, determine the type of the elements and use that to help determine the
// collection type // collection type
if ( elementType instanceof AnyType ) { if ( elementType instanceof AnyType ) {
@ -577,7 +568,7 @@ public class AttributeFactory {
} }
private static AttributeClassification collectionClassification( private static AttributeClassification collectionClassification(
org.hibernate.type.Type elementType, Value elementValue, boolean isManyToMany) { org.hibernate.type.Type elementType, boolean isManyToMany) {
if ( elementType instanceof EntityType ) { if ( elementType instanceof EntityType ) {
return isManyToMany ? return isManyToMany ?
AttributeClassification.MANY_TO_MANY : AttributeClassification.MANY_TO_MANY :
@ -588,7 +579,7 @@ public class AttributeFactory {
} }
} }
private static AttributeClassification keyClassification(org.hibernate.type.Type keyType, Value keyValue) { private static AttributeClassification keyClassification(org.hibernate.type.Type keyType) {
if ( keyType instanceof AnyType ) { if ( keyType instanceof AnyType ) {
return AttributeClassification.ANY; return AttributeClassification.ANY;
} }
@ -604,47 +595,48 @@ public class AttributeFactory {
} }
public static AttributeClassification determineSingularAssociationClassification(Member member) { public static AttributeClassification determineSingularAssociationClassification(Member member) {
if ( member instanceof Field ) { if ( member instanceof Field field ) {
return ( (Field) member ).getAnnotation( OneToOne.class ) != null return field.getAnnotation( OneToOne.class ) != null
? AttributeClassification.ONE_TO_ONE ? AttributeClassification.ONE_TO_ONE
: AttributeClassification.MANY_TO_ONE; : AttributeClassification.MANY_TO_ONE;
} }
else if ( member instanceof MapMember ) { else if ( member instanceof MapMember ) {
return AttributeClassification.MANY_TO_ONE; // curious to see how this works for non-annotated methods return AttributeClassification.MANY_TO_ONE; // curious to see how this works for non-annotated methods
} }
else { else if ( member instanceof Method method) {
return ( (Method) member ).getAnnotation( OneToOne.class ) != null return method.getAnnotation( OneToOne.class ) != null
? AttributeClassification.ONE_TO_ONE ? AttributeClassification.ONE_TO_ONE
: AttributeClassification.MANY_TO_ONE; : AttributeClassification.MANY_TO_ONE;
} }
else {
throw new AssertionFailure( "Unexpected member type" );
}
} }
public static ParameterizedType getSignatureType(Member member) { public static ParameterizedType getSignatureType(Member member) {
final java.lang.reflect.Type type; final java.lang.reflect.Type type;
if ( member instanceof Field ) { if ( member instanceof Field field ) {
type = ( (Field) member ).getGenericType(); type = field.getGenericType();
} }
else if ( member instanceof Method ) { else if ( member instanceof Method method ) {
type = ( (Method) member ).getGenericReturnType(); type = method.getGenericReturnType();
}
else if ( member instanceof MapMember mapMember ) {
type = mapMember.getType();
} }
else { else {
type = ( (MapMember) member ).getType(); throw new AssertionFailure( "Unexpected member type" );
} }
//this is a raw type //this is a raw type
if ( type instanceof Class ) { return type instanceof Class ? null : (ParameterizedType) type;
return null;
}
else {
return (ParameterizedType) type;
}
} }
public static boolean isManyToMany(Member member) { public static boolean isManyToMany(Member member) {
if ( member instanceof Field ) { if ( member instanceof Field field ) {
return ( (Field) member ).getAnnotation( ManyToMany.class ) != null; return field.getAnnotation( ManyToMany.class ) != null;
} }
else if ( member instanceof Method ) { else if ( member instanceof Method method ) {
return ( (Method) member ).getAnnotation( ManyToMany.class ) != null; return method.getAnnotation( ManyToMany.class ) != null;
} }
else { else {
return false; return false;

View File

@ -74,15 +74,10 @@ public abstract class AbstractIdentifiableType<J>
} }
@Override @Override
protected InFlightAccessImpl createInFlightAccess() { protected InFlightAccess<J> createInFlightAccess() {
return new InFlightAccessImpl( super.createInFlightAccess() ); return new InFlightAccessImpl( super.createInFlightAccess() );
} }
@Override
public InFlightAccessImpl getInFlightAccess() {
return (InFlightAccessImpl) super.getInFlightAccess();
}
@Override @Override
public SqmPathSource<?> getIdentifierDescriptor() { public SqmPathSource<?> getIdentifierDescriptor() {
return identifierDescriptor; return identifierDescriptor;

View File

@ -599,7 +599,7 @@ public class JpaMetamodelImpl implements JpaMetamodelImplementor, Serializable {
Collection<NamedEntityGraphDefinition> namedEntityGraphDefinitions, Collection<NamedEntityGraphDefinition> namedEntityGraphDefinitions,
RuntimeModelCreationContext runtimeModelCreationContext) { RuntimeModelCreationContext runtimeModelCreationContext) {
bootMetamodel.getImports() bootMetamodel.getImports()
.forEach( ( k, v ) -> this.nameToImportMap.put( k, new ImportInfo<>( v, null ) ) ); .forEach( (key, value) -> this.nameToImportMap.put( key, new ImportInfo<>( value, null ) ) );
this.entityProxyInterfaceMap.putAll( entityProxyInterfaceMap ); this.entityProxyInterfaceMap.putAll( entityProxyInterfaceMap );
final MetadataContext context = new MetadataContext( final MetadataContext context = new MetadataContext(