HHH-17675 add enum type support to H2LegacyDialect

This commit is contained in:
HJK181 2024-01-25 08:45:51 +01:00 committed by Christian Beikov
parent 43e925b6b4
commit c2b23508f7
1 changed files with 16 additions and 0 deletions

View File

@ -78,6 +78,7 @@ import org.hibernate.type.descriptor.jdbc.TimestampUtcAsInstantJdbcType;
import org.hibernate.type.descriptor.jdbc.UUIDJdbcType; import org.hibernate.type.descriptor.jdbc.UUIDJdbcType;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry; import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
import org.hibernate.type.descriptor.sql.internal.DdlTypeImpl; import org.hibernate.type.descriptor.sql.internal.DdlTypeImpl;
import org.hibernate.type.descriptor.sql.internal.NativeEnumDdlTypeImpl;
import org.hibernate.type.descriptor.sql.spi.DdlTypeRegistry; import org.hibernate.type.descriptor.sql.spi.DdlTypeRegistry;
import org.hibernate.type.spi.TypeConfiguration; import org.hibernate.type.spi.TypeConfiguration;
@ -117,6 +118,7 @@ import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTimestampWithN
* A legacy {@linkplain Dialect SQL dialect} for H2. * A legacy {@linkplain Dialect SQL dialect} for H2.
* *
* @author Thomas Mueller * @author Thomas Mueller
* @author Jürgen Kreitler
*/ */
public class H2LegacyDialect extends Dialect { public class H2LegacyDialect extends Dialect {
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( H2LegacyDialect.class ); private static final CoreMessageLogger LOG = CoreLogging.messageLogger( H2LegacyDialect.class );
@ -262,6 +264,7 @@ public class H2LegacyDialect extends Dialect {
ddlTypeRegistry.addDescriptor( new DdlTypeImpl( JSON, "json", this ) ); ddlTypeRegistry.addDescriptor( new DdlTypeImpl( JSON, "json", this ) );
} }
} }
ddlTypeRegistry.addDescriptor( new NativeEnumDdlTypeImpl( this ) );
} }
@Override @Override
@ -289,6 +292,7 @@ public class H2LegacyDialect extends Dialect {
if ( getVersion().isSameOrAfter( 1, 4, 200 ) ) { if ( getVersion().isSameOrAfter( 1, 4, 200 ) ) {
jdbcTypeRegistry.addDescriptorIfAbsent( H2FormatJsonJdbcType.INSTANCE ); jdbcTypeRegistry.addDescriptorIfAbsent( H2FormatJsonJdbcType.INSTANCE );
} }
jdbcTypeRegistry.addDescriptor( new MySQLEnumJdbcType() );
} }
@Override @Override
@ -932,6 +936,18 @@ public class H2LegacyDialect extends Dialect {
return "set referential_integrity true"; return "set referential_integrity true";
} }
@Override
public String getEnumTypeDeclaration(String name, String[] values) {
StringBuilder type = new StringBuilder();
type.append( "enum (" );
String separator = "";
for ( String value : values ) {
type.append( separator ).append('\'').append( value ).append('\'');
separator = ",";
}
return type.append( ')' ).toString();
}
@Override @Override
public String getDisableConstraintsStatement() { public String getDisableConstraintsStatement() {
return "set referential_integrity false"; return "set referential_integrity false";