Skip to content

Commit

Permalink
fix some more warnings and add static imports
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinking committed Jan 24, 2025
1 parent 66a92c2 commit efb8b2e
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
Expand All @@ -37,6 +36,9 @@
import org.hibernate.service.ServiceRegistry;
import org.hibernate.type.SerializationException;

import static java.util.Collections.addAll;
import static java.util.Collections.emptyList;
import static java.util.Collections.emptySet;
import static org.hibernate.internal.util.collections.CollectionHelper.arrayList;

/**
Expand Down Expand Up @@ -132,7 +134,7 @@ public XmlMappingBinderAccess getXmlMappingBinderAccess() {
@Deprecated(since = "7.0")
public List<Binding<JaxbBindableMappingDescriptor>> getXmlBindings() {
if ( mappingXmlBindings == null && hbmXmlBindings == null ) {
return Collections.emptyList();
return emptyList();
}

if ( hbmXmlBindings == null ) {
Expand All @@ -143,30 +145,31 @@ public List<Binding<JaxbBindableMappingDescriptor>> getXmlBindings() {
return (List) hbmXmlBindings;
}

final ArrayList<Binding<JaxbBindableMappingDescriptor>> combined = arrayList( mappingXmlBindings.size() + hbmXmlBindings.size() );
final ArrayList<Binding<JaxbBindableMappingDescriptor>> combined =
arrayList( mappingXmlBindings.size() + hbmXmlBindings.size() );
combined.addAll( (List) mappingXmlBindings );
combined.addAll( (List) hbmXmlBindings );
return combined;
}

public List<Binding<JaxbEntityMappingsImpl>> getMappingXmlBindings() {
return mappingXmlBindings == null ? Collections.emptyList() : mappingXmlBindings;
return mappingXmlBindings == null ? emptyList() : mappingXmlBindings;
}

public List<Binding<JaxbHbmHibernateMapping>> getHbmXmlBindings() {
return hbmXmlBindings == null ? Collections.emptyList() : hbmXmlBindings;
return hbmXmlBindings == null ? emptyList() : hbmXmlBindings;
}

public Collection<String> getAnnotatedPackages() {
return annotatedPackages == null ? Collections.emptySet() : annotatedPackages;
return annotatedPackages == null ? emptySet() : annotatedPackages;
}

public Collection<Class<?>> getAnnotatedClasses() {
return annotatedClasses == null ? Collections.emptySet() : annotatedClasses;
return annotatedClasses == null ? emptySet() : annotatedClasses;
}

public Collection<String> getAnnotatedClassNames() {
return annotatedClassNames == null ? Collections.emptySet() : annotatedClassNames;
return annotatedClassNames == null ? emptySet() : annotatedClassNames;
}

public Map<String,Class<?>> getExtraQueryImports() {
Expand Down Expand Up @@ -269,7 +272,7 @@ public MetadataSources addAnnotatedClasses(Class<?>... annotatedClasses) {
if ( this.annotatedClasses == null ) {
this.annotatedClasses = new LinkedHashSet<>();
}
Collections.addAll( this.annotatedClasses, annotatedClasses );
addAll( this.annotatedClasses, annotatedClasses );
}
return this;
}
Expand Down Expand Up @@ -297,7 +300,7 @@ public MetadataSources addAnnotatedClassName(String annotatedClassName) {
*/
public MetadataSources addAnnotatedClassNames(String... annotatedClassNames) {
if ( annotatedClassNames != null && annotatedClassNames.length > 0 ) {
Collections.addAll( this.annotatedClassNames, annotatedClassNames );
addAll( this.annotatedClassNames, annotatedClassNames );
}
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
import java.util.Map;
import java.util.Set;

import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.type.descriptor.converter.spi.BasicValueConverter;
import org.hibernate.type.descriptor.java.EnumJavaType;
import org.hibernate.type.descriptor.java.JavaType;

import org.checkerframework.checker.nullness.qual.Nullable;

import static org.hibernate.internal.util.ReflectHelper.ensureAccessibility;
import static org.hibernate.internal.util.collections.CollectionHelper.mapOfSize;

/**
* @author Steve Ebersole
*/
Expand All @@ -33,14 +34,13 @@ public EnumeratedValueConverter(
this.enumJavaType = enumJavaType;
this.relationalJavaType = relationalJavaType;

ReflectHelper.ensureAccessibility( valueField );
ensureAccessibility( valueField );

final Class<E> enumJavaTypeClass = enumJavaType.getJavaTypeClass();
final E[] enumConstants = enumJavaTypeClass.getEnumConstants();
relationalToEnumMap = CollectionHelper.mapOfSize( enumConstants.length );
enumToRelationalMap = CollectionHelper.mapOfSize( enumConstants.length );
for ( int i = 0; i < enumConstants.length; i++ ) {
final E enumConstant = enumConstants[i];
relationalToEnumMap = mapOfSize( enumConstants.length );
enumToRelationalMap = mapOfSize( enumConstants.length );
for ( final E enumConstant : enumConstants ) {
try {
//noinspection unchecked
final R relationalValue = (R) valueField.get( enumConstant );
Expand All @@ -60,18 +60,12 @@ public Set<R> getRelationalValueSet() {

@Override
public @Nullable E toDomainValue(@Nullable R relationalForm) {
if ( relationalForm == null ) {
return null;
}
return relationalToEnumMap.get( relationalForm );
return relationalForm == null ? null : relationalToEnumMap.get( relationalForm );
}

@Override
public @Nullable R toRelationalValue(@Nullable E domainForm) {
if ( domainForm == null ) {
return null;
}
return enumToRelationalMap.get( domainForm );
return domainForm == null ? null : enumToRelationalMap.get( domainForm );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@

import jakarta.persistence.AttributeConverter;

import static java.util.Collections.unmodifiableCollection;
import static java.util.Collections.unmodifiableSet;


/**
* @author Steve Ebersole
*/
public class ManagedResourcesImpl implements ManagedResources {
private final Map<Class<? extends AttributeConverter>, ConverterDescriptor> attributeConverterDescriptorMap = new HashMap<>();
private final Map<Class<? extends AttributeConverter<?,?>>, ConverterDescriptor> attributeConverterDescriptorMap = new HashMap<>();
private final Set<Class<?>> annotatedClassReferences = new LinkedHashSet<>();
private final Set<String> annotatedClassNames = new LinkedHashSet<>();
private final Set<String> annotatedPackageNames = new LinkedHashSet<>();
Expand Down Expand Up @@ -68,22 +71,22 @@ public ManagedResourcesImpl() {

@Override
public Collection<ConverterDescriptor> getAttributeConverterDescriptors() {
return Collections.unmodifiableCollection( attributeConverterDescriptorMap.values() );
return unmodifiableCollection( attributeConverterDescriptorMap.values() );
}

@Override
public Collection<Class<?>> getAnnotatedClassReferences() {
return Collections.unmodifiableSet( annotatedClassReferences );
return unmodifiableSet( annotatedClassReferences );
}

@Override
public Collection<String> getAnnotatedClassNames() {
return Collections.unmodifiableSet( annotatedClassNames );
return unmodifiableSet( annotatedClassNames );
}

@Override
public Collection<String> getAnnotatedPackageNames() {
return Collections.unmodifiableSet( annotatedPackageNames );
return unmodifiableSet( annotatedPackageNames );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.hibernate.dialect.Dialect;
import org.hibernate.mapping.BasicValue;
import org.hibernate.metamodel.mapping.JdbcMapping;
import org.hibernate.type.BasicTypeRegistry;
import org.hibernate.type.descriptor.converter.spi.BasicValueConverter;
import org.hibernate.type.BasicType;
import org.hibernate.type.descriptor.java.BasicJavaType;
Expand All @@ -26,26 +27,24 @@
/**
* @author Steve Ebersole
*/
@SuppressWarnings("rawtypes")
public class VersionResolution<E> implements BasicValue.Resolution<E> {

// todo (6.0) : support explicit JTD?
// todo (6.0) : support explicit STD?

@SuppressWarnings({"rawtypes", "unchecked"})
public static <E> VersionResolution<E> from(
Function<TypeConfiguration, java.lang.reflect.Type> implicitJavaTypeAccess,
TimeZoneStorageType timeZoneStorageType,
@SuppressWarnings("unused") MetadataBuildingContext context) {
MetadataBuildingContext context) {

// todo (6.0) : add support for Dialect-specific interpretation?

final TypeConfiguration typeConfiguration = context.getBootstrapContext().getTypeConfiguration();
final java.lang.reflect.Type implicitJavaType = implicitJavaTypeAccess.apply( typeConfiguration );
final JavaType registered = typeConfiguration.getJavaTypeRegistry().resolveDescriptor( implicitJavaType );
final BasicJavaType jtd = (BasicJavaType) registered;
final JavaType<E> registered = typeConfiguration.getJavaTypeRegistry().resolveDescriptor( implicitJavaType );
final BasicJavaType<E> basicJavaType = (BasicJavaType<E>) registered;

final JdbcType recommendedJdbcType = jtd.getRecommendedJdbcType(
final JdbcType recommendedJdbcType = basicJavaType.getRecommendedJdbcType(
new JdbcTypeIndicators() {
@Override
public TypeConfiguration getTypeConfiguration() {
Expand Down Expand Up @@ -105,25 +104,26 @@ public Dialect getDialect() {
}
);

final BasicType<?> basicType = typeConfiguration.getBasicTypeRegistry().resolve( jtd, recommendedJdbcType );
final BasicType legacyType = typeConfiguration.getBasicTypeRegistry().getRegisteredType( jtd.getJavaType() );
final BasicTypeRegistry basicTypeRegistry = typeConfiguration.getBasicTypeRegistry();
final BasicType<?> basicType = basicTypeRegistry.resolve( basicJavaType, recommendedJdbcType );
final BasicType<E> legacyType = basicTypeRegistry.getRegisteredType( basicJavaType.getJavaType() );

assert legacyType.getJdbcType().getDefaultSqlTypeCode() == recommendedJdbcType.getDefaultSqlTypeCode();

return new VersionResolution<>( jtd, recommendedJdbcType, basicType, legacyType );
return new VersionResolution<>( basicJavaType, recommendedJdbcType, basicType, legacyType );
}

private final JavaType javaType;
private final JavaType<E> javaType;
private final JdbcType jdbcType;

private final JdbcMapping jdbcMapping;
private final BasicType legacyType;
private final BasicType<E> legacyType;

public VersionResolution(
JavaType javaType,
JavaType<E> javaType,
JdbcType jdbcType,
JdbcMapping jdbcMapping,
BasicType legacyType) {
BasicType<E> legacyType) {
this.javaType = javaType;
this.jdbcType = jdbcType;
this.jdbcMapping = jdbcMapping;
Expand All @@ -136,13 +136,11 @@ public JdbcMapping getJdbcMapping() {
}

@Override
@SuppressWarnings("unchecked")
public BasicType getLegacyResolvedBasicType() {
public BasicType<E> getLegacyResolvedBasicType() {
return legacyType;
}

@Override
@SuppressWarnings("unchecked")
public JavaType<E> getDomainJavaType() {
return javaType;
}
Expand All @@ -158,7 +156,7 @@ public JdbcType getJdbcType() {
}

@Override
public BasicValueConverter<E,E> getValueConverter() {
public BasicValueConverter<E,?> getValueConverter() {
return legacyType.getValueConverter();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ public BasicValue(MetadataBuildingContext buildingContext, Table table) {
public BasicValue(BasicValue original) {
super( original );
this.explicitTypeName = original.explicitTypeName;
this.explicitLocalTypeParams = original.explicitLocalTypeParams == null
? null
: new HashMap<>(original.explicitLocalTypeParams);
this.explicitLocalTypeParams =
original.explicitLocalTypeParams == null ? null
: new HashMap<>( original.explicitLocalTypeParams );
this.explicitJavaTypeAccess = original.explicitJavaTypeAccess;
this.explicitJdbcTypeAccess = original.explicitJdbcTypeAccess;
this.explicitMutabilityPlanAccess = original.explicitMutabilityPlanAccess;
Expand Down

0 comments on commit efb8b2e

Please sign in to comment.