Fix Sybase error when use jdbc metadata defaults is set to false

This commit is contained in:
Andrea Boriero 2021-07-09 15:45:41 +02:00
parent 6c98d3400f
commit 8dcd63dcee
2 changed files with 29 additions and 2 deletions

View File

@ -10,6 +10,9 @@ import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.boot.model.TypeContributions;
import org.hibernate.dialect.function.CommonFunctionFactory;
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
import org.hibernate.engine.jdbc.env.spi.IdentifierCaseStrategy;
import org.hibernate.engine.jdbc.env.spi.IdentifierHelper;
import org.hibernate.engine.jdbc.env.spi.IdentifierHelperBuilder;
import org.hibernate.engine.spi.LoadQueryInfluencers;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.query.CastType;
@ -37,6 +40,8 @@ import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor;
import org.hibernate.type.descriptor.jdbc.NClobTypeDescriptor;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeDescriptorRegistry;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.sql.Types;
import javax.persistence.TemporalType;
@ -271,4 +276,15 @@ public class SybaseDialect extends AbstractTransactSQLDialect {
throw new NotYetImplementedFor6Exception( "format() function not supported on Sybase");
}
@Override
public IdentifierHelper buildIdentifierHelper(IdentifierHelperBuilder builder, DatabaseMetaData dbMetaData)
throws SQLException {
if ( dbMetaData == null ) {
builder.setUnquotedCaseStrategy( IdentifierCaseStrategy.MIXED );
builder.setQuotedCaseStrategy( IdentifierCaseStrategy.MIXED );
}
return super.buildIdentifierHelper( builder, dbMetaData );
}
}

View File

@ -357,6 +357,10 @@ public class InformationExtractorJdbcDatabaseMetaDataImpl implements Information
catch (SQLException ignore) {
log.sqlWarning( ignore.getErrorCode(), ignore.getSQLState() );
}
catch (AbstractMethodError error) {
// The jTDS driver doesn't implement the getSchema()
return null;
}
}
return currentSchema;
}
@ -417,6 +421,11 @@ public class InformationExtractorJdbcDatabaseMetaDataImpl implements Information
catch (SQLException ignore) {
log.sqlWarning( ignore.getErrorCode(), ignore.getSQLState() );
}
catch (AbstractMethodError error) {
// The jTDS driver doesn't implement the getSchema()
log.debug( "The jTDS driver doesn't implement the getSchema() method" );
return null;
}
}
return currentSchemaFilter;
}
@ -438,7 +447,8 @@ public class InformationExtractorJdbcDatabaseMetaDataImpl implements Information
catalogFilter = toMetaDataObjectName( extractionContext.getDefaultCatalog() );
}
else {
catalogFilter = "";
// 3) look in all namespaces
catalogFilter = null;
}
}
}
@ -457,7 +467,8 @@ public class InformationExtractorJdbcDatabaseMetaDataImpl implements Information
schemaFilter = toMetaDataObjectName( extractionContext.getDefaultSchema() );
}
else {
schemaFilter = "";
// 3) look in all namespaces
schemaFilter = null;
}
}
}