remove some uses of java.util.Properties

This commit is contained in:
Gavin King 2022-10-27 23:29:09 +02:00
parent 239fc9a835
commit 5ea136781c
6 changed files with 58 additions and 44 deletions

View File

@ -14,7 +14,6 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Properties;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -457,9 +456,9 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector
} }
private CollectionTypeRegistrationDescriptor toDescriptor(CollectionTypeRegistration registrationAnnotation) { private CollectionTypeRegistrationDescriptor toDescriptor(CollectionTypeRegistration registrationAnnotation) {
final Properties parameters; final Map<String,String> parameters;
if ( registrationAnnotation.parameters().length > 0 ) { if ( registrationAnnotation.parameters().length > 0 ) {
parameters = new Properties(); parameters = new HashMap<>();
for ( Parameter parameter : registrationAnnotation.parameters() ) { for ( Parameter parameter : registrationAnnotation.parameters() ) {
parameters.put( parameter.name(), parameter.value() ); parameters.put( parameter.name(), parameter.value() );
} }

View File

@ -764,24 +764,24 @@ public class ModelBinder {
String unsavedValue, String unsavedValue,
SimpleValue identifierValue) { SimpleValue identifierValue) {
if ( generator != null ) { if ( generator != null ) {
String generatorName = generator.getStrategy(); final Map<String,Object> params = new HashMap<>();
Properties params = new Properties();
// see if the specified generator name matches a registered <identifier-generator/> // see if the specified generator name matches a registered <identifier-generator/>
IdentifierGeneratorDefinition generatorDef = sourceDocument.getMetadataCollector().getIdentifierGenerator( generatorName ); String generatorName = generator.getStrategy();
final IdentifierGeneratorDefinition generatorDef = sourceDocument.getMetadataCollector()
.getIdentifierGenerator( generatorName );
if ( generatorDef != null ) { if ( generatorDef != null ) {
generatorName = generatorDef.getStrategy(); generatorName = generatorDef.getStrategy();
params.putAll( generatorDef.getParameters() ); params.putAll( generatorDef.getParameters() );
} }
identifierValue.setIdentifierGeneratorStrategy( generatorName ); identifierValue.setIdentifierGeneratorStrategy( generatorName );
// YUCK! but cannot think of a clean way to do this given the string-config based scheme // YUCK! but cannot think of a clean way to do this given the string-config based scheme
params.put( PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER, objectNameNormalizer); params.put( PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER, objectNameNormalizer );
params.putAll( generator.getParameters() ); params.putAll( generator.getParameters() );
identifierValue.setIdentifierGeneratorProperties( params ); identifierValue.setIdentifierGeneratorParameters( params );
} }
identifierValue.getTable().setIdentifierValue( identifierValue ); identifierValue.getTable().setIdentifierValue( identifierValue );

View File

@ -362,9 +362,9 @@ public interface InFlightMetadataCollector extends Mapping, MetadataImplementor
class CollectionTypeRegistrationDescriptor { class CollectionTypeRegistrationDescriptor {
private final Class<? extends UserCollectionType> implementation; private final Class<? extends UserCollectionType> implementation;
private final Properties parameters; private final Map<String,String> parameters;
public CollectionTypeRegistrationDescriptor(Class<? extends UserCollectionType> implementation, Properties parameters) { public CollectionTypeRegistrationDescriptor(Class<? extends UserCollectionType> implementation, Map<String,String> parameters) {
this.implementation = implementation; this.implementation = implementation;
this.parameters = parameters; this.parameters = parameters;
} }
@ -373,7 +373,7 @@ public interface InFlightMetadataCollector extends Mapping, MetadataImplementor
return implementation; return implementation;
} }
public Properties getParameters() { public Map<String,String> getParameters() {
return parameters; return parameters;
} }
} }

View File

@ -17,7 +17,6 @@ import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties;
import java.util.Set; import java.util.Set;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -730,13 +729,13 @@ public class BinderHelper {
//generator settings //generator settings
id.setIdentifierGeneratorStrategy( generatorType ); id.setIdentifierGeneratorStrategy( generatorType );
Properties params = new Properties(); final Map<String,Object> params = new HashMap<>();
//always settable //always settable
params.setProperty( PersistentIdentifierGenerator.TABLE, table.getName() ); params.put( PersistentIdentifierGenerator.TABLE, table.getName() );
if ( id.getColumnSpan() == 1 ) { if ( id.getColumnSpan() == 1 ) {
params.setProperty( PersistentIdentifierGenerator.PK, id.getColumns().get(0).getName() ); params.put( PersistentIdentifierGenerator.PK, id.getColumns().get(0).getName() );
} }
// YUCK! but cannot think of a clean way to do this given the string-config based scheme // YUCK! but cannot think of a clean way to do this given the string-config based scheme
params.put( PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER, buildingContext.getObjectNameNormalizer() ); params.put( PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER, buildingContext.getObjectNameNormalizer() );
@ -764,17 +763,16 @@ public class BinderHelper {
id.setIdentifierGeneratorStrategy( identifierGeneratorStrategy ); id.setIdentifierGeneratorStrategy( identifierGeneratorStrategy );
} }
//checkIfMatchingGenerator(gen, generatorType, generatorName); //checkIfMatchingGenerator(gen, generatorType, generatorName);
for ( Map.Entry<?,?> elt : gen.getParameters().entrySet() ) { for ( Map.Entry<String,String> elt : gen.getParameters().entrySet() ) {
if ( elt.getKey() == null ) { if ( elt.getKey() != null ) {
continue; params.put( elt.getKey(), elt.getValue() );
} }
params.setProperty( (String) elt.getKey(), (String) elt.getValue() );
} }
} }
if ( "assigned".equals( generatorType ) ) { if ( "assigned".equals( generatorType ) ) {
id.setNullValue( "undefined" ); id.setNullValue( "undefined" );
} }
id.setIdentifierGeneratorProperties( params ); id.setIdentifierGeneratorParameters( params );
} }
/** /**

View File

@ -233,7 +233,7 @@ public abstract class CollectionBinder {
private SortComparator comparatorSort; private SortComparator comparatorSort;
private String explicitType; private String explicitType;
private final Properties explicitTypeParameters = new Properties(); private final Map<String,String> explicitTypeParameters = new HashMap<>();
protected CollectionBinder( protected CollectionBinder(
Supplier<ManagedBean<? extends UserCollectionType>> customTypeBeanResolver, Supplier<ManagedBean<? extends UserCollectionType>> customTypeBeanResolver,
@ -758,7 +758,7 @@ public abstract class CollectionBinder {
// todo (6.0) - technically, these should no longer be needed // todo (6.0) - technically, these should no longer be needed
binder.explicitType = typeAnnotation.type().getName(); binder.explicitType = typeAnnotation.type().getName();
for ( Parameter param : typeAnnotation.parameters() ) { for ( Parameter param : typeAnnotation.parameters() ) {
binder.explicitTypeParameters.setProperty( param.name(), param.value() ); binder.explicitTypeParameters.put( param.name(), param.value() );
} }
} }
else { else {
@ -798,7 +798,7 @@ public abstract class CollectionBinder {
private static ManagedBean<? extends UserCollectionType> createCustomType( private static ManagedBean<? extends UserCollectionType> createCustomType(
String role, String role,
Class<? extends UserCollectionType> implementation, Class<? extends UserCollectionType> implementation,
Properties parameters, Map<String,String> parameters,
MetadataBuildingContext buildingContext) { MetadataBuildingContext buildingContext) {
final StandardServiceRegistry serviceRegistry = buildingContext.getBuildingOptions().getServiceRegistry(); final StandardServiceRegistry serviceRegistry = buildingContext.getBuildingOptions().getServiceRegistry();
final ManagedBeanRegistry beanRegistry = serviceRegistry.getService( ManagedBeanRegistry.class ); final ManagedBeanRegistry beanRegistry = serviceRegistry.getService( ManagedBeanRegistry.class );
@ -812,7 +812,9 @@ public abstract class CollectionBinder {
// a separate bean instance which means uniquely naming it // a separate bean instance which means uniquely naming it
final ManagedBean<? extends UserCollectionType> typeBean = beanRegistry.getBean( role, implementation ); final ManagedBean<? extends UserCollectionType> typeBean = beanRegistry.getBean( role, implementation );
final UserCollectionType type = typeBean.getBeanInstance(); final UserCollectionType type = typeBean.getBeanInstance();
( (ParameterizedType) type ).setParameterValues( parameters ); final Properties properties = new Properties();
properties.putAll( parameters );
( (ParameterizedType) type ).setParameterValues( properties );
return typeBean; return typeBean;
} }
else { else {

View File

@ -10,6 +10,7 @@ import java.io.Serializable;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.sql.Types; import java.sql.Types;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
@ -21,6 +22,7 @@ import jakarta.persistence.AttributeConverter;
import org.hibernate.AssertionFailure; import org.hibernate.AssertionFailure;
import org.hibernate.FetchMode; import org.hibernate.FetchMode;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.Remove;
import org.hibernate.TimeZoneStorageStrategy; import org.hibernate.TimeZoneStorageStrategy;
import org.hibernate.annotations.common.reflection.XProperty; import org.hibernate.annotations.common.reflection.XProperty;
import org.hibernate.boot.model.convert.internal.ClassBasedConverterDescriptor; import org.hibernate.boot.model.convert.internal.ClassBasedConverterDescriptor;
@ -85,7 +87,7 @@ public abstract class SimpleValue implements KeyValue {
private boolean isNationalized; private boolean isNationalized;
private boolean isLob; private boolean isLob;
private Properties identifierGeneratorProperties; private Map<String,Object> identifierGeneratorParameters;
private String identifierGeneratorStrategy = DEFAULT_ID_GEN_STRATEGY; private String identifierGeneratorStrategy = DEFAULT_ID_GEN_STRATEGY;
private String nullValue; private String nullValue;
@ -120,9 +122,7 @@ public abstract class SimpleValue implements KeyValue {
this.isVersion = original.isVersion; this.isVersion = original.isVersion;
this.isNationalized = original.isNationalized; this.isNationalized = original.isNationalized;
this.isLob = original.isLob; this.isLob = original.isLob;
this.identifierGeneratorProperties = original.identifierGeneratorProperties == null this.identifierGeneratorParameters = original.identifierGeneratorParameters;
? null
: new Properties( original.identifierGeneratorProperties );
this.identifierGeneratorStrategy = original.identifierGeneratorStrategy; this.identifierGeneratorStrategy = original.identifierGeneratorStrategy;
this.nullValue = original.nullValue; this.nullValue = original.nullValue;
this.table = original.table; this.table = original.table;
@ -494,8 +494,8 @@ public abstract class SimpleValue implements KeyValue {
params.setProperty( OptimizableGenerator.IMPLICIT_NAME_BASE, tableName ); params.setProperty( OptimizableGenerator.IMPLICIT_NAME_BASE, tableName );
} }
if ( identifierGeneratorProperties != null ) { if ( identifierGeneratorParameters != null ) {
params.putAll( identifierGeneratorProperties ); params.putAll(identifierGeneratorParameters);
} }
// TODO : we should pass along all settings once "config lifecycle" is hashed out... // TODO : we should pass along all settings once "config lifecycle" is hashed out...
@ -556,28 +556,43 @@ public abstract class SimpleValue implements KeyValue {
); );
} }
public Map<String, Object> getIdentifierGeneratorParameters() {
return identifierGeneratorParameters;
}
public void setIdentifierGeneratorParameters(Map<String, Object> identifierGeneratorParameters) {
this.identifierGeneratorParameters = identifierGeneratorParameters;
}
/**
* @deprecated use {@link #getIdentifierGeneratorParameters()}
*/
@Deprecated @Remove
public Properties getIdentifierGeneratorProperties() { public Properties getIdentifierGeneratorProperties() {
return identifierGeneratorProperties;
}
/**
* Sets the identifierGeneratorProperties.
* @param identifierGeneratorProperties The identifierGeneratorProperties to set
*/
public void setIdentifierGeneratorProperties(Properties identifierGeneratorProperties) {
this.identifierGeneratorProperties = identifierGeneratorProperties;
}
/**
* Sets the identifierGeneratorProperties.
* @param identifierGeneratorProperties The identifierGeneratorProperties to set
*/
public void setIdentifierGeneratorProperties(Map identifierGeneratorProperties) {
if ( identifierGeneratorProperties != null ) {
Properties properties = new Properties(); Properties properties = new Properties();
properties.putAll( identifierGeneratorProperties ); properties.putAll( identifierGeneratorParameters );
setIdentifierGeneratorProperties( properties ); return properties;
} }
/**
* @deprecated use {@link #setIdentifierGeneratorParameters(Map)}
*/
@Deprecated @Remove
public void setIdentifierGeneratorProperties(Properties identifierGeneratorProperties) {
this.identifierGeneratorParameters = new HashMap<>();
identifierGeneratorProperties.forEach((key, value) -> {
if (key instanceof String) {
identifierGeneratorParameters.put((String) key, value);
}
});
}
/**
* @deprecated use {@link #setIdentifierGeneratorParameters(Map)}
*/
@Deprecated @Remove
public void setIdentifierGeneratorProperties(Map<String,Object> identifierGeneratorProperties) {
this.identifierGeneratorParameters = identifierGeneratorProperties;
} }
public String getNullValue() { public String getNullValue() {
@ -634,7 +649,7 @@ public abstract class SimpleValue implements KeyValue {
} }
public boolean isNullable() { public boolean isNullable() {
for (Selectable selectable : getSelectables()) { for ( Selectable selectable : getSelectables() ) {
if ( selectable instanceof Formula ) { if ( selectable instanceof Formula ) {
// if there are *any* formulas, then the Value overall is // if there are *any* formulas, then the Value overall is
// considered nullable // considered nullable