use of org.hibernate.type.descriptor.jdbc.JdbcType in project hibernate-orm by hibernate.
the class InferredBasicValueResolver method fromTemporal.
public static <T> InferredBasicValueResolution<T, T> fromTemporal(TemporalJavaType<T> reflectedJtd, BasicJavaType<?> explicitJavaType, JdbcType explicitJdbcType, Type resolvedJavaType, JdbcTypeIndicators stdIndicators, TypeConfiguration typeConfiguration) {
final TemporalType requestedTemporalPrecision = stdIndicators.getTemporalPrecision();
if (explicitJavaType != null) {
if (!(explicitJavaType instanceof TemporalJavaType)) {
throw new MappingException("Explicit JavaType [" + explicitJavaType + "] defined for temporal value must implement TemporalJavaType");
}
@SuppressWarnings("unchecked") final TemporalJavaType<T> explicitTemporalJtd = (TemporalJavaType<T>) explicitJavaType;
if (requestedTemporalPrecision != null && explicitTemporalJtd.getPrecision() != requestedTemporalPrecision) {
throw new MappingException("Temporal precision (`jakarta.persistence.TemporalType`) mismatch... requested precision = " + requestedTemporalPrecision + "; explicit JavaType (`" + explicitTemporalJtd + "`) precision = " + explicitTemporalJtd.getPrecision());
}
final JdbcType jdbcType = explicitJdbcType != null ? explicitJdbcType : explicitTemporalJtd.getRecommendedJdbcType(stdIndicators);
final BasicType<T> jdbcMapping = typeConfiguration.getBasicTypeRegistry().resolve(explicitTemporalJtd, jdbcType);
return new InferredBasicValueResolution<>(jdbcMapping, explicitTemporalJtd, explicitTemporalJtd, jdbcType, null, jdbcMapping, explicitTemporalJtd.getMutabilityPlan());
}
if (explicitJdbcType != null) {
final TemporalJavaType<T> jtd;
if (requestedTemporalPrecision != null) {
jtd = reflectedJtd.resolveTypeForPrecision(requestedTemporalPrecision, typeConfiguration);
} else {
jtd = reflectedJtd;
}
final BasicType<T> jdbcMapping = typeConfiguration.getBasicTypeRegistry().resolve(jtd, explicitJdbcType);
return new InferredBasicValueResolution<>(jdbcMapping, jtd, jtd, explicitJdbcType, null, jdbcMapping, jtd.getMutabilityPlan());
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Case #3 - no explicit JavaType or JdbcType
//
// - for the moment continue to use the legacy resolution to registered
// BasicType
final BasicType<T> basicType;
if (requestedTemporalPrecision != null && requestedTemporalPrecision != reflectedJtd.getPrecision()) {
basicType = typeConfiguration.getBasicTypeRegistry().resolve(reflectedJtd.resolveTypeForPrecision(requestedTemporalPrecision, typeConfiguration), TemporalJavaType.resolveJdbcTypeCode(requestedTemporalPrecision));
} else {
basicType = typeConfiguration.getBasicTypeRegistry().resolve(reflectedJtd, reflectedJtd.getRecommendedJdbcType(stdIndicators));
}
return new InferredBasicValueResolution<>(basicType, basicType.getJavaTypeDescriptor(), basicType.getJavaTypeDescriptor(), basicType.getJdbcType(), null, basicType, reflectedJtd.getMutabilityPlan());
}
use of org.hibernate.type.descriptor.jdbc.JdbcType 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.jdbc.JdbcType 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.jdbc.JdbcType 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.jdbc.JdbcType in project hibernate-orm by hibernate.
the class ArgumentTypesValidator method validate.
/**
* We do an initial validation phase with just the SQM tree, even though we don't
* have all typing information available here (in particular, we don't have the
* final JDBC type codes for things with converters) because this is the phase
* that is run at startup for named queries, and can be done in an IDE.
*/
@Override
public void validate(List<? extends SqmTypedNode<?>> arguments, String functionName, QueryEngine queryEngine) {
delegate.validate(arguments, functionName, queryEngine);
int count = 0;
for (SqmTypedNode<?> argument : arguments) {
JdbcTypeIndicators indicators = queryEngine.getTypeConfiguration().getCurrentBaseSqlTypeIndicators();
SqmExpressible<?> nodeType = argument.getNodeType();
FunctionParameterType type = count < types.length ? types[count++] : types[types.length - 1];
if (nodeType != null) {
JavaType<?> javaType = nodeType.getExpressibleJavaType();
if (javaType != null) {
try {
JdbcType jdbcType = javaType.getRecommendedJdbcType(indicators);
checkType(count, functionName, type, jdbcType.getJdbcTypeCode(), javaType.getJavaTypeClass());
} catch (JdbcTypeRecommendationException e) {
// it's a converter or something like that, and we will check it later
}
}
switch(type) {
case TEMPORAL_UNIT:
if (!(argument instanceof SqmExtractUnit) && !(argument instanceof SqmDurationUnit)) {
throwError(type, Object.class, functionName, count);
}
break;
// something crazy by the parser
case TRIM_SPEC:
if (!(argument instanceof SqmTrimSpecification)) {
throwError(type, Object.class, functionName, count);
}
break;
case COLLATION:
if (!(argument instanceof SqmCollation)) {
throwError(type, Object.class, functionName, count);
}
break;
}
} else {
// TODO: appropriate error?
}
}
}
Aggregations