Skip to content

Commit

Permalink
HHH-15009 Allow augmenting supported physical table types through dia…
Browse files Browse the repository at this point in the history
…lect for H2 2.0.202+ support
  • Loading branch information
beikov authored and Sanne committed Jan 25, 2022
1 parent 7a46be6 commit f4cfda2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2953,6 +2953,10 @@ public boolean isJdbcLogWarningsEnabledByDefault() {
return true;
}

public void augmentPhysicalTableTypes(List<String> tableTypesList) {
// nothing to do
}

public void augmentRecognizedTableTypes(List<String> tableTypesList) {
// noihing to do
}
Expand Down
18 changes: 18 additions & 0 deletions hibernate-core/src/main/java/org/hibernate/dialect/H2Dialect.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.sql.SQLException;
import java.sql.Types;
import java.util.List;

import org.hibernate.JDBCException;
import org.hibernate.PessimisticLockException;
Expand Down Expand Up @@ -75,6 +76,7 @@ public boolean bindLimitParametersInReverseOrder() {

private final boolean supportsTuplesInSubqueries;
private final boolean requiresParensForTupleDistinctCounts;
private final boolean isVersion2;
private final String querySequenceString;
private final SequenceInformationExtractor sequenceInformationExtractor;

Expand All @@ -87,6 +89,7 @@ public H2Dialect() {
int buildId = Integer.MIN_VALUE;
boolean supportsTuplesInSubqueries = false;
boolean requiresParensForTupleDistinctCounts = false;
boolean isVersion2 = false;

try {
// HHH-2300
Expand All @@ -101,6 +104,7 @@ public H2Dialect() {
supportsTuplesInSubqueries = majorVersion > 1 || minorVersion > 4 || buildId >= 198;
// As of 1.4.200, this is not necessary anymore
requiresParensForTupleDistinctCounts = !( majorVersion > 1 || minorVersion > 4 || buildId >= 200 );
isVersion2 = majorVersion > 1;
}
catch ( Exception e ) {
// probably H2 not in the classpath, though in certain app server environments it might just mean we are
Expand All @@ -120,6 +124,7 @@ public H2Dialect() {
}
this.supportsTuplesInSubqueries = supportsTuplesInSubqueries;
this.requiresParensForTupleDistinctCounts = requiresParensForTupleDistinctCounts;
this.isVersion2 = isVersion2;

registerColumnType( Types.BOOLEAN, "boolean" );
registerColumnType( Types.BIGINT, "bigint" );
Expand Down Expand Up @@ -240,6 +245,12 @@ public H2Dialect() {
getDefaultProperties().setProperty( AvailableSettings.NON_CONTEXTUAL_LOB_CREATION, "true" );
}

public boolean hasOddDstBehavior() {
// H2 1.4.200 has a bug: https://github.com/h2database/h2database/issues/3184
// requiresParensForTupleDistinctCounts will be false for 1.4.200+
return !requiresParensForTupleDistinctCounts;
}

@Override
public String getAddColumnString() {
return "add column";
Expand Down Expand Up @@ -432,6 +443,13 @@ public boolean supportsUnionAll() {

// Overridden informational metadata ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@Override
public void augmentPhysicalTableTypes(List<String> tableTypesList) {
if ( isVersion2 ) {
tableTypesList.add( "BASE TABLE" );
}
}

@Override
public boolean supportsLobValueChangePropogation() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,27 @@ public AbstractInformationExtractorImpl(ExtractionContext extractionContext) {
""
)
);
final List<String> physicalTableTypesList = new ArrayList<>();
if ( ! StringHelper.isBlank( extraPhysicalTableTypesConfig ) ) {
this.extraPhysicalTableTypes = StringHelper.splitTrimmingTokens(
",;",
extraPhysicalTableTypesConfig,
false
Collections.addAll(
physicalTableTypesList,
StringHelper.splitTrimmingTokens(
",;",
extraPhysicalTableTypesConfig,
false
)
);
}
extractionContext.getJdbcEnvironment().getDialect().augmentPhysicalTableTypes( physicalTableTypesList );
this.extraPhysicalTableTypes = physicalTableTypesList.toArray( new String[0] );

final List<String> tableTypesList = new ArrayList<>();
tableTypesList.add( "TABLE" );
tableTypesList.add( "VIEW" );
if ( ConfigurationHelper.getBoolean( AvailableSettings.ENABLE_SYNONYMS, configService.getSettings(), false ) ) {
tableTypesList.add( "SYNONYM" );
}
if ( extraPhysicalTableTypes != null ) {
Collections.addAll( tableTypesList, extraPhysicalTableTypes );
}
Collections.addAll( tableTypesList, extraPhysicalTableTypes );
extractionContext.getJdbcEnvironment().getDialect().augmentRecognizedTableTypes( tableTypesList );

this.tableTypes = tableTypesList.toArray( new String[ tableTypesList.size() ] );
Expand Down

0 comments on commit f4cfda2

Please sign in to comment.