HHH-15464 Allow JdbcType to expose the type code to use for DDL

This commit is contained in:
Christian Beikov 2022-08-25 17:08:17 +02:00
parent a094d4c5d5
commit 4901d2bb61
51 changed files with 396 additions and 109 deletions

View File

@ -12,6 +12,7 @@ import java.util.function.Consumer;
import org.hibernate.LockMode;
import org.hibernate.dialect.DatabaseVersion;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.metamodel.mapping.JdbcMappingContainer;
import org.hibernate.query.sqm.ComparisonOperator;
import org.hibernate.query.sqm.FetchClauseType;
import org.hibernate.sql.ast.SqlAstNodeRenderingMode;
@ -40,6 +41,7 @@ import org.hibernate.sql.ast.tree.select.QuerySpec;
import org.hibernate.sql.ast.tree.select.SelectStatement;
import org.hibernate.sql.ast.tree.update.UpdateStatement;
import org.hibernate.sql.exec.spi.JdbcOperation;
import org.hibernate.type.SqlTypes;
/**
* A SQL AST translator for DB2.
@ -376,10 +378,79 @@ public class DB2LegacySqlAstTranslator<T extends JdbcOperation> extends Abstract
renderComparisonStandard( lhs, operator, rhs );
}
else {
final JdbcMappingContainer lhsExpressionType = lhs.getExpressionType();
if ( lhsExpressionType != null
&& lhsExpressionType.getJdbcMappings().get( 0 ).getJdbcType().getDdlTypeCode() == SqlTypes.SQLXML ) {
// In SQL Server, XMLTYPE is not "comparable", so we have to cast the two parts to varchar for this purpose
switch ( operator ) {
case DISTINCT_FROM:
appendSql( "decode(" );
appendSql( "xmlserialize(" );
lhs.accept( this );
appendSql( " as varchar(32672))" );
appendSql( ',' );
appendSql( "xmlserialize(" );
rhs.accept( this );
appendSql( " as varchar(32672))" );
appendSql( ",0,1)=1" );
return;
case NOT_DISTINCT_FROM:
appendSql( "decode(" );
appendSql( "xmlserialize(" );
lhs.accept( this );
appendSql( " as varchar(32672))" );
appendSql( ',' );
appendSql( "xmlserialize(" );
rhs.accept( this );
appendSql( " as varchar(32672))" );
appendSql( ",0,1)=0" );
return;
case EQUAL:
case NOT_EQUAL:
appendSql( "xmlserialize(" );
lhs.accept( this );
appendSql( " as varchar(32672))" );
appendSql( operator.sqlText() );
appendSql( "xmlserialize(" );
rhs.accept( this );
appendSql( " as varchar(32672))" );
return;
default:
// Fall through
break;
}
}
renderComparisonEmulateDecode( lhs, operator, rhs );
}
}
@Override
protected void renderComparisonStandard(Expression lhs, ComparisonOperator operator, Expression rhs) {
final JdbcMappingContainer lhsExpressionType = lhs.getExpressionType();
if ( lhsExpressionType != null
&& lhsExpressionType.getJdbcMappings().get( 0 ).getJdbcType().getDdlTypeCode() == SqlTypes.SQLXML ) {
// In SQL Server, XMLTYPE is not "comparable", so we have to cast the two parts to varchar for this purpose
switch ( operator ) {
case EQUAL:
case NOT_DISTINCT_FROM:
case NOT_EQUAL:
case DISTINCT_FROM:
appendSql( "xmlserialize(" );
lhs.accept( this );
appendSql( " as varchar(32672))" );
appendSql( operator.sqlText() );
appendSql( "xmlserialize(" );
rhs.accept( this );
appendSql( " as varchar(32672))" );
return;
default:
// Fall through
break;
}
}
super.renderComparisonStandard( lhs, operator, rhs );
}
@Override
protected void renderSelectExpression(Expression expression) {
renderSelectExpressionWithCastedOrInlinedPlainParameters( expression );

View File

@ -176,49 +176,42 @@ public class DerbyLegacyDialect extends Dialect {
super.registerColumnTypes( typeContributions, serviceRegistry );
final DdlTypeRegistry ddlTypeRegistry = typeContributions.getTypeConfiguration().getDdlTypeRegistry();
//long varchar is the right type to use for lengths between 32_672 and 32_700
int maxLongVarcharLength = 32_700;
int varcharDdlTypeCapacity = 32_672;
ddlTypeRegistry.addDescriptor(
CapacityDependentDdlType.builder( VARBINARY, columnType( BLOB ), columnType( VARBINARY ), this )
.withTypeCapacity( getMaxVarbinaryLength(), columnType( VARBINARY ) )
.withTypeCapacity( maxLongVarcharLength, columnType( LONG32VARBINARY ) )
CapacityDependentDdlType.builder( VARBINARY, columnType( LONG32VARBINARY ), columnType( VARBINARY ), this )
.withTypeCapacity( varcharDdlTypeCapacity, columnType( VARBINARY ) )
.build()
);
ddlTypeRegistry.addDescriptor(
CapacityDependentDdlType.builder( VARCHAR, columnType( CLOB ), columnType( VARCHAR ), this )
.withTypeCapacity( getMaxVarcharLength(), columnType( VARCHAR ) )
.withTypeCapacity( maxLongVarcharLength, columnType( LONG32VARCHAR ) )
CapacityDependentDdlType.builder( VARCHAR, columnType( LONG32VARCHAR ), columnType( VARCHAR ), this )
.withTypeCapacity( varcharDdlTypeCapacity, columnType( VARCHAR ) )
.build()
);
ddlTypeRegistry.addDescriptor(
CapacityDependentDdlType.builder( NVARCHAR, columnType( CLOB ), columnType( NVARCHAR ), this )
.withTypeCapacity( getMaxVarcharLength(), columnType( NVARCHAR ) )
.withTypeCapacity( maxLongVarcharLength, columnType( LONG32VARCHAR ) )
CapacityDependentDdlType.builder( NVARCHAR, columnType( LONG32VARCHAR ), columnType( NVARCHAR ), this )
.withTypeCapacity( varcharDdlTypeCapacity, columnType( NVARCHAR ) )
.build()
);
ddlTypeRegistry.addDescriptor(
CapacityDependentDdlType.builder( BINARY, columnType( BLOB ), columnType( VARBINARY ), this )
CapacityDependentDdlType.builder( BINARY, columnType( LONG32VARBINARY ), columnType( VARBINARY ), this )
.withTypeCapacity( 254, "char($l) for bit data" )
.withTypeCapacity( getMaxVarbinaryLength(), columnType( VARBINARY ) )
.withTypeCapacity( maxLongVarcharLength, columnType( LONG32VARBINARY ) )
.withTypeCapacity( varcharDdlTypeCapacity, columnType( VARBINARY ) )
.build()
);
// This is the maximum size for the CHAR datatype on Derby
ddlTypeRegistry.addDescriptor(
CapacityDependentDdlType.builder( CHAR, columnType( CLOB ), columnType( CHAR ), this )
CapacityDependentDdlType.builder( CHAR, columnType( LONG32VARCHAR ), columnType( CHAR ), this )
.withTypeCapacity( 254, columnType( CHAR ) )
.withTypeCapacity( getMaxVarcharLength(), columnType( VARCHAR ) )
.withTypeCapacity( maxLongVarcharLength, columnType( LONG32VARCHAR ) )
.build()
);
ddlTypeRegistry.addDescriptor(
CapacityDependentDdlType.builder( NCHAR, columnType( CLOB ), columnType( NCHAR ), this )
CapacityDependentDdlType.builder( NCHAR, columnType( LONG32NVARCHAR ), columnType( NCHAR ), this )
.withTypeCapacity( 254, columnType( NCHAR ) )
.withTypeCapacity( getMaxVarcharLength(), columnType( NVARCHAR ) )
.withTypeCapacity( maxLongVarcharLength, columnType( LONG32NVARCHAR ) )
.build()
);
}
@ -228,6 +221,11 @@ public class DerbyLegacyDialect extends Dialect {
return 32_672;
}
@Override
public int getMaxVarcharCapacity() {
return 32_700;
}
@Override
public int getDefaultDecimalPrecision() {
//this is the maximum allowed in Derby

View File

@ -11,7 +11,6 @@ import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.Arrays;
import org.hibernate.LockOptions;
import org.hibernate.PessimisticLockException;
@ -245,6 +244,12 @@ public class MySQLLegacyDialect extends Dialect {
}
}
@Override
public boolean useMaterializedLobWhenCapacityExceeded() {
// MySQL has no real concept of LOBs, so we can just use longtext/longblob with the materialized JDBC APIs
return false;
}
@Override
protected String castType(int sqlTypeCode) {
switch ( sqlTypeCode ) {
@ -337,7 +342,7 @@ public class MySQLLegacyDialect extends Dialect {
)
.withTypeCapacity( getMaxVarbinaryLength(), "varbinary($l)" )
.withTypeCapacity( maxMediumLobLen, "mediumblob" );
if ( getMaxVarcharLength() < maxLobLen ) {
if ( getMaxVarbinaryLength() < maxLobLen ) {
varbinaryBuilder.withTypeCapacity( maxLobLen, "blob" );
}
ddlTypeRegistry.addDescriptor( varbinaryBuilder.build() );

View File

@ -380,7 +380,7 @@ public class OracleLegacySqlAstTranslator<T extends JdbcOperation> extends Abstr
renderComparisonEmulateDecode( lhs, operator, rhs );
return;
}
switch ( lhsExpressionType.getJdbcMappings().get( 0 ).getJdbcType().getJdbcTypeCode() ) {
switch ( lhsExpressionType.getJdbcMappings().get( 0 ).getJdbcType().getDdlTypeCode() ) {
case SqlTypes.SQLXML:
// In Oracle, XMLTYPE is not "comparable", so we have to use the xmldiff function for this purpose
switch ( operator ) {
@ -402,8 +402,11 @@ public class OracleLegacySqlAstTranslator<T extends JdbcOperation> extends Abstr
rhs.accept( this );
appendSql( "),'/*[local-name()=''xdiff'']/*')" );
break;
case SqlTypes.CLOB:
case SqlTypes.NCLOB:
case SqlTypes.BLOB:
// In Oracle, BLOB types are not "comparable", so we have to use the dbms_lob.compare function for this purpose
// In Oracle, BLOB, CLOB and NCLOB types are not "comparable",
// so we have to use the dbms_lob.compare function for this purpose
switch ( operator ) {
case EQUAL:
appendSql( "0=" );

View File

@ -278,6 +278,12 @@ public class PostgreSQLLegacyDialect extends Dialect {
return 10_485_760;
}
@Override
public int getMaxVarcharCapacity() {
// 1GB according to PostgreSQL docs
return 1_073_741_824;
}
@Override
public int getMaxVarbinaryLength() {
//postgres has no varbinary-like type
@ -1018,6 +1024,13 @@ public class PostgreSQLLegacyDialect extends Dialect {
return false;
}
@Override
public boolean supportsMaterializedLobAccess() {
// Prefer using text and bytea over oid (LOB), because oid is very restricted.
// If someone really wants a type bigger than 1GB, they should ask for it by using @Lob explicitly
return false;
}
@Override
public boolean supportsTemporalLiteralOffset() {
return true;

View File

@ -8,6 +8,7 @@ package org.hibernate.community.dialect;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.metamodel.mapping.JdbcMappingContainer;
import org.hibernate.query.sqm.ComparisonOperator;
import org.hibernate.query.sqm.FetchClauseType;
import org.hibernate.sql.ast.spi.AbstractSqlAstTranslator;
import org.hibernate.sql.ast.tree.Statement;
@ -25,6 +26,7 @@ import org.hibernate.sql.ast.tree.select.QueryPart;
import org.hibernate.sql.ast.tree.select.QuerySpec;
import org.hibernate.sql.exec.spi.JdbcOperation;
import org.hibernate.sql.model.internal.TableInsertStandard;
import org.hibernate.type.SqlTypes;
/**
* A SQL AST translator for PostgreSQL.
@ -48,6 +50,33 @@ public class PostgreSQLLegacySqlAstTranslator<T extends JdbcOperation> extends A
expression.accept( this );
}
@Override
protected void renderComparison(Expression lhs, ComparisonOperator operator, Expression rhs) {
final JdbcMappingContainer lhsExpressionType = lhs.getExpressionType();
if ( lhsExpressionType != null
&& lhsExpressionType.getJdbcMappings().get( 0 ).getJdbcType().getDdlTypeCode() == SqlTypes.SQLXML ) {
// In PostgreSQL, XMLTYPE is not "comparable", so we have to cast the two parts to varchar for this purpose
switch ( operator ) {
case EQUAL:
case NOT_DISTINCT_FROM:
case NOT_EQUAL:
case DISTINCT_FROM:
appendSql( "cast(" );
lhs.accept( this );
appendSql( " as text)" );
appendSql( operator.sqlText() );
appendSql( "cast(" );
rhs.accept( this );
appendSql( " as text)" );
return;
default:
// Fall through
break;
}
}
renderComparisonStandard( lhs, operator, rhs );
}
@Override
public void visitBooleanExpressionPredicate(BooleanExpressionPredicate booleanExpressionPredicate) {
final boolean isNegated = booleanExpressionPredicate.isNegated();

View File

@ -11,6 +11,7 @@ import java.util.List;
import org.hibernate.LockMode;
import org.hibernate.LockOptions;
import org.hibernate.dialect.DatabaseVersion;
import org.hibernate.metamodel.mapping.JdbcMappingContainer;
import org.hibernate.query.sqm.FetchClauseType;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.query.sqm.ComparisonOperator;
@ -37,6 +38,7 @@ import org.hibernate.sql.ast.tree.select.QuerySpec;
import org.hibernate.sql.ast.tree.select.SelectClause;
import org.hibernate.sql.ast.tree.select.SortSpecification;
import org.hibernate.sql.exec.spi.JdbcOperation;
import org.hibernate.type.SqlTypes;
/**
* A SQL AST translator for SQL Server.
@ -394,6 +396,28 @@ public class SQLServerLegacySqlAstTranslator<T extends JdbcOperation> extends Ab
@Override
protected void renderComparison(Expression lhs, ComparisonOperator operator, Expression rhs) {
final JdbcMappingContainer lhsExpressionType = lhs.getExpressionType();
if ( lhsExpressionType != null
&& lhsExpressionType.getJdbcMappings().get( 0 ).getJdbcType().getDdlTypeCode() == SqlTypes.SQLXML ) {
// In SQL Server, XMLTYPE is not "comparable", so we have to cast the two parts to varchar for this purpose
switch ( operator ) {
case EQUAL:
case NOT_DISTINCT_FROM:
case NOT_EQUAL:
case DISTINCT_FROM:
appendSql( "cast(" );
lhs.accept( this );
appendSql( " as nvarchar(max))" );
appendSql( operator.sqlText() );
appendSql( "cast(" );
rhs.accept( this );
appendSql( " as nvarchar(max))" );
return;
default:
// Fall through
break;
}
}
renderComparisonEmulateIntersect( lhs, operator, rhs );
}

View File

@ -48,7 +48,7 @@ public @interface JdbcTypeRegistration {
* The type-code under which to register this descriptor. Can either add a new descriptor
* or override an existing one.
*
* By default we will use {@link JdbcType#getJdbcTypeCode}
* By default we will use {@link JdbcType#getDefaultSqlTypeCode()}
*/
int registrationCode() default Integer.MIN_VALUE;
}

View File

@ -626,7 +626,7 @@ public final class AnnotationBinder {
final Class<? extends JdbcType> jdbcTypeClass = annotation.value();
final JdbcType jdbcType = managedBeanRegistry.getBean( jdbcTypeClass ).getBeanInstance();
final int typeCode = annotation.registrationCode() == Integer.MIN_VALUE
? jdbcType.getJdbcTypeCode()
? jdbcType.getDefaultSqlTypeCode()
: annotation.registrationCode();
context.getMetadataCollector().addJdbcTypeRegistration( typeCode, jdbcType );
}

View File

@ -96,7 +96,7 @@ public class VersionResolution<E> implements BasicValue.Resolution<E> {
final BasicType<?> basicType = typeConfiguration.getBasicTypeRegistry().resolve( jtd, recommendedJdbcType );
final BasicType legacyType = typeConfiguration.getBasicTypeRegistry().getRegisteredType( jtd.getJavaType() );
assert legacyType.getJdbcType().getJdbcTypeCode() == recommendedJdbcType.getJdbcTypeCode();
assert legacyType.getJdbcType().getDefaultSqlTypeCode() == recommendedJdbcType.getDefaultSqlTypeCode();
return new VersionResolution<>( jtd, recommendedJdbcType, basicType, legacyType );
}

View File

@ -1911,7 +1911,7 @@ public class ModelBinder {
.getBasicTypeRegistry()
.getRegisteredType( value.getTypeName() );
if ( basicType instanceof AbstractSingleColumnStandardBasicType ) {
if ( isLob( basicType.getJdbcType().getJdbcTypeCode(), null ) ) {
if ( isLob( basicType.getJdbcType().getDdlTypeCode(), null ) ) {
value.makeLob();
}
}

View File

@ -11,6 +11,7 @@ import java.util.function.Consumer;
import org.hibernate.LockMode;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.metamodel.mapping.JdbcMappingContainer;
import org.hibernate.query.sqm.ComparisonOperator;
import org.hibernate.query.sqm.FetchClauseType;
import org.hibernate.sql.ast.SqlAstNodeRenderingMode;
@ -40,6 +41,7 @@ import org.hibernate.sql.ast.tree.select.SelectStatement;
import org.hibernate.sql.ast.tree.update.UpdateStatement;
import org.hibernate.sql.exec.spi.JdbcOperation;
import org.hibernate.sql.model.internal.TableInsertStandard;
import org.hibernate.type.SqlTypes;
import static org.hibernate.internal.util.collections.CollectionHelper.isEmpty;
import static org.hibernate.internal.util.collections.CollectionHelper.isNotEmpty;
@ -400,10 +402,79 @@ public class DB2SqlAstTranslator<T extends JdbcOperation> extends AbstractSqlAst
renderComparisonStandard( lhs, operator, rhs );
}
else {
final JdbcMappingContainer lhsExpressionType = lhs.getExpressionType();
if ( lhsExpressionType != null
&& lhsExpressionType.getJdbcMappings().get( 0 ).getJdbcType().getDdlTypeCode() == SqlTypes.SQLXML ) {
// In SQL Server, XMLTYPE is not "comparable", so we have to cast the two parts to varchar for this purpose
switch ( operator ) {
case DISTINCT_FROM:
appendSql( "decode(" );
appendSql( "xmlserialize(" );
lhs.accept( this );
appendSql( " as varchar(32672))" );
appendSql( ',' );
appendSql( "xmlserialize(" );
rhs.accept( this );
appendSql( " as varchar(32672))" );
appendSql( ",0,1)=1" );
return;
case NOT_DISTINCT_FROM:
appendSql( "decode(" );
appendSql( "xmlserialize(" );
lhs.accept( this );
appendSql( " as varchar(32672))" );
appendSql( ',' );
appendSql( "xmlserialize(" );
rhs.accept( this );
appendSql( " as varchar(32672))" );
appendSql( ",0,1)=0" );
return;
case EQUAL:
case NOT_EQUAL:
appendSql( "xmlserialize(" );
lhs.accept( this );
appendSql( " as varchar(32672))" );
appendSql( operator.sqlText() );
appendSql( "xmlserialize(" );
rhs.accept( this );
appendSql( " as varchar(32672))" );
return;
default:
// Fall through
break;
}
}
renderComparisonEmulateDecode( lhs, operator, rhs );
}
}
@Override
protected void renderComparisonStandard(Expression lhs, ComparisonOperator operator, Expression rhs) {
final JdbcMappingContainer lhsExpressionType = lhs.getExpressionType();
if ( lhsExpressionType != null
&& lhsExpressionType.getJdbcMappings().get( 0 ).getJdbcType().getDdlTypeCode() == SqlTypes.SQLXML ) {
// In SQL Server, XMLTYPE is not "comparable", so we have to cast the two parts to varchar for this purpose
switch ( operator ) {
case EQUAL:
case NOT_DISTINCT_FROM:
case NOT_EQUAL:
case DISTINCT_FROM:
appendSql( "xmlserialize(" );
lhs.accept( this );
appendSql( " as varchar(32672))" );
appendSql( operator.sqlText() );
appendSql( "xmlserialize(" );
rhs.accept( this );
appendSql( " as varchar(32672))" );
return;
default:
// Fall through
break;
}
}
super.renderComparisonStandard( lhs, operator, rhs );
}
@Override
protected void renderSelectExpression(Expression expression) {
renderSelectExpressionWithCastedOrInlinedPlainParameters( expression );

View File

@ -4279,13 +4279,13 @@ public abstract class Dialect implements ConversionContext {
Integer scale,
Long length) {
final Size size = new Size();
int jdbcTypeCode = jdbcType.getDefaultSqlTypeCode();
final int ddlTypeCode = jdbcType.getDdlTypeCode();
// Set the explicit length to null if we encounter the JPA default 255
if ( length != null && length == Size.DEFAULT_LENGTH ) {
length = null;
}
switch ( jdbcTypeCode ) {
switch ( ddlTypeCode ) {
case SqlTypes.BIT:
case SqlTypes.CHAR:
case SqlTypes.NCHAR:

View File

@ -123,7 +123,7 @@ public class MySQLDialect extends Dialect {
Integer precision,
Integer scale,
Long length) {
switch ( jdbcType.getDefaultSqlTypeCode() ) {
switch ( jdbcType.getDdlTypeCode() ) {
case Types.BIT:
// MySQL allows BIT with a length up to 64 (less the default length 255)
if ( length != null ) {
@ -310,9 +310,9 @@ public class MySQLDialect extends Dialect {
"char",
this
)
.withTypeCapacity( getVarcharDdlTypeCapacity(), "varchar($l)" )
.withTypeCapacity( getMaxVarcharLength(), "varchar($l)" )
.withTypeCapacity( maxMediumLobLen, "mediumtext" );
if ( getVarcharDdlTypeCapacity() < maxLobLen ) {
if ( getMaxVarcharLength() < maxLobLen ) {
varcharBuilder.withTypeCapacity( maxLobLen, "text" );
}
ddlTypeRegistry.addDescriptor( varcharBuilder.build() );
@ -323,9 +323,9 @@ public class MySQLDialect extends Dialect {
"char",
this
)
.withTypeCapacity( getVarcharDdlTypeCapacity(), "varchar($l)" )
.withTypeCapacity( getMaxVarcharLength(), "varchar($l)" )
.withTypeCapacity( maxMediumLobLen, "mediumtext" );
if ( getVarcharDdlTypeCapacity() < maxLobLen ) {
if ( getMaxVarcharLength() < maxLobLen ) {
nvarcharBuilder.withTypeCapacity( maxLobLen, "text" );
}
ddlTypeRegistry.addDescriptor( nvarcharBuilder.build() );
@ -336,9 +336,9 @@ public class MySQLDialect extends Dialect {
"binary",
this
)
.withTypeCapacity( getVarbinaryDdlTypeCapacity(), "varbinary($l)" )
.withTypeCapacity( getMaxVarbinaryLength(), "varbinary($l)" )
.withTypeCapacity( maxMediumLobLen, "mediumblob" );
if ( getVarbinaryDdlTypeCapacity() < maxLobLen ) {
if ( getMaxVarbinaryLength() < maxLobLen ) {
varbinaryBuilder.withTypeCapacity( maxLobLen, "blob" );
}
ddlTypeRegistry.addDescriptor( varbinaryBuilder.build() );
@ -431,11 +431,13 @@ public class MySQLDialect extends Dialect {
}
}
public int getVarcharDdlTypeCapacity() {
@Override
public int getMaxVarcharLength() {
return maxVarcharLength;
}
public int getVarbinaryDdlTypeCapacity() {
@Override
public int getMaxVarbinaryLength() {
return maxVarbinaryLength;
}

View File

@ -96,7 +96,7 @@ public class OracleArrayJdbcType extends ArrayJdbcType {
if ( typeName == null || typeName.isBlank() ) {
typeName = dialect.getArrayTypeName(
typeConfiguration.getDdlTypeRegistry().getTypeName(
elementType.getDefaultSqlTypeCode(),
elementType.getDdlTypeCode(),
dialect
)
);

View File

@ -379,7 +379,7 @@ public class OracleSqlAstTranslator<T extends JdbcOperation> extends AbstractSql
renderComparisonEmulateDecode( lhs, operator, rhs );
return;
}
switch ( lhsExpressionType.getJdbcMappings().get( 0 ).getJdbcType().getJdbcTypeCode() ) {
switch ( lhsExpressionType.getJdbcMappings().get( 0 ).getJdbcType().getDdlTypeCode() ) {
case SqlTypes.SQLXML:
// In Oracle, XMLTYPE is not "comparable", so we have to use the xmldiff function for this purpose
switch ( operator ) {
@ -401,8 +401,11 @@ public class OracleSqlAstTranslator<T extends JdbcOperation> extends AbstractSql
rhs.accept( this );
appendSql( "),'/*[local-name()=''xdiff'']/*')" );
break;
case SqlTypes.CLOB:
case SqlTypes.NCLOB:
case SqlTypes.BLOB:
// In Oracle, BLOB types are not "comparable", so we have to use the dbms_lob.compare function for this purpose
// In Oracle, BLOB, CLOB and NCLOB types are not "comparable",
// so we have to use the dbms_lob.compare function for this purpose
switch ( operator ) {
case EQUAL:
appendSql( "0=" );

View File

@ -7,9 +7,9 @@
package org.hibernate.dialect;
import org.hibernate.metamodel.mapping.JdbcMappingContainer;
import org.hibernate.query.sqm.ComparisonOperator;
import org.hibernate.query.sqm.FetchClauseType;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.query.sqm.FetchClauseType;
import org.hibernate.sql.ast.spi.AbstractSqlAstTranslator;
import org.hibernate.sql.ast.tree.Statement;
import org.hibernate.sql.ast.tree.cte.CteMaterialization;
@ -26,6 +26,7 @@ import org.hibernate.sql.ast.tree.select.QueryPart;
import org.hibernate.sql.ast.tree.select.QuerySpec;
import org.hibernate.sql.exec.spi.JdbcOperation;
import org.hibernate.sql.model.internal.TableInsertStandard;
import org.hibernate.type.SqlTypes;
/**
* A SQL AST translator for PostgreSQL.
@ -50,6 +51,33 @@ public class PostgreSQLSqlAstTranslator<T extends JdbcOperation> extends Abstrac
expression.accept( this );
}
@Override
protected void renderComparison(Expression lhs, ComparisonOperator operator, Expression rhs) {
final JdbcMappingContainer lhsExpressionType = lhs.getExpressionType();
if ( lhsExpressionType != null
&& lhsExpressionType.getJdbcMappings().get( 0 ).getJdbcType().getDdlTypeCode() == SqlTypes.SQLXML ) {
// In PostgreSQL, XMLTYPE is not "comparable", so we have to cast the two parts to varchar for this purpose
switch ( operator ) {
case EQUAL:
case NOT_DISTINCT_FROM:
case NOT_EQUAL:
case DISTINCT_FROM:
appendSql( "cast(" );
lhs.accept( this );
appendSql( " as text)" );
appendSql( operator.sqlText() );
appendSql( "cast(" );
rhs.accept( this );
appendSql( " as text)" );
return;
default:
// Fall through
break;
}
}
renderComparisonStandard( lhs, operator, rhs );
}
@Override
public void visitBooleanExpressionPredicate(BooleanExpressionPredicate booleanExpressionPredicate) {
final boolean isNegated = booleanExpressionPredicate.isNegated();

View File

@ -11,6 +11,7 @@ import java.util.List;
import org.hibernate.LockMode;
import org.hibernate.LockOptions;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.metamodel.mapping.JdbcMappingContainer;
import org.hibernate.query.sqm.ComparisonOperator;
import org.hibernate.query.sqm.FetchClauseType;
import org.hibernate.sql.ast.Clause;
@ -35,6 +36,7 @@ import org.hibernate.sql.ast.tree.select.QuerySpec;
import org.hibernate.sql.ast.tree.select.SelectClause;
import org.hibernate.sql.ast.tree.select.SortSpecification;
import org.hibernate.sql.exec.spi.JdbcOperation;
import org.hibernate.type.SqlTypes;
/**
* A SQL AST translator for SQL Server.
@ -369,6 +371,28 @@ public class SQLServerSqlAstTranslator<T extends JdbcOperation> extends Abstract
@Override
protected void renderComparison(Expression lhs, ComparisonOperator operator, Expression rhs) {
final JdbcMappingContainer lhsExpressionType = lhs.getExpressionType();
if ( lhsExpressionType != null
&& lhsExpressionType.getJdbcMappings().get( 0 ).getJdbcType().getDdlTypeCode() == SqlTypes.SQLXML ) {
// In SQL Server, XMLTYPE is not "comparable", so we have to cast the two parts to varchar for this purpose
switch ( operator ) {
case EQUAL:
case NOT_DISTINCT_FROM:
case NOT_EQUAL:
case DISTINCT_FROM:
appendSql( "cast(" );
lhs.accept( this );
appendSql( " as nvarchar(max))" );
appendSql( operator.sqlText() );
appendSql( "cast(" );
rhs.accept( this );
appendSql( " as nvarchar(max))" );
return;
default:
// Fall through
break;
}
}
renderComparisonEmulateIntersect( lhs, operator, rhs );
}

View File

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

View File

@ -54,7 +54,7 @@ public class ConcatPipeFunction extends AbstractSqmSelfRenderingFunctionDescript
final Expression expression = (Expression) sqlAstArguments.get( i );
final JdbcType jdbcType = expression.getExpressionType().getJdbcMappings().get( 0 ).getJdbcType();
sqlAppender.appendSql( separator );
switch ( jdbcType.getJdbcTypeCode() ) {
switch ( jdbcType.getDdlTypeCode() ) {
case SqlTypes.CLOB:
case SqlTypes.NCLOB:
clobPatternRenderer.render( sqlAppender, Collections.singletonList( expression ), walker );

View File

@ -57,7 +57,7 @@ public class LengthFunction extends AbstractSqmSelfRenderingFunctionDescriptor {
SqlAstTranslator<?> walker) {
final Expression expression = (Expression) sqlAstArguments.get( 0 );
final JdbcType jdbcType = expression.getExpressionType().getJdbcMappings().get( 0 ).getJdbcType();
switch ( jdbcType.getJdbcTypeCode() ) {
switch ( jdbcType.getDdlTypeCode() ) {
case SqlTypes.CLOB:
case SqlTypes.NCLOB:
clobPatternRenderer.render( sqlAppender, sqlAstArguments, walker );

View File

@ -73,7 +73,7 @@ class SumReturnTypeResolver implements FunctionReturnTypeResolver {
return impliedType;
}
}
switch ( basicType.getJdbcType().getJdbcTypeCode() ) {
switch ( basicType.getJdbcType().getDefaultSqlTypeCode() ) {
case Types.SMALLINT:
case Types.TINYINT:
case Types.INTEGER:
@ -102,7 +102,7 @@ class SumReturnTypeResolver implements FunctionReturnTypeResolver {
}
// Resolve according to JPA spec 4.8.5
final BasicValuedMapping specifiedArgType = extractArgumentValuedMapping( arguments, 1 );
switch ( specifiedArgType.getJdbcMapping().getJdbcType().getJdbcTypeCode() ) {
switch ( specifiedArgType.getJdbcMapping().getJdbcType().getDefaultSqlTypeCode() ) {
case Types.SMALLINT:
case Types.TINYINT:
case Types.INTEGER:

View File

@ -45,7 +45,7 @@ public class StandardTemporaryTableExporter implements TemporaryTableExporter {
for ( TemporaryTableColumn column : temporaryTable.getColumnsForExport() ) {
buffer.append( column.getColumnName() ).append( ' ' );
final int sqlTypeCode = column.getJdbcMapping().getJdbcType().getDefaultSqlTypeCode();
final int sqlTypeCode = column.getJdbcMapping().getJdbcType().getDdlTypeCode();
final String databaseTypeName = column.getSqlTypeDefinition();
buffer.append( databaseTypeName );

View File

@ -135,7 +135,7 @@ public class TemporaryTable implements Exportable, Contributable {
this,
uuidType,
typeConfiguration.getDdlTypeRegistry().getTypeName(
uuidType.getJdbcType().getDefaultSqlTypeCode(),
uuidType.getJdbcType().getDdlTypeCode(),
size
),
size
@ -406,7 +406,7 @@ public class TemporaryTable implements Exportable, Contributable {
final String rowNumberType;
if ( dialect.supportsWindowFunctions() ) {
rowNumberType = typeConfiguration.getDdlTypeRegistry().getTypeName(
integerBasicType.getJdbcType().getJdbcTypeCode(),
integerBasicType.getJdbcType().getDdlTypeCode(),
dialect.getSizeStrategy().resolveSize(
integerBasicType.getJdbcType(),
integerBasicType.getJavaTypeDescriptor(),
@ -418,7 +418,7 @@ public class TemporaryTable implements Exportable, Contributable {
}
else if ( dialect.getIdentityColumnSupport().supportsIdentityColumns() ) {
rowNumberType = typeConfiguration.getDdlTypeRegistry().getTypeName(
integerBasicType.getJdbcType().getJdbcTypeCode(),
integerBasicType.getJdbcType().getDdlTypeCode(),
dialect.getSizeStrategy().resolveSize(
integerBasicType.getJdbcType(),
integerBasicType.getJavaTypeDescriptor(),
@ -426,13 +426,13 @@ public class TemporaryTable implements Exportable, Contributable {
null,
null
)
) + " " +
dialect.getIdentityColumnSupport().getIdentityColumnString( integerBasicType.getJdbcType().getJdbcTypeCode() );
) + " " + dialect.getIdentityColumnSupport()
.getIdentityColumnString( integerBasicType.getJdbcType().getDdlTypeCode() );
}
else {
LOG.multiTableInsertNotAvailable( entityBinding.getEntityName() );
rowNumberType = typeConfiguration.getDdlTypeRegistry().getTypeName(
integerBasicType.getJdbcType().getJdbcTypeCode(),
integerBasicType.getJdbcType().getDdlTypeCode(),
dialect.getSizeStrategy().resolveSize(
integerBasicType.getJdbcType(),
integerBasicType.getJavaTypeDescriptor(),

View File

@ -13,6 +13,7 @@ import java.util.NoSuchElementException;
import org.hibernate.FetchMode;
import org.hibernate.MappingException;
import org.hibernate.boot.model.relational.Database;
import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.engine.spi.Mapping;
import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.mapping.Column;
@ -37,7 +38,7 @@ public class ExportableColumn extends Column {
type,
database.getTypeConfiguration()
.getDdlTypeRegistry()
.getTypeName( type.getJdbcType().getDefaultSqlTypeCode(), database.getDialect() )
.getTypeName( type.getJdbcType().getDdlTypeCode(), database.getDialect() )
);
}

View File

@ -330,7 +330,7 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol
private void resolveColumn(Column column, Dialect dialect) {
if ( column.getSqlTypeCode() == null ) {
column.setSqlTypeCode( resolution.getJdbcType().getDefaultSqlTypeCode() );
column.setSqlTypeCode( resolution.getJdbcType().getDdlTypeCode() );
}
if ( resolution.getValueConverter() != null ) {

View File

@ -241,7 +241,7 @@ public class Column implements Selectable, Serializable, Cloneable, ColumnTypeIn
final BasicType<?> elementType = containerType.getElementType();
final int sqlTypeCode;
try {
sqlTypeCode = elementType.getJdbcType().getDefaultSqlTypeCode();
sqlTypeCode = elementType.getJdbcType().getDdlTypeCode();
}
catch (Exception e) {
throw new MappingException(

View File

@ -724,7 +724,7 @@ public abstract class SimpleValue implements KeyValue {
}
}
);
int jdbcTypeCode = recommendedJdbcType.getDefaultSqlTypeCode();
int jdbcTypeCode = recommendedJdbcType.getDdlTypeCode();
if ( isLob() ) {
if ( LobTypeMappings.isMappedToKnownLobCode( jdbcTypeCode ) ) {
jdbcTypeCode = LobTypeMappings.getLobCodeTypeMapping( jdbcTypeCode );

View File

@ -60,10 +60,6 @@ public class NamedEnumValueConverter<E extends Enum<E>> implements EnumValueConv
@Override
public int getJdbcTypeCode() {
return jdbcType.getJdbcTypeCode();
}
public int getDefaultSqlTypeCode() {
return jdbcType.getDefaultSqlTypeCode();
}

View File

@ -50,7 +50,7 @@ public class OrdinalEnumValueConverter<E extends Enum<E>, N extends Number> impl
@Override
public int getJdbcTypeCode() {
return jdbcType.getJdbcTypeCode();
return jdbcType.getDefaultSqlTypeCode();
}
@Override

View File

@ -2742,7 +2742,7 @@ public abstract class AbstractEntityPersister
.getIdentitySelectString(
getTableName( 0 ),
getKeyColumns( 0 )[0],
( (BasicType<?>) getIdentifierType() ).getJdbcType().getDefaultSqlTypeCode()
( (BasicType<?>) getIdentifierType() ).getJdbcType().getDdlTypeCode()
);
}

View File

@ -591,7 +591,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister {
// If there is no selectable mapping for a table name, we render a null expression
selectableMapping = selectableMappings.values().iterator().next();
final int sqlType = selectableMapping.getJdbcMapping().getJdbcType()
.getDefaultSqlTypeCode();
.getDdlTypeCode();
buf.append( dialect.getSelectClauseNullString( sqlType, getFactory().getTypeConfiguration() ) )
.append( " as " );
}

View File

@ -33,18 +33,18 @@ import jakarta.persistence.ParameterMode;
*/
public class FunctionReturnImpl<T> implements FunctionReturnImplementor<T> {
private final ProcedureCallImplementor<T> procedureCall;
private final int jdbcTypeCode;
private final int sqlTypeCode;
private OutputableType<T> ormType;
public FunctionReturnImpl(ProcedureCallImplementor<T> procedureCall, int jdbcTypeCode) {
public FunctionReturnImpl(ProcedureCallImplementor<T> procedureCall, int sqlTypeCode) {
this.procedureCall = procedureCall;
this.jdbcTypeCode = jdbcTypeCode;
this.sqlTypeCode = sqlTypeCode;
}
public FunctionReturnImpl(ProcedureCallImplementor<T> procedureCall, OutputableType<T> ormType) {
this.procedureCall = procedureCall;
this.jdbcTypeCode = ormType.getJdbcType().getJdbcTypeCode();
this.sqlTypeCode = ormType.getJdbcType().getDefaultSqlTypeCode();
this.ormType = ormType;
}
@ -85,7 +85,7 @@ public class FunctionReturnImpl<T> implements FunctionReturnImplementor<T> {
@Override
public int getJdbcTypeCode() {
return jdbcTypeCode;
return sqlTypeCode;
}
@Override
@ -137,7 +137,7 @@ public class FunctionReturnImpl<T> implements FunctionReturnImplementor<T> {
return new FunctionReturnImpl<>( procedureCall, ormType );
}
else {
return new FunctionReturnImpl<>( procedureCall, jdbcTypeCode );
return new FunctionReturnImpl<>( procedureCall, sqlTypeCode );
}
};
}

View File

@ -320,7 +320,7 @@ public abstract class AbstractSelectionQuery<R>
}
}
if ( jdbcType != null ) {
switch ( jdbcType.getJdbcTypeCode() ) {
switch ( jdbcType.getDefaultSqlTypeCode() ) {
case Types.DATE:
if ( resultClass.isAssignableFrom( java.sql.Date.class ) ) {
return;

View File

@ -140,8 +140,8 @@ public class StandardFunctionReturnTypeResolvers {
//that is determined by how the function is used in the HQL query. In essence
//the types are compatible if the map to the same JDBC type, of if they are
//both numeric types.
int impliedTypeCode = ((BasicType<?>) implied).getJdbcMapping().getJdbcType().getJdbcTypeCode();
int definedTypeCode = ((BasicType<?>) defined).getJdbcMapping().getJdbcType().getJdbcTypeCode();
int impliedTypeCode = ((BasicType<?>) implied).getJdbcMapping().getJdbcType().getDefaultSqlTypeCode();
int definedTypeCode = ((BasicType<?>) defined).getJdbcMapping().getJdbcType().getDefaultSqlTypeCode();
return impliedTypeCode == definedTypeCode
|| isNumeric( impliedTypeCode ) && isNumeric( definedTypeCode );
}
@ -181,8 +181,8 @@ public class StandardFunctionReturnTypeResolvers {
//that is determined by how the function is used in the HQL query. In essence
//the types are compatible if the map to the same JDBC type, of if they are
//both numeric types.
int impliedTypeCode = implied.getJdbcMapping().getJdbcType().getJdbcTypeCode();
int definedTypeCode = defined.getJdbcMapping().getJdbcType().getJdbcTypeCode();
int impliedTypeCode = implied.getJdbcMapping().getJdbcType().getDefaultSqlTypeCode();
int definedTypeCode = defined.getJdbcMapping().getJdbcType().getDefaultSqlTypeCode();
return impliedTypeCode == definedTypeCode
|| isNumeric( impliedTypeCode ) && isNumeric( definedTypeCode );

View File

@ -5525,7 +5525,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
else {
SqlTypedMapping sqlTypedMapping = null;
if ( bindable instanceof BasicType<?> ) {
final int sqlTypeCode = ( (BasicType<?>) bindable ).getJdbcType().getDefaultSqlTypeCode();
final int sqlTypeCode = ( (BasicType<?>) bindable ).getJdbcType().getDdlTypeCode();
if ( sqlTypeCode == SqlTypes.NUMERIC || sqlTypeCode == SqlTypes.DECIMAL ) {
// For numeric and decimal parameter types we must determine the precision/scale of the value.
// When we need to cast the parameter later, it is necessary to know the size to avoid truncation.

View File

@ -6120,7 +6120,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
final BasicPluralType<?, ?> containerType = (BasicPluralType<?, ?>) expressionType;
final BasicType<?> elementType = containerType.getElementType();
final String elementTypeName = sessionFactory.getTypeConfiguration().getDdlTypeRegistry()
.getDescriptor( elementType.getJdbcType().getDefaultSqlTypeCode() )
.getDescriptor( elementType.getJdbcType().getDdlTypeCode() )
.getCastTypeName(
elementType,
castTarget.getLength(),
@ -6135,7 +6135,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
}
final DdlTypeRegistry ddlTypeRegistry = getSessionFactory().getTypeConfiguration().getDdlTypeRegistry();
DdlType ddlType = ddlTypeRegistry
.getDescriptor( expressionType.getJdbcMapping().getJdbcType().getDefaultSqlTypeCode() );
.getDescriptor( expressionType.getJdbcMapping().getJdbcType().getDdlTypeCode() );
if ( ddlType == null ) {
// this may happen when selecting a null value like `SELECT null from ...`
// some dbs need the value to be cast so not knowing the real type we fall back to INTEGER

View File

@ -50,7 +50,7 @@ public abstract class AbstractStandardBasicType<T>
public AbstractStandardBasicType(JdbcType jdbcType, JavaType<T> javaType) {
this.jdbcType = jdbcType;
this.sqlTypes = new int[] { jdbcType.getDefaultSqlTypeCode() };
this.sqlTypes = new int[] { jdbcType.getDdlTypeCode() };
this.javaType = javaType;
this.jdbcValueBinder = jdbcType.getBinder( javaType );
@ -347,7 +347,7 @@ public abstract class AbstractStandardBasicType<T>
// and the cast type determination here. Note that we interpret the converter in ConvertedBasicTypeImpl
// to properly determine the correct cast type
final JdbcType jdbcType = getJdbcType();
final int jdbcTypeCode = jdbcType.getJdbcTypeCode();
final int jdbcTypeCode = jdbcType.getDdlTypeCode();
switch ( jdbcTypeCode ) {
case Types.BIT:
case Types.SMALLINT:

View File

@ -140,7 +140,7 @@ public class CustomType<J>
@Override
public int[] getSqlTypeCodes(Mapping pi) {
return new int[] { jdbcType.getDefaultSqlTypeCode() };
return new int[] { jdbcType.getDdlTypeCode() };
}
@Override

View File

@ -60,7 +60,7 @@ public class SerializableToBlobType<T extends Serializable> implements BasicType
public SerializableToBlobType() {
this.jdbcType = BlobJdbcType.DEFAULT;
this.sqlTypes = new int[] { jdbcType.getDefaultSqlTypeCode() };
this.sqlTypes = new int[] { jdbcType.getDdlTypeCode() };
this.javaType = new SerializableJavaType( Serializable.class );
this.jdbcValueBinder = jdbcType.getBinder( javaType );

View File

@ -29,7 +29,7 @@ public class StandardBasicTypeTemplate<J> extends AbstractSingleColumnStandardBa
this.registrationKeys = registrationKeys;
this.name = javaType.getJavaType() == null ? "(map-mode)" : javaType.getJavaType().getTypeName()
+ " -> " + jdbcType.getJdbcTypeCode();
+ " -> " + jdbcType.getDefaultSqlTypeCode();
}
@Override

View File

@ -142,7 +142,7 @@ public class DurationJavaType extends AbstractClassJavaType<Duration> {
@Override
public int getDefaultSqlPrecision(Dialect dialect, JdbcType jdbcType) {
if ( jdbcType.getDefaultSqlTypeCode() == SqlTypes.INTERVAL_SECOND ) {
if ( jdbcType.getDdlTypeCode() == SqlTypes.INTERVAL_SECOND ) {
// Usually the maximum precision for interval types
return 18;
}
@ -158,7 +158,7 @@ public class DurationJavaType extends AbstractClassJavaType<Duration> {
@Override
public int getDefaultSqlScale(Dialect dialect, JdbcType jdbcType) {
if ( jdbcType.getDefaultSqlTypeCode() == SqlTypes.INTERVAL_SECOND ) {
if ( jdbcType.getDdlTypeCode() == SqlTypes.INTERVAL_SECOND ) {
// The default scale necessary is 9 i.e. nanosecond resolution
return 9;
}

View File

@ -183,7 +183,7 @@ public class ArrayJdbcType implements JdbcType {
.resolveSize( elementJdbcType, containerJavaType.getElementJavaType(), null, null, null );
String typeName = session.getTypeConfiguration()
.getDdlTypeRegistry()
.getDescriptor( elementJdbcType.getDefaultSqlTypeCode() )
.getDescriptor( elementJdbcType.getDdlTypeCode() )
.getTypeName( size );
int cutIndex = typeName.indexOf( '(' );
if ( cutIndex > 0 ) {

View File

@ -12,6 +12,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import org.hibernate.query.sqm.CastType;
import org.hibernate.type.descriptor.ValueBinder;
import org.hibernate.type.descriptor.ValueExtractor;
import org.hibernate.type.descriptor.WrapperOptions;
@ -43,10 +44,15 @@ public class DoubleJdbcType implements JdbcType {
* @return {@link Types#FLOAT} for schema generation
*/
@Override
public int getDefaultSqlTypeCode() {
public int getDdlTypeCode() {
return Types.FLOAT;
}
@Override
public CastType getCastType() {
return CastType.DOUBLE;
}
@Override
public String getFriendlyName() {
return "DOUBLE";

View File

@ -70,6 +70,18 @@ public interface JdbcType extends Serializable {
*/
int getJdbcTypeCode();
/**
* A {@linkplain SqlTypes JDBC type code} that identifies the SQL column type.
* <p>
* This value might be different from {@link #getDdlTypeCode()} if the actual type
* e.g. JSON is emulated through a type like CLOB.
*
* @return a JDBC type code
*/
default int getDefaultSqlTypeCode() {
return getJdbcTypeCode();
}
/**
* A {@linkplain SqlTypes JDBC type code} that identifies the SQL column type to
* be used for schema generation.
@ -78,9 +90,10 @@ public interface JdbcType extends Serializable {
* to obtain the SQL column type.
*
* @return a JDBC type code
* @since 6.2
*/
default int getDefaultSqlTypeCode() {
return getJdbcTypeCode();
default int getDdlTypeCode() {
return getDefaultSqlTypeCode();
}
default <T> JavaType<T> getJdbcRecommendedJavaTypeMapping(
@ -148,37 +161,37 @@ public interface JdbcType extends Serializable {
}
default boolean isInteger() {
int typeCode = getJdbcTypeCode();
int typeCode = getDdlTypeCode();
return SqlTypes.isIntegral(typeCode)
|| typeCode == Types.BIT; //HIGHLY DUBIOUS!
}
default boolean isFloat() {
return SqlTypes.isFloatOrRealOrDouble( getJdbcTypeCode() );
return SqlTypes.isFloatOrRealOrDouble( getDdlTypeCode() );
}
default boolean isDecimal() {
return SqlTypes.isNumericOrDecimal( getJdbcTypeCode() );
return SqlTypes.isNumericOrDecimal( getDdlTypeCode() );
}
default boolean isNumber() {
return SqlTypes.isNumericType( getJdbcTypeCode() );
return SqlTypes.isNumericType( getDdlTypeCode() );
}
default boolean isBinary() {
return SqlTypes.isBinaryType( getJdbcTypeCode() );
return SqlTypes.isBinaryType( getDdlTypeCode() );
}
default boolean isString() {
return SqlTypes.isCharacterOrClobType( getJdbcTypeCode() );
return SqlTypes.isCharacterOrClobType( getDdlTypeCode() );
}
default boolean isTemporal() {
return SqlTypes.isTemporalType( getDefaultSqlTypeCode() );
return SqlTypes.isTemporalType( getDdlTypeCode() );
}
default boolean isLob() {
return isLob( getJdbcTypeCode() );
return isLob( getDdlTypeCode() );
}
static boolean isLob(int jdbcTypeCode) {
@ -193,7 +206,7 @@ public interface JdbcType extends Serializable {
}
default boolean isNationalized() {
return isNationalized( getJdbcTypeCode() );
return isNationalized( getDdlTypeCode() );
}
static boolean isNationalized(int jdbcTypeCode) {
@ -210,11 +223,11 @@ public interface JdbcType extends Serializable {
}
default boolean isInterval() {
return SqlTypes.isIntervalType( getDefaultSqlTypeCode() );
return SqlTypes.isIntervalType( getDdlTypeCode() );
}
default CastType getCastType() {
return getCastType( getJdbcTypeCode() );
return getCastType( getDdlTypeCode() );
}
static CastType getCastType(int typeCode) {

View File

@ -97,7 +97,7 @@ public class DdlTypeImpl implements DdlType {
Long length = null;
Integer precision = null;
Integer scale = null;
switch ( jdbcType.getDefaultSqlTypeCode() ) {
switch ( jdbcType.getDdlTypeCode() ) {
case SqlTypes.VARCHAR:
length = (long) dialect.getMaxVarcharLength();
break;

View File

@ -87,7 +87,7 @@ public class ConvertedBasicTypeImpl<J> implements ConvertedBasicType<J>,
this.description = description;
this.converter = converter;
this.jdbcType = jdbcType;
this.sqlTypes = new int[] { jdbcType.getDefaultSqlTypeCode() };
this.sqlTypes = new int[] { jdbcType.getDdlTypeCode() };
this.jdbcValueBinder = (ValueBinder<J>) jdbcType.getBinder( converter.getRelationalJavaType() );
this.jdbcValueExtractor = (ValueExtractor<J>) jdbcType.getExtractor( converter.getRelationalJavaType() );
this.jdbcLiteralFormatter = (JdbcLiteralFormatter<J>) jdbcType.getJdbcLiteralFormatter( converter.getRelationalJavaType() );
@ -377,7 +377,7 @@ public class ConvertedBasicTypeImpl<J> implements ConvertedBasicType<J>,
@Override
public CastType getCastType() {
final JdbcType jdbcType = getJdbcType();
final int jdbcTypeCode = jdbcType.getJdbcTypeCode();
final int jdbcTypeCode = jdbcType.getDefaultSqlTypeCode();
switch ( jdbcTypeCode ) {
case Types.BIT:
case Types.SMALLINT:

View File

@ -63,7 +63,7 @@ public abstract class BaseUserTypeSupport<T> implements UserType<T> {
@Override
public int getSqlType() {
ensureResolved();
return jdbcType.getDefaultSqlTypeCode();
return jdbcType.getDdlTypeCode();
}
@Override

View File

@ -96,7 +96,7 @@ public class StaticUserTypeSupport<T> implements UserType<T> {
@Override
public int getSqlType() {
return jdbcType.getDefaultSqlTypeCode();
return jdbcType.getDdlTypeCode();
}
@Override

View File

@ -543,8 +543,8 @@ public abstract class AbstractCollectionMetadataGenerator extends AbstractMetada
if ( !type.isComponentType() && !type.isAssociationType() && type instanceof BasicType<?> ) {
final BasicType<?> basicType = (BasicType<?>) type;
return basicType.getJavaType() == String.class && (
basicType.getJdbcType().getJdbcTypeCode() == Types.CLOB
|| basicType.getJdbcType().getJdbcTypeCode() == Types.NCLOB
basicType.getJdbcType().getDdlTypeCode() == Types.CLOB
|| basicType.getJdbcType().getDdlTypeCode() == Types.NCLOB
);
}
}

View File

@ -451,8 +451,8 @@ public class ValidityAuditStrategy implements AuditStrategy {
if ( collectionElementType instanceof BasicType<?> ) {
final BasicType<?> basicType = (BasicType<?>) collectionElementType;
return basicType.getJavaType() == String.class && (
basicType.getJdbcType().getJdbcTypeCode() == Types.CLOB
|| basicType.getJdbcType().getJdbcTypeCode() == Types.NCLOB
basicType.getJdbcType().getDdlTypeCode() == Types.CLOB
|| basicType.getJdbcType().getDdlTypeCode() == Types.NCLOB
);
}
return false;