Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
*/
package org.hibernate.community.dialect;

import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.sql.Types;
import java.time.temporal.TemporalAccessor;
import java.util.Date;
import java.util.TimeZone;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.model.FunctionContributions;
import org.hibernate.boot.model.TypeContributions;
Expand All @@ -24,6 +27,9 @@
import org.hibernate.dialect.NullOrdering;
import org.hibernate.dialect.Replacer;
import org.hibernate.dialect.SelectItemReferenceStrategy;
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.exception.ConstraintViolationException;
import org.hibernate.exception.LockAcquisitionException;
import org.hibernate.exception.spi.SQLExceptionConversionDelegate;
Expand Down Expand Up @@ -737,6 +743,11 @@ public void appendBinaryLiteral(SqlAppender appender, byte[] bytes) {
throw new UnsupportedOperationException( "Informix does not support binary literals" );
}

@Override
public String getCatalogSeparator() {
return ":";
}

@Override
public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(
EntityMappingType rootEntityDescriptor,
Expand Down Expand Up @@ -1036,4 +1047,13 @@ public boolean supportsRowValueConstructorSyntaxInInList() {
public boolean requiresColumnListInCreateView() {
return true;
}

@Override
public IdentifierHelper buildIdentifierHelper(IdentifierHelperBuilder builder, @Nullable DatabaseMetaData metadata)
throws SQLException {
if ( metadata == null ) {
builder.setUnquotedCaseStrategy( IdentifierCaseStrategy.LOWER );
}
return super.buildIdentifierHelper( builder, metadata );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3039,6 +3039,10 @@ public boolean supportsIfExistsAfterTypeName() {
return false;
}

public String getCatalogSeparator() {
return ".";
}

// callable statement support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ public JdbcEnvironmentImpl(final ServiceRegistryImplementor serviceRegistry, fin
currentCatalog = identifierHelper.toIdentifier( cfgService.getSetting( DEFAULT_CATALOG, STRING ) );
currentSchema = Identifier.toIdentifier( cfgService.getSetting( DEFAULT_SCHEMA, STRING ) );

qualifiedObjectNameFormatter = new QualifiedObjectNameFormatterStandardImpl( nameQualifierSupport );
qualifiedObjectNameFormatter =
new QualifiedObjectNameFormatterStandardImpl( nameQualifierSupport, dialect.getCatalogSeparator() );

lobCreatorBuilder = makeLobCreatorBuilder( dialect );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ private Format buildFormat(
}
}

public QualifiedObjectNameFormatterStandardImpl(NameQualifierSupport nameQualifierSupport) {
public QualifiedObjectNameFormatterStandardImpl(NameQualifierSupport nameQualifierSupport, String catalogSeparator) {
// most dbs simply do <catalog>.<schema>.<name>
this( nameQualifierSupport, ".", false );
this( nameQualifierSupport, catalogSeparator, false );
}

public QualifiedObjectNameFormatterStandardImpl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import java.sql.SQLException;

import jakarta.persistence.EnumType;
import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.spi.SqlExceptionHelper;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.type.BasicType;
import org.hibernate.type.descriptor.java.JavaType;
import org.hibernate.type.descriptor.jdbc.JdbcType;
Expand Down Expand Up @@ -75,15 +75,19 @@ public int getColumnCount() {
@Override
public int resolveColumnPosition(String columnName) {
try {
return getResultSet()
.findColumn( StringHelper.unquote( columnName, getDialect() ) );
return getResultSet().findColumn( normalizeColumnName( columnName ) );
}
catch (SQLException e) {
throw getSqlExceptionHelper()
.convert( e, "Unable to find column position by name: " + columnName );
}
}

private String normalizeColumnName(String columnName) {
return getFactory().getJdbcServices().getJdbcEnvironment().getIdentifierHelper()
.toMetaDataObjectName( Identifier.toIdentifier( columnName ) );
}

@Override
public String resolveColumnName(int position) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import org.hibernate.boot.model.naming.DatabaseIdentifier;
import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.boot.model.relational.QualifiedTableName;
import org.hibernate.dialect.Dialect;
import org.hibernate.tool.schema.extract.spi.ExtractionContext;
import org.hibernate.tool.schema.extract.spi.TableInformation;
Expand Down Expand Up @@ -157,11 +158,12 @@ protected void addColumns(TableInformation tableInformation) {

// We use this dummy query to retrieve the table information through the ResultSetMetaData
// Significantly better than using DatabaseMetaData especially on Oracle with synonyms enabled
final QualifiedTableName qualifiedTableName = tableInformation.getName();
final String tableName =
extractionContext.getSqlStringGenerationContext()
// The name comes from the database, so the case is correct
// But we quote here to avoid issues with reserved words
.format( tableInformation.getName().quote() );
.format( qualifiedTableName.quote() );

try {
extractionContext.getQueryResults(
Expand All @@ -178,9 +180,7 @@ protected void addColumns(TableInformation tableInformation) {
);
}
catch (SQLException e) {
throw convertSQLException( e,
"Error accessing column metadata: "
+ tableInformation.getName().toString() );
throw convertSQLException( e, "Error accessing column metadata: " + qualifiedTableName );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

Expand Down Expand Up @@ -38,7 +37,7 @@ default <T> T getQueryResults(
String queryString,
Object[] positionalParameters,
ResultSetProcessor<T> resultSetProcessor) throws SQLException {
try (PreparedStatement statement = getJdbcConnection().prepareStatement( queryString )) {
try ( var statement = getJdbcConnection().prepareStatement( queryString ) ) {
if ( positionalParameters != null ) {
for ( int i = 0 ; i < positionalParameters.length ; i++ ) {
statement.setObject( i + 1, positionalParameters[i] );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public Identifier getCurrentSchema() {

@Override
public QualifiedObjectNameFormatter getQualifiedObjectNameFormatter() {
return new QualifiedObjectNameFormatterStandardImpl(getNameQualifierSupport());
return new QualifiedObjectNameFormatterStandardImpl(getNameQualifierSupport(), ".");
}

@Override
Expand Down