Get rid of JdbcTypeDescriptor remapping

This commit is contained in:
Christian Beikov 2021-10-07 11:17:29 +02:00
parent ac1a30f808
commit 597f4bdf6a
63 changed files with 152 additions and 591 deletions

View File

@ -25,11 +25,6 @@ public class CustomBinaryJdbcType implements JdbcTypeDescriptor {
return Types.VARBINARY;
}
@Override
public boolean canBeRemapped() {
return false;
}
@Override
public <X> ValueBinder<X> getBinder(JavaTypeDescriptor<X> javaTypeDescriptor) {
return VarbinaryJdbcTypeDescriptor.INSTANCE.getBinder( javaTypeDescriptor );

View File

@ -15,6 +15,7 @@ import java.util.TimeZone;
import jakarta.persistence.TemporalType;
import org.hibernate.ScrollMode;
import org.hibernate.boot.model.TypeContributions;
import org.hibernate.community.dialect.identity.SQLiteIdentityColumnSupport;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.NationalizationSupport;
@ -41,6 +42,7 @@ import org.hibernate.query.TemporalUnit;
import org.hibernate.query.TrimSpec;
import org.hibernate.query.spi.QueryEngine;
import org.hibernate.query.sqm.produce.function.StandardFunctionReturnTypeResolvers;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.sql.ast.SqlAstNodeRenderingMode;
import org.hibernate.sql.ast.SqlAstTranslator;
import org.hibernate.sql.ast.SqlAstTranslatorFactory;
@ -54,6 +56,7 @@ import org.hibernate.type.StandardBasicTypes;
import org.hibernate.type.descriptor.jdbc.BlobJdbcTypeDescriptor;
import org.hibernate.type.descriptor.jdbc.ClobJdbcTypeDescriptor;
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeDescriptorRegistry;
import static org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtractor.extractUsingTemplate;
import static org.hibernate.query.TemporalUnit.DAY;
@ -322,15 +325,12 @@ public class SQLiteDialect extends Dialect {
}
@Override
public JdbcTypeDescriptor getSqlTypeDescriptorOverride(int sqlCode) {
switch (sqlCode) {
case Types.BLOB:
return BlobJdbcTypeDescriptor.PRIMITIVE_ARRAY_BINDING;
case Types.CLOB:
return ClobJdbcTypeDescriptor.STRING_BINDING;
default:
return super.getSqlTypeDescriptorOverride( sqlCode );
}
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
super.contributeTypes( typeContributions, serviceRegistry );
final JdbcTypeDescriptorRegistry jdbcTypeRegistry = typeContributions.getTypeConfiguration()
.getJdbcTypeDescriptorRegistry();
jdbcTypeRegistry.addDescriptor( Types.BLOB, BlobJdbcTypeDescriptor.PRIMITIVE_ARRAY_BINDING );
jdbcTypeRegistry.addDescriptor( Types.CLOB, ClobJdbcTypeDescriptor.STRING_BINDING );
}
@Override

View File

@ -60,6 +60,7 @@ import org.hibernate.type.descriptor.java.DataHelper;
import org.hibernate.type.descriptor.java.DoubleJavaTypeDescriptor;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.descriptor.jdbc.*;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeDescriptorRegistry;
import org.hibernate.type.internal.BasicTypeImpl;
import java.io.*;
@ -309,11 +310,6 @@ public abstract class AbstractHANADialect extends Dialect {
return Types.BLOB;
}
@Override
public boolean canBeRemapped() {
return true;
}
@Override
public <X> ValueBinder<X> getBinder(JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicBinder<X>( javaTypeDescriptor, this ) {
@ -604,11 +600,6 @@ public abstract class AbstractHANADialect extends Dialect {
return "HANABlobTypeDescriptor";
}
@Override
public boolean canBeRemapped() {
return true;
}
@Override
public <X> ValueExtractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicExtractor<X>( javaTypeDescriptor, this ) {
@ -1027,29 +1018,6 @@ public abstract class AbstractHANADialect extends Dialect {
return SequenceInformationExtractorHANADatabaseImpl.INSTANCE;
}
@Override
protected JdbcTypeDescriptor getSqlTypeDescriptorOverride(final int sqlCode) {
switch ( sqlCode ) {
case Types.CLOB:
return this.clobTypeDescriptor;
case Types.NCLOB:
return this.nClobTypeDescriptor;
case Types.BLOB:
return this.blobTypeDescriptor;
case Types.TINYINT:
// tinyint is unsigned on HANA
return SmallIntJdbcTypeDescriptor.INSTANCE;
case Types.VARCHAR:
return this.isUseUnicodeStringTypes() ? NVarcharJdbcTypeDescriptor.INSTANCE : VarcharJdbcTypeDescriptor.INSTANCE;
case Types.CHAR:
return this.isUseUnicodeStringTypes() ? NCharJdbcTypeDescriptor.INSTANCE : CharJdbcTypeDescriptor.INSTANCE;
case Types.DOUBLE:
return this.treatDoubleTypedFieldsAsDecimal ? DecimalJdbcTypeDescriptor.INSTANCE : DoubleJdbcTypeDescriptor.INSTANCE;
default:
return super.getSqlTypeDescriptorOverride( sqlCode );
}
}
@Override
public boolean isCurrentTimestampSelectStringCallable() {
return false;
@ -1471,6 +1439,8 @@ public abstract class AbstractHANADialect extends Dialect {
this.treatDoubleTypedFieldsAsDecimal = configurationService.getSetting( TREAT_DOUBLE_TYPED_FIELDS_AS_DECIMAL_PARAMETER_NAME, StandardConverters.BOOLEAN,
TREAT_DOUBLE_TYPED_FIELDS_AS_DECIMAL_DEFAULT_VALUE ).booleanValue();
final JdbcTypeDescriptorRegistry jdbcTypeRegistry = typeContributions.getTypeConfiguration()
.getJdbcTypeDescriptorRegistry();
if ( this.treatDoubleTypedFieldsAsDecimal ) {
registerHibernateType( Types.FLOAT, StandardBasicTypes.BIG_DECIMAL.getName() );
registerHibernateType( Types.REAL, StandardBasicTypes.BIG_DECIMAL.getName() );
@ -1501,19 +1471,32 @@ public abstract class AbstractHANADialect extends Dialect {
typeContributions.getTypeConfiguration().getJdbcToHibernateTypeContributionMap()
.get( Types.DOUBLE )
.add( StandardBasicTypes.BIG_DECIMAL.getName() );
typeContributions.getTypeConfiguration().getJdbcTypeDescriptorRegistry().addDescriptor(
jdbcTypeRegistry.addDescriptor(
Types.FLOAT,
NumericJdbcTypeDescriptor.INSTANCE
);
typeContributions.getTypeConfiguration().getJdbcTypeDescriptorRegistry().addDescriptor(
jdbcTypeRegistry.addDescriptor(
Types.REAL,
NumericJdbcTypeDescriptor.INSTANCE
);
typeContributions.getTypeConfiguration().getJdbcTypeDescriptorRegistry().addDescriptor(
jdbcTypeRegistry.addDescriptor(
Types.DOUBLE,
NumericJdbcTypeDescriptor.INSTANCE
);
}
jdbcTypeRegistry.addDescriptor( Types.CLOB, this.clobTypeDescriptor );
jdbcTypeRegistry.addDescriptor( Types.NCLOB, this.nClobTypeDescriptor );
jdbcTypeRegistry.addDescriptor( Types.BLOB, this.blobTypeDescriptor );
// tinyint is unsigned on HANA
jdbcTypeRegistry.addDescriptor( Types.TINYINT, SmallIntJdbcTypeDescriptor.INSTANCE );
if ( isUseUnicodeStringTypes() ) {
jdbcTypeRegistry.addDescriptor( Types.VARCHAR, NVarcharJdbcTypeDescriptor.INSTANCE );
jdbcTypeRegistry.addDescriptor( Types.CHAR, NCharJdbcTypeDescriptor.INSTANCE );
}
if ( this.treatDoubleTypedFieldsAsDecimal ) {
jdbcTypeRegistry.addDescriptor( Types.DOUBLE, DecimalJdbcTypeDescriptor.INSTANCE );
}
}
public JdbcTypeDescriptor getBlobTypeDescriptor() {

View File

@ -46,6 +46,7 @@ import org.hibernate.type.JavaObjectType;
import org.hibernate.type.StandardBasicTypes;
import org.hibernate.type.descriptor.java.PrimitiveByteArrayJavaTypeDescriptor;
import org.hibernate.type.descriptor.jdbc.*;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeDescriptorRegistry;
import java.sql.CallableStatement;
import java.sql.ResultSet;
@ -499,49 +500,37 @@ public class DB2Dialect extends Dialect {
return false;
}
@Override
protected JdbcTypeDescriptor getSqlTypeDescriptorOverride(int sqlCode) {
final int version = getVersion();
if ( version < 1100 && sqlCode == Types.BOOLEAN ) {
return SmallIntJdbcTypeDescriptor.INSTANCE;
}
else if ( version < 1100 && sqlCode == Types.VARBINARY ) {
// Binary literals were only added in 11. See https://www.ibm.com/support/knowledgecenter/SSEPGG_11.1.0/com.ibm.db2.luw.sql.ref.doc/doc/r0000731.html#d79816e393
return VarbinaryJdbcTypeDescriptor.INSTANCE_WITHOUT_LITERALS;
}
else if ( version < 970 ) {
return sqlCode == Types.NUMERIC
? DecimalJdbcTypeDescriptor.INSTANCE
: super.getSqlTypeDescriptorOverride(sqlCode);
}
else {
// See HHH-12753
// It seems that DB2's JDBC 4.0 support as of 9.5 does not
// support the N-variant methods like NClob or NString.
// Therefore here we overwrite the sql type descriptors to
// use the non-N variants which are supported.
switch ( sqlCode ) {
case Types.NCHAR:
return CharJdbcTypeDescriptor.INSTANCE;
case Types.NCLOB:
return useInputStreamToInsertBlob()
? ClobJdbcTypeDescriptor.STREAM_BINDING
: ClobJdbcTypeDescriptor.CLOB_BINDING;
case Types.NVARCHAR:
return VarcharJdbcTypeDescriptor.INSTANCE;
case Types.NUMERIC:
return DecimalJdbcTypeDescriptor.INSTANCE;
default:
return super.getSqlTypeDescriptorOverride(sqlCode);
}
}
}
@Override
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
super.contributeTypes( typeContributions, serviceRegistry );
final int version = getVersion();
final JdbcTypeDescriptorRegistry jdbcTypeRegistry = typeContributions.getTypeConfiguration()
.getJdbcTypeDescriptorRegistry();
if ( version < 1100 ) {
jdbcTypeRegistry.addDescriptor( Types.BOOLEAN, SmallIntJdbcTypeDescriptor.INSTANCE );
// Binary literals were only added in 11. See https://www.ibm.com/support/knowledgecenter/SSEPGG_11.1.0/com.ibm.db2.luw.sql.ref.doc/doc/r0000731.html#d79816e393
jdbcTypeRegistry.addDescriptor( Types.VARBINARY, VarbinaryJdbcTypeDescriptor.INSTANCE_WITHOUT_LITERALS );
if ( version < 970 ) {
jdbcTypeRegistry.addDescriptor( Types.NUMERIC, DecimalJdbcTypeDescriptor.INSTANCE );
}
}
// See HHH-12753
// It seems that DB2's JDBC 4.0 support as of 9.5 does not
// support the N-variant methods like NClob or NString.
// Therefore here we overwrite the sql type descriptors to
// use the non-N variants which are supported.
jdbcTypeRegistry.addDescriptor( Types.NCHAR, CharJdbcTypeDescriptor.INSTANCE );
jdbcTypeRegistry.addDescriptor(
Types.NCLOB,
useInputStreamToInsertBlob()
? ClobJdbcTypeDescriptor.STREAM_BINDING
: ClobJdbcTypeDescriptor.CLOB_BINDING
);
jdbcTypeRegistry.addDescriptor( Types.NVARCHAR, VarcharJdbcTypeDescriptor.INSTANCE );
jdbcTypeRegistry.addDescriptor( Types.NUMERIC, DecimalJdbcTypeDescriptor.INSTANCE );
// DB2 requires a custom binder for binding untyped nulls that resolves the type through the statement
typeContributions.contributeJdbcTypeDescriptor( ObjectNullResolvingJdbcTypeDescriptor.INSTANCE );

View File

@ -62,6 +62,7 @@ import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor;
import org.hibernate.type.descriptor.jdbc.ObjectNullResolvingJdbcTypeDescriptor;
import org.hibernate.type.descriptor.jdbc.SmallIntJdbcTypeDescriptor;
import org.hibernate.type.descriptor.jdbc.TimestampJdbcTypeDescriptor;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeDescriptorRegistry;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
@ -497,23 +498,16 @@ public class DerbyDialect extends Dialect {
return false;
}
protected JdbcTypeDescriptor getSqlTypeDescriptorOverride(int sqlCode) {
if ( getVersion() < 1070 && sqlCode == Types.BOOLEAN) {
return SmallIntJdbcTypeDescriptor.INSTANCE;
}
switch ( sqlCode ) {
case Types.NUMERIC:
return DecimalJdbcTypeDescriptor.INSTANCE;
case Types.TIMESTAMP_WITH_TIMEZONE:
return TimestampJdbcTypeDescriptor.INSTANCE;
default:
return super.getSqlTypeDescriptorOverride(sqlCode);
}
}
@Override
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
super.contributeTypes( typeContributions, serviceRegistry );
final JdbcTypeDescriptorRegistry jdbcTypeRegistry = typeContributions.getTypeConfiguration()
.getJdbcTypeDescriptorRegistry();
if ( getVersion() < 1070 ) {
jdbcTypeRegistry.addDescriptor( Types.BOOLEAN, SmallIntJdbcTypeDescriptor.INSTANCE );
}
jdbcTypeRegistry.addDescriptor( Types.NUMERIC, DecimalJdbcTypeDescriptor.INSTANCE );
jdbcTypeRegistry.addDescriptor( Types.TIMESTAMP_WITH_TIMEZONE, TimestampJdbcTypeDescriptor.INSTANCE );
// Derby requires a custom binder for binding untyped nulls that resolves the type through the statement
typeContributions.contributeJdbcTypeDescriptor( ObjectNullResolvingJdbcTypeDescriptor.INSTANCE );

View File

@ -1004,6 +1004,13 @@ public abstract class Dialect implements ConversionContext {
typeContributions.contributeJdbcTypeDescriptor( LongNVarcharJdbcTypeDescriptor.INSTANCE );
typeContributions.contributeJdbcTypeDescriptor( NClobJdbcTypeDescriptor.DEFAULT );
}
if ( useInputStreamToInsertBlob() ) {
typeContributions.getTypeConfiguration().getJdbcTypeDescriptorRegistry().addDescriptor(
Types.CLOB,
ClobJdbcTypeDescriptor.STREAM_BINDING
);
}
}
/**
@ -1156,58 +1163,6 @@ public abstract class Dialect implements ConversionContext {
typeNames.put( code, name );
}
/**
* Allows the dialect to override a {@link JdbcTypeDescriptor}.
* <p/>
* If the passed {@code sqlTypeDescriptor} allows itself to be remapped (per
* {@link JdbcTypeDescriptor#canBeRemapped()}), then this method uses
* {@link #getSqlTypeDescriptorOverride} to get an optional override based on the SQL code returned by
* {@link JdbcTypeDescriptor#getJdbcTypeCode()}.
* <p/>
* If this dialect does not provide an override or if the {@code sqlTypeDescriptor} does not allow itself to be
* remapped, then this method simply returns the original passed {@code sqlTypeDescriptor}
*
* @param jdbcTypeDescriptor The {@link JdbcTypeDescriptor} to override
* @return The {@link JdbcTypeDescriptor} that should be used for this dialect;
* if there is no override, then original {@code sqlTypeDescriptor} is returned.
* @throws IllegalArgumentException if {@code sqlTypeDescriptor} is null.
*
* @see #getSqlTypeDescriptorOverride
*/
public JdbcTypeDescriptor remapSqlTypeDescriptor(JdbcTypeDescriptor jdbcTypeDescriptor) {
if ( jdbcTypeDescriptor == null ) {
throw new IllegalArgumentException( "sqlTypeDescriptor is null" );
}
if ( ! jdbcTypeDescriptor.canBeRemapped() ) {
return jdbcTypeDescriptor;
}
final JdbcTypeDescriptor overridden = getSqlTypeDescriptorOverride( jdbcTypeDescriptor.getJdbcTypeCode() );
return overridden == null ? jdbcTypeDescriptor : overridden;
}
/**
* Returns the {@link JdbcTypeDescriptor} that should be used to handle the given JDBC type code. Returns
* {@code null} if there is no override.
*
* @param sqlCode A {@link Types} constant indicating the SQL column type
* @return The {@link JdbcTypeDescriptor} to use as an override, or {@code null} if there is no override.
*/
protected JdbcTypeDescriptor getSqlTypeDescriptorOverride(int sqlCode) {
JdbcTypeDescriptor descriptor;
switch ( sqlCode ) {
case Types.CLOB: {
descriptor = useInputStreamToInsertBlob() ? ClobJdbcTypeDescriptor.STREAM_BINDING : null;
break;
}
default: {
descriptor = null;
break;
}
}
return descriptor;
}
/**
* The legacy behavior of Hibernate. LOBs are not processed by merge
*/

View File

@ -71,6 +71,7 @@ import org.hibernate.type.descriptor.jdbc.BlobJdbcTypeDescriptor;
import org.hibernate.type.descriptor.jdbc.ClobJdbcTypeDescriptor;
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor;
import org.hibernate.type.descriptor.jdbc.ObjectNullAsBinaryTypeJdbcTypeDescriptor;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeDescriptorRegistry;
import static org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtractor.extractUsingTemplate;
import static org.hibernate.query.TemporalUnit.*;
@ -345,25 +346,6 @@ public class PostgreSQLDialect extends Dialect {
}
}
@Override
public JdbcTypeDescriptor getSqlTypeDescriptorOverride(int sqlCode) {
// For discussion of BLOB support in Postgres, as of 8.4, have a peek at
// <a href="http://jdbc.postgresql.org/documentation/84/binary-data.html">http://jdbc.postgresql.org/documentation/84/binary-data.html</a>.
// For the effects in regards to Hibernate see <a href="http://in.relation.to/15492.lace">http://in.relation.to/15492.lace</a>
switch ( sqlCode ) {
case Types.BLOB:
// Force BLOB binding. Otherwise, byte[] fields annotated
// with @Lob will attempt to use
// BlobTypeDescriptor.PRIMITIVE_ARRAY_BINDING. Since the
// dialect uses oid for Blobs, byte arrays cannot be used.
return BlobJdbcTypeDescriptor.BLOB_BINDING;
case Types.CLOB:
return ClobJdbcTypeDescriptor.CLOB_BINDING;
default:
return super.getSqlTypeDescriptorOverride( sqlCode );
}
}
@Override
public NameQualifierSupport getNameQualifierSupport() {
// This method is overridden so the correct value will be returned when
@ -943,6 +925,19 @@ public class PostgreSQLDialect extends Dialect {
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
super.contributeTypes(typeContributions, serviceRegistry);
final JdbcTypeDescriptorRegistry jdbcTypeRegistry = typeContributions.getTypeConfiguration()
.getJdbcTypeDescriptorRegistry();
// For discussion of BLOB support in Postgres, as of 8.4, have a peek at
// <a href="http://jdbc.postgresql.org/documentation/84/binary-data.html">http://jdbc.postgresql.org/documentation/84/binary-data.html</a>.
// For the effects in regards to Hibernate see <a href="http://in.relation.to/15492.lace">http://in.relation.to/15492.lace</a>
// Force BLOB binding. Otherwise, byte[] fields annotated
// with @Lob will attempt to use
// BlobTypeDescriptor.PRIMITIVE_ARRAY_BINDING. Since the
// dialect uses oid for Blobs, byte arrays cannot be used.
jdbcTypeRegistry.addDescriptor( Types.BLOB, BlobJdbcTypeDescriptor.BLOB_BINDING );
jdbcTypeRegistry.addDescriptor( Types.CLOB, ClobJdbcTypeDescriptor.CLOB_BINDING );
if ( getVersion() >= 820 ) {
// HHH-9562
typeContributions.contributeType( PostgresUUIDType.INSTANCE );

View File

@ -8,6 +8,7 @@ package org.hibernate.dialect;
import org.hibernate.*;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.model.TypeContributions;
import org.hibernate.boot.model.relational.QualifiedSequenceName;
import org.hibernate.boot.model.relational.Sequence;
import org.hibernate.dialect.function.CommonFunctionFactory;
@ -35,6 +36,7 @@ import org.hibernate.query.CastType;
import org.hibernate.query.FetchClauseType;
import org.hibernate.query.TemporalUnit;
import org.hibernate.query.spi.QueryEngine;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.sql.ast.SqlAstNodeRenderingMode;
import org.hibernate.sql.ast.SqlAstTranslator;
import org.hibernate.sql.ast.SqlAstTranslatorFactory;
@ -160,10 +162,13 @@ public class SQLServerDialect extends AbstractTransactSQLDialect {
}
@Override
protected JdbcTypeDescriptor getSqlTypeDescriptorOverride(int sqlCode) {
return sqlCode == Types.TINYINT
? SmallIntJdbcTypeDescriptor.INSTANCE
: super.getSqlTypeDescriptorOverride( sqlCode );
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
super.contributeTypes( typeContributions, serviceRegistry );
typeContributions.getTypeConfiguration().getJdbcTypeDescriptorRegistry().addDescriptor(
Types.TINYINT,
SmallIntJdbcTypeDescriptor.INSTANCE
);
}
@Override

View File

@ -15,6 +15,7 @@ import java.util.Map;
import jakarta.persistence.TemporalType;
import org.hibernate.LockOptions;
import org.hibernate.boot.model.TypeContributions;
import org.hibernate.dialect.pagination.LimitHandler;
import org.hibernate.dialect.pagination.TopLimitHandler;
import org.hibernate.engine.jdbc.Size;
@ -27,6 +28,7 @@ import org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtractor;
import org.hibernate.exception.spi.ViolatedConstraintNameExtractor;
import org.hibernate.internal.util.JdbcExceptionHelper;
import org.hibernate.query.TemporalUnit;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.sql.ForUpdateFragment;
import org.hibernate.sql.ast.SqlAstTranslator;
import org.hibernate.sql.ast.SqlAstTranslatorFactory;
@ -37,6 +39,7 @@ import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor;
import org.hibernate.type.descriptor.jdbc.TimestampJdbcTypeDescriptor;
import org.hibernate.type.descriptor.jdbc.TinyIntJdbcTypeDescriptor;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeDescriptorRegistry;
import static org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtractor.extractUsingTemplate;
@ -182,17 +185,15 @@ public class SybaseASEDialect extends SybaseDialect {
}
@Override
protected JdbcTypeDescriptor getSqlTypeDescriptorOverride(int sqlCode) {
switch ( sqlCode ) {
case Types.BOOLEAN:
return TinyIntJdbcTypeDescriptor.INSTANCE;
case Types.TIMESTAMP_WITH_TIMEZONE:
// At least the jTDS driver does not support this type code
if ( jtdsDriver ) {
return TimestampJdbcTypeDescriptor.INSTANCE;
}
default:
return super.getSqlTypeDescriptorOverride( sqlCode );
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
super.contributeTypes( typeContributions, serviceRegistry );
final JdbcTypeDescriptorRegistry jdbcTypeRegistry = typeContributions.getTypeConfiguration()
.getJdbcTypeDescriptorRegistry();
jdbcTypeRegistry.addDescriptor( Types.BOOLEAN, TinyIntJdbcTypeDescriptor.INSTANCE );
// At least the jTDS driver does not support this type code
if ( jtdsDriver ) {
jdbcTypeRegistry.addDescriptor( Types.TIMESTAMP_WITH_TIMEZONE, TimestampJdbcTypeDescriptor.INSTANCE );
}
}

View File

@ -113,14 +113,6 @@ public class SybaseDialect extends AbstractTransactSQLDialect {
);
}
@Override
public JdbcTypeDescriptor remapSqlTypeDescriptor(JdbcTypeDescriptor jdbcTypeDescriptor) {
if ( jtdsDriver && TinyIntJdbcTypeDescriptor.INSTANCE == jdbcTypeDescriptor ) {
return SmallIntJdbcTypeDescriptor.INSTANCE;
}
return super.remapSqlTypeDescriptor( jdbcTypeDescriptor );
}
@Override
public SqmTranslatorFactory getSqmTranslatorFactory() {
return new StandardSqmTranslatorFactory() {
@ -173,18 +165,23 @@ public class SybaseDialect extends AbstractTransactSQLDialect {
@Override
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
super.contributeTypes(typeContributions, serviceRegistry);
final JdbcTypeDescriptorRegistry jdbcTypeRegistry = typeContributions.getTypeConfiguration()
.getJdbcTypeDescriptorRegistry();
if ( jtdsDriver ) {
typeContributions.getTypeConfiguration().getJdbcTypeDescriptorRegistry().addDescriptor(
Types.NCLOB,
ClobJdbcTypeDescriptor.CLOB_BINDING
);
typeContributions.getTypeConfiguration().getJdbcTypeDescriptorRegistry().addDescriptor(
Types.NVARCHAR,
ClobJdbcTypeDescriptor.CLOB_BINDING
);
typeContributions.contributeJdbcTypeDescriptor( ClobJdbcTypeDescriptor.CLOB_BINDING );
jdbcTypeRegistry.addDescriptor( Types.TINYINT, SmallIntJdbcTypeDescriptor.INSTANCE );
// The jTDS driver doesn't support the JDBC4 signatures using 'long length' for stream bindings
jdbcTypeRegistry.addDescriptor( Types.CLOB, ClobJdbcTypeDescriptor.CLOB_BINDING );
jdbcTypeRegistry.addDescriptor( Types.NCLOB, NClobJdbcTypeDescriptor.NCLOB_BINDING );
// The jTDS driver doesn't support the JDBC4 setNString method
jdbcTypeRegistry.addDescriptor( Types.NVARCHAR, NClobJdbcTypeDescriptor.NCLOB_BINDING );
}
else {
// Some Sybase drivers cannot support getClob. See HHH-7889
jdbcTypeRegistry.addDescriptor( Types.CLOB, ClobJdbcTypeDescriptor.STREAM_BINDING_EXTRACTING );
}
jdbcTypeRegistry.addDescriptor( Types.BLOB, BlobJdbcTypeDescriptor.PRIMITIVE_ARRAY_BINDING );
// Sybase requires a custom binder for binding untyped nulls with the NULL type
typeContributions.contributeJdbcTypeDescriptor( ObjectNullAsNullTypeJdbcTypeDescriptor.INSTANCE );
@ -206,30 +203,6 @@ public class SybaseDialect extends AbstractTransactSQLDialect {
return jtdsDriver ? NationalizationSupport.IMPLICIT : super.getNationalizationSupport();
}
@Override
protected JdbcTypeDescriptor getSqlTypeDescriptorOverride(int sqlCode) {
switch (sqlCode) {
case Types.BLOB:
return BlobJdbcTypeDescriptor.PRIMITIVE_ARRAY_BINDING;
case Types.CLOB:
// Some Sybase drivers cannot support getClob. See HHH-7889
// The jTDS driver doesn't support the JDBC4 signatures using 'long length' for stream bindings
return jtdsDriver ? ClobJdbcTypeDescriptor.CLOB_BINDING : ClobJdbcTypeDescriptor.STREAM_BINDING_EXTRACTING;
case Types.NCLOB:
// The jTDS driver doesn't support the JDBC4 signatures using 'long length' for stream bindings
if ( jtdsDriver ) {
return NClobJdbcTypeDescriptor.NCLOB_BINDING;
}
case Types.NVARCHAR:
// The jTDS driver doesn't support the JDBC4 setNString method
if ( jtdsDriver ) {
return NClobJdbcTypeDescriptor.NCLOB_BINDING;
}
default:
return super.getSqlTypeDescriptorOverride( sqlCode );
}
}
@Override
public void initializeFunctionRegistry(QueryEngine queryEngine) {
super.initializeFunctionRegistry(queryEngine);

View File

@ -38,11 +38,6 @@ public abstract class AbstractDelegatingWrapperOptions implements WrapperOptions
return delegate().getLobCreator();
}
@Override
public JdbcTypeDescriptor remapSqlTypeDescriptor(JdbcTypeDescriptor jdbcTypeDescriptor) {
return delegate().remapSqlTypeDescriptor( jdbcTypeDescriptor );
}
@Override
public TimeZone getJdbcTimeZone() {
return delegate().getJdbcTimeZone();

View File

@ -1098,11 +1098,6 @@ public class SessionDelegatorBaseImpl implements SessionImplementor {
return delegate.getLobCreator();
}
@Override
public JdbcTypeDescriptor remapSqlTypeDescriptor(JdbcTypeDescriptor jdbcTypeDescriptor) {
return delegate.remapSqlTypeDescriptor( jdbcTypeDescriptor );
}
@Override
public Integer getJdbcBatchSize() {
return delegate.getJdbcBatchSize();

View File

@ -583,11 +583,6 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
);
}
@Override
public JdbcTypeDescriptor remapSqlTypeDescriptor(JdbcTypeDescriptor jdbcTypeDescriptor) {
return fastSessionServices.remapSqlTypeDescriptor( jdbcTypeDescriptor );
}
@Override
public TimeZone getJdbcTimeZone() {
return jdbcTimeZone;

View File

@ -254,15 +254,6 @@ public final class FastSessionServices {
return elr.getEventListenerGroup( type );
}
public JdbcTypeDescriptor remapSqlTypeDescriptor(JdbcTypeDescriptor jdbcTypeDescriptor) {
if ( !jdbcTypeDescriptor.canBeRemapped() ) {
return jdbcTypeDescriptor;
}
final JdbcTypeDescriptor remapped = dialect.remapSqlTypeDescriptor( jdbcTypeDescriptor );
return remapped == null ? jdbcTypeDescriptor : remapped;
}
private static boolean isTransactionAccessible(SessionFactoryImpl sf, TransactionCoordinatorBuilder transactionCoordinatorBuilder) {
// JPA requires that access not be provided to the transaction when using JTA.
// This is overridden when SessionFactoryOptions isJtaTransactionAccessEnabled() is true.

View File

@ -695,17 +695,9 @@ public abstract class SimpleValue implements KeyValue {
jdbcTypeCode = NationalizedTypeMappings.toNationalizedTypeCode( jdbcTypeCode );
}
// find the standard SqlTypeDescriptor for that JDBC type code (allow it to be remapped if needed!)
final JdbcTypeDescriptor jdbcTypeDescriptor = getMetadata()
.getMetadataBuildingOptions()
.getServiceRegistry()
.getService( JdbcServices.class )
.getJdbcEnvironment()
.getDialect()
.remapSqlTypeDescriptor(
metadata.getTypeConfiguration()
final JdbcTypeDescriptor jdbcTypeDescriptor = metadata.getTypeConfiguration()
.getJdbcTypeDescriptorRegistry()
.getDescriptor( jdbcTypeCode ) );
.getDescriptor( jdbcTypeCode );
// and finally construct the adapter, which injects the AttributeConverter calls into the binding/extraction
// process...

View File

@ -46,11 +46,6 @@ public class SessionFactoryBasedWrapperOptions implements WrapperOptions {
return factory.getJdbcServices().getLobCreator( getSession() );
}
@Override
public JdbcTypeDescriptor remapSqlTypeDescriptor(JdbcTypeDescriptor jdbcTypeDescriptor) {
return jdbcTypeDescriptor;
}
@Override
public TimeZone getJdbcTimeZone() {
return factory.getSessionFactoryOptions().getJdbcTimeZone();

View File

@ -292,11 +292,6 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
return sessionFactory.getFastSessionServices().getPreferredSqlTypeCodeForBoolean();
}
@Override
public JdbcTypeDescriptor remapSqlTypeDescriptor(JdbcTypeDescriptor jdbcTypeDescriptor) {
return sessionFactory.getFastSessionServices().remapSqlTypeDescriptor( jdbcTypeDescriptor );
}
@Override
public TimeZone getJdbcTimeZone() {
return sessionFactory.getSessionFactoryOptions().getJdbcTimeZone();

View File

@ -301,11 +301,7 @@ public abstract class AbstractStandardBasicType<T>
@SuppressWarnings({ "unchecked" })
protected void nullSafeSet(PreparedStatement st, Object value, int index, WrapperOptions options) throws SQLException {
remapSqlTypeDescriptor( options ).getBinder( javaTypeDescriptor ).bind( st, ( T ) value, index, options );
}
protected JdbcTypeDescriptor remapSqlTypeDescriptor(WrapperOptions options) {
return options.remapSqlTypeDescriptor( jdbcTypeDescriptor );
jdbcTypeDescriptor.getBinder( javaTypeDescriptor ).bind( st, ( T ) value, index, options );
}
public void set(PreparedStatement st, T value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException {
@ -408,7 +404,7 @@ public abstract class AbstractStandardBasicType<T>
@Override
public T extract(CallableStatement statement, int startIndex, final SharedSessionContractImplementor session) throws SQLException {
return remapSqlTypeDescriptor( session ).getExtractor( javaTypeDescriptor ).extract(
return jdbcTypeDescriptor.getExtractor( javaTypeDescriptor ).extract(
statement,
startIndex,
session
@ -417,7 +413,7 @@ public abstract class AbstractStandardBasicType<T>
@Override
public T extract(CallableStatement statement, String paramName, final SharedSessionContractImplementor session) throws SQLException {
return remapSqlTypeDescriptor( session ).getExtractor( javaTypeDescriptor ).extract(
return jdbcTypeDescriptor.getExtractor( javaTypeDescriptor ).extract(
statement,
paramName,
session
@ -441,7 +437,7 @@ public abstract class AbstractStandardBasicType<T>
@SuppressWarnings("unchecked")
protected final void nullSafeSet(CallableStatement st, Object value, String name, WrapperOptions options) throws SQLException {
remapSqlTypeDescriptor( options ).getBinder( javaTypeDescriptor ).bind( st, (T) value, name, options );
jdbcTypeDescriptor.getBinder( javaTypeDescriptor ).bind( st, (T) value, name, options );
}
@Override

View File

@ -70,11 +70,6 @@ public class PostgresUUIDType extends AbstractSingleColumnStandardBasicType<UUID
return JDBC_TYPE_CODE;
}
@Override
public boolean canBeRemapped() {
return true;
}
@Override
public <J> BasicJavaTypeDescriptor<J> getJdbcRecommendedJavaTypeMapping(
Integer length,

View File

@ -45,15 +45,6 @@ public interface WrapperOptions {
*/
LobCreator getLobCreator();
/**
* Allow remapping of descriptors for dealing with sql type.
*
* @param jdbcTypeDescriptor The known descriptor
*
* @return The remapped descriptor. May be the same as the known descriptor indicating no remapping.
*/
JdbcTypeDescriptor remapSqlTypeDescriptor(JdbcTypeDescriptor jdbcTypeDescriptor);
/**
* The JDBC {@link TimeZone} used when persisting Timestamp and DateTime properties into the database.
* This setting is used when storing timestamps using the {@link java.sql.PreparedStatement#setTimestamp(int, Timestamp, Calendar)} method.

View File

@ -60,13 +60,6 @@ public class AttributeConverterJdbcTypeDescriptorAdapter implements JdbcTypeDesc
return "AttributeConverterSqlTypeDescriptorAdapter(" + converter.getClass().getName() + ")";
}
@Override
public boolean canBeRemapped() {
// any remapping of the underlying SqlTypeDescriptor should have
// happened prior to it being passed to us.
return false;
}
// Binding ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -36,11 +36,6 @@ public class BigIntJdbcTypeDescriptor implements JdbcTypeDescriptor {
return Types.BIGINT;
}
@Override
public boolean canBeRemapped() {
return true;
}
@Override
public <T> BasicJavaTypeDescriptor<T> getJdbcRecommendedJavaTypeMapping(
Integer length,

View File

@ -47,11 +47,6 @@ public abstract class BlobJdbcTypeDescriptor implements JdbcTypeDescriptor {
return "BlobTypeDescriptor";
}
@Override
public boolean canBeRemapped() {
return true;
}
@Override
public <T> BasicJavaTypeDescriptor<T> getJdbcRecommendedJavaTypeMapping(
Integer length,

View File

@ -45,11 +45,6 @@ public class BooleanJdbcTypeDescriptor implements AdjustableJdbcTypeDescriptor {
return "BooleanTypeDescriptor";
}
@Override
public boolean canBeRemapped() {
return true;
}
@Override
public <T> BasicJavaTypeDescriptor<T> getJdbcRecommendedJavaTypeMapping(
Integer length,

View File

@ -43,11 +43,6 @@ public abstract class ClobJdbcTypeDescriptor implements AdjustableJdbcTypeDescri
return "ClobTypeDescriptor";
}
@Override
public boolean canBeRemapped() {
return true;
}
@Override
public JdbcTypeDescriptor resolveIndicatedType(
JdbcTypeDescriptorIndicators indicators,

View File

@ -50,11 +50,6 @@ public class DateJdbcTypeDescriptor implements JdbcTypeDescriptor {
return "DateTypeDescriptor";
}
@Override
public boolean canBeRemapped() {
return true;
}
@Override
public <T> BasicJavaTypeDescriptor<T> getJdbcRecommendedJavaTypeMapping(
Integer length,

View File

@ -47,11 +47,6 @@ public class DecimalJdbcTypeDescriptor implements JdbcTypeDescriptor {
return "DecimalTypeDescriptor";
}
@Override
public boolean canBeRemapped() {
return true;
}
@Override
public <T> BasicJavaTypeDescriptor<T> getJdbcRecommendedJavaTypeMapping(
Integer length,

View File

@ -57,11 +57,6 @@ public class DoubleJdbcTypeDescriptor implements JdbcTypeDescriptor {
return "DoubleTypeDescriptor";
}
@Override
public boolean canBeRemapped() {
return true;
}
@Override
public <T> BasicJavaTypeDescriptor<T> getJdbcRecommendedJavaTypeMapping(
Integer length,

View File

@ -47,11 +47,6 @@ public class FloatJdbcTypeDescriptor implements JdbcTypeDescriptor {
return "FloatTypeDescriptor";
}
@Override
public boolean canBeRemapped() {
return true;
}
@Override
public <T> BasicJavaTypeDescriptor<T> getJdbcRecommendedJavaTypeMapping(
Integer length,

View File

@ -46,11 +46,6 @@ public class IntegerJdbcTypeDescriptor implements JdbcTypeDescriptor {
return "IntegerTypeDescriptor";
}
@Override
public boolean canBeRemapped() {
return true;
}
@Override
public <T> BasicJavaTypeDescriptor<T> getJdbcRecommendedJavaTypeMapping(
Integer length,

View File

@ -55,16 +55,6 @@ public interface JdbcTypeDescriptor extends Serializable {
return getJdbcTypeCode();
}
/**
* Is this descriptor available for remapping?
*
* @return {@code true} indicates this descriptor can be remapped; otherwise, {@code false}
*
* @see org.hibernate.type.descriptor.WrapperOptions#remapSqlTypeDescriptor
* @see org.hibernate.dialect.Dialect#remapSqlTypeDescriptor
*/
boolean canBeRemapped();
default <T> BasicJavaTypeDescriptor<T> getJdbcRecommendedJavaTypeMapping(
Integer precision,
Integer scale,

View File

@ -41,11 +41,6 @@ public abstract class NClobJdbcTypeDescriptor implements JdbcTypeDescriptor {
return "NClobTypeDescriptor";
}
@Override
public boolean canBeRemapped() {
return true;
}
@Override
public <X> ValueExtractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicExtractor<X>( javaTypeDescriptor, this ) {

View File

@ -46,11 +46,6 @@ public class NVarcharJdbcTypeDescriptor implements JdbcTypeDescriptor {
return "NVarcharTypeDescriptor";
}
@Override
public boolean canBeRemapped() {
return true;
}
@Override
public <T> BasicJavaTypeDescriptor<T> getJdbcRecommendedJavaTypeMapping(
Integer length,

View File

@ -32,11 +32,6 @@ public class NullJdbcTypeDescriptor implements JdbcTypeDescriptor {
return Types.NULL;
}
@Override
public boolean canBeRemapped() {
return false;
}
@Override
public <X> ValueExtractor<X> getExtractor(JavaTypeDescriptor<X> javaTypeDescriptor) {
return null;

View File

@ -45,11 +45,6 @@ public class ObjectJdbcTypeDescriptor implements JdbcTypeDescriptor {
return "ObjectSqlTypeDescriptor(" + jdbcTypeCode + ")";
}
@Override
public boolean canBeRemapped() {
return true;
}
@Override
public <X> ValueBinder<X> getBinder(JavaTypeDescriptor<X> javaTypeDescriptor) {
if ( Serializable.class.isAssignableFrom( javaTypeDescriptor.getJavaTypeClass() ) ) {

View File

@ -46,11 +46,6 @@ public class SmallIntJdbcTypeDescriptor implements JdbcTypeDescriptor {
return "SmallIntTypeDescriptor";
}
@Override
public boolean canBeRemapped() {
return true;
}
@Override
public <T> BasicJavaTypeDescriptor<T> getJdbcRecommendedJavaTypeMapping(
Integer length,

View File

@ -50,11 +50,6 @@ public class TimeJdbcTypeDescriptor implements JdbcTypeDescriptor {
return "TimeTypeDescriptor";
}
@Override
public boolean canBeRemapped() {
return true;
}
@Override
public <T> BasicJavaTypeDescriptor<T> getJdbcRecommendedJavaTypeMapping(
Integer length,

View File

@ -50,11 +50,6 @@ public class TimestampJdbcTypeDescriptor implements JdbcTypeDescriptor {
return "TimestampTypeDescriptor";
}
@Override
public boolean canBeRemapped() {
return true;
}
@Override
public <T> BasicJavaTypeDescriptor<T> getJdbcRecommendedJavaTypeMapping(
Integer length,

View File

@ -49,11 +49,6 @@ public class TimestampWithTimeZoneJdbcTypeDescriptor implements JdbcTypeDescript
return "TimestampWithTimeZoneDescriptor";
}
@Override
public boolean canBeRemapped() {
return true;
}
@Override
public <T> BasicJavaTypeDescriptor<T> getJdbcRecommendedJavaTypeMapping(
Integer length,

View File

@ -49,11 +49,6 @@ public class TinyIntJdbcTypeDescriptor implements JdbcTypeDescriptor {
return "TinyIntTypeDescriptor";
}
@Override
public boolean canBeRemapped() {
return true;
}
@Override
public <T> BasicJavaTypeDescriptor<T> getJdbcRecommendedJavaTypeMapping(
Integer length,

View File

@ -54,11 +54,6 @@ public class VarbinaryJdbcTypeDescriptor implements AdjustableJdbcTypeDescriptor
return Types.VARBINARY;
}
@Override
public boolean canBeRemapped() {
return true;
}
@Override
public <T> BasicJavaTypeDescriptor<T> getJdbcRecommendedJavaTypeMapping(
Integer length,

View File

@ -47,11 +47,6 @@ public class VarcharJdbcTypeDescriptor implements AdjustableJdbcTypeDescriptor {
return "VarcharTypeDescriptor";
}
@Override
public boolean canBeRemapped() {
return true;
}
@Override
public <T> BasicJavaTypeDescriptor<T> getJdbcRecommendedJavaTypeMapping(
Integer length,

View File

@ -29,7 +29,7 @@ import org.jboss.logging.Logger;
public class JdbcTypeDescriptorRegistry implements JdbcTypeDescriptorBaseline.BaselineTarget, Serializable {
private static final Logger log = Logger.getLogger( JdbcTypeDescriptorRegistry.class );
private ConcurrentHashMap<Integer, JdbcTypeDescriptor> descriptorMap = new ConcurrentHashMap<>();
private final ConcurrentHashMap<Integer, JdbcTypeDescriptor> descriptorMap = new ConcurrentHashMap<>();
public JdbcTypeDescriptorRegistry(TypeConfiguration typeConfiguration) {
// this.typeConfiguration = typeConfiguration;

View File

@ -51,11 +51,6 @@ public class UserTypeSqlTypeAdapter<J> implements JdbcTypeDescriptor {
return userType.sqlTypes()[0];
}
@Override
public boolean canBeRemapped() {
return false;
}
@Override
@SuppressWarnings({ "unchecked" })
public <X> ValueBinder<X> getBinder(JavaTypeDescriptor<X> javaTypeDescriptor) {

View File

@ -152,11 +152,6 @@ public class JdbcTypeTests {
return Types.TINYINT;
}
@Override
public boolean canBeRemapped() {
return false;
}
@Override
public <X> ValueBinder<X> getBinder(JavaTypeDescriptor<X> javaTypeDescriptor) {
return TinyIntJdbcTypeDescriptor.INSTANCE.getBinder( javaTypeDescriptor );

View File

@ -45,11 +45,6 @@ public class MyCustomJdbcTypeDescriptor implements JdbcTypeDescriptor {
return Types.VARCHAR;
}
@Override
public boolean canBeRemapped() {
return false;
}
@Override
public <X> ValueBinder<X> getBinder(JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicBinder<X>( javaTypeDescriptor, this ) {

View File

@ -111,11 +111,6 @@ public class MaterializedNClobBindTest {
return NonContextualLobCreator.INSTANCE;
}
@Override
public JdbcTypeDescriptor remapSqlTypeDescriptor(JdbcTypeDescriptor jdbcTypeDescriptor) {
return null;
}
@Override
public TimeZone getJdbcTimeZone() {
return null;

View File

@ -100,11 +100,6 @@ public class QueryParametersValidationArrayTest {
return Types.ARRAY;
}
@Override
public boolean canBeRemapped() {
return true;
}
@Override
public <X> ValueBinder<X> getBinder(JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicBinder<X>( javaTypeDescriptor, this) {

View File

@ -1,25 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.orm.test.typeoverride;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor;
import org.hibernate.type.descriptor.jdbc.VarcharJdbcTypeDescriptor;
/**
*
* @author Gail Badner
*/
public class H2DialectOverridePrefixedVarcharSqlTypeDesc extends H2Dialect {
@Override
public JdbcTypeDescriptor remapSqlTypeDescriptor(JdbcTypeDescriptor jdbcTypeDescriptor) {
return jdbcTypeDescriptor == StoredPrefixedStringType.INSTANCE.getJdbcTypeDescriptor() ?
VarcharJdbcTypeDescriptor.INSTANCE :
super.remapSqlTypeDescriptor( jdbcTypeDescriptor );
}
}

View File

@ -1,26 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.orm.test.typeoverride;
import java.sql.Types;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor;
/**
*
* @author Gail Badner
*/
public class H2DialectOverrideVarcharSqlCode extends H2Dialect {
@Override
public JdbcTypeDescriptor getSqlTypeDescriptorOverride(int sqlCode) {
return sqlCode == Types.VARCHAR ?
StoredPrefixedStringType.INSTANCE.getJdbcTypeDescriptor() :
super.getSqlTypeDescriptorOverride( sqlCode );
}
}

View File

@ -6,6 +6,8 @@
*/
package org.hibernate.orm.test.typeoverride;
import java.sql.Types;
import org.hibernate.boot.MetadataBuilder;
import org.hibernate.dialect.AbstractHANADialect;
import org.hibernate.dialect.CockroachDialect;
@ -18,6 +20,8 @@ import org.hibernate.type.descriptor.jdbc.IntegerJdbcTypeDescriptor;
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor;
import org.hibernate.type.descriptor.jdbc.VarbinaryJdbcTypeDescriptor;
import org.hibernate.type.descriptor.jdbc.VarcharJdbcTypeDescriptor;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeDescriptorRegistry;
import org.hibernate.type.spi.TypeConfiguration;
import org.hibernate.testing.orm.junit.BaseSessionFactoryFunctionalTest;
import org.hibernate.testing.orm.junit.SkipForDialect;
@ -46,73 +50,44 @@ public class TypeOverrideTest extends BaseSessionFactoryFunctionalTest {
@Test
public void testStandardBasicSqlTypeDescriptor() {
final JdbcTypeDescriptorRegistry jdbcTypeRegistry = getMetadata().getTypeConfiguration()
.getJdbcTypeDescriptorRegistry();
// no override
assertSame( IntegerJdbcTypeDescriptor.INSTANCE, remapSqlTypeDescriptor( IntegerJdbcTypeDescriptor.INSTANCE ) );
assertSame( IntegerJdbcTypeDescriptor.INSTANCE, jdbcTypeRegistry.getDescriptor( Types.INTEGER ) );
// A few dialects explicitly override BlobTypeDescriptor.DEFAULT
if ( CockroachDialect.class.isInstance( getDialect() ) ) {
assertSame(
VarbinaryJdbcTypeDescriptor.INSTANCE,
getDialect().remapSqlTypeDescriptor( BlobJdbcTypeDescriptor.DEFAULT )
jdbcTypeRegistry.getDescriptor( Types.BLOB )
);
}
else if ( PostgreSQL81Dialect.class.isInstance( getDialect() ) || PostgreSQLDialect.class.isInstance( getDialect() ) ) {
else if ( PostgreSQLDialect.class.isInstance( getDialect() ) ) {
assertSame(
BlobJdbcTypeDescriptor.BLOB_BINDING,
getDialect().remapSqlTypeDescriptor( BlobJdbcTypeDescriptor.DEFAULT )
jdbcTypeRegistry.getDescriptor( Types.BLOB )
);
}
else if ( SybaseDialect.class.isInstance( getDialect() ) ) {
assertSame(
BlobJdbcTypeDescriptor.PRIMITIVE_ARRAY_BINDING,
getDialect().remapSqlTypeDescriptor( BlobJdbcTypeDescriptor.DEFAULT )
jdbcTypeRegistry.getDescriptor( Types.BLOB )
);
}
else if ( AbstractHANADialect.class.isInstance( getDialect() ) ) {
assertSame(
( (AbstractHANADialect) getDialect() ).getBlobTypeDescriptor(),
getDialect().remapSqlTypeDescriptor( BlobJdbcTypeDescriptor.DEFAULT )
jdbcTypeRegistry.getDescriptor( Types.BLOB )
);
}
else {
assertSame(
BlobJdbcTypeDescriptor.DEFAULT,
getDialect().remapSqlTypeDescriptor( BlobJdbcTypeDescriptor.DEFAULT )
jdbcTypeRegistry.getDescriptor( Types.BLOB )
);
}
}
@Test
public void testNonStandardSqlTypeDescriptor() {
// no override
JdbcTypeDescriptor jdbcTypeDescriptor = new IntegerJdbcTypeDescriptor() {
@Override
public boolean canBeRemapped() {
return false;
}
};
assertSame( jdbcTypeDescriptor, remapSqlTypeDescriptor( jdbcTypeDescriptor ) );
}
@Test
public void testDialectWithNonStandardSqlTypeDescriptor() {
assertNotSame( VarcharJdbcTypeDescriptor.INSTANCE, StoredPrefixedStringType.INSTANCE.getJdbcTypeDescriptor() );
final Dialect dialect = new H2DialectOverridePrefixedVarcharSqlTypeDesc();
final JdbcTypeDescriptor remapped = remapSqlTypeDescriptor(
dialect,
StoredPrefixedStringType.PREFIXED_VARCHAR_TYPE_DESCRIPTOR
);
assertSame( VarcharJdbcTypeDescriptor.INSTANCE, remapped );
}
private JdbcTypeDescriptor remapSqlTypeDescriptor(JdbcTypeDescriptor jdbcTypeDescriptor) {
return remapSqlTypeDescriptor( sessionFactory().getDialect(), jdbcTypeDescriptor );
}
private JdbcTypeDescriptor remapSqlTypeDescriptor(Dialect dialect, JdbcTypeDescriptor jdbcTypeDescriptor) {
return dialect.remapSqlTypeDescriptor( jdbcTypeDescriptor );
}
@AfterEach
public void tearDown() {
inTransaction(

View File

@ -35,11 +35,6 @@ public class InetJdbcTypeDescriptor implements JdbcTypeDescriptor {
return Types.OTHER;
}
@Override
public boolean canBeRemapped() {
return true;
}
@Override
public <X> ValueBinder<X> getBinder(JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicBinder<X>( javaTypeDescriptor, this ) {

View File

@ -39,11 +39,6 @@ public class JsonJdbcTypeDescriptor implements JdbcTypeDescriptor {
return "OTHER (json)";
}
@Override
public boolean canBeRemapped() {
return true;
}
@Override
public <X> ValueBinder<X> getBinder(JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicBinder<X>( javaTypeDescriptor, this ) {

View File

@ -20,10 +20,13 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.function.Consumer;
import org.hibernate.boot.model.TypeContributions;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor;
import org.hibernate.testing.TestForIssue;
@ -400,14 +403,15 @@ abstract class AbstractJavaTimeTypeTest<T, E> extends BaseCoreFunctionalTestCase
}
@Override
protected JdbcTypeDescriptor getSqlTypeDescriptorOverride(int sqlCode) {
if ( overriddenSqlTypeCode == sqlCode ) {
return overriddenJdbcTypeDescriptor;
}
else {
return super.getSqlTypeDescriptorOverride( sqlCode );
}
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
super.contributeTypes( typeContributions, serviceRegistry );
typeContributions.getTypeConfiguration().getJdbcTypeDescriptorRegistry().addDescriptor(
overriddenSqlTypeCode,
overriddenJdbcTypeDescriptor
);
}
}
}

View File

@ -44,11 +44,6 @@ public class DB2GeometryTypeDescriptor implements JdbcTypeDescriptor {
return Types.CLOB;
}
@Override
public boolean canBeRemapped() {
return false;
}
@Override
public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {

View File

@ -40,11 +40,6 @@ public class GeoDBGeometryTypeDescriptor implements JdbcTypeDescriptor {
return Types.ARRAY;
}
@Override
public boolean canBeRemapped() {
return false;
}
@Override
public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicBinder<X>( javaTypeDescriptor, this ) {

View File

@ -38,11 +38,6 @@ public class HANAGeometryTypeDescriptor implements JdbcTypeDescriptor {
return Types.OTHER;
}
@Override
public boolean canBeRemapped() {
return false;
}
@Override
public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicBinder<X>( javaTypeDescriptor, this ) {

View File

@ -35,11 +35,6 @@ public class HANAPointTypeDescriptor implements JdbcTypeDescriptor {
return Types.STRUCT;
}
@Override
public boolean canBeRemapped() {
return false;
}
@Override
public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicBinder<X>( javaTypeDescriptor, this ) {

View File

@ -39,11 +39,6 @@ public class MariaDBGeometryTypeDescriptor implements JdbcTypeDescriptor {
return Types.ARRAY;
}
@Override
public boolean canBeRemapped() {
return false;
}
@Override
public <X> ValueBinder<X> getBinder(JavaTypeDescriptor<X> javaTypeDescriptor) {

View File

@ -45,11 +45,6 @@ public class MySQLGeometryTypeDescriptor implements JdbcTypeDescriptor {
return Types.ARRAY;
}
@Override
public boolean canBeRemapped() {
return false;
}
@Override
public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicBinder<X>( javaTypeDescriptor, this ) {

View File

@ -39,11 +39,6 @@ public class SDOGeometryTypeDescriptor implements JdbcTypeDescriptor {
return Types.STRUCT;
}
@Override
public boolean canBeRemapped() {
return false;
}
@Override
public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return (ValueBinder<X>) new SDOGeometryValueBinder( javaTypeDescriptor, this, typeFactory );

View File

@ -111,11 +111,6 @@ public class PGGeometryTypeDescriptor implements JdbcTypeDescriptor {
return 5432;
}
@Override
public boolean canBeRemapped() {
return false;
}
@Override
public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicBinder<X>( javaTypeDescriptor, this ) {

View File

@ -44,11 +44,6 @@ public class SqlServer2008GeometryTypeDescriptor implements JdbcTypeDescriptor {
return Types.ARRAY;
}
@Override
public boolean canBeRemapped() {
return false;
}
@Override
public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicBinder<X>( javaTypeDescriptor, this ) {