Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class SessionFactoryObserverForNamedQueryValidation implements SessionFactoryObs

@Override
public void sessionFactoryCreated(SessionFactory factory) {
final SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) factory;
final QueryEngine queryEngine = sessionFactory.getQueryEngine();
final var sessionFactory = (SessionFactoryImplementor) factory;
final var queryEngine = sessionFactory.getQueryEngine();
queryEngine.getNamedObjectRepository().prepare( sessionFactory, metadata );
if ( sessionFactory.getSessionFactoryOptions().isNamedQueryStartupCheckingEnabled() ) {
queryEngine.validateNamedQueries();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class SessionFactoryObserverForRegistration implements SessionFactoryObserver {

@Override
public void sessionFactoryCreated(SessionFactory factory) {
final SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) factory;
final var sessionFactory = (SessionFactoryImplementor) factory;
jndiService = sessionFactory.getServiceRegistry().getService( JndiService.class );
SessionFactoryRegistry.INSTANCE.addSessionFactory(
sessionFactory.getUuid(),
Expand All @@ -38,7 +38,7 @@ public void sessionFactoryCreated(SessionFactory factory) {

@Override
public void sessionFactoryClosed(SessionFactory factory) {
final SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) factory;
final var sessionFactory = (SessionFactoryImplementor) factory;
SessionFactoryRegistry.INSTANCE.removeSessionFactory(
sessionFactory.getUuid(),
sessionFactory.getName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.hibernate.type.spi.TypeBootstrapContext;
import org.hibernate.service.ServiceRegistry;

import java.lang.reflect.Constructor;
import java.util.Map;

import static org.hibernate.internal.util.ReflectHelper.getConstructorOrNull;
Expand All @@ -33,7 +32,7 @@ public TypeBeanInstanceProducer(ConfigurationService configurationService, Servi

@Override
public <B> B produceBeanInstance(Class<B> beanType) {
final Constructor<? extends B> bootstrapContextAwareConstructor =
final var bootstrapContextAwareConstructor =
getConstructorOrNull( beanType, TypeBootstrapContext.class );
if ( bootstrapContextAwareConstructor != null ) {
try {
Expand All @@ -44,7 +43,7 @@ public <B> B produceBeanInstance(Class<B> beanType) {
}
}
else {
final Constructor<? extends B> constructor = getConstructorOrNull( beanType );
final var constructor = getConstructorOrNull( beanType );
if ( constructor != null ) {
try {
return constructor.newInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.boot.spi.MetadataBuildingOptions;
import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.mapping.BasicValue;
import org.hibernate.metamodel.mapping.JdbcMapping;
import org.hibernate.resource.beans.spi.BeanInstanceProducer;
import org.hibernate.resource.beans.spi.ManagedBean;
import org.hibernate.resource.beans.spi.ManagedBeanRegistry;
import org.hibernate.type.BasicType;
import org.hibernate.type.CustomType;
Expand All @@ -39,6 +37,7 @@

import static java.util.Collections.emptyMap;
import static org.hibernate.boot.model.process.internal.InferredBasicValueResolver.resolveSqlTypeIndicators;
import static org.hibernate.internal.util.collections.CollectionHelper.isEmpty;
import static org.hibernate.mapping.MappingHelper.injectParameters;

/**
Expand Down Expand Up @@ -97,13 +96,21 @@

public BasicValue.Resolution<?> resolve(
Map<?,?> localConfigParameters,
MetadataBuildingContext context,
JdbcTypeIndicators indicators) {
return resolve( localConfigParameters, null, context, indicators );
}

public BasicValue.Resolution<?> resolve(
Map<?,?> localConfigParameters,
// TODO: why is this parameter ignored??
MutabilityPlan<?> explicitMutabilityPlan,
MetadataBuildingContext context,
JdbcTypeIndicators indicators) {
if ( CollectionHelper.isEmpty( localConfigParameters ) ) {
if ( isEmpty( localConfigParameters ) ) {
// we can use the re-usable resolution...

Check notice

Code scanning / CodeQL

Possible confusion of local and field Note

Potentially confusing name: method
resolve
also refers to field
name
(as this.name).
if ( reusableResolution == null ) {
reusableResolution = createResolution( name, emptyMap(), indicators, context );
reusableResolution = createResolution( this.name, emptyMap(), indicators, context );
}
return reusableResolution;
}
Expand Down Expand Up @@ -152,7 +159,7 @@
configurationAware.setTypeConfiguration( typeConfiguration );
}

final Properties combinedTypeParameters = new Properties();
final var combinedTypeParameters = new Properties();
if ( parameters!=null ) {
combinedTypeParameters.putAll( parameters );
}
Expand Down Expand Up @@ -225,19 +232,21 @@

private static <T> BasicValue.Resolution<T> resolveLegacyCases(
Class<T> typeImplementorClass, JdbcTypeIndicators indicators, TypeConfiguration typeConfiguration) {
final BasicType<T> legacyType;
return createBasicTypeResolution( getLegacyType( typeImplementorClass ),
typeImplementorClass, indicators, typeConfiguration );
}

private static <T> BasicType<T> getLegacyType(Class<T> typeImplementorClass) {
if ( Serializable.class.isAssignableFrom( typeImplementorClass ) ) {
legacyType = new SerializableType( typeImplementorClass );
return new SerializableType( typeImplementorClass );
}
else if ( typeImplementorClass.isInterface() ) {
legacyType = (BasicType<T>) new JavaObjectType();
return (BasicType<T>) new JavaObjectType();
}
else {
throw new IllegalArgumentException( "Named type [" + typeImplementorClass
+ "] did not implement BasicType nor UserType" );
+ "] did not implement BasicType nor UserType" );
}

return createBasicTypeResolution( legacyType, typeImplementorClass, indicators, typeConfiguration );
}

private static <T> BasicValue.Resolution<T> createBasicTypeResolution(
Expand Down Expand Up @@ -304,7 +313,7 @@
}
else {
final var beanRegistry = serviceRegistry.requireService( ManagedBeanRegistry.class );
final ManagedBean<T> typeBean = name != null
final var typeBean = name != null
? beanRegistry.getBean( name, typeImplementorClass, instanceProducer )
: beanRegistry.getBean( typeImplementorClass, instanceProducer );
return typeBean.getBeanInstance();
Expand All @@ -321,29 +330,31 @@
typeImplementorClass,
localTypeParams,
null,
buildingContext.getBootstrapContext().getTypeConfiguration().getCurrentBaseSqlTypeIndicators(),
buildingContext.getBootstrapContext().getTypeConfiguration()
.getCurrentBaseSqlTypeIndicators(),
buildingContext
);
}

@Override
public boolean equals(Object o) {
if ( this == o ) {
public boolean equals(Object object) {
if ( this == object ) {
return true;
}
if ( !(o instanceof TypeDefinition that) ) {
else if ( !(object instanceof TypeDefinition that) ) {
return false;
}

return Objects.equals( this.name, that.name )
&& Objects.equals( this.typeImplementorClass, that.typeImplementorClass )
&& Arrays.equals( this.registrationKeys, that.registrationKeys )
&& Objects.equals( this.parameters, that.parameters );
else {
return Objects.equals( this.name, that.name )
&& Objects.equals( this.typeImplementorClass, that.typeImplementorClass )
&& Arrays.equals( this.registrationKeys, that.registrationKeys )
&& Objects.equals( this.parameters, that.parameters );
}
}

@Override
public int hashCode() {
return Objects.hash( name, typeImplementorClass, registrationKeys, parameters );
return Objects.hash( name, typeImplementorClass, Arrays.hashCode( registrationKeys ), parameters );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1178,12 +1178,12 @@ private void bindCollectionMetadata(MappingDocument mappingDocument, PluralAttri
final Map<String,String> typeParameters = new HashMap<>();
if ( typeName != null ) {
// see if there is a corresponding type-def
final TypeDefinition typeDef =
final var typeDefinition =
mappingDocument.getMetadataCollector().getTypeDefinition( typeName );
if ( typeDef != null ) {
typeName = typeDef.getTypeImplementorClass().getName();
if ( typeDef.getParameters() != null ) {
typeParameters.putAll( typeDef.getParameters() );
if ( typeDefinition != null ) {
typeName = typeDefinition.getTypeImplementorClass().getName();
if ( typeDefinition.getParameters() != null ) {
typeParameters.putAll( typeDefinition.getParameters() );
}
}
else {
Expand Down Expand Up @@ -2081,16 +2081,12 @@ private BasicType<?> resolveExplicitlyNamedAnyDiscriminatorType(
}

// see if it is a named TypeDefinition
final TypeDefinition typeDefinition =
final var typeDefinition =
metadataBuildingContext.getTypeDefinitionRegistry().resolve( typeName );
if ( typeDefinition != null ) {
final BasicValue.Resolution<?> resolution = typeDefinition.resolve(
parameters,
null,
metadataBuildingContext,
typeConfiguration.getCurrentBaseSqlTypeIndicators()
);

final var resolution =
typeDefinition.resolve( parameters, metadataBuildingContext,
typeConfiguration.getCurrentBaseSqlTypeIndicators() );
if ( resolution.getCombinedTypeParameters() != null ) {
discriminatorMapping.setTypeParameters( resolution.getCombinedTypeParameters() );
}
Expand Down Expand Up @@ -2222,7 +2218,7 @@ private String toCascadeString(EnumSet<CascadeType> defaultCascadeTypes) {
}
else {
boolean firstPass = true;
final StringBuilder buffer = new StringBuilder();
final var buffer = new StringBuilder();
for ( var cascadeType : defaultCascadeTypes ) {
if ( firstPass ) {
firstPass = false;
Expand Down Expand Up @@ -2530,7 +2526,7 @@ private static TypeResolution resolveType(
return null;
}

final TypeDefinition typeDefinition =
final var typeDefinition =
sourceDocument.getMetadataCollector()
.getTypeDefinition( typeSource.getName() );
final Map<String,String> typeParameters = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public static <T> Constructor<T> getDefaultConstructor(Class<T> clazz) throws Pr
}

try {
final Constructor<T> constructor = clazz.getDeclaredConstructor( NO_PARAM_SIGNATURE );
final var constructor = clazz.getDeclaredConstructor( NO_PARAM_SIGNATURE );
ensureAccessibility( constructor );
return constructor;
}
Expand All @@ -314,7 +314,7 @@ public static <T> Supplier<T> getDefaultSupplier(Class<T> clazz) {
}

try {
final Constructor<T> constructor = clazz.getDeclaredConstructor( NO_PARAM_SIGNATURE );
final var constructor = clazz.getDeclaredConstructor( NO_PARAM_SIGNATURE );
ensureAccessibility( constructor );
return () -> {
try {
Expand Down Expand Up @@ -370,20 +370,19 @@ public static boolean isFinalClass(Class<?> clazz) {
public static <T> Constructor<T> getConstructorOrNull(
Class<T> clazz,
Class<?>... constructorArgs) {
Constructor<T> constructor = null;
try {
constructor = clazz.getDeclaredConstructor( constructorArgs );
final var constructor = clazz.getDeclaredConstructor( constructorArgs );
try {
ensureAccessibility( constructor );
}
catch ( SecurityException e ) {
constructor = null;
return null;
}
return constructor;
}
catch ( NoSuchMethodException ignore ) {
return null;
}

return constructor;
}

public static Method getMethod(Class<?> clazz, Method method) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ private <T> Resolution<?> resolution(BasicJavaType explicitJavaType, JavaType<T>
final var autoAppliedTypeDef = context.getTypeDefinitionRegistry().resolveAutoApplied( castType );
if ( autoAppliedTypeDef != null ) {
LOG.trace( "BasicValue resolution matched auto-applied type definition" );
return autoAppliedTypeDef.resolve( getTypeParameters(), null, context, this );
return autoAppliedTypeDef.resolve( getTypeParameters(), context, this );
}
}

Expand Down Expand Up @@ -874,7 +874,7 @@ public TypeConfiguration getTypeConfiguration() {
// see if it is a named TypeDefinition
final var typeDefinition = context.getTypeDefinitionRegistry().resolve( name );
if ( typeDefinition != null ) {
final Resolution<?> resolution = typeDefinition.resolve(
final var resolution = typeDefinition.resolve(
localTypeParams,
getMutabilityPlan( explicitMutabilityPlanAccess, typeConfiguration ),
context,
Expand Down Expand Up @@ -1099,14 +1099,15 @@ private UserType<?> getConfiguredUserTypeBean(Class<? extends UserType<?>> expli
return typeInstance;
}

private <T> ManagedBean<T> getUserTypeBean(Class<T> explicitCustomType, Properties properties) {
private <T> ManagedBean<? extends T> getUserTypeBean(Class<T> explicitCustomType, Properties properties) {
final var producer = getBuildingContext().getBootstrapContext().getCustomTypeProducer();
final var managedBeanRegistry = getManagedBeanRegistry();
if ( isNotEmpty( properties ) ) {
final String name = explicitCustomType.getName() + COUNTER++;
return getManagedBeanRegistry().getBean( name, explicitCustomType, producer );
return managedBeanRegistry.getBean( name, explicitCustomType, producer );
}
else {
return getManagedBeanRegistry().getBean( explicitCustomType, producer );
return managedBeanRegistry.getBean( explicitCustomType, producer );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/
package org.hibernate.resource.beans.internal;

import java.lang.reflect.Constructor;

import org.hibernate.InstantiationException;
import org.hibernate.resource.beans.spi.BeanInstanceProducer;
Expand Down Expand Up @@ -36,7 +35,7 @@ private FallbackBeanInstanceProducer() {
public <B> B produceBeanInstance(Class<B> beanType) {
LOG.tracef( "Creating ManagedBean [%s] using direct instantiation", beanType.getName() );
try {
final Constructor<B> constructor = beanType.getDeclaredConstructor();
final var constructor = beanType.getDeclaredConstructor();
constructor.setAccessible( true );
return constructor.newInstance();
}
Expand Down
Loading