mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-21 18:45:09 +00:00
Fix SybaseASEDialect column lenght resolution
This commit is contained in:
parent
7cc7bac5d4
commit
af6c8eefea
@ -508,6 +508,23 @@ public JdbcType resolveSqlTypeDescriptor(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int resolveSqlTypeLength(
|
||||||
|
String columnTypeName,
|
||||||
|
int jdbcTypeCode,
|
||||||
|
int precision,
|
||||||
|
int scale,
|
||||||
|
int displaySize) {
|
||||||
|
// It seems MariaDB/MySQL return the precision in bytes depending on the charset,
|
||||||
|
// so to detect whether we have a single character here, we check the display size
|
||||||
|
if ( jdbcTypeCode == Types.CHAR && precision <= 4 ) {
|
||||||
|
return displaySize;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return precision;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getPreferredSqlTypeCodeForBoolean() {
|
public int getPreferredSqlTypeCodeForBoolean() {
|
||||||
return Types.BIT;
|
return Types.BIT;
|
||||||
|
@ -10,14 +10,12 @@
|
|||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Types;
|
import java.sql.Types;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.hibernate.LockMode;
|
import org.hibernate.LockMode;
|
||||||
import org.hibernate.LockOptions;
|
import org.hibernate.LockOptions;
|
||||||
import org.hibernate.boot.model.TypeContributions;
|
import org.hibernate.boot.model.TypeContributions;
|
||||||
import org.hibernate.dialect.DatabaseVersion;
|
import org.hibernate.dialect.DatabaseVersion;
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.dialect.RowLockStrategy;
|
|
||||||
import org.hibernate.dialect.SybaseDriverKind;
|
import org.hibernate.dialect.SybaseDriverKind;
|
||||||
import org.hibernate.dialect.pagination.LimitHandler;
|
import org.hibernate.dialect.pagination.LimitHandler;
|
||||||
import org.hibernate.dialect.pagination.TopLimitHandler;
|
import org.hibernate.dialect.pagination.TopLimitHandler;
|
||||||
@ -33,7 +31,6 @@
|
|||||||
import org.hibernate.query.sqm.IntervalType;
|
import org.hibernate.query.sqm.IntervalType;
|
||||||
import org.hibernate.query.sqm.TemporalUnit;
|
import org.hibernate.query.sqm.TemporalUnit;
|
||||||
import org.hibernate.service.ServiceRegistry;
|
import org.hibernate.service.ServiceRegistry;
|
||||||
import org.hibernate.sql.ForUpdateFragment;
|
|
||||||
import org.hibernate.sql.ast.SqlAstTranslator;
|
import org.hibernate.sql.ast.SqlAstTranslator;
|
||||||
import org.hibernate.sql.ast.SqlAstTranslatorFactory;
|
import org.hibernate.sql.ast.SqlAstTranslatorFactory;
|
||||||
import org.hibernate.sql.ast.spi.StandardSqlAstTranslatorFactory;
|
import org.hibernate.sql.ast.spi.StandardSqlAstTranslatorFactory;
|
||||||
@ -237,22 +234,6 @@ public void contributeTypes(TypeContributions typeContributions, ServiceRegistry
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int resolveSqlTypeLength(
|
|
||||||
String columnTypeName,
|
|
||||||
int jdbcTypeCode,
|
|
||||||
int precision,
|
|
||||||
int scale,
|
|
||||||
int displaySize) {
|
|
||||||
// Sybase ASE reports the "actual" precision in the display size
|
|
||||||
switch ( jdbcTypeCode ) {
|
|
||||||
case Types.REAL:
|
|
||||||
case Types.DOUBLE:
|
|
||||||
return displaySize;
|
|
||||||
}
|
|
||||||
return super.resolveSqlTypeLength( columnTypeName, jdbcTypeCode, precision, scale, displaySize );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String currentDate() {
|
public String currentDate() {
|
||||||
return "current_date()";
|
return "current_date()";
|
||||||
|
@ -158,6 +158,23 @@ public JdbcType resolveSqlTypeDescriptor(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int resolveSqlTypeLength(
|
||||||
|
String columnTypeName,
|
||||||
|
int jdbcTypeCode,
|
||||||
|
int precision,
|
||||||
|
int scale,
|
||||||
|
int displaySize) {
|
||||||
|
// Sybase jconnect driver reports the "actual" precision in the display size
|
||||||
|
switch ( jdbcTypeCode ) {
|
||||||
|
case Types.VARCHAR:
|
||||||
|
case Types.REAL:
|
||||||
|
case Types.DOUBLE:
|
||||||
|
return displaySize;
|
||||||
|
}
|
||||||
|
return super.resolveSqlTypeLength( columnTypeName, jdbcTypeCode, precision, scale, displaySize );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SqmTranslatorFactory getSqmTranslatorFactory() {
|
public SqmTranslatorFactory getSqmTranslatorFactory() {
|
||||||
return new StandardSqmTranslatorFactory() {
|
return new StandardSqmTranslatorFactory() {
|
||||||
|
@ -764,14 +764,7 @@ public int resolveSqlTypeLength(
|
|||||||
int precision,
|
int precision,
|
||||||
int scale,
|
int scale,
|
||||||
int displaySize) {
|
int displaySize) {
|
||||||
// It seems MariaDB/MySQL return the precision in bytes depending on the charset,
|
return precision;
|
||||||
// so to detect whether we have a single character here, we check the display size
|
|
||||||
if ( jdbcTypeCode == Types.CHAR && precision <= 4 ) {
|
|
||||||
return displaySize;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return precision;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -544,6 +544,23 @@ public JdbcType resolveSqlTypeDescriptor(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int resolveSqlTypeLength(
|
||||||
|
String columnTypeName,
|
||||||
|
int jdbcTypeCode,
|
||||||
|
int precision,
|
||||||
|
int scale,
|
||||||
|
int displaySize) {
|
||||||
|
// It seems MariaDB/MySQL return the precision in bytes depending on the charset,
|
||||||
|
// so to detect whether we have a single character here, we check the display size
|
||||||
|
if ( jdbcTypeCode == Types.CHAR && precision <= 4 ) {
|
||||||
|
return displaySize;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return precision;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getPreferredSqlTypeCodeForBoolean() {
|
public int getPreferredSqlTypeCodeForBoolean() {
|
||||||
return Types.BIT;
|
return Types.BIT;
|
||||||
|
@ -251,22 +251,6 @@ public void contributeTypes(TypeContributions typeContributions, ServiceRegistry
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int resolveSqlTypeLength(
|
|
||||||
String columnTypeName,
|
|
||||||
int jdbcTypeCode,
|
|
||||||
int precision,
|
|
||||||
int scale,
|
|
||||||
int displaySize) {
|
|
||||||
// Sybase ASE reports the "actual" precision in the display size
|
|
||||||
switch ( jdbcTypeCode ) {
|
|
||||||
case Types.REAL:
|
|
||||||
case Types.DOUBLE:
|
|
||||||
return displaySize;
|
|
||||||
}
|
|
||||||
return super.resolveSqlTypeLength( columnTypeName, jdbcTypeCode, precision, scale, displaySize );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String currentDate() {
|
public String currentDate() {
|
||||||
return "current_date()";
|
return "current_date()";
|
||||||
|
@ -140,6 +140,23 @@ public JdbcType resolveSqlTypeDescriptor(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int resolveSqlTypeLength(
|
||||||
|
String columnTypeName,
|
||||||
|
int jdbcTypeCode,
|
||||||
|
int precision,
|
||||||
|
int scale,
|
||||||
|
int displaySize) {
|
||||||
|
// Sybase jconnect driver reports the "actual" precision in the display size
|
||||||
|
switch ( jdbcTypeCode ) {
|
||||||
|
case Types.VARCHAR:
|
||||||
|
case Types.REAL:
|
||||||
|
case Types.DOUBLE:
|
||||||
|
return displaySize;
|
||||||
|
}
|
||||||
|
return super.resolveSqlTypeLength( columnTypeName, jdbcTypeCode, precision, scale, displaySize );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SqmTranslatorFactory getSqmTranslatorFactory() {
|
public SqmTranslatorFactory getSqmTranslatorFactory() {
|
||||||
return new StandardSqmTranslatorFactory() {
|
return new StandardSqmTranslatorFactory() {
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
import org.hibernate.boot.model.naming.DatabaseIdentifier;
|
import org.hibernate.boot.model.naming.DatabaseIdentifier;
|
||||||
import org.hibernate.boot.model.naming.Identifier;
|
import org.hibernate.boot.model.naming.Identifier;
|
||||||
|
import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.tool.schema.extract.spi.ExtractionContext;
|
import org.hibernate.tool.schema.extract.spi.ExtractionContext;
|
||||||
import org.hibernate.tool.schema.extract.spi.TableInformation;
|
import org.hibernate.tool.schema.extract.spi.TableInformation;
|
||||||
|
|
||||||
@ -134,6 +135,8 @@ protected <T> T processImportedKeysResultSet(
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void addColumns(TableInformation tableInformation) {
|
protected void addColumns(TableInformation tableInformation) {
|
||||||
|
final Dialect dialect = getExtractionContext().getJdbcEnvironment().getDialect();
|
||||||
|
|
||||||
final ExtractionContext extractionContext = getExtractionContext();
|
final ExtractionContext extractionContext = getExtractionContext();
|
||||||
// We use this dummy query to retrieve the table information through the ResultSetMetaData
|
// We use this dummy query to retrieve the table information through the ResultSetMetaData
|
||||||
// This is significantly better than to use the DatabaseMetaData especially on Oracle with synonyms enabled
|
// This is significantly better than to use the DatabaseMetaData especially on Oracle with synonyms enabled
|
||||||
@ -153,13 +156,22 @@ protected void addColumns(TableInformation tableInformation) {
|
|||||||
|
|
||||||
for ( int i = 1; i <= columnCount; i++ ) {
|
for ( int i = 1; i <= columnCount; i++ ) {
|
||||||
final String columnName = metaData.getColumnName( i );
|
final String columnName = metaData.getColumnName( i );
|
||||||
|
final int columnType = metaData.getColumnType( i );
|
||||||
|
final String typeName = new StringTokenizer( metaData.getColumnTypeName( i ), "()" ).nextToken();
|
||||||
|
final int scale = metaData.getScale( i );
|
||||||
final ColumnInformationImpl columnInformation = new ColumnInformationImpl(
|
final ColumnInformationImpl columnInformation = new ColumnInformationImpl(
|
||||||
tableInformation,
|
tableInformation,
|
||||||
DatabaseIdentifier.toIdentifier( columnName ),
|
DatabaseIdentifier.toIdentifier( columnName ),
|
||||||
metaData.getColumnType( i ),
|
columnType,
|
||||||
new StringTokenizer( metaData.getColumnTypeName( i ), "()" ).nextToken(),
|
typeName,
|
||||||
metaData.getPrecision( i ),
|
dialect.resolveSqlTypeLength(
|
||||||
metaData.getScale( i ),
|
typeName,
|
||||||
|
columnType,
|
||||||
|
metaData.getPrecision( i ),
|
||||||
|
scale,
|
||||||
|
metaData.getColumnDisplaySize( i )
|
||||||
|
),
|
||||||
|
scale,
|
||||||
interpretNullable( metaData.isNullable( i ) )
|
interpretNullable( metaData.isNullable( i ) )
|
||||||
);
|
);
|
||||||
tableInformation.addColumn( columnInformation );
|
tableInformation.addColumn( columnInformation );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user