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:
parent
80e77b63d5
commit
07096e7cc1
|
@ -27,7 +27,7 @@ public class BitSetUserType implements UserType {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int[] sqlTypes() {
|
public int[] sqlTypes() {
|
||||||
return new int[] {StringType.INSTANCE.sqlType()};
|
return new int[] {StringType.INSTANCE.getJdbcTypeDescriptor().getDefaultSqlTypeCode()};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1983,7 +1983,7 @@ public class ModelBinder {
|
||||||
.getBasicTypeRegistry()
|
.getBasicTypeRegistry()
|
||||||
.getRegisteredType( value.getTypeName() );
|
.getRegisteredType( value.getTypeName() );
|
||||||
if ( basicType instanceof AbstractSingleColumnStandardBasicType ) {
|
if ( basicType instanceof AbstractSingleColumnStandardBasicType ) {
|
||||||
if ( isLob( basicType.getJdbcTypeDescriptor().getJdbcType(), null ) ) {
|
if ( isLob( basicType.getJdbcTypeDescriptor().getJdbcTypeCode(), null ) ) {
|
||||||
value.makeLob();
|
value.makeLob();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2004,9 +2004,9 @@ public class ModelBinder {
|
||||||
|
|
||||||
private static boolean isLob(Integer sqlType, String sqlTypeName) {
|
private static boolean isLob(Integer sqlType, String sqlTypeName) {
|
||||||
if ( sqlType != null ) {
|
if ( sqlType != null ) {
|
||||||
return ClobType.INSTANCE.getJdbcTypeDescriptor().getJdbcType() == sqlType ||
|
return ClobType.INSTANCE.getJdbcTypeDescriptor().getJdbcTypeCode() == sqlType ||
|
||||||
BlobType.INSTANCE.getJdbcTypeDescriptor().getJdbcType() == sqlType ||
|
BlobType.INSTANCE.getJdbcTypeDescriptor().getJdbcTypeCode() == sqlType ||
|
||||||
NClobType.INSTANCE.getJdbcTypeDescriptor().getJdbcType() == sqlType;
|
NClobType.INSTANCE.getJdbcTypeDescriptor().getJdbcTypeCode() == sqlType;
|
||||||
}
|
}
|
||||||
else if ( sqlTypeName != null ) {
|
else if ( sqlTypeName != null ) {
|
||||||
return ClobType.INSTANCE.getName().equalsIgnoreCase( sqlTypeName ) ||
|
return ClobType.INSTANCE.getName().equalsIgnoreCase( sqlTypeName ) ||
|
||||||
|
|
|
@ -1097,7 +1097,7 @@ public abstract class Dialect implements ConversionContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTypeName(JdbcTypeDescriptor jdbcTypeDescriptor) throws HibernateException {
|
public String getTypeName(JdbcTypeDescriptor jdbcTypeDescriptor) throws HibernateException {
|
||||||
return getTypeName( jdbcTypeDescriptor.getJdbcTypeCode() );
|
return getTypeName( jdbcTypeDescriptor.getDefaultSqlTypeCode() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTypeName(int code) throws HibernateException {
|
public String getTypeName(int code) throws HibernateException {
|
||||||
|
|
|
@ -191,8 +191,7 @@ public class MySQLDialect extends Dialect {
|
||||||
Integer precision,
|
Integer precision,
|
||||||
Integer scale,
|
Integer scale,
|
||||||
Long length) {
|
Long length) {
|
||||||
final int jdbcTypeCode = jdbcType.getJdbcType();
|
switch ( jdbcType.getDefaultSqlTypeCode() ) {
|
||||||
switch ( jdbcTypeCode ) {
|
|
||||||
case Types.BIT:
|
case Types.BIT:
|
||||||
// MySQL allows BIT with a length up to 64
|
// MySQL allows BIT with a length up to 64
|
||||||
if ( length != null ) {
|
if ( length != null ) {
|
||||||
|
|
|
@ -110,7 +110,7 @@ public class PostgreSQLDialect extends Dialect {
|
||||||
registerColumnType( Types.LONGNVARCHAR, "text" );
|
registerColumnType( Types.LONGNVARCHAR, "text" );
|
||||||
|
|
||||||
if ( getVersion() >= 820 ) {
|
if ( getVersion() >= 820 ) {
|
||||||
registerColumnType( PostgresUUIDType.INSTANCE.sqlType(), "uuid" );
|
registerColumnType( PostgresUUIDType.INSTANCE.getJdbcTypeDescriptor().getDefaultSqlTypeCode(), "uuid" );
|
||||||
|
|
||||||
if ( getVersion() >= 920 ) {
|
if ( getVersion() >= 920 ) {
|
||||||
registerColumnType( Types.JAVA_OBJECT, "json" );
|
registerColumnType( Types.JAVA_OBJECT, "json" );
|
||||||
|
|
|
@ -109,8 +109,7 @@ public class SybaseASEDialect extends SybaseDialect {
|
||||||
Integer precision,
|
Integer precision,
|
||||||
Integer scale,
|
Integer scale,
|
||||||
Long length) {
|
Long length) {
|
||||||
final int jdbcTypeCode = jdbcType.getJdbcType();
|
switch ( jdbcType.getDefaultSqlTypeCode() ) {
|
||||||
switch ( jdbcTypeCode ) {
|
|
||||||
case Types.FLOAT:
|
case Types.FLOAT:
|
||||||
// Sybase ASE allows FLOAT with a precision up to 48
|
// Sybase ASE allows FLOAT with a precision up to 48
|
||||||
if ( precision != null ) {
|
if ( precision != null ) {
|
||||||
|
|
|
@ -36,7 +36,7 @@ public class ExportableColumn extends Column {
|
||||||
table,
|
table,
|
||||||
name,
|
name,
|
||||||
type,
|
type,
|
||||||
database.getDialect().getTypeName( type.sqlTypes( null )[0] )
|
database.getDialect().getTypeName( type.getSqlTypeCodes( null )[0] )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -256,7 +256,7 @@ public class BasicValue extends SimpleValue implements JdbcTypeDescriptorIndicat
|
||||||
if ( column instanceof Column && resolution.getValueConverter() == null ) {
|
if ( column instanceof Column && resolution.getValueConverter() == null ) {
|
||||||
final Column physicalColumn = (Column) column;
|
final Column physicalColumn = (Column) column;
|
||||||
if ( physicalColumn.getSqlTypeCode() == null ) {
|
if ( physicalColumn.getSqlTypeCode() == null ) {
|
||||||
physicalColumn.setSqlTypeCode( resolution.getJdbcTypeDescriptor().getJdbcTypeCode() );
|
physicalColumn.setSqlTypeCode( resolution.getJdbcTypeDescriptor().getDefaultSqlTypeCode() );
|
||||||
}
|
}
|
||||||
|
|
||||||
final BasicType<?> basicType = resolution.getLegacyResolvedBasicType();
|
final BasicType<?> basicType = resolution.getLegacyResolvedBasicType();
|
||||||
|
|
|
@ -202,7 +202,7 @@ public class Column implements Selectable, Serializable, Cloneable {
|
||||||
public int getSqlTypeCode(Mapping mapping) throws MappingException {
|
public int getSqlTypeCode(Mapping mapping) throws MappingException {
|
||||||
org.hibernate.type.Type type = getValue().getType();
|
org.hibernate.type.Type type = getValue().getType();
|
||||||
try {
|
try {
|
||||||
int sqlTypeCode = type.sqlTypes( mapping )[getTypeIndex()];
|
int sqlTypeCode = type.getSqlTypeCodes( mapping )[getTypeIndex()];
|
||||||
if ( getSqlTypeCode() != null && getSqlTypeCode() != sqlTypeCode ) {
|
if ( getSqlTypeCode() != null && getSqlTypeCode() != sqlTypeCode ) {
|
||||||
throw new MappingException( "SQLType code's does not match. mapped as " + sqlTypeCode + " but is " + getSqlTypeCode() );
|
throw new MappingException( "SQLType code's does not match. mapped as " + sqlTypeCode + " but is " + getSqlTypeCode() );
|
||||||
}
|
}
|
||||||
|
|
|
@ -649,7 +649,7 @@ public abstract class SimpleValue implements KeyValue {
|
||||||
// todo (6.0) : handle the other JdbcRecommendedSqlTypeMappingContext methods
|
// todo (6.0) : handle the other JdbcRecommendedSqlTypeMappingContext methods
|
||||||
metadata::getTypeConfiguration
|
metadata::getTypeConfiguration
|
||||||
);
|
);
|
||||||
int jdbcTypeCode = recommendedJdbcType.getJdbcType();
|
int jdbcTypeCode = recommendedJdbcType.getJdbcTypeCode();
|
||||||
if ( isLob() ) {
|
if ( isLob() ) {
|
||||||
if ( LobTypeMappings.isMappedToKnownLobCode( jdbcTypeCode ) ) {
|
if ( LobTypeMappings.isMappedToKnownLobCode( jdbcTypeCode ) ) {
|
||||||
jdbcTypeCode = LobTypeMappings.getLobCodeTypeMapping( jdbcTypeCode );
|
jdbcTypeCode = LobTypeMappings.getLobCodeTypeMapping( jdbcTypeCode );
|
||||||
|
|
|
@ -3430,7 +3430,7 @@ public abstract class AbstractEntityPersister
|
||||||
.getIdentitySelectString(
|
.getIdentitySelectString(
|
||||||
getTableName( 0 ),
|
getTableName( 0 ),
|
||||||
getKeyColumns( 0 )[0],
|
getKeyColumns( 0 )[0],
|
||||||
getIdentifierType().sqlTypes( getFactory() )[0]
|
getIdentifierType().getSqlTypeCodes( getFactory() )[0]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,14 +22,8 @@ import org.hibernate.engine.spi.Mapping;
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||||
import org.hibernate.internal.util.collections.ArrayHelper;
|
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.AbstractType;
|
||||||
import org.hibernate.type.BasicType;
|
import org.hibernate.type.BasicType;
|
||||||
import org.hibernate.type.Type;
|
|
||||||
import org.hibernate.type.descriptor.ValueBinder;
|
import org.hibernate.type.descriptor.ValueBinder;
|
||||||
import org.hibernate.type.descriptor.ValueExtractor;
|
import org.hibernate.type.descriptor.ValueExtractor;
|
||||||
import org.hibernate.type.descriptor.WrapperOptions;
|
import org.hibernate.type.descriptor.WrapperOptions;
|
||||||
|
@ -207,8 +201,8 @@ public class DiscriminatorType<T> extends AbstractType implements org.hibernate.
|
||||||
// simple delegation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
// simple delegation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int[] sqlTypes(Mapping mapping) throws MappingException {
|
public int[] getSqlTypeCodes(Mapping mapping) throws MappingException {
|
||||||
return underlyingType.sqlTypes( mapping );
|
return underlyingType.getSqlTypeCodes( mapping );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -57,7 +57,7 @@ public class TempIdTableExporter implements IdTableExporter {
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer.append( column.getColumnName() ).append( ' ' );
|
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 );
|
final String databaseTypeName = databaseTypeNameResolver.apply( sqlTypeCode );
|
||||||
|
|
||||||
buffer.append( " " ).append( databaseTypeName ).append( " " );
|
buffer.append( " " ).append( databaseTypeName ).append( " " );
|
||||||
|
|
|
@ -28,8 +28,8 @@ public abstract class AbstractSingleColumnStandardBasicType<T>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final int sqlType() {
|
public final int getJdbcTypeCode() {
|
||||||
return getJdbcTypeDescriptor().getJdbcType();
|
return getJdbcTypeDescriptor().getJdbcTypeCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -54,7 +54,7 @@ public abstract class AbstractStandardBasicType<T>
|
||||||
|
|
||||||
public AbstractStandardBasicType(JdbcTypeDescriptor jdbcTypeDescriptor, JavaTypeDescriptor<T> javaTypeDescriptor) {
|
public AbstractStandardBasicType(JdbcTypeDescriptor jdbcTypeDescriptor, JavaTypeDescriptor<T> javaTypeDescriptor) {
|
||||||
this.jdbcTypeDescriptor = jdbcTypeDescriptor;
|
this.jdbcTypeDescriptor = jdbcTypeDescriptor;
|
||||||
this.sqlTypes = new int[] { jdbcTypeDescriptor.getJdbcType() };
|
this.sqlTypes = new int[] { jdbcTypeDescriptor.getDefaultSqlTypeCode() };
|
||||||
this.javaTypeDescriptor = javaTypeDescriptor;
|
this.javaTypeDescriptor = javaTypeDescriptor;
|
||||||
|
|
||||||
this.jdbcValueBinder = jdbcTypeDescriptor.getBinder( javaTypeDescriptor );
|
this.jdbcValueBinder = jdbcTypeDescriptor.getBinder( javaTypeDescriptor );
|
||||||
|
@ -156,7 +156,7 @@ public abstract class AbstractStandardBasicType<T>
|
||||||
|
|
||||||
public final void setSqlTypeDescriptor(JdbcTypeDescriptor jdbcTypeDescriptor) {
|
public final void setSqlTypeDescriptor(JdbcTypeDescriptor jdbcTypeDescriptor) {
|
||||||
this.jdbcTypeDescriptor = jdbcTypeDescriptor;
|
this.jdbcTypeDescriptor = jdbcTypeDescriptor;
|
||||||
this.sqlTypes = new int[] { jdbcTypeDescriptor.getJdbcType() };
|
this.sqlTypes = new int[] { jdbcTypeDescriptor.getDefaultSqlTypeCode() };
|
||||||
|
|
||||||
this.jdbcValueBinder = getJdbcTypeDescriptor().getBinder( javaTypeDescriptor );
|
this.jdbcValueBinder = getJdbcTypeDescriptor().getBinder( javaTypeDescriptor );
|
||||||
this.jdbcValueExtractor = getJdbcTypeDescriptor().getExtractor( javaTypeDescriptor );
|
this.jdbcValueExtractor = getJdbcTypeDescriptor().getExtractor( javaTypeDescriptor );
|
||||||
|
@ -173,7 +173,7 @@ public abstract class AbstractStandardBasicType<T>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final int[] sqlTypes(Mapping mapping) throws MappingException {
|
public final int[] getSqlTypeCodes(Mapping mapping) throws MappingException {
|
||||||
return sqlTypes;
|
return sqlTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -81,8 +81,8 @@ public class AnyType extends AbstractType implements CompositeType, AssociationT
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int[] sqlTypes(Mapping mapping) throws MappingException {
|
public int[] getSqlTypeCodes(Mapping mapping) throws MappingException {
|
||||||
return ArrayHelper.join( discriminatorType.sqlTypes( mapping ), identifierType.sqlTypes( mapping ) );
|
return ArrayHelper.join( discriminatorType.getSqlTypeCodes( mapping ), identifierType.getSqlTypeCodes( mapping ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -163,7 +163,7 @@ public abstract class CollectionType extends AbstractType implements Association
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int[] sqlTypes(Mapping session) throws MappingException {
|
public int[] getSqlTypeCodes(Mapping session) throws MappingException {
|
||||||
return ArrayHelper.EMPTY_INT_ARRAY;
|
return ArrayHelper.EMPTY_INT_ARRAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -113,12 +113,12 @@ public class ComponentType extends AbstractType implements CompositeType, Proced
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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 :)
|
//Not called at runtime so doesn't matter if it's slow :)
|
||||||
int[] sqlTypes = new int[getColumnSpan( mapping )];
|
int[] sqlTypes = new int[getColumnSpan( mapping )];
|
||||||
int n = 0;
|
int n = 0;
|
||||||
for ( int i = 0; i < propertySpan; i++ ) {
|
for ( int i = 0; i < propertySpan; i++ ) {
|
||||||
int[] subtypes = propertyTypes[i].sqlTypes( mapping );
|
int[] subtypes = propertyTypes[i].getSqlTypeCodes( mapping );
|
||||||
for ( int subtype : subtypes ) {
|
for ( int subtype : subtypes ) {
|
||||||
sqlTypes[n++] = subtype;
|
sqlTypes[n++] = subtype;
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,8 +128,8 @@ public class CustomType
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int[] sqlTypes(Mapping pi) {
|
public int[] getSqlTypeCodes(Mapping pi) {
|
||||||
return new int[] { jdbcTypeDescriptor.getJdbcType() };
|
return new int[] { jdbcTypeDescriptor.getDefaultSqlTypeCode() };
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -25,7 +25,7 @@ public class DoubleType
|
||||||
public static final Double ZERO = 0.0;
|
public static final Double ZERO = 0.0;
|
||||||
|
|
||||||
public DoubleType() {
|
public DoubleType() {
|
||||||
super( org.hibernate.type.descriptor.jdbc.FloatTypeDescriptor.INSTANCE, DoubleTypeDescriptor.INSTANCE );
|
super( org.hibernate.type.descriptor.jdbc.DoubleTypeDescriptor.INSTANCE, DoubleTypeDescriptor.INSTANCE );
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
|
|
@ -108,8 +108,8 @@ public class ManyToOneType extends EntityType {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int[] sqlTypes(Mapping mapping) throws MappingException {
|
public int[] getSqlTypeCodes(Mapping mapping) throws MappingException {
|
||||||
return requireIdentifierOrUniqueKeyType( mapping ).sqlTypes( mapping );
|
return requireIdentifierOrUniqueKeyType( mapping ).getSqlTypeCodes( mapping );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -51,8 +51,8 @@ public class MetaType extends AbstractType {
|
||||||
return discriminatorValuesToEntityNameMap;
|
return discriminatorValuesToEntityNameMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int[] sqlTypes(Mapping mapping) throws MappingException {
|
public int[] getSqlTypeCodes(Mapping mapping) throws MappingException {
|
||||||
return baseType.sqlTypes(mapping);
|
return baseType.getSqlTypeCodes(mapping);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -84,7 +84,7 @@ public class OneToOneType extends EntityType {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int[] sqlTypes(Mapping session) throws MappingException {
|
public int[] getSqlTypeCodes(Mapping session) throws MappingException {
|
||||||
return ArrayHelper.EMPTY_INT_ARRAY;
|
return ArrayHelper.EMPTY_INT_ARRAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,11 +70,6 @@ public class PostgresUUIDType extends AbstractSingleColumnStandardBasicType<UUID
|
||||||
return JDBC_TYPE_CODE;
|
return JDBC_TYPE_CODE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getJdbcTypeCode() {
|
|
||||||
return getJdbcType();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canBeRemapped() {
|
public boolean canBeRemapped() {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -20,7 +20,7 @@ import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||||
*/
|
*/
|
||||||
public interface SingleColumnType<T> extends Type {
|
public interface SingleColumnType<T> extends Type {
|
||||||
|
|
||||||
int sqlType();
|
int getJdbcTypeCode();
|
||||||
|
|
||||||
String toString(T value) throws HibernateException;
|
String toString(T value) throws HibernateException;
|
||||||
|
|
||||||
|
|
|
@ -60,8 +60,8 @@ public class SpecialOneToOneType extends OneToOneType {
|
||||||
return super.getIdentifierOrUniqueKeyType( mapping ).getColumnSpan( mapping );
|
return super.getIdentifierOrUniqueKeyType( mapping ).getColumnSpan( mapping );
|
||||||
}
|
}
|
||||||
|
|
||||||
public int[] sqlTypes(Mapping mapping) throws MappingException {
|
public int[] getSqlTypeCodes(Mapping mapping) throws MappingException {
|
||||||
return super.getIdentifierOrUniqueKeyType( mapping ).sqlTypes( mapping );
|
return super.getIdentifierOrUniqueKeyType( mapping ).getSqlTypeCodes( mapping );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -108,7 +108,7 @@ public interface Type extends Serializable {
|
||||||
*
|
*
|
||||||
* @throws MappingException Generally indicates an issue accessing the passed mapping object.
|
* @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
|
* Return the column sizes dictated by this type. For example, the mapping for a {@code char}/{@link Character} would
|
||||||
|
|
|
@ -31,7 +31,7 @@ public class DoubleTypeDescriptor extends AbstractClassTypeDescriptor<Double> im
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JdbcTypeDescriptor getRecommendedJdbcType(JdbcTypeDescriptorIndicators indicators) {
|
public JdbcTypeDescriptor getRecommendedJdbcType(JdbcTypeDescriptorIndicators indicators) {
|
||||||
return indicators.getTypeConfiguration().getJdbcTypeDescriptorRegistry().getDescriptor( Types.REAL );
|
return org.hibernate.type.descriptor.jdbc.DoubleTypeDescriptor.INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -13,6 +13,8 @@ import java.util.Locale;
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.type.descriptor.WrapperOptions;
|
import org.hibernate.type.descriptor.WrapperOptions;
|
||||||
import org.hibernate.type.descriptor.java.spi.Primitive;
|
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.
|
* Descriptor for {@link Float} handling.
|
||||||
|
@ -25,6 +27,12 @@ public class FloatTypeDescriptor extends AbstractClassTypeDescriptor<Float> impl
|
||||||
public FloatTypeDescriptor() {
|
public FloatTypeDescriptor() {
|
||||||
super( Float.class );
|
super( Float.class );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JdbcTypeDescriptor getRecommendedJdbcType(JdbcTypeDescriptorIndicators indicators) {
|
||||||
|
return org.hibernate.type.descriptor.jdbc.FloatTypeDescriptor.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(Float value) {
|
public String toString(Float value) {
|
||||||
return value == null ? null : value.toString();
|
return value == null ? null : value.toString();
|
||||||
|
|
|
@ -50,7 +50,7 @@ public abstract class BasicBinder<J> implements ValueBinder<J>, Serializable {
|
||||||
String.format(
|
String.format(
|
||||||
NULL_BIND_MSG_TEMPLATE,
|
NULL_BIND_MSG_TEMPLATE,
|
||||||
index,
|
index,
|
||||||
JdbcTypeNameMapper.getTypeName( getJdbcTypeDescriptor().getJdbcType() )
|
JdbcTypeNameMapper.getTypeName( getJdbcTypeDescriptor().getJdbcTypeCode() )
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ public abstract class BasicBinder<J> implements ValueBinder<J>, Serializable {
|
||||||
String.format(
|
String.format(
|
||||||
BIND_MSG_TEMPLATE,
|
BIND_MSG_TEMPLATE,
|
||||||
index,
|
index,
|
||||||
JdbcTypeNameMapper.getTypeName( jdbcTypeDescriptor.getJdbcType() ),
|
JdbcTypeNameMapper.getTypeName( jdbcTypeDescriptor.getJdbcTypeCode() ),
|
||||||
getJavaTypeDescriptor().extractLoggableRepresentation( value )
|
getJavaTypeDescriptor().extractLoggableRepresentation( value )
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -79,7 +79,7 @@ public abstract class BasicBinder<J> implements ValueBinder<J>, Serializable {
|
||||||
String.format(
|
String.format(
|
||||||
NULL_BIND_MSG_TEMPLATE,
|
NULL_BIND_MSG_TEMPLATE,
|
||||||
name,
|
name,
|
||||||
JdbcTypeNameMapper.getTypeName( getJdbcTypeDescriptor().getJdbcType() )
|
JdbcTypeNameMapper.getTypeName( getJdbcTypeDescriptor().getJdbcTypeCode() )
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ public abstract class BasicBinder<J> implements ValueBinder<J>, Serializable {
|
||||||
String.format(
|
String.format(
|
||||||
BIND_MSG_TEMPLATE,
|
BIND_MSG_TEMPLATE,
|
||||||
name,
|
name,
|
||||||
JdbcTypeNameMapper.getTypeName( jdbcTypeDescriptor.getJdbcType() ),
|
JdbcTypeNameMapper.getTypeName( jdbcTypeDescriptor.getJdbcTypeCode() ),
|
||||||
getJavaTypeDescriptor().extractLoggableRepresentation( value )
|
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.
|
* @throws SQLException Indicates a problem binding to the prepared statement.
|
||||||
*/
|
*/
|
||||||
protected void doBindNull(PreparedStatement st, int index, WrapperOptions options) throws SQLException {
|
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.
|
* @throws SQLException Indicates a problem binding to the callable statement.
|
||||||
*/
|
*/
|
||||||
protected void doBindNull(CallableStatement st, String name, WrapperOptions options) throws SQLException {
|
protected void doBindNull(CallableStatement st, String name, WrapperOptions options) throws SQLException {
|
||||||
st.setNull( name, jdbcTypeDescriptor.getJdbcType() );
|
st.setNull( name, jdbcTypeDescriptor.getJdbcTypeCode() );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -47,7 +47,7 @@ public abstract class BasicExtractor<J> implements ValueExtractor<J>, Serializab
|
||||||
JdbcExtractingLogging.LOGGER.tracef(
|
JdbcExtractingLogging.LOGGER.tracef(
|
||||||
"extracted value ([%s] : [%s]) - [null]",
|
"extracted value ([%s] : [%s]) - [null]",
|
||||||
paramIndex,
|
paramIndex,
|
||||||
JdbcTypeNameMapper.getTypeName( getJdbcTypeDescriptor().getJdbcType() )
|
JdbcTypeNameMapper.getTypeName( getJdbcTypeDescriptor().getJdbcTypeCode() )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -57,7 +57,7 @@ public abstract class BasicExtractor<J> implements ValueExtractor<J>, Serializab
|
||||||
JdbcExtractingLogging.LOGGER.tracef(
|
JdbcExtractingLogging.LOGGER.tracef(
|
||||||
"extracted value ([%s] : [%s]) - [%s]",
|
"extracted value ([%s] : [%s]) - [%s]",
|
||||||
paramIndex,
|
paramIndex,
|
||||||
JdbcTypeNameMapper.getTypeName( getJdbcTypeDescriptor().getJdbcType() ),
|
JdbcTypeNameMapper.getTypeName( getJdbcTypeDescriptor().getJdbcTypeCode() ),
|
||||||
getJavaTypeDescriptor().extractLoggableRepresentation( value )
|
getJavaTypeDescriptor().extractLoggableRepresentation( value )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,7 @@ public abstract class BasicExtractor<J> implements ValueExtractor<J>, Serializab
|
||||||
JdbcExtractingLogging.LOGGER.tracef(
|
JdbcExtractingLogging.LOGGER.tracef(
|
||||||
"extracted procedure output parameter ([%s] : [%s]) - [null]",
|
"extracted procedure output parameter ([%s] : [%s]) - [null]",
|
||||||
paramIndex,
|
paramIndex,
|
||||||
JdbcTypeNameMapper.getTypeName( getJdbcTypeDescriptor().getJdbcType() )
|
JdbcTypeNameMapper.getTypeName( getJdbcTypeDescriptor().getJdbcTypeCode() )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -95,7 +95,7 @@ public abstract class BasicExtractor<J> implements ValueExtractor<J>, Serializab
|
||||||
JdbcExtractingLogging.LOGGER.tracef(
|
JdbcExtractingLogging.LOGGER.tracef(
|
||||||
"extracted procedure output parameter ([%s] : [%s]) - [%s]",
|
"extracted procedure output parameter ([%s] : [%s]) - [%s]",
|
||||||
paramIndex,
|
paramIndex,
|
||||||
JdbcTypeNameMapper.getTypeName( getJdbcTypeDescriptor().getJdbcType() ),
|
JdbcTypeNameMapper.getTypeName( getJdbcTypeDescriptor().getJdbcTypeCode() ),
|
||||||
getJavaTypeDescriptor().extractLoggableRepresentation( value )
|
getJavaTypeDescriptor().extractLoggableRepresentation( value )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,7 @@ public abstract class BasicExtractor<J> implements ValueExtractor<J>, Serializab
|
||||||
JdbcExtractingLogging.LOGGER.tracef(
|
JdbcExtractingLogging.LOGGER.tracef(
|
||||||
"extracted named procedure output parameter ([%s] : [%s]) - [null]",
|
"extracted named procedure output parameter ([%s] : [%s]) - [null]",
|
||||||
paramName,
|
paramName,
|
||||||
JdbcTypeNameMapper.getTypeName( getJdbcTypeDescriptor().getJdbcType() )
|
JdbcTypeNameMapper.getTypeName( getJdbcTypeDescriptor().getJdbcTypeCode() )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -133,7 +133,7 @@ public abstract class BasicExtractor<J> implements ValueExtractor<J>, Serializab
|
||||||
JdbcExtractingLogging.LOGGER.tracef(
|
JdbcExtractingLogging.LOGGER.tracef(
|
||||||
"extracted named procedure output parameter ([%s] : [%s]) - [%s]",
|
"extracted named procedure output parameter ([%s] : [%s]) - [%s]",
|
||||||
paramName,
|
paramName,
|
||||||
JdbcTypeNameMapper.getTypeName( getJdbcTypeDescriptor().getJdbcType() ),
|
JdbcTypeNameMapper.getTypeName( getJdbcTypeDescriptor().getJdbcTypeCode() ),
|
||||||
getJavaTypeDescriptor().extractLoggableRepresentation( value )
|
getJavaTypeDescriptor().extractLoggableRepresentation( value )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,11 +31,22 @@ public class DoubleTypeDescriptor implements JdbcTypeDescriptor {
|
||||||
public DoubleTypeDescriptor() {
|
public DoubleTypeDescriptor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {@link Types#DOUBLE}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int getJdbcType() {
|
public int getJdbcType() {
|
||||||
return Types.DOUBLE;
|
return Types.DOUBLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {@link Types#FLOAT} for schema generation
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int getDefaultSqlTypeCode() {
|
||||||
|
return Types.FLOAT;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getFriendlyName() {
|
public String getFriendlyName() {
|
||||||
return "DOUBLE";
|
return "DOUBLE";
|
||||||
|
@ -43,7 +54,7 @@ public class DoubleTypeDescriptor implements JdbcTypeDescriptor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "SqlTypeDescriptor(" + getFriendlyName() + ")";
|
return "DoubleTypeDescriptor";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -6,9 +6,18 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.type.descriptor.jdbc;
|
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 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.BasicJavaDescriptor;
|
||||||
|
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||||
|
import org.hibernate.type.descriptor.jdbc.internal.JdbcLiteralFormatterNumericData;
|
||||||
import org.hibernate.type.spi.TypeConfiguration;
|
import org.hibernate.type.spi.TypeConfiguration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,19 +25,76 @@ import org.hibernate.type.spi.TypeConfiguration;
|
||||||
*
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class FloatTypeDescriptor extends RealTypeDescriptor {
|
public class FloatTypeDescriptor implements JdbcTypeDescriptor {
|
||||||
public static final FloatTypeDescriptor INSTANCE = new FloatTypeDescriptor();
|
public static final FloatTypeDescriptor INSTANCE = new FloatTypeDescriptor();
|
||||||
|
|
||||||
public 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
|
@Override
|
||||||
public <T> BasicJavaDescriptor<T> getJdbcRecommendedJavaTypeMapping(TypeConfiguration typeConfiguration) {
|
public <T> BasicJavaDescriptor<T> getJdbcRecommendedJavaTypeMapping(TypeConfiguration typeConfiguration) {
|
||||||
return (BasicJavaDescriptor<T>) typeConfiguration.getJavaTypeDescriptorRegistry().getDescriptor( Double.class );
|
return (BasicJavaDescriptor<T>) typeConfiguration.getJavaTypeDescriptorRegistry().getDescriptor( Double.class );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getJdbcType() {
|
@SuppressWarnings("unchecked")
|
||||||
return Types.FLOAT;
|
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 );
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ public interface JdbcTypeDescriptor extends Serializable {
|
||||||
* A "friendly" name for use in logging
|
* A "friendly" name for use in logging
|
||||||
*/
|
*/
|
||||||
default String getFriendlyName() {
|
default String getFriendlyName() {
|
||||||
return Integer.toString( getJdbcType() );
|
return Integer.toString( getJdbcTypeCode() );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -50,6 +50,16 @@ public interface JdbcTypeDescriptor extends Serializable {
|
||||||
return getJdbcType();
|
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?
|
* Is this descriptor available for remapping?
|
||||||
*
|
*
|
||||||
|
@ -63,7 +73,7 @@ public interface JdbcTypeDescriptor extends Serializable {
|
||||||
default <T> BasicJavaDescriptor<T> getJdbcRecommendedJavaTypeMapping(TypeConfiguration typeConfiguration) {
|
default <T> BasicJavaDescriptor<T> getJdbcRecommendedJavaTypeMapping(TypeConfiguration typeConfiguration) {
|
||||||
// match legacy behavior
|
// match legacy behavior
|
||||||
return (BasicJavaDescriptor<T>) typeConfiguration.getJavaTypeDescriptorRegistry().getDescriptor(
|
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);
|
<X> ValueExtractor<X> getExtractor(JavaTypeDescriptor<X> javaTypeDescriptor);
|
||||||
|
|
||||||
default boolean isInteger() {
|
default boolean isInteger() {
|
||||||
switch ( getJdbcType() ) {
|
switch ( getJdbcTypeCode() ) {
|
||||||
case Types.BIT:
|
case Types.BIT:
|
||||||
case Types.TINYINT:
|
case Types.TINYINT:
|
||||||
case Types.SMALLINT:
|
case Types.SMALLINT:
|
||||||
|
@ -107,7 +117,7 @@ public interface JdbcTypeDescriptor extends Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
default boolean isNumber() {
|
default boolean isNumber() {
|
||||||
switch ( getJdbcType() ) {
|
switch ( getJdbcTypeCode() ) {
|
||||||
case Types.BIT:
|
case Types.BIT:
|
||||||
case Types.TINYINT:
|
case Types.TINYINT:
|
||||||
case Types.SMALLINT:
|
case Types.SMALLINT:
|
||||||
|
@ -124,7 +134,7 @@ public interface JdbcTypeDescriptor extends Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
default boolean isBinary() {
|
default boolean isBinary() {
|
||||||
switch ( getJdbcType() ) {
|
switch ( getJdbcTypeCode() ) {
|
||||||
case Types.BINARY:
|
case Types.BINARY:
|
||||||
case Types.VARBINARY:
|
case Types.VARBINARY:
|
||||||
case Types.LONGVARBINARY:
|
case Types.LONGVARBINARY:
|
||||||
|
@ -135,7 +145,7 @@ public interface JdbcTypeDescriptor extends Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
default boolean isString() {
|
default boolean isString() {
|
||||||
switch ( getJdbcType() ) {
|
switch ( getJdbcTypeCode() ) {
|
||||||
case Types.CHAR:
|
case Types.CHAR:
|
||||||
case Types.NCHAR:
|
case Types.NCHAR:
|
||||||
case Types.VARCHAR:
|
case Types.VARCHAR:
|
||||||
|
@ -150,7 +160,7 @@ public interface JdbcTypeDescriptor extends Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
default boolean isTemporal() {
|
default boolean isTemporal() {
|
||||||
switch ( getJdbcType() ) {
|
switch ( getJdbcTypeCode() ) {
|
||||||
case Types.DATE:
|
case Types.DATE:
|
||||||
case Types.TIME:
|
case Types.TIME:
|
||||||
case Types.TIMESTAMP:
|
case Types.TIMESTAMP:
|
||||||
|
@ -161,7 +171,7 @@ public interface JdbcTypeDescriptor extends Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
default CastType getCastType() {
|
default CastType getCastType() {
|
||||||
switch ( getJdbcType() ) {
|
switch ( getJdbcTypeCode() ) {
|
||||||
case Types.INTEGER:
|
case Types.INTEGER:
|
||||||
case Types.TINYINT:
|
case Types.TINYINT:
|
||||||
case Types.SMALLINT:
|
case Types.SMALLINT:
|
||||||
|
|
|
@ -6,27 +6,20 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.type.descriptor.jdbc;
|
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 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.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;
|
import org.hibernate.type.spi.TypeConfiguration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Descriptor for {@link Types#REAL REAL} handling.
|
* Descriptor for {@link Types#REAL REAL} handling.
|
||||||
*
|
*
|
||||||
* @author Steve Ebersole
|
* @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 static final RealTypeDescriptor INSTANCE = new RealTypeDescriptor();
|
||||||
|
|
||||||
public RealTypeDescriptor() {
|
public RealTypeDescriptor() {
|
||||||
|
@ -47,55 +40,8 @@ public class RealTypeDescriptor implements JdbcTypeDescriptor {
|
||||||
return "RealTypeDescriptor";
|
return "RealTypeDescriptor";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canBeRemapped() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> BasicJavaDescriptor<T> getJdbcRecommendedJavaTypeMapping(TypeConfiguration typeConfiguration) {
|
public <T> BasicJavaDescriptor<T> getJdbcRecommendedJavaTypeMapping(TypeConfiguration typeConfiguration) {
|
||||||
return (BasicJavaDescriptor<T>) typeConfiguration.getJavaTypeDescriptorRegistry().getDescriptor( Float.class );
|
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 );
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ public class StandardBasicTypeImpl<J>
|
||||||
@Override
|
@Override
|
||||||
public CastType getCastType() {
|
public CastType getCastType() {
|
||||||
if ( getJavaTypeDescriptor() == BooleanTypeDescriptor.INSTANCE ) {
|
if ( getJavaTypeDescriptor() == BooleanTypeDescriptor.INSTANCE ) {
|
||||||
switch ( sqlType() ) {
|
switch ( getJdbcTypeCode() ) {
|
||||||
case Types.BIT:
|
case Types.BIT:
|
||||||
case Types.SMALLINT:
|
case Types.SMALLINT:
|
||||||
case Types.TINYINT:
|
case Types.TINYINT:
|
||||||
|
|
|
@ -233,7 +233,7 @@ public class TypeConfiguration implements SessionFactoryObserver, Serializable {
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
int[] jdbcTypes = basicType.sqlTypes( null );
|
int[] jdbcTypes = basicType.getSqlTypeCodes( null );
|
||||||
|
|
||||||
if ( jdbcTypes.length == 1 ) {
|
if ( jdbcTypes.length == 1 ) {
|
||||||
int jdbcType = jdbcTypes[0];
|
int jdbcType = jdbcTypes[0];
|
||||||
|
@ -650,7 +650,7 @@ public class TypeConfiguration implements SessionFactoryObserver, Serializable {
|
||||||
return getSqlTemporalType( ( (BasicValuedMapping) type ).getJdbcMapping().getJdbcTypeDescriptor() );
|
return getSqlTemporalType( ( (BasicValuedMapping) type ).getJdbcMapping().getJdbcTypeDescriptor() );
|
||||||
}
|
}
|
||||||
else if (type instanceof SingleColumnType) {
|
else if (type instanceof SingleColumnType) {
|
||||||
return getSqlTemporalType( ((SingleColumnType<?>) type).sqlType() );
|
return getSqlTemporalType( ((SingleColumnType<?>) type).getJdbcTypeCode() );
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ public class NestedEmbeddableMetadataTest {
|
||||||
Component amountMetadata = (Component) investmentMetadata.getProperty( "amount" ).getValue();
|
Component amountMetadata = (Component) investmentMetadata.getProperty( "amount" ).getValue();
|
||||||
SimpleValue currencyMetadata = (SimpleValue) amountMetadata.getProperty( "currency" ).getValue();
|
SimpleValue currencyMetadata = (SimpleValue) amountMetadata.getProperty( "currency" ).getValue();
|
||||||
CustomType currencyType = (CustomType) currencyMetadata.getType();
|
CustomType currencyType = (CustomType) currencyMetadata.getType();
|
||||||
int[] currencySqlTypes = currencyType.sqlTypes( metadata );
|
int[] currencySqlTypes = currencyType.getSqlTypeCodes( metadata );
|
||||||
assertEquals( 1, currencySqlTypes.length );
|
assertEquals( 1, currencySqlTypes.length );
|
||||||
assertJdbcTypeCode( Types.VARCHAR, currencySqlTypes[0] );
|
assertJdbcTypeCode( Types.VARCHAR, currencySqlTypes[0] );
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class FieldAccessedNestedEmbeddableMetadataTest {
|
||||||
Component amountMetadata = (Component) investmentMetadata.getProperty( "amount" ).getValue();
|
Component amountMetadata = (Component) investmentMetadata.getProperty( "amount" ).getValue();
|
||||||
SimpleValue currencyMetadata = (SimpleValue) amountMetadata.getProperty( "currency" ).getValue();
|
SimpleValue currencyMetadata = (SimpleValue) amountMetadata.getProperty( "currency" ).getValue();
|
||||||
CustomType currencyType = (CustomType) currencyMetadata.getType();
|
CustomType currencyType = (CustomType) currencyMetadata.getType();
|
||||||
int[] currencySqlTypes = currencyType.sqlTypes( metadata );
|
int[] currencySqlTypes = currencyType.getSqlTypeCodes( metadata );
|
||||||
assertEquals( 1, currencySqlTypes.length );
|
assertEquals( 1, currencySqlTypes.length );
|
||||||
assertJdbcTypeCode( Types.VARCHAR, currencySqlTypes[0] );
|
assertJdbcTypeCode( Types.VARCHAR, currencySqlTypes[0] );
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,7 +132,7 @@ public class UserTypeComparableIdTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int[] sqlTypes() {
|
public int[] sqlTypes() {
|
||||||
return new int[] { SQL_TYPE.sqlType() };
|
return new int[] { SQL_TYPE.getJdbcTypeCode() };
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -152,7 +152,7 @@ public class UserTypeComparableIdTest {
|
||||||
CustomId customId = (CustomId) value;
|
CustomId customId = (CustomId) value;
|
||||||
|
|
||||||
if ( customId == null ) {
|
if ( customId == null ) {
|
||||||
preparedStatement.setNull( index, SQL_TYPE.sqlType() );
|
preparedStatement.setNull( index, SQL_TYPE.getJdbcTypeCode() );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
preparedStatement.setLong( index, customId.getValue() );
|
preparedStatement.setLong( index, customId.getValue() );
|
||||||
|
|
|
@ -119,7 +119,7 @@ public class UserTypeNonComparableIdTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int[] sqlTypes() {
|
public int[] sqlTypes() {
|
||||||
return new int[] { SQL_TYPE.sqlType() };
|
return new int[] { SQL_TYPE.getJdbcTypeCode() };
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -139,7 +139,7 @@ public class UserTypeNonComparableIdTest {
|
||||||
CustomId customId = (CustomId) value;
|
CustomId customId = (CustomId) value;
|
||||||
|
|
||||||
if ( customId == null ) {
|
if ( customId == null ) {
|
||||||
preparedStatement.setNull( index, SQL_TYPE.sqlType() );
|
preparedStatement.setNull( index, SQL_TYPE.getJdbcTypeCode() );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
preparedStatement.setLong( index, customId.getValue() );
|
preparedStatement.setLong( index, customId.getValue() );
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.orm.test.mapping.converted.converter;
|
package org.hibernate.orm.test.mapping.converted.converter;
|
||||||
|
|
||||||
import java.sql.Types;
|
|
||||||
import javax.persistence.AttributeConverter;
|
import javax.persistence.AttributeConverter;
|
||||||
import javax.persistence.Convert;
|
import javax.persistence.Convert;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
@ -49,7 +48,7 @@ public class AndNationalizedTests extends BaseUnitTestCase {
|
||||||
final Dialect dialect = metadata.getDatabase().getDialect();
|
final Dialect dialect = metadata.getDatabase().getDialect();
|
||||||
assertEquals(
|
assertEquals(
|
||||||
dialect.getNationalizationSupport().getVarcharVariantCode(),
|
dialect.getNationalizationSupport().getVarcharVariantCode(),
|
||||||
entityBinding.getProperty( "name" ).getType().sqlTypes( metadata )[0]
|
entityBinding.getProperty( "name" ).getType().getSqlTypeCodes( metadata )[0]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
|
|
|
@ -39,7 +39,7 @@ public class FormulaFromHbmTests {
|
||||||
(rootClass) -> {
|
(rootClass) -> {
|
||||||
final Property stringFormula = rootClass.getProperty( "stringFormula" );
|
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.length, is( 1 ) );
|
||||||
assertThat( sqlTypes[ 0 ], is( Types.VARCHAR ) );
|
assertThat( sqlTypes[ 0 ], is( Types.VARCHAR ) );
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ public class FormulaFromHbmTests {
|
||||||
|
|
||||||
final Property integerFormula = rootClass.getProperty( "integerFormula" );
|
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.length, is( 1 ) );
|
||||||
assertThat( sqlTypes[ 0 ], is( Types.INTEGER ) );
|
assertThat( sqlTypes[ 0 ], is( Types.INTEGER ) );
|
||||||
|
|
||||||
|
|
|
@ -108,8 +108,8 @@ public class AttributeOverrideEnhancedUserTypeTest {
|
||||||
@Override
|
@Override
|
||||||
public int[] sqlTypes() {
|
public int[] sqlTypes() {
|
||||||
return new int[] {
|
return new int[] {
|
||||||
IntegerType.INSTANCE.sqlType(),
|
IntegerType.INSTANCE.getJdbcTypeCode(),
|
||||||
IntegerType.INSTANCE.sqlType(),
|
IntegerType.INSTANCE.getJdbcTypeCode(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -107,7 +107,7 @@ public class MyStringType implements UserType, DynamicParameterizedType {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int[] sqlTypes() {
|
public int[] sqlTypes() {
|
||||||
return new int[] { StringType.INSTANCE.sqlType() };
|
return new int[] { StringType.INSTANCE.getJdbcTypeCode() };
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -25,7 +25,7 @@ public class StringWrapperUserType implements UserType {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int[] sqlTypes() {
|
public int[] sqlTypes() {
|
||||||
return new int[] {StringType.INSTANCE.sqlType()};
|
return new int[] {StringType.INSTANCE.getJdbcTypeCode()};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -21,7 +21,7 @@ public class AgeType implements UserType {
|
||||||
@Override
|
@Override
|
||||||
public int[] sqlTypes() {
|
public int[] sqlTypes() {
|
||||||
return new int[] {
|
return new int[] {
|
||||||
IntegerType.INSTANCE.sqlType()
|
IntegerType.INSTANCE.getJdbcTypeCode()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue