HHH-18150 Fix for Informix float and double precision in decimal digits

This commit is contained in:
Vladimír Kuruc 2024-05-22 11:17:10 +02:00 committed by Christian Beikov
parent abf07078d8
commit 0fd9edc501
1 changed files with 39 additions and 1 deletions

View File

@ -7,6 +7,8 @@
package org.hibernate.community.dialect;
import org.hibernate.boot.Metadata;
import java.sql.Types;
import org.hibernate.boot.model.FunctionContributions;
import org.hibernate.boot.model.TypeContributions;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
@ -27,6 +29,7 @@ import org.hibernate.dialect.sequence.SequenceSupport;
import org.hibernate.dialect.temptable.TemporaryTable;
import org.hibernate.dialect.temptable.TemporaryTableKind;
import org.hibernate.dialect.unique.UniqueDelegate;
import org.hibernate.engine.jdbc.Size;
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
import org.hibernate.engine.spi.LoadQueryInfluencers;
import org.hibernate.engine.spi.SessionFactoryImplementor;
@ -62,6 +65,8 @@ import org.hibernate.sql.exec.spi.JdbcOperation;
import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor;
import org.hibernate.tool.schema.internal.StandardForeignKeyExporter;
import org.hibernate.tool.schema.spi.Exporter;
import org.hibernate.type.descriptor.java.JavaType;
import org.hibernate.type.descriptor.jdbc.JdbcType;
import org.hibernate.type.descriptor.sql.internal.CapacityDependentDdlType;
import org.hibernate.type.descriptor.sql.spi.DdlTypeRegistry;
import org.hibernate.type.spi.TypeConfiguration;
@ -114,6 +119,24 @@ public class InformixDialect extends Dialect {
}
};
private final SizeStrategy sizeStrategy = new SizeStrategyImpl() {
@Override
public Size resolveSize(
JdbcType jdbcType,
JavaType<?> javaType,
Integer precision,
Integer scale,
Long length) {
switch ( jdbcType.getDdlTypeCode() ) {
case Types.FLOAT:
// Informix allows FLOAT with a precision up to 16
if ( precision != null ) {
return Size.precision( Math.min( Math.max( precision, 1 ), 16 ) );
}
}
return super.resolveSize( jdbcType, javaType, precision, scale, length );
}
};
public InformixDialect(DialectResolutionInfo info) {
this( info.makeCopyOrDefault( DEFAULT_VERSION ) );
registerKeywords( info );
@ -179,7 +202,7 @@ public class InformixDialect extends Dialect {
//double precision.
ddlTypeRegistry.addDescriptor(
CapacityDependentDdlType.builder( FLOAT, "float($p)", this )
.withTypeCapacity( 24, "smallfloat" )
.withTypeCapacity( 8, "smallfloat" )
.build()
);
@ -226,6 +249,21 @@ public class InformixDialect extends Dialect {
return 5;
}
@Override
public int getFloatPrecision() {
return 8;
}
@Override
public int getDoublePrecision() {
return 16;
}
@Override
public SizeStrategy getSizeStrategy() {
return sizeStrategy;
}
@Override
public void initializeFunctionRegistry(FunctionContributions functionContributions) {
super.initializeFunctionRegistry(functionContributions);