use of org.hibernate.type.descriptor.java.JavaType in project hibernate-orm by hibernate.
the class TypeDefinition method createResolution.
private static BasicValue.Resolution<?> createResolution(String name, Class<?> typeImplementorClass, Properties parameters, Map<?, ?> usageSiteProperties, JdbcTypeIndicators indicators, MetadataBuildingContext context) {
final BootstrapContext bootstrapContext = context.getBootstrapContext();
final TypeConfiguration typeConfiguration = bootstrapContext.getTypeConfiguration();
final BeanInstanceProducer instanceProducer = bootstrapContext.getBeanInstanceProducer();
final boolean isKnownType = Type.class.isAssignableFrom(typeImplementorClass) || UserType.class.isAssignableFrom(typeImplementorClass);
// support for AttributeConverter would be nice too
if (isKnownType) {
final Object typeInstance = instantiateType(bootstrapContext.getServiceRegistry(), name, typeImplementorClass, instanceProducer);
if (typeInstance instanceof TypeConfigurationAware) {
((TypeConfigurationAware) typeInstance).setTypeConfiguration(typeConfiguration);
}
final Properties combinedTypeParameters;
if (CollectionHelper.isNotEmpty(usageSiteProperties)) {
combinedTypeParameters = new Properties(parameters);
combinedTypeParameters.putAll(usageSiteProperties);
} else {
combinedTypeParameters = parameters;
}
injectParameters(typeInstance, combinedTypeParameters);
if (typeInstance instanceof UserType) {
final UserType<Object> userType = (UserType<Object>) typeInstance;
final CustomType<Object> customType = new CustomType<>(userType, typeConfiguration);
return new UserTypeResolution(customType, null, combinedTypeParameters);
}
if (typeInstance instanceof BasicType) {
final BasicType resolvedBasicType = (BasicType) typeInstance;
return new BasicValue.Resolution<Object>() {
@Override
public JdbcMapping getJdbcMapping() {
return resolvedBasicType;
}
@Override
public BasicType getLegacyResolvedBasicType() {
return resolvedBasicType;
}
@Override
public Properties getCombinedTypeParameters() {
return combinedTypeParameters;
}
@Override
public JavaType<Object> getDomainJavaType() {
return resolvedBasicType.getMappedJavaType();
}
@Override
public JavaType<?> getRelationalJavaType() {
return resolvedBasicType.getMappedJavaType();
}
@Override
public JdbcType getJdbcType() {
return resolvedBasicType.getJdbcType();
}
@Override
public BasicValueConverter getValueConverter() {
return null;
}
@Override
public MutabilityPlan<Object> getMutabilityPlan() {
// a TypeDefinition does not explicitly provide a MutabilityPlan (yet?)
return resolvedBasicType.isMutable() ? getDomainJavaType().getMutabilityPlan() : ImmutableMutabilityPlan.instance();
}
};
}
}
if (Serializable.class.isAssignableFrom(typeImplementorClass)) {
final JavaType<Serializable> jtd = typeConfiguration.getJavaTypeRegistry().resolveDescriptor(typeImplementorClass);
final JdbcType jdbcType = typeConfiguration.getJdbcTypeRegistry().getDescriptor(Types.VARBINARY);
final BasicType<Serializable> resolved = typeConfiguration.getBasicTypeRegistry().resolve(jtd, jdbcType);
final SerializableType legacyType = new SerializableType(typeImplementorClass);
return new BasicValue.Resolution<Object>() {
@Override
public JdbcMapping getJdbcMapping() {
return resolved;
}
@Override
public BasicType getLegacyResolvedBasicType() {
return legacyType;
}
@Override
public JavaType<Object> getDomainJavaType() {
return (JavaType) resolved.getMappedJavaType();
}
@Override
public JavaType<?> getRelationalJavaType() {
return resolved.getMappedJavaType();
}
@Override
public JdbcType getJdbcType() {
return resolved.getJdbcType();
}
@Override
public BasicValueConverter getValueConverter() {
return null;
}
@Override
public MutabilityPlan<Object> getMutabilityPlan() {
// a TypeDefinition does not explicitly provide a MutabilityPlan (yet?)
return resolved.isMutable() ? getDomainJavaType().getMutabilityPlan() : ImmutableMutabilityPlan.instance();
}
};
}
throw new IllegalArgumentException("Named type [" + typeImplementorClass + "] did not implement BasicType nor UserType");
}
use of org.hibernate.type.descriptor.java.JavaType in project hibernate-orm by hibernate.
the class VersionResolution method from.
// 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, Function<TypeConfiguration, BasicJavaType> explicitJtdAccess, Function<TypeConfiguration, JdbcType> explicitStdAccess, TimeZoneStorageType timeZoneStorageType, TypeConfiguration typeConfiguration, @SuppressWarnings("unused") MetadataBuildingContext context) {
// todo (6.0) : add support for Dialect-specific interpretation?
final java.lang.reflect.Type implicitJavaType = implicitJavaTypeAccess.apply(typeConfiguration);
final JavaType registered = typeConfiguration.getJavaTypeRegistry().resolveDescriptor(implicitJavaType);
final BasicJavaType jtd = (BasicJavaType) registered;
final JdbcType recommendedJdbcType = jtd.getRecommendedJdbcType(new JdbcTypeIndicators() {
@Override
public TypeConfiguration getTypeConfiguration() {
return typeConfiguration;
}
@Override
public TemporalType getTemporalPrecision() {
// if it is a temporal version, it needs to be a TIMESTAMP
return TemporalType.TIMESTAMP;
}
@Override
public TimeZoneStorageStrategy getDefaultTimeZoneStorageStrategy() {
if (timeZoneStorageType != null) {
switch(timeZoneStorageType) {
case NATIVE:
return TimeZoneStorageStrategy.NATIVE;
case NORMALIZE:
return TimeZoneStorageStrategy.NORMALIZE;
}
}
return context.getBuildingOptions().getDefaultTimeZoneStorage();
}
});
final BasicType<?> basicType = typeConfiguration.getBasicTypeRegistry().resolve(jtd, recommendedJdbcType);
final BasicType legacyType = typeConfiguration.getBasicTypeRegistry().getRegisteredType(jtd.getJavaType());
assert legacyType.getJdbcType().equals(recommendedJdbcType);
return new VersionResolution<>(jtd, recommendedJdbcType, basicType, legacyType);
}
use of org.hibernate.type.descriptor.java.JavaType in project hibernate-orm by hibernate.
the class AnnotationBinder method resolveFilterParamType.
private static JdbcMapping resolveFilterParamType(Class<?> type, MetadataBuildingContext context) {
if (UserType.class.isAssignableFrom(type)) {
// noinspection unchecked
return resolveUserType((Class<UserType<?>>) type, context);
}
if (AttributeConverter.class.isAssignableFrom(type)) {
// noinspection unchecked
return resolveAttributeConverter((Class<AttributeConverter<?, ?>>) type, context);
}
if (JavaType.class.isAssignableFrom(type)) {
// noinspection unchecked
return resolveJavaType((Class<JavaType<?>>) type, context);
}
final TypeConfiguration typeConfiguration = context.getBootstrapContext().getTypeConfiguration();
final JavaType<Object> jtd = typeConfiguration.getJavaTypeRegistry().findDescriptor(type);
if (jtd != null) {
final JdbcType jdbcType = jtd.getRecommendedJdbcType(typeConfiguration.getCurrentBaseSqlTypeIndicators());
return typeConfiguration.getBasicTypeRegistry().resolve(jtd, jdbcType);
}
return null;
}
use of org.hibernate.type.descriptor.java.JavaType in project hibernate-orm by hibernate.
the class Predicate method createDomainResult.
@Override
default DomainResult<Boolean> createDomainResult(String resultVariable, DomainResultCreationState creationState) {
final SqlAstCreationState sqlAstCreationState = creationState.getSqlAstCreationState();
final SqlExpressionResolver sqlExpressionResolver = sqlAstCreationState.getSqlExpressionResolver();
final JavaType javaType = getExpressionType().getJdbcMappings().get(0).getJavaTypeDescriptor();
final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection(this, javaType, sqlAstCreationState.getCreationContext().getMappingMetamodel().getTypeConfiguration());
// noinspection unchecked
return new BasicResult(sqlSelection.getValuesArrayPosition(), resultVariable, javaType);
}
use of org.hibernate.type.descriptor.java.JavaType in project hibernate-orm by hibernate.
the class QuerySpec method createDomainResult.
@Override
public DomainResult createDomainResult(String resultVariable, DomainResultCreationState creationState) {
TypeConfiguration typeConfiguration = creationState.getSqlAstCreationState().getCreationContext().getMappingMetamodel().getTypeConfiguration();
final SqlExpressionResolver sqlExpressionResolver = creationState.getSqlAstCreationState().getSqlExpressionResolver();
if (selectClause.getSqlSelections().size() == 1) {
SqlSelection first = selectClause.getSqlSelections().get(0);
JavaType descriptor = first.getExpressionType().getJdbcMappings().get(0).getJavaTypeDescriptor();
final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection(this, descriptor, typeConfiguration);
return new BasicResult<>(sqlSelection.getValuesArrayPosition(), resultVariable, descriptor);
} else {
throw new UnsupportedOperationException("Domain result for non-scalar subquery shouldn't be created!");
}
}
Aggregations