use of org.hibernate.type.descriptor.java.BasicJavaType in project hibernate-orm by hibernate.
the class BasicValueBinder method prepareAnyKey.
private void prepareAnyKey(XProperty modelXProperty) {
implicitJavaTypeAccess = (typeConfiguration) -> null;
explicitJavaTypeAccess = (typeConfiguration) -> {
final AnyKeyJavaType javaTypeAnn = findAnnotation(modelXProperty, AnyKeyJavaType.class);
if (javaTypeAnn != null) {
final Class<? extends BasicJavaType<?>> javaType = normalizeJavaType(javaTypeAnn.value());
if (javaType != null) {
return getManagedBeanRegistry().getBean(javaType).getBeanInstance();
}
}
final AnyKeyJavaClass javaClassAnn = findAnnotation(modelXProperty, AnyKeyJavaClass.class);
if (javaClassAnn != null) {
// noinspection rawtypes
return (BasicJavaType) typeConfiguration.getJavaTypeRegistry().getDescriptor(javaClassAnn.value());
}
return null;
};
explicitJdbcTypeAccess = (typeConfiguration) -> {
final AnyKeyJdbcType jdbcTypeAnn = findAnnotation(modelXProperty, AnyKeyJdbcType.class);
if (jdbcTypeAnn != null) {
final Class<? extends JdbcType> jdbcType = normalizeJdbcType(jdbcTypeAnn.value());
if (jdbcType != null) {
final ManagedBean<? extends JdbcType> jtdBean = getManagedBeanRegistry().getBean(jdbcType);
return jtdBean.getBeanInstance();
}
}
final AnyKeyJdbcTypeCode jdbcTypeCodeAnn = findAnnotation(modelXProperty, AnyKeyJdbcTypeCode.class);
if (jdbcTypeCodeAnn != null) {
if (jdbcTypeCodeAnn.value() != Integer.MIN_VALUE) {
return typeConfiguration.getJdbcTypeRegistry().getDescriptor(jdbcTypeCodeAnn.value());
}
}
return null;
};
}
use of org.hibernate.type.descriptor.java.BasicJavaType in project hibernate-orm by hibernate.
the class BasicValue method buildResolution.
protected Resolution<?> buildResolution() {
Properties typeParameters = getTypeParameters();
if (typeParameters != null && Boolean.parseBoolean(typeParameters.getProperty(DynamicParameterizedType.IS_DYNAMIC)) && typeParameters.get(DynamicParameterizedType.PARAMETER_TYPE) == null) {
createParameterImpl();
}
if (explicitTypeName != null) {
return interpretExplicitlyNamedType(explicitTypeName, enumerationStyle, implicitJavaTypeAccess, explicitJavaTypeAccess, explicitJdbcTypeAccess, explicitMutabilityPlanAccess, getAttributeConverterDescriptor(), typeParameters, this::setTypeParameters, this, typeConfiguration, getBuildingContext());
}
if (isVersion()) {
return VersionResolution.from(implicitJavaTypeAccess, explicitJavaTypeAccess, explicitJdbcTypeAccess, timeZoneStorageType, typeConfiguration, getBuildingContext());
}
final ConverterDescriptor attributeConverterDescriptor = getAttributeConverterDescriptor();
if (attributeConverterDescriptor != null) {
final ManagedBeanRegistry managedBeanRegistry = getBuildingContext().getBootstrapContext().getServiceRegistry().getService(ManagedBeanRegistry.class);
final JpaAttributeConverterCreationContext converterCreationContext = new JpaAttributeConverterCreationContext() {
@Override
public ManagedBeanRegistry getManagedBeanRegistry() {
return managedBeanRegistry;
}
@Override
public TypeConfiguration getTypeConfiguration() {
return typeConfiguration;
}
};
return NamedConverterResolution.from(attributeConverterDescriptor, explicitJavaTypeAccess, explicitJdbcTypeAccess, explicitMutabilityPlanAccess, this, converterCreationContext, getBuildingContext());
}
JavaType<?> jtd = null;
// determine JavaType if we can
final BasicJavaType explicitJtd;
if (explicitJavaTypeAccess != null) {
explicitJtd = explicitJavaTypeAccess.apply(typeConfiguration);
if (explicitJtd != null) {
jtd = explicitJtd;
}
} else {
explicitJtd = null;
}
if (jtd == null) {
if (implicitJavaTypeAccess != null) {
final java.lang.reflect.Type implicitJtd = implicitJavaTypeAccess.apply(typeConfiguration);
if (implicitJtd != null) {
jtd = typeConfiguration.getJavaTypeRegistry().getDescriptor(implicitJtd);
}
}
}
if (jtd == null) {
final JavaType<?> reflectedJtd = determineReflectedJavaType();
if (reflectedJtd != null) {
jtd = reflectedJtd;
}
}
final JdbcType jdbcType;
if (explicitJdbcTypeAccess != null) {
jdbcType = explicitJdbcTypeAccess.apply(typeConfiguration);
} else {
jdbcType = null;
}
if (jtd == null) {
if (jdbcType != null) {
jtd = jdbcType.getJdbcRecommendedJavaTypeMapping(null, null, typeConfiguration);
}
}
if (jtd == null) {
throw new MappingException("Unable to determine JavaType to use : " + this);
}
final TypeDefinitionRegistry typeDefinitionRegistry = getBuildingContext().getTypeDefinitionRegistry();
final TypeDefinition autoAppliedTypeDef = typeDefinitionRegistry.resolveAutoApplied((BasicJavaType<?>) jtd);
if (autoAppliedTypeDef != null && (!jtd.getJavaTypeClass().isEnum() || enumerationStyle == null)) {
log.debug("BasicValue resolution matched auto-applied type-definition");
return autoAppliedTypeDef.resolve(typeParameters, null, getBuildingContext(), this);
}
return InferredBasicValueResolver.from(explicitJtd, jdbcType, resolvedJavaType, this::determineReflectedJavaType, this, getTable(), getColumn(), ownerName, propertyName, typeConfiguration);
}
use of org.hibernate.type.descriptor.java.BasicJavaType in project hibernate-orm by hibernate.
the class EnumType method interpretParameters.
private EnumValueConverter<T, Object> interpretParameters(Properties parameters) {
// noinspection rawtypes
final EnumJavaType enumJavaType = (EnumJavaType) typeConfiguration.getJavaTypeRegistry().getDescriptor(enumClass);
// this method should only be called for hbm.xml handling
assert parameters.get(PARAMETER_TYPE) == null;
final LocalJdbcTypeIndicators localIndicators = new LocalJdbcTypeIndicators(// use ORDINAL as default for hbm.xml mappings
jakarta.persistence.EnumType.ORDINAL, // etc
-1L, null);
final BasicJavaType<?> stringJavaType = (BasicJavaType<?>) typeConfiguration.getJavaTypeRegistry().getDescriptor(String.class);
final BasicJavaType<?> integerJavaType = (BasicJavaType<?>) typeConfiguration.getJavaTypeRegistry().getDescriptor(Integer.class);
if (parameters.containsKey(NAMED)) {
final boolean useNamed = ConfigurationHelper.getBoolean(NAMED, parameters);
if (useNamed) {
// noinspection rawtypes
return new NamedEnumValueConverter(enumJavaType, stringJavaType.getRecommendedJdbcType(localIndicators), stringJavaType);
} else {
// noinspection rawtypes
return new OrdinalEnumValueConverter(enumJavaType, integerJavaType.getRecommendedJdbcType(localIndicators), typeConfiguration.getJavaTypeRegistry().getDescriptor(Integer.class));
}
}
if (parameters.containsKey(TYPE)) {
final int type = Integer.decode((String) parameters.get(TYPE));
if (isNumericType(type)) {
// noinspection rawtypes
return new OrdinalEnumValueConverter(enumJavaType, integerJavaType.getRecommendedJdbcType(localIndicators), typeConfiguration.getJavaTypeRegistry().getDescriptor(Integer.class));
} else if (isCharacterType(type)) {
// noinspection rawtypes
return new NamedEnumValueConverter(enumJavaType, stringJavaType.getRecommendedJdbcType(localIndicators), stringJavaType);
} else {
throw new HibernateException(String.format(Locale.ENGLISH, "Passed JDBC type code [%s] not recognized as numeric nor character", type));
}
}
// the fallback
return new OrdinalEnumValueConverter(enumJavaType, integerJavaType.getRecommendedJdbcType(localIndicators), typeConfiguration.getJavaTypeRegistry().getDescriptor(Integer.class));
}
use of org.hibernate.type.descriptor.java.BasicJavaType in project hibernate-orm by hibernate.
the class BaseSqmToSqlAstConverter method visitEnumLiteral.
@SuppressWarnings({ "raw", "unchecked" })
@Override
public Object visitEnumLiteral(SqmEnumLiteral<?> sqmEnumLiteral) {
final BasicValuedMapping inferrableType = (BasicValuedMapping) resolveInferredType();
if (inferrableType instanceof ConvertibleModelPart) {
final ConvertibleModelPart inferredPart = (ConvertibleModelPart) inferrableType;
final BasicValueConverter<Enum<?>, ?> valueConverter = inferredPart.getValueConverter();
final Object jdbcValue = valueConverter.toRelationalValue(sqmEnumLiteral.getEnumValue());
return new QueryLiteral<>(jdbcValue, inferredPart);
}
final EnumJavaType<?> enumJtd = sqmEnumLiteral.getExpressibleJavaType();
final JdbcType jdbcType = getTypeConfiguration().getJdbcTypeRegistry().getDescriptor(SqlTypes.TINYINT);
final BasicJavaType<Integer> relationalJtd = (BasicJavaType) getTypeConfiguration().getJavaTypeRegistry().getDescriptor(Integer.class);
final BasicType<?> jdbcMappingType = getTypeConfiguration().getBasicTypeRegistry().resolve(relationalJtd, jdbcType);
return new ConvertedQueryLiteral(sqmEnumLiteral.getEnumValue(), new OrdinalEnumValueConverter<>(enumJtd, jdbcType, relationalJtd), jdbcMappingType);
}
use of org.hibernate.type.descriptor.java.BasicJavaType in project hibernate-orm by hibernate.
the class YesNoBinder method bind.
@Override
public void bind(YesNo annotation, MetadataBuildingContext buildingContext, PersistentClass persistentClass, Property property) {
final BasicValue booleanValueMapping = (BasicValue) property.getValue();
final BasicJavaType<?> javaType = (BasicJavaType<?>) buildingContext.getBootstrapContext().getTypeConfiguration().getJavaTypeRegistry().getDescriptor(Boolean.class);
final JdbcType jdbcType = buildingContext.getBootstrapContext().getTypeConfiguration().getJdbcTypeRegistry().getDescriptor(Types.CHAR);
final InstanceBasedConverterDescriptor converter = new InstanceBasedConverterDescriptor(YesNoConverter.INSTANCE, buildingContext.getBootstrapContext().getClassmateContext());
booleanValueMapping.setExplicitJavaTypeAccess((typeConfiguration) -> javaType);
booleanValueMapping.setExplicitJdbcTypeAccess((typeConfiguration) -> jdbcType);
booleanValueMapping.setJpaAttributeConverterDescriptor(converter);
}
Aggregations