introduce JDBCTypeDescriptor.getDefaultSqlTypeCode()

and rename sqlType -> jdbcTypeCode in Type hierarchy for consistency

See https://github.com/hibernate/hibernate-orm/discussions/4088
This commit is contained in:
Gavin King 2021-07-23 21:24:09 +02:00 committed by Christian Beikov
parent 80e77b63d5
commit 07096e7cc1
47 changed files with 180 additions and 153 deletions

View File

@ -27,7 +27,7 @@ public class BitSetUserType implements UserType {
@Override
public int[] sqlTypes() {
return new int[] {StringType.INSTANCE.sqlType()};
return new int[] {StringType.INSTANCE.getJdbcTypeDescriptor().getDefaultSqlTypeCode()};
}
@Override

View File

@ -1983,7 +1983,7 @@ public class ModelBinder {
.getBasicTypeRegistry()
.getRegisteredType( value.getTypeName() );
if ( basicType instanceof AbstractSingleColumnStandardBasicType ) {
if ( isLob( basicType.getJdbcTypeDescriptor().getJdbcType(), null ) ) {
if ( isLob( basicType.getJdbcTypeDescriptor().getJdbcTypeCode(), null ) ) {
value.makeLob();
}
}
@ -2004,9 +2004,9 @@ public class ModelBinder {
private static boolean isLob(Integer sqlType, String sqlTypeName) {
if ( sqlType != null ) {
return ClobType.INSTANCE.getJdbcTypeDescriptor().getJdbcType() == sqlType ||
BlobType.INSTANCE.getJdbcTypeDescriptor().getJdbcType() == sqlType ||
NClobType.INSTANCE.getJdbcTypeDescriptor().getJdbcType() == sqlType;
return ClobType.INSTANCE.getJdbcTypeDescriptor().getJdbcTypeCode() == sqlType ||
BlobType.INSTANCE.getJdbcTypeDescriptor().getJdbcTypeCode() == sqlType ||
NClobType.INSTANCE.getJdbcTypeDescriptor().getJdbcTypeCode() == sqlType;
}
else if ( sqlTypeName != null ) {
return ClobType.INSTANCE.getName().equalsIgnoreCase( sqlTypeName ) ||

View File

@ -1097,7 +1097,7 @@ public abstract class Dialect implements ConversionContext {
}
public String getTypeName(JdbcTypeDescriptor jdbcTypeDescriptor) throws HibernateException {
return getTypeName( jdbcTypeDescriptor.getJdbcTypeCode() );
return getTypeName( jdbcTypeDescriptor.getDefaultSqlTypeCode() );
}
public String getTypeName(int code) throws HibernateException {

View File

@ -191,8 +191,7 @@ public class MySQLDialect extends Dialect {
Integer precision,
Integer scale,
Long length) {
final int jdbcTypeCode = jdbcType.getJdbcType();
switch ( jdbcTypeCode ) {
switch ( jdbcType.getDefaultSqlTypeCode() ) {
case Types.BIT:
// MySQL allows BIT with a length up to 64
if ( length != null ) {

View File

@ -110,7 +110,7 @@ public class PostgreSQLDialect extends Dialect {
registerColumnType( Types.LONGNVARCHAR, "text" );
if ( getVersion() >= 820 ) {
registerColumnType( PostgresUUIDType.INSTANCE.sqlType(), "uuid" );
registerColumnType( PostgresUUIDType.INSTANCE.getJdbcTypeDescriptor().getDefaultSqlTypeCode(), "uuid" );
if ( getVersion() >= 920 ) {
registerColumnType( Types.JAVA_OBJECT, "json" );

View File

@ -109,8 +109,7 @@ public class SybaseASEDialect extends SybaseDialect {
Integer precision,
Integer scale,
Long length) {
final int jdbcTypeCode = jdbcType.getJdbcType();
switch ( jdbcTypeCode ) {
switch ( jdbcType.getDefaultSqlTypeCode() ) {
case Types.FLOAT:
// Sybase ASE allows FLOAT with a precision up to 48
if ( precision != null ) {

View File

@ -36,7 +36,7 @@ public class ExportableColumn extends Column {
table,
name,
type,
database.getDialect().getTypeName( type.sqlTypes( null )[0] )
database.getDialect().getTypeName( type.getSqlTypeCodes( null )[0] )
);
}

View File

@ -256,7 +256,7 @@ public class BasicValue extends SimpleValue implements JdbcTypeDescriptorIndicat
if ( column instanceof Column && resolution.getValueConverter() == null ) {
final Column physicalColumn = (Column) column;
if ( physicalColumn.getSqlTypeCode() == null ) {
physicalColumn.setSqlTypeCode( resolution.getJdbcTypeDescriptor().getJdbcTypeCode() );
physicalColumn.setSqlTypeCode( resolution.getJdbcTypeDescriptor().getDefaultSqlTypeCode() );
}
final BasicType<?> basicType = resolution.getLegacyResolvedBasicType();

View File

@ -202,7 +202,7 @@ public class Column implements Selectable, Serializable, Cloneable {
public int getSqlTypeCode(Mapping mapping) throws MappingException {
org.hibernate.type.Type type = getValue().getType();
try {
int sqlTypeCode = type.sqlTypes( mapping )[getTypeIndex()];
int sqlTypeCode = type.getSqlTypeCodes( mapping )[getTypeIndex()];
if ( getSqlTypeCode() != null && getSqlTypeCode() != sqlTypeCode ) {
throw new MappingException( "SQLType code's does not match. mapped as " + sqlTypeCode + " but is " + getSqlTypeCode() );
}

View File

@ -649,7 +649,7 @@ public abstract class SimpleValue implements KeyValue {
// todo (6.0) : handle the other JdbcRecommendedSqlTypeMappingContext methods
metadata::getTypeConfiguration
);
int jdbcTypeCode = recommendedJdbcType.getJdbcType();
int jdbcTypeCode = recommendedJdbcType.getJdbcTypeCode();
if ( isLob() ) {
if ( LobTypeMappings.isMappedToKnownLobCode( jdbcTypeCode ) ) {
jdbcTypeCode = LobTypeMappings.getLobCodeTypeMapping( jdbcTypeCode );

View File

@ -3430,7 +3430,7 @@ public abstract class AbstractEntityPersister
.getIdentitySelectString(
getTableName( 0 ),
getKeyColumns( 0 )[0],
getIdentifierType().sqlTypes( getFactory() )[0]
getIdentifierType().getSqlTypeCodes( getFactory() )[0]
);
}

View File

@ -22,14 +22,8 @@ import org.hibernate.engine.spi.Mapping;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.mapping.IndexedConsumer;
import org.hibernate.metamodel.mapping.JdbcMapping;
import org.hibernate.metamodel.mapping.MappingType;
import org.hibernate.metamodel.model.domain.DomainType;
import org.hibernate.sql.ast.Clause;
import org.hibernate.type.AbstractType;
import org.hibernate.type.BasicType;
import org.hibernate.type.Type;
import org.hibernate.type.descriptor.ValueBinder;
import org.hibernate.type.descriptor.ValueExtractor;
import org.hibernate.type.descriptor.WrapperOptions;
@ -207,8 +201,8 @@ public class DiscriminatorType<T> extends AbstractType implements org.hibernate.
// simple delegation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@Override
public int[] sqlTypes(Mapping mapping) throws MappingException {
return underlyingType.sqlTypes( mapping );
public int[] getSqlTypeCodes(Mapping mapping) throws MappingException {
return underlyingType.getSqlTypeCodes( mapping );
}
@Override

View File

@ -57,7 +57,7 @@ public class TempIdTableExporter implements IdTableExporter {
}
buffer.append( column.getColumnName() ).append( ' ' );
final int sqlTypeCode = column.getJdbcMapping().getJdbcTypeDescriptor().getJdbcType();
final int sqlTypeCode = column.getJdbcMapping().getJdbcTypeDescriptor().getDefaultSqlTypeCode();
final String databaseTypeName = databaseTypeNameResolver.apply( sqlTypeCode );
buffer.append( " " ).append( databaseTypeName ).append( " " );

View File

@ -28,8 +28,8 @@ public abstract class AbstractSingleColumnStandardBasicType<T>
}
@Override
public final int sqlType() {
return getJdbcTypeDescriptor().getJdbcType();
public final int getJdbcTypeCode() {
return getJdbcTypeDescriptor().getJdbcTypeCode();
}
@Override

View File

@ -54,7 +54,7 @@ public abstract class AbstractStandardBasicType<T>
public AbstractStandardBasicType(JdbcTypeDescriptor jdbcTypeDescriptor, JavaTypeDescriptor<T> javaTypeDescriptor) {
this.jdbcTypeDescriptor = jdbcTypeDescriptor;
this.sqlTypes = new int[] { jdbcTypeDescriptor.getJdbcType() };
this.sqlTypes = new int[] { jdbcTypeDescriptor.getDefaultSqlTypeCode() };
this.javaTypeDescriptor = javaTypeDescriptor;
this.jdbcValueBinder = jdbcTypeDescriptor.getBinder( javaTypeDescriptor );
@ -156,7 +156,7 @@ public abstract class AbstractStandardBasicType<T>
public final void setSqlTypeDescriptor(JdbcTypeDescriptor jdbcTypeDescriptor) {
this.jdbcTypeDescriptor = jdbcTypeDescriptor;
this.sqlTypes = new int[] { jdbcTypeDescriptor.getJdbcType() };
this.sqlTypes = new int[] { jdbcTypeDescriptor.getDefaultSqlTypeCode() };
this.jdbcValueBinder = getJdbcTypeDescriptor().getBinder( javaTypeDescriptor );
this.jdbcValueExtractor = getJdbcTypeDescriptor().getExtractor( javaTypeDescriptor );
@ -173,7 +173,7 @@ public abstract class AbstractStandardBasicType<T>
}
@Override
public final int[] sqlTypes(Mapping mapping) throws MappingException {
public final int[] getSqlTypeCodes(Mapping mapping) throws MappingException {
return sqlTypes;
}

View File

@ -81,8 +81,8 @@ public class AnyType extends AbstractType implements CompositeType, AssociationT
}
@Override
public int[] sqlTypes(Mapping mapping) throws MappingException {
return ArrayHelper.join( discriminatorType.sqlTypes( mapping ), identifierType.sqlTypes( mapping ) );
public int[] getSqlTypeCodes(Mapping mapping) throws MappingException {
return ArrayHelper.join( discriminatorType.getSqlTypeCodes( mapping ), identifierType.getSqlTypeCodes( mapping ) );
}
@Override

View File

@ -163,7 +163,7 @@ public abstract class CollectionType extends AbstractType implements Association
}
@Override
public int[] sqlTypes(Mapping session) throws MappingException {
public int[] getSqlTypeCodes(Mapping session) throws MappingException {
return ArrayHelper.EMPTY_INT_ARRAY;
}

View File

@ -113,12 +113,12 @@ public class ComponentType extends AbstractType implements CompositeType, Proced
}
@Override
public int[] sqlTypes(Mapping mapping) throws MappingException {
public int[] getSqlTypeCodes(Mapping mapping) throws MappingException {
//Not called at runtime so doesn't matter if it's slow :)
int[] sqlTypes = new int[getColumnSpan( mapping )];
int n = 0;
for ( int i = 0; i < propertySpan; i++ ) {
int[] subtypes = propertyTypes[i].sqlTypes( mapping );
int[] subtypes = propertyTypes[i].getSqlTypeCodes( mapping );
for ( int subtype : subtypes ) {
sqlTypes[n++] = subtype;
}

View File

@ -128,8 +128,8 @@ public class CustomType
}
@Override
public int[] sqlTypes(Mapping pi) {
return new int[] { jdbcTypeDescriptor.getJdbcType() };
public int[] getSqlTypeCodes(Mapping pi) {
return new int[] { jdbcTypeDescriptor.getDefaultSqlTypeCode() };
}
@Override

View File

@ -25,7 +25,7 @@ public class DoubleType
public static final Double ZERO = 0.0;
public DoubleType() {
super( org.hibernate.type.descriptor.jdbc.FloatTypeDescriptor.INSTANCE, DoubleTypeDescriptor.INSTANCE );
super( org.hibernate.type.descriptor.jdbc.DoubleTypeDescriptor.INSTANCE, DoubleTypeDescriptor.INSTANCE );
}
@Override
public String getName() {

View File

@ -108,8 +108,8 @@ public class ManyToOneType extends EntityType {
}
@Override
public int[] sqlTypes(Mapping mapping) throws MappingException {
return requireIdentifierOrUniqueKeyType( mapping ).sqlTypes( mapping );
public int[] getSqlTypeCodes(Mapping mapping) throws MappingException {
return requireIdentifierOrUniqueKeyType( mapping ).getSqlTypeCodes( mapping );
}
@Override

View File

@ -51,8 +51,8 @@ public class MetaType extends AbstractType {
return discriminatorValuesToEntityNameMap;
}
public int[] sqlTypes(Mapping mapping) throws MappingException {
return baseType.sqlTypes(mapping);
public int[] getSqlTypeCodes(Mapping mapping) throws MappingException {
return baseType.getSqlTypeCodes(mapping);
}
@Override

View File

@ -84,7 +84,7 @@ public class OneToOneType extends EntityType {
}
@Override
public int[] sqlTypes(Mapping session) throws MappingException {
public int[] getSqlTypeCodes(Mapping session) throws MappingException {
return ArrayHelper.EMPTY_INT_ARRAY;
}

View File

@ -70,11 +70,6 @@ public class PostgresUUIDType extends AbstractSingleColumnStandardBasicType<UUID
return JDBC_TYPE_CODE;
}
@Override
public int getJdbcTypeCode() {
return getJdbcType();
}
@Override
public boolean canBeRemapped() {
return true;

View File

@ -20,7 +20,7 @@ import org.hibernate.engine.spi.SharedSessionContractImplementor;
*/
public interface SingleColumnType<T> extends Type {
int sqlType();
int getJdbcTypeCode();
String toString(T value) throws HibernateException;

View File

@ -60,8 +60,8 @@ public class SpecialOneToOneType extends OneToOneType {
return super.getIdentifierOrUniqueKeyType( mapping ).getColumnSpan( mapping );
}
public int[] sqlTypes(Mapping mapping) throws MappingException {
return super.getIdentifierOrUniqueKeyType( mapping ).sqlTypes( mapping );
public int[] getSqlTypeCodes(Mapping mapping) throws MappingException {
return super.getIdentifierOrUniqueKeyType( mapping ).getSqlTypeCodes( mapping );
}
@Override

View File

@ -108,7 +108,7 @@ public interface Type extends Serializable {
*
* @throws MappingException Generally indicates an issue accessing the passed mapping object.
*/
int[] sqlTypes(Mapping mapping) throws MappingException;
int[] getSqlTypeCodes(Mapping mapping) throws MappingException;
/**
* Return the column sizes dictated by this type. For example, the mapping for a {@code char}/{@link Character} would

View File

@ -31,7 +31,7 @@ public class DoubleTypeDescriptor extends AbstractClassTypeDescriptor<Double> im
@Override
public JdbcTypeDescriptor getRecommendedJdbcType(JdbcTypeDescriptorIndicators indicators) {
return indicators.getTypeConfiguration().getJdbcTypeDescriptorRegistry().getDescriptor( Types.REAL );
return org.hibernate.type.descriptor.jdbc.DoubleTypeDescriptor.INSTANCE;
}
@Override

View File

@ -13,6 +13,8 @@ import java.util.Locale;
import org.hibernate.dialect.Dialect;
import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.java.spi.Primitive;
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor;
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptorIndicators;
/**
* Descriptor for {@link Float} handling.
@ -25,6 +27,12 @@ public class FloatTypeDescriptor extends AbstractClassTypeDescriptor<Float> impl
public FloatTypeDescriptor() {
super( Float.class );
}
@Override
public JdbcTypeDescriptor getRecommendedJdbcType(JdbcTypeDescriptorIndicators indicators) {
return org.hibernate.type.descriptor.jdbc.FloatTypeDescriptor.INSTANCE;
}
@Override
public String toString(Float value) {
return value == null ? null : value.toString();

View File

@ -50,7 +50,7 @@ public abstract class BasicBinder<J> implements ValueBinder<J>, Serializable {
String.format(
NULL_BIND_MSG_TEMPLATE,
index,
JdbcTypeNameMapper.getTypeName( getJdbcTypeDescriptor().getJdbcType() )
JdbcTypeNameMapper.getTypeName( getJdbcTypeDescriptor().getJdbcTypeCode() )
)
);
}
@ -62,7 +62,7 @@ public abstract class BasicBinder<J> implements ValueBinder<J>, Serializable {
String.format(
BIND_MSG_TEMPLATE,
index,
JdbcTypeNameMapper.getTypeName( jdbcTypeDescriptor.getJdbcType() ),
JdbcTypeNameMapper.getTypeName( jdbcTypeDescriptor.getJdbcTypeCode() ),
getJavaTypeDescriptor().extractLoggableRepresentation( value )
)
);
@ -79,7 +79,7 @@ public abstract class BasicBinder<J> implements ValueBinder<J>, Serializable {
String.format(
NULL_BIND_MSG_TEMPLATE,
name,
JdbcTypeNameMapper.getTypeName( getJdbcTypeDescriptor().getJdbcType() )
JdbcTypeNameMapper.getTypeName( getJdbcTypeDescriptor().getJdbcTypeCode() )
)
);
}
@ -91,7 +91,7 @@ public abstract class BasicBinder<J> implements ValueBinder<J>, Serializable {
String.format(
BIND_MSG_TEMPLATE,
name,
JdbcTypeNameMapper.getTypeName( jdbcTypeDescriptor.getJdbcType() ),
JdbcTypeNameMapper.getTypeName( jdbcTypeDescriptor.getJdbcTypeCode() ),
getJavaTypeDescriptor().extractLoggableRepresentation( value )
)
);
@ -110,7 +110,7 @@ public abstract class BasicBinder<J> implements ValueBinder<J>, Serializable {
* @throws SQLException Indicates a problem binding to the prepared statement.
*/
protected void doBindNull(PreparedStatement st, int index, WrapperOptions options) throws SQLException {
st.setNull( index, jdbcTypeDescriptor.getJdbcType() );
st.setNull( index, jdbcTypeDescriptor.getJdbcTypeCode() );
}
/**
@ -123,7 +123,7 @@ public abstract class BasicBinder<J> implements ValueBinder<J>, Serializable {
* @throws SQLException Indicates a problem binding to the callable statement.
*/
protected void doBindNull(CallableStatement st, String name, WrapperOptions options) throws SQLException {
st.setNull( name, jdbcTypeDescriptor.getJdbcType() );
st.setNull( name, jdbcTypeDescriptor.getJdbcTypeCode() );
}
/**

View File

@ -47,7 +47,7 @@ public abstract class BasicExtractor<J> implements ValueExtractor<J>, Serializab
JdbcExtractingLogging.LOGGER.tracef(
"extracted value ([%s] : [%s]) - [null]",
paramIndex,
JdbcTypeNameMapper.getTypeName( getJdbcTypeDescriptor().getJdbcType() )
JdbcTypeNameMapper.getTypeName( getJdbcTypeDescriptor().getJdbcTypeCode() )
);
}
return null;
@ -57,7 +57,7 @@ public abstract class BasicExtractor<J> implements ValueExtractor<J>, Serializab
JdbcExtractingLogging.LOGGER.tracef(
"extracted value ([%s] : [%s]) - [%s]",
paramIndex,
JdbcTypeNameMapper.getTypeName( getJdbcTypeDescriptor().getJdbcType() ),
JdbcTypeNameMapper.getTypeName( getJdbcTypeDescriptor().getJdbcTypeCode() ),
getJavaTypeDescriptor().extractLoggableRepresentation( value )
);
}
@ -85,7 +85,7 @@ public abstract class BasicExtractor<J> implements ValueExtractor<J>, Serializab
JdbcExtractingLogging.LOGGER.tracef(
"extracted procedure output parameter ([%s] : [%s]) - [null]",
paramIndex,
JdbcTypeNameMapper.getTypeName( getJdbcTypeDescriptor().getJdbcType() )
JdbcTypeNameMapper.getTypeName( getJdbcTypeDescriptor().getJdbcTypeCode() )
);
}
return null;
@ -95,7 +95,7 @@ public abstract class BasicExtractor<J> implements ValueExtractor<J>, Serializab
JdbcExtractingLogging.LOGGER.tracef(
"extracted procedure output parameter ([%s] : [%s]) - [%s]",
paramIndex,
JdbcTypeNameMapper.getTypeName( getJdbcTypeDescriptor().getJdbcType() ),
JdbcTypeNameMapper.getTypeName( getJdbcTypeDescriptor().getJdbcTypeCode() ),
getJavaTypeDescriptor().extractLoggableRepresentation( value )
);
}
@ -123,7 +123,7 @@ public abstract class BasicExtractor<J> implements ValueExtractor<J>, Serializab
JdbcExtractingLogging.LOGGER.tracef(
"extracted named procedure output parameter ([%s] : [%s]) - [null]",
paramName,
JdbcTypeNameMapper.getTypeName( getJdbcTypeDescriptor().getJdbcType() )
JdbcTypeNameMapper.getTypeName( getJdbcTypeDescriptor().getJdbcTypeCode() )
);
}
return null;
@ -133,7 +133,7 @@ public abstract class BasicExtractor<J> implements ValueExtractor<J>, Serializab
JdbcExtractingLogging.LOGGER.tracef(
"extracted named procedure output parameter ([%s] : [%s]) - [%s]",
paramName,
JdbcTypeNameMapper.getTypeName( getJdbcTypeDescriptor().getJdbcType() ),
JdbcTypeNameMapper.getTypeName( getJdbcTypeDescriptor().getJdbcTypeCode() ),
getJavaTypeDescriptor().extractLoggableRepresentation( value )
);
}

View File

@ -31,11 +31,22 @@ public class DoubleTypeDescriptor implements JdbcTypeDescriptor {
public DoubleTypeDescriptor() {
}
/**
* @return {@link Types#DOUBLE}
*/
@Override
public int getJdbcType() {
return Types.DOUBLE;
}
/**
* @return {@link Types#FLOAT} for schema generation
*/
@Override
public int getDefaultSqlTypeCode() {
return Types.FLOAT;
}
@Override
public String getFriendlyName() {
return "DOUBLE";
@ -43,7 +54,7 @@ public class DoubleTypeDescriptor implements JdbcTypeDescriptor {
@Override
public String toString() {
return "SqlTypeDescriptor(" + getFriendlyName() + ")";
return "DoubleTypeDescriptor";
}
@Override

View File

@ -6,9 +6,18 @@
*/
package org.hibernate.type.descriptor.jdbc;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import org.hibernate.type.descriptor.ValueBinder;
import org.hibernate.type.descriptor.ValueExtractor;
import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.java.BasicJavaDescriptor;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.descriptor.jdbc.internal.JdbcLiteralFormatterNumericData;
import org.hibernate.type.spi.TypeConfiguration;
/**
@ -16,19 +25,76 @@ import org.hibernate.type.spi.TypeConfiguration;
*
* @author Steve Ebersole
*/
public class FloatTypeDescriptor extends RealTypeDescriptor {
public class FloatTypeDescriptor implements JdbcTypeDescriptor {
public static final FloatTypeDescriptor INSTANCE = new FloatTypeDescriptor();
public FloatTypeDescriptor() {
}
@Override
public int getJdbcType() {
return Types.FLOAT;
}
@Override
public String getFriendlyName() {
return "FLOAT";
}
@Override
public String toString() {
return "FloatTypeDescriptor";
}
@Override
public boolean canBeRemapped() {
return true;
}
@Override
public <T> BasicJavaDescriptor<T> getJdbcRecommendedJavaTypeMapping(TypeConfiguration typeConfiguration) {
return (BasicJavaDescriptor<T>) typeConfiguration.getJavaTypeDescriptorRegistry().getDescriptor( Double.class );
}
@Override
public int getJdbcType() {
return Types.FLOAT;
@SuppressWarnings("unchecked")
public <T> JdbcLiteralFormatter<T> getJdbcLiteralFormatter(JavaTypeDescriptor<T> javaTypeDescriptor) {
return new JdbcLiteralFormatterNumericData( javaTypeDescriptor, Float.class );
}
@Override
public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicBinder<X>( javaTypeDescriptor, this ) {
@Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
st.setFloat( index, javaTypeDescriptor.unwrap( value, Float.class, options ) );
}
@Override
protected void doBind(CallableStatement st, X value, String name, WrapperOptions options)
throws SQLException {
st.setFloat( name, javaTypeDescriptor.unwrap( value, Float.class, options ) );
}
};
}
@Override
public <X> ValueExtractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicExtractor<X>( javaTypeDescriptor, this ) {
@Override
protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
return javaTypeDescriptor.wrap( rs.getFloat( paramIndex ), options );
}
@Override
protected X doExtract(CallableStatement statement, int index, WrapperOptions options) throws SQLException {
return javaTypeDescriptor.wrap( statement.getFloat( index ), options );
}
@Override
protected X doExtract(CallableStatement statement, String name, WrapperOptions options) throws SQLException {
return javaTypeDescriptor.wrap( statement.getFloat( name ), options );
}
};
}
}

View File

@ -29,7 +29,7 @@ public interface JdbcTypeDescriptor extends Serializable {
* A "friendly" name for use in logging
*/
default String getFriendlyName() {
return Integer.toString( getJdbcType() );
return Integer.toString( getJdbcTypeCode() );
}
/**
@ -50,6 +50,16 @@ public interface JdbcTypeDescriptor extends Serializable {
return getJdbcType();
}
/**
* Get a JDBC type code that identifies the SQL column type to be
* used for schema generation.
*
* @see #getJdbcType
*/
default int getDefaultSqlTypeCode() {
return getJdbcType();
}
/**
* Is this descriptor available for remapping?
*
@ -63,7 +73,7 @@ public interface JdbcTypeDescriptor extends Serializable {
default <T> BasicJavaDescriptor<T> getJdbcRecommendedJavaTypeMapping(TypeConfiguration typeConfiguration) {
// match legacy behavior
return (BasicJavaDescriptor<T>) typeConfiguration.getJavaTypeDescriptorRegistry().getDescriptor(
JdbcTypeJavaClassMappings.INSTANCE.determineJavaClassForJdbcTypeCode( getJdbcType() )
JdbcTypeJavaClassMappings.INSTANCE.determineJavaClassForJdbcTypeCode( getJdbcTypeCode() )
);
}
@ -95,7 +105,7 @@ public interface JdbcTypeDescriptor extends Serializable {
<X> ValueExtractor<X> getExtractor(JavaTypeDescriptor<X> javaTypeDescriptor);
default boolean isInteger() {
switch ( getJdbcType() ) {
switch ( getJdbcTypeCode() ) {
case Types.BIT:
case Types.TINYINT:
case Types.SMALLINT:
@ -107,7 +117,7 @@ public interface JdbcTypeDescriptor extends Serializable {
}
default boolean isNumber() {
switch ( getJdbcType() ) {
switch ( getJdbcTypeCode() ) {
case Types.BIT:
case Types.TINYINT:
case Types.SMALLINT:
@ -124,7 +134,7 @@ public interface JdbcTypeDescriptor extends Serializable {
}
default boolean isBinary() {
switch ( getJdbcType() ) {
switch ( getJdbcTypeCode() ) {
case Types.BINARY:
case Types.VARBINARY:
case Types.LONGVARBINARY:
@ -135,7 +145,7 @@ public interface JdbcTypeDescriptor extends Serializable {
}
default boolean isString() {
switch ( getJdbcType() ) {
switch ( getJdbcTypeCode() ) {
case Types.CHAR:
case Types.NCHAR:
case Types.VARCHAR:
@ -150,7 +160,7 @@ public interface JdbcTypeDescriptor extends Serializable {
}
default boolean isTemporal() {
switch ( getJdbcType() ) {
switch ( getJdbcTypeCode() ) {
case Types.DATE:
case Types.TIME:
case Types.TIMESTAMP:
@ -161,7 +171,7 @@ public interface JdbcTypeDescriptor extends Serializable {
}
default CastType getCastType() {
switch ( getJdbcType() ) {
switch ( getJdbcTypeCode() ) {
case Types.INTEGER:
case Types.TINYINT:
case Types.SMALLINT:

View File

@ -6,27 +6,20 @@
*/
package org.hibernate.type.descriptor.jdbc;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import org.hibernate.type.descriptor.ValueBinder;
import org.hibernate.type.descriptor.ValueExtractor;
import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.java.BasicJavaDescriptor;
import org.hibernate.type.descriptor.java.FloatTypeDescriptor;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.descriptor.jdbc.internal.JdbcLiteralFormatterNumericData;
import org.hibernate.type.spi.TypeConfiguration;
/**
* Descriptor for {@link Types#REAL REAL} handling.
*
* @author Steve Ebersole
*
* @deprecated use {@link FloatTypeDescriptor}
*/
public class RealTypeDescriptor implements JdbcTypeDescriptor {
@Deprecated
public class RealTypeDescriptor extends FloatTypeDescriptor {
public static final RealTypeDescriptor INSTANCE = new RealTypeDescriptor();
public RealTypeDescriptor() {
@ -47,55 +40,8 @@ public class RealTypeDescriptor implements JdbcTypeDescriptor {
return "RealTypeDescriptor";
}
@Override
public boolean canBeRemapped() {
return true;
}
@Override
public <T> BasicJavaDescriptor<T> getJdbcRecommendedJavaTypeMapping(TypeConfiguration typeConfiguration) {
return (BasicJavaDescriptor<T>) typeConfiguration.getJavaTypeDescriptorRegistry().getDescriptor( Float.class );
}
@Override
@SuppressWarnings("unchecked")
public <T> JdbcLiteralFormatter<T> getJdbcLiteralFormatter(JavaTypeDescriptor<T> javaTypeDescriptor) {
return new JdbcLiteralFormatterNumericData( javaTypeDescriptor, Float.class );
}
@Override
public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicBinder<X>( javaTypeDescriptor, this ) {
@Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
st.setFloat( index, javaTypeDescriptor.unwrap( value, Float.class, options ) );
}
@Override
protected void doBind(CallableStatement st, X value, String name, WrapperOptions options)
throws SQLException {
st.setFloat( name, javaTypeDescriptor.unwrap( value, Float.class, options ) );
}
};
}
@Override
public <X> ValueExtractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicExtractor<X>( javaTypeDescriptor, this ) {
@Override
protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
return javaTypeDescriptor.wrap( rs.getFloat( paramIndex ), options );
}
@Override
protected X doExtract(CallableStatement statement, int index, WrapperOptions options) throws SQLException {
return javaTypeDescriptor.wrap( statement.getFloat( index ), options );
}
@Override
protected X doExtract(CallableStatement statement, String name, WrapperOptions options) throws SQLException {
return javaTypeDescriptor.wrap( statement.getFloat( name ), options );
}
};
}
}

View File

@ -61,7 +61,7 @@ public class StandardBasicTypeImpl<J>
@Override
public CastType getCastType() {
if ( getJavaTypeDescriptor() == BooleanTypeDescriptor.INSTANCE ) {
switch ( sqlType() ) {
switch ( getJdbcTypeCode() ) {
case Types.BIT:
case Types.SMALLINT:
case Types.TINYINT:

View File

@ -233,7 +233,7 @@ public class TypeConfiguration implements SessionFactoryObserver, Serializable {
);
try {
int[] jdbcTypes = basicType.sqlTypes( null );
int[] jdbcTypes = basicType.getSqlTypeCodes( null );
if ( jdbcTypes.length == 1 ) {
int jdbcType = jdbcTypes[0];
@ -650,7 +650,7 @@ public class TypeConfiguration implements SessionFactoryObserver, Serializable {
return getSqlTemporalType( ( (BasicValuedMapping) type ).getJdbcMapping().getJdbcTypeDescriptor() );
}
else if (type instanceof SingleColumnType) {
return getSqlTemporalType( ((SingleColumnType<?>) type).sqlType() );
return getSqlTemporalType( ((SingleColumnType<?>) type).getJdbcTypeCode() );
}
return null;
}

View File

@ -55,7 +55,7 @@ public class NestedEmbeddableMetadataTest {
Component amountMetadata = (Component) investmentMetadata.getProperty( "amount" ).getValue();
SimpleValue currencyMetadata = (SimpleValue) amountMetadata.getProperty( "currency" ).getValue();
CustomType currencyType = (CustomType) currencyMetadata.getType();
int[] currencySqlTypes = currencyType.sqlTypes( metadata );
int[] currencySqlTypes = currencyType.getSqlTypeCodes( metadata );
assertEquals( 1, currencySqlTypes.length );
assertJdbcTypeCode( Types.VARCHAR, currencySqlTypes[0] );
}

View File

@ -53,7 +53,7 @@ public class FieldAccessedNestedEmbeddableMetadataTest {
Component amountMetadata = (Component) investmentMetadata.getProperty( "amount" ).getValue();
SimpleValue currencyMetadata = (SimpleValue) amountMetadata.getProperty( "currency" ).getValue();
CustomType currencyType = (CustomType) currencyMetadata.getType();
int[] currencySqlTypes = currencyType.sqlTypes( metadata );
int[] currencySqlTypes = currencyType.getSqlTypeCodes( metadata );
assertEquals( 1, currencySqlTypes.length );
assertJdbcTypeCode( Types.VARCHAR, currencySqlTypes[0] );
}

View File

@ -132,7 +132,7 @@ public class UserTypeComparableIdTest {
@Override
public int[] sqlTypes() {
return new int[] { SQL_TYPE.sqlType() };
return new int[] { SQL_TYPE.getJdbcTypeCode() };
}
@Override
@ -152,7 +152,7 @@ public class UserTypeComparableIdTest {
CustomId customId = (CustomId) value;
if ( customId == null ) {
preparedStatement.setNull( index, SQL_TYPE.sqlType() );
preparedStatement.setNull( index, SQL_TYPE.getJdbcTypeCode() );
}
else {
preparedStatement.setLong( index, customId.getValue() );

View File

@ -119,7 +119,7 @@ public class UserTypeNonComparableIdTest {
@Override
public int[] sqlTypes() {
return new int[] { SQL_TYPE.sqlType() };
return new int[] { SQL_TYPE.getJdbcTypeCode() };
}
@Override
@ -139,7 +139,7 @@ public class UserTypeNonComparableIdTest {
CustomId customId = (CustomId) value;
if ( customId == null ) {
preparedStatement.setNull( index, SQL_TYPE.sqlType() );
preparedStatement.setNull( index, SQL_TYPE.getJdbcTypeCode() );
}
else {
preparedStatement.setLong( index, customId.getValue() );

View File

@ -6,7 +6,6 @@
*/
package org.hibernate.orm.test.mapping.converted.converter;
import java.sql.Types;
import javax.persistence.AttributeConverter;
import javax.persistence.Convert;
import javax.persistence.Entity;
@ -49,7 +48,7 @@ public class AndNationalizedTests extends BaseUnitTestCase {
final Dialect dialect = metadata.getDatabase().getDialect();
assertEquals(
dialect.getNationalizationSupport().getVarcharVariantCode(),
entityBinding.getProperty( "name" ).getType().sqlTypes( metadata )[0]
entityBinding.getProperty( "name" ).getType().getSqlTypeCodes( metadata )[0]
);
}
finally {

View File

@ -39,7 +39,7 @@ public class FormulaFromHbmTests {
(rootClass) -> {
final Property stringFormula = rootClass.getProperty( "stringFormula" );
{
final int[] sqlTypes = stringFormula.getType().sqlTypes( scope.getDomainModel() );
final int[] sqlTypes = stringFormula.getType().getSqlTypeCodes( scope.getDomainModel() );
assertThat( sqlTypes.length, is( 1 ) );
assertThat( sqlTypes[ 0 ], is( Types.VARCHAR ) );
@ -49,7 +49,7 @@ public class FormulaFromHbmTests {
final Property integerFormula = rootClass.getProperty( "integerFormula" );
{
final int[] sqlTypes = integerFormula.getType().sqlTypes( scope.getDomainModel() );
final int[] sqlTypes = integerFormula.getType().getSqlTypeCodes( scope.getDomainModel() );
assertThat( sqlTypes.length, is( 1 ) );
assertThat( sqlTypes[ 0 ], is( Types.INTEGER ) );

View File

@ -108,8 +108,8 @@ public class AttributeOverrideEnhancedUserTypeTest {
@Override
public int[] sqlTypes() {
return new int[] {
IntegerType.INSTANCE.sqlType(),
IntegerType.INSTANCE.sqlType(),
IntegerType.INSTANCE.getJdbcTypeCode(),
IntegerType.INSTANCE.getJdbcTypeCode(),
};
}

View File

@ -107,7 +107,7 @@ public class MyStringType implements UserType, DynamicParameterizedType {
@Override
public int[] sqlTypes() {
return new int[] { StringType.INSTANCE.sqlType() };
return new int[] { StringType.INSTANCE.getJdbcTypeCode() };
}
@Override

View File

@ -25,7 +25,7 @@ public class StringWrapperUserType implements UserType {
@Override
public int[] sqlTypes() {
return new int[] {StringType.INSTANCE.sqlType()};
return new int[] {StringType.INSTANCE.getJdbcTypeCode()};
}
@Override

View File

@ -21,7 +21,7 @@ public class AgeType implements UserType {
@Override
public int[] sqlTypes() {
return new int[] {
IntegerType.INSTANCE.sqlType()
IntegerType.INSTANCE.getJdbcTypeCode()
};
}