use of jakarta.persistence.TemporalType in project hibernate-orm by hibernate.
the class OffsetDateTimeJavaType method getRecommendedJdbcType.
@Override
public JdbcType getRecommendedJdbcType(JdbcTypeIndicators stdIndicators) {
final TemporalType temporalPrecision = stdIndicators.getTemporalPrecision();
final JdbcTypeRegistry jdbcTypeRegistry = stdIndicators.getTypeConfiguration().getJdbcTypeRegistry();
if (temporalPrecision == null || temporalPrecision == TemporalType.TIMESTAMP) {
return stdIndicators.getDefaultTimeZoneStorageStrategy() == TimeZoneStorageStrategy.NORMALIZE ? jdbcTypeRegistry.getDescriptor(Types.TIMESTAMP) : jdbcTypeRegistry.getDescriptor(Types.TIMESTAMP_WITH_TIMEZONE);
}
switch(temporalPrecision) {
case TIME:
{
return jdbcTypeRegistry.getDescriptor(Types.TIME);
}
case DATE:
{
return jdbcTypeRegistry.getDescriptor(Types.DATE);
}
default:
{
throw new IllegalArgumentException("Unexpected jakarta.persistence.TemporalType : " + temporalPrecision);
}
}
}
use of jakarta.persistence.TemporalType in project hibernate-orm by hibernate.
the class TimestampaddFunction method patternRenderer.
PatternRenderer patternRenderer(TemporalUnit unit, Expression interval, Expression to) {
TemporalType temporalType = getSqlTemporalType(to.getExpressionType());
IntervalType intervalType = getSqlIntervalType(interval.getExpressionType().getJdbcMappings().get(0));
return new PatternRenderer(dialect.timestampaddPattern(unit, temporalType, intervalType));
}
use of jakarta.persistence.TemporalType in project hibernate-orm by hibernate.
the class TimestampdiffFunction method patternRenderer.
private PatternRenderer patternRenderer(TemporalUnit unit, Expression from, Expression to) {
TemporalType lhsTemporalType = getSqlTemporalType(from.getExpressionType());
TemporalType rhsTemporalType = getSqlTemporalType(to.getExpressionType());
return new PatternRenderer(dialect.timestampdiffPattern(unit, lhsTemporalType, rhsTemporalType));
}
use of jakarta.persistence.TemporalType in project hibernate-orm by hibernate.
the class BaseSqmToSqlAstConverter method visitBinaryArithmeticExpression.
@Override
public Object visitBinaryArithmeticExpression(SqmBinaryArithmetic<?> expression) {
SqmExpression<?> leftOperand = expression.getLeftHandOperand();
SqmExpression<?> rightOperand = expression.getRightHandOperand();
boolean durationToRight = isDuration(rightOperand.getNodeType());
TypeConfiguration typeConfiguration = getCreationContext().getMappingMetamodel().getTypeConfiguration();
TemporalType temporalTypeToLeft = typeConfiguration.getSqlTemporalType(leftOperand.getNodeType());
TemporalType temporalTypeToRight = typeConfiguration.getSqlTemporalType(rightOperand.getNodeType());
boolean temporalTypeSomewhereToLeft = adjustedTimestamp != null || temporalTypeToLeft != null;
if (temporalTypeToLeft != null && durationToRight) {
if (adjustmentScale != null || negativeAdjustment) {
// we can't distribute a scale over a date/timestamp
throw new SemanticException("scalar multiplication of temporal value");
}
}
if (durationToRight && temporalTypeSomewhereToLeft) {
return transformDurationArithmetic(expression);
} else if (temporalTypeToLeft != null && temporalTypeToRight != null) {
return transformDatetimeArithmetic(expression);
} else {
// Infer one operand type through the other
final FromClauseIndex fromClauseIndex = fromClauseIndexStack.getCurrent();
inferrableTypeAccessStack.push(() -> determineValueMapping(rightOperand, fromClauseIndex));
final Expression lhs = toSqlExpression(leftOperand.accept(this));
inferrableTypeAccessStack.pop();
inferrableTypeAccessStack.push(() -> determineValueMapping(leftOperand, fromClauseIndex));
final Expression rhs = toSqlExpression(rightOperand.accept(this));
inferrableTypeAccessStack.pop();
if (durationToRight && appliedByUnit != null) {
return new BinaryArithmeticExpression(lhs, expression.getOperator(), rhs, // we always get a Long value back
(BasicValuedMapping) appliedByUnit.getNodeType());
} else {
return new BinaryArithmeticExpression(lhs, expression.getOperator(), rhs, getExpressionType(expression));
}
}
}
use of jakarta.persistence.TemporalType 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());
}
Aggregations