HHH-15009 Allow augmenting supported physical table types through dialect for H2 2.0.202+ support

This commit is contained in:
Christian Beikov 2022-01-18 13:19:50 +01:00 committed by Sanne Grinovero
parent 7a46be6572
commit f4cfda2b73
3 changed files with 33 additions and 7 deletions

View File

@ -2953,6 +2953,10 @@ public abstract class Dialect implements ConversionContext {
return true;
}
public void augmentPhysicalTableTypes(List<String> tableTypesList) {
// nothing to do
}
public void augmentRecognizedTableTypes(List<String> tableTypesList) {
// noihing to do
}

View File

@ -8,6 +8,7 @@ package org.hibernate.dialect;
import java.sql.SQLException;
import java.sql.Types;
import java.util.List;
import org.hibernate.JDBCException;
import org.hibernate.PessimisticLockException;
@ -75,6 +76,7 @@ public class H2Dialect extends Dialect {
private final boolean supportsTuplesInSubqueries;
private final boolean requiresParensForTupleDistinctCounts;
private final boolean isVersion2;
private final String querySequenceString;
private final SequenceInformationExtractor sequenceInformationExtractor;
@ -87,6 +89,7 @@ public class H2Dialect extends Dialect {
int buildId = Integer.MIN_VALUE;
boolean supportsTuplesInSubqueries = false;
boolean requiresParensForTupleDistinctCounts = false;
boolean isVersion2 = false;
try {
// HHH-2300
@ -101,6 +104,7 @@ public class H2Dialect extends Dialect {
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
@ -120,6 +124,7 @@ public class H2Dialect extends Dialect {
}
this.supportsTuplesInSubqueries = supportsTuplesInSubqueries;
this.requiresParensForTupleDistinctCounts = requiresParensForTupleDistinctCounts;
this.isVersion2 = isVersion2;
registerColumnType( Types.BOOLEAN, "boolean" );
registerColumnType( Types.BIGINT, "bigint" );
@ -240,6 +245,12 @@ public class H2Dialect extends Dialect {
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";
@ -432,6 +443,13 @@ public class H2Dialect extends Dialect {
// Overridden informational metadata ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@Override
public void augmentPhysicalTableTypes(List<String> tableTypesList) {
if ( isVersion2 ) {
tableTypesList.add( "BASE TABLE" );
}
}
@Override
public boolean supportsLobValueChangePropogation() {
return false;

View File

@ -84,13 +84,19 @@ public abstract class AbstractInformationExtractorImpl implements InformationExt
""
)
);
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" );
@ -98,9 +104,7 @@ public abstract class AbstractInformationExtractorImpl implements InformationExt
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() ] );