Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -15,7 +15,6 @@
import org.hibernate.boot.spi.ClassmateContext;
import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.internal.util.GenericsHelper;
import org.hibernate.internal.util.type.PrimitiveWrapperHelper;
import org.hibernate.models.spi.MemberDetails;

import com.fasterxml.classmate.ResolvedType;
Expand All @@ -24,6 +23,8 @@
import com.fasterxml.classmate.members.ResolvedMethod;
import jakarta.persistence.AttributeConverter;

import static org.hibernate.internal.util.type.PrimitiveWrappers.canonicalize;

/**
* Helpers related to handling converters
*/
Expand Down Expand Up @@ -100,11 +101,8 @@ else if ( converterParamTypes.size() != 2 ) {
* @return {@code true} if they match, otherwise {@code false}.
*/
public static boolean typesMatch(ResolvedType converterDefinedType, ResolvedType checkType) {
Class<?> erasedCheckType = checkType.getErasedType();
if ( erasedCheckType.isPrimitive() ) {
erasedCheckType = PrimitiveWrapperHelper.getDescriptorByPrimitiveType( erasedCheckType ).getWrapperClass();
}
else if ( erasedCheckType.isArray() ) {
final var erasedCheckType = canonicalize( checkType.getErasedType() );
if ( erasedCheckType.isArray() ) {
// converterDefinedType have type parameters if it extends super generic class
// but checkType doesn't have any type parameters
// comparing erased type is enough
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,29 @@
*/
public class VersionResolution<E> implements BasicValue.Resolution<E> {

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

public static <E> VersionResolution<E> from(
public static VersionResolution<?> from(
Function<TypeConfiguration, java.lang.reflect.Type> implicitJavaTypeAccess,
TimeZoneStorageType timeZoneStorageType,
MetadataBuildingContext context) {

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

final var typeConfiguration = context.getBootstrapContext().getTypeConfiguration();
final var implicitJavaType = implicitJavaTypeAccess.apply( typeConfiguration );
final JavaType<E> registered = typeConfiguration.getJavaTypeRegistry().getDescriptor( implicitJavaType );
final var basicJavaType = (BasicJavaType<E>) registered;
final var registered = typeConfiguration.getJavaTypeRegistry().resolveDescriptor( implicitJavaType );
return resolve( timeZoneStorageType, context, (BasicJavaType<?>) registered );
}

private static <E> VersionResolution<E> resolve(
TimeZoneStorageType timeZoneStorageType,
MetadataBuildingContext context,
BasicJavaType<E> basicJavaType) {
final var typeConfiguration = context.getBootstrapContext().getTypeConfiguration();
final var recommendedJdbcType = basicJavaType.getRecommendedJdbcType(
new JdbcTypeIndicators() {
@Override
public TypeConfiguration getTypeConfiguration() {
return typeConfiguration;
}

@Override
@Override @SuppressWarnings("deprecation")
public TemporalType getTemporalPrecision() {
// if it is a temporal version, it needs to be a TIMESTAMP
return TemporalType.TIMESTAMP;
Expand Down Expand Up @@ -106,7 +106,6 @@ public Dialect getDialect() {
final var basicTypeRegistry = typeConfiguration.getBasicTypeRegistry();
final var basicType = basicTypeRegistry.resolve( basicJavaType, recommendedJdbcType );
final var legacyType = basicTypeRegistry.getRegisteredType( basicJavaType.getJavaTypeClass() );

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

return new VersionResolution<>( basicJavaType, recommendedJdbcType, basicType, legacyType );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
*/
package org.hibernate.cache.internal;

import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -71,9 +68,6 @@ public class EnabledCaching implements CacheImplementor, DomainDataRegionBuildin
private final Map<String, QueryResultsCache> namedQueryResultsCacheMap = new ConcurrentHashMap<>();


private final Set<String> legacySecondLevelCacheNames = new LinkedHashSet<>();
private final Map<String,Set<NaturalIdDataAccess>> legacyNaturalIdAccessesForRegion = new ConcurrentHashMap<>();

public EnabledCaching(SessionFactoryImplementor sessionFactory) {
this.sessionFactory = sessionFactory;
final var options = sessionFactory.getSessionFactoryOptions();
Expand Down Expand Up @@ -105,7 +99,6 @@ private TimestampsCache buildTimestampsCache(SessionFactoryImplementor sessionFa
DEFAULT_UPDATE_TIMESTAMPS_REGION_UNQUALIFIED_NAME,
sessionFactory
);
legacySecondLevelCacheNames.add( timestampsRegion.getName() );
return sessionFactory.getSessionFactoryOptions().getTimestampsCacheFactory()
.buildTimestampsCache( this, timestampsRegion );
}
Expand Down Expand Up @@ -134,27 +127,16 @@ public void prime(Set<DomainDataRegionConfig> cacheRegionConfigs) {
for ( var entityAccessConfig : regionConfig.getEntityCaching() ) {
final var navigableRole = entityAccessConfig.getNavigableRole();
entityAccessMap.put( navigableRole, region.getEntityDataAccess( navigableRole ) );
legacySecondLevelCacheNames.add( qualifiedRegionName( region ) );
}


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Natural-id caching

final var naturalIdCaching = regionConfig.getNaturalIdCaching();
if ( naturalIdCaching.isEmpty() ) {
legacyNaturalIdAccessesForRegion.put( region.getName(), Collections.emptySet() );
}
else {
final Set<NaturalIdDataAccess> accesses = new HashSet<>();
for ( var naturalIdAccessConfig : naturalIdCaching ) {
final var navigableRole = naturalIdAccessConfig.getNavigableRole();
final var naturalIdDataAccess =
naturalIdAccessMap.put( navigableRole,
region.getNaturalIdDataAccess( navigableRole ) );
accesses.add( naturalIdDataAccess );
}
legacyNaturalIdAccessesForRegion.put( region.getName(), accesses );
for ( var naturalIdAccessConfig : regionConfig.getNaturalIdCaching() ) {
final var navigableRole = naturalIdAccessConfig.getNavigableRole();
naturalIdAccessMap.put( navigableRole,
region.getNaturalIdDataAccess( navigableRole ) );
}


Expand All @@ -165,7 +147,6 @@ public void prime(Set<DomainDataRegionConfig> cacheRegionConfigs) {
final var navigableRole = collectionAccessConfig.getNavigableRole();
collectionAccessMap.put( navigableRole,
region.getCollectionDataAccess( navigableRole ) );
legacySecondLevelCacheNames.add( qualifiedRegionName( region ) );
}
}

Expand Down Expand Up @@ -213,7 +194,6 @@ public Region getRegion(String regionName) {
}



// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Entity data

Expand Down Expand Up @@ -309,7 +289,6 @@ public void evictEntityData() {
}



// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Natural-id data

Expand Down Expand Up @@ -341,7 +320,6 @@ private void evictNaturalIdData(NavigableRole rootEntityRole, NaturalIdDataAcces
}



// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Collection data

Expand Down Expand Up @@ -427,7 +405,7 @@ private void evictQueryResultRegion(QueryResultsCache cache) {
public void evictQueryRegions() {
LOG.evictingAllQueryRegions();
evictQueryResultRegion( defaultQueryResultsCache );
for ( QueryResultsCache cache : namedQueryResultsCacheMap.values() ) {
for ( var cache : namedQueryResultsCacheMap.values() ) {
evictQueryResultRegion( cache );
}
}
Expand Down Expand Up @@ -470,7 +448,7 @@ else if ( regionName == null || regionName.equals( getDefaultResultCacheName() )
}
else {
final var existing = namedQueryResultsCacheMap.get( regionName );
return existing != null ? existing : makeQueryResultsRegionAccess( regionName );
return existing != null ? existing : makeQueryResultsCache( regionName );
}
}

Expand All @@ -487,21 +465,20 @@ else if ( regionName == null || regionName.equals( getDefaultResultCacheName() )
}
}

protected QueryResultsCache makeQueryResultsRegionAccess(String regionName) {
final var regionAccess = new QueryResultsCacheImpl( getQueryResultsRegion( regionName ), timestampsCache );
protected QueryResultsCache makeQueryResultsCache(String regionName) {
final var regionAccess = new QueryResultsCacheImpl( queryResultsRegion( regionName ), timestampsCache );
namedQueryResultsCacheMap.put( regionName, regionAccess );
legacySecondLevelCacheNames.add( regionName );
return regionAccess;
}

private QueryResultsRegion getQueryResultsRegion(String regionName) {
final Region region = regionsByName.computeIfAbsent( regionName, this::makeQueryResultsRegion );
return region instanceof QueryResultsRegion queryResultsRegion
private QueryResultsRegion queryResultsRegion(String regionName) {
return regionsByName.computeIfAbsent( regionName, this::buildQueryResultsRegion )
instanceof QueryResultsRegion queryResultsRegion
? queryResultsRegion // There was already a different type of Region with the same name.
: queryResultsRegionsByDuplicateName.computeIfAbsent( regionName, this::makeQueryResultsRegion );
: queryResultsRegionsByDuplicateName.computeIfAbsent( regionName, this::buildQueryResultsRegion );
}

protected QueryResultsRegion makeQueryResultsRegion(String regionName) {
protected QueryResultsRegion buildQueryResultsRegion(String regionName) {
return regionFactory.buildQueryResultsRegion( regionName, getSessionFactory() );
}

Expand Down Expand Up @@ -544,7 +521,6 @@ public void close() {
}



// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// JPA-defined methods

Expand All @@ -567,8 +543,6 @@ public void evict(Class cls) {
}




// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Deprecations

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,28 @@
import java.lang.reflect.Type;
import java.util.List;

import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.Size;
import org.hibernate.internal.build.AllowReflection;
import org.hibernate.metamodel.mapping.JdbcMappingContainer;
import org.hibernate.metamodel.mapping.SqlTypedMapping;
import org.hibernate.metamodel.model.domain.DomainType;
import org.hibernate.metamodel.model.domain.ReturnableType;
import org.hibernate.sql.ast.spi.AbstractSqlAstTranslator;
import org.hibernate.type.BasicType;
import org.hibernate.type.descriptor.java.BasicPluralJavaType;
import org.hibernate.type.descriptor.sql.DdlType;
import org.hibernate.type.descriptor.sql.spi.DdlTypeRegistry;
import org.hibernate.type.internal.ParameterizedTypeImpl;
import org.hibernate.type.spi.TypeConfiguration;

public class DdlTypeHelper {
@SuppressWarnings("unchecked")
@AllowReflection
// @AllowReflection
public static BasicType<?> resolveArrayType(DomainType<?> elementType, TypeConfiguration typeConfiguration) {
@SuppressWarnings("unchecked")
final var arrayJavaType =
(BasicPluralJavaType<Object>)
typeConfiguration.getJavaTypeRegistry()
.resolveArrayDescriptor( elementType.getJavaType() );
final Dialect dialect = typeConfiguration.getCurrentBaseSqlTypeIndicators().getDialect();
return arrayJavaType.resolveType(
typeConfiguration,
dialect,
typeConfiguration.getCurrentBaseSqlTypeIndicators().getDialect(),
(BasicType<Object>) elementType,
null,
typeConfiguration.getCurrentBaseSqlTypeIndicators()
Expand All @@ -43,7 +37,6 @@ public static BasicType<?> resolveArrayType(DomainType<?> elementType, TypeConfi

@SuppressWarnings("unchecked")
public static BasicType<?> resolveListType(DomainType<?> elementType, TypeConfiguration typeConfiguration) {
@SuppressWarnings("unchecked")
final BasicPluralJavaType<Object> arrayJavaType =
(BasicPluralJavaType<Object>)
typeConfiguration.getJavaTypeRegistry()
Expand All @@ -52,10 +45,9 @@ public static BasicType<?> resolveListType(DomainType<?> elementType, TypeConfig
new ParameterizedTypeImpl( List.class, new Type[]{ elementType.getJavaType() }, null ),
typeConfiguration
);
final Dialect dialect = typeConfiguration.getCurrentBaseSqlTypeIndicators().getDialect();
return arrayJavaType.resolveType(
typeConfiguration,
dialect,
typeConfiguration.getCurrentBaseSqlTypeIndicators().getDialect(),
(BasicType<Object>) elementType,
null,
typeConfiguration.getCurrentBaseSqlTypeIndicators()
Expand All @@ -79,11 +71,9 @@ public static String getTypeName(JdbcMappingContainer type, Size size, TypeConfi
return AbstractSqlAstTranslator.getSqlTypeName( sqlTypedMapping, typeConfiguration );
}
else {
final BasicType<?> basicType = (BasicType<?>) type.getSingleJdbcMapping();
final DdlTypeRegistry ddlTypeRegistry = typeConfiguration.getDdlTypeRegistry();
final DdlType ddlType = ddlTypeRegistry.getDescriptor(
basicType.getJdbcType().getDdlTypeCode()
);
final var basicType = (BasicType<?>) type.getSingleJdbcMapping();
final var ddlTypeRegistry = typeConfiguration.getDdlTypeRegistry();
final var ddlType = ddlTypeRegistry.getDescriptor( basicType.getJdbcType().getDdlTypeCode() );
return ddlType.getTypeName( size, basicType, ddlTypeRegistry );
}
}
Expand All @@ -97,11 +87,9 @@ public static String getTypeName(ReturnableType<?> type, Size size, TypeConfigur
return AbstractSqlAstTranslator.getSqlTypeName( sqlTypedMapping, typeConfiguration );
}
else {
final BasicType<?> basicType = (BasicType<?>) ( (JdbcMappingContainer) type ).getSingleJdbcMapping();
final DdlTypeRegistry ddlTypeRegistry = typeConfiguration.getDdlTypeRegistry();
final DdlType ddlType = ddlTypeRegistry.getDescriptor(
basicType.getJdbcType().getDdlTypeCode()
);
final var basicType = (BasicType<?>) ( (JdbcMappingContainer) type ).getSingleJdbcMapping();
final var ddlTypeRegistry = typeConfiguration.getDdlTypeRegistry();
final var ddlType = ddlTypeRegistry.getDescriptor( basicType.getJdbcType().getDdlTypeCode() );
return ddlType.getTypeName( size, basicType, ddlTypeRegistry );
}
}
Expand All @@ -123,11 +111,9 @@ public static String getCastTypeName(JdbcMappingContainer type, Size size, TypeC
return AbstractSqlAstTranslator.getCastTypeName( sqlTypedMapping, typeConfiguration );
}
else {
final BasicType<?> basicType = (BasicType<?>) type.getSingleJdbcMapping();
final DdlTypeRegistry ddlTypeRegistry = typeConfiguration.getDdlTypeRegistry();
final DdlType ddlType = ddlTypeRegistry.getDescriptor(
basicType.getJdbcType().getDdlTypeCode()
);
final var basicType = (BasicType<?>) type.getSingleJdbcMapping();
final var ddlTypeRegistry = typeConfiguration.getDdlTypeRegistry();
final var ddlType = ddlTypeRegistry.getDescriptor( basicType.getJdbcType().getDdlTypeCode() );
return ddlType.getCastTypeName( size, basicType, ddlTypeRegistry );
}
}
Expand All @@ -141,11 +127,9 @@ public static String getCastTypeName(ReturnableType<?> type, Size size, TypeConf
return AbstractSqlAstTranslator.getCastTypeName( sqlTypedMapping, typeConfiguration );
}
else {
final BasicType<?> basicType = (BasicType<?>) ( (JdbcMappingContainer) type ).getSingleJdbcMapping();
final DdlTypeRegistry ddlTypeRegistry = typeConfiguration.getDdlTypeRegistry();
final DdlType ddlType = ddlTypeRegistry.getDescriptor(
basicType.getJdbcType().getDdlTypeCode()
);
final var basicType = (BasicType<?>) ( (JdbcMappingContainer) type ).getSingleJdbcMapping();
final var ddlTypeRegistry = typeConfiguration.getDdlTypeRegistry();
final var ddlType = ddlTypeRegistry.getDescriptor( basicType.getJdbcType().getDdlTypeCode() );
return ddlType.getCastTypeName( size, basicType, ddlTypeRegistry );
}
}
Expand Down
Loading
Loading