HHH-16221 Improve extensibility of CockroachDB and PostgreSQL dialects

This commit is contained in:
Sanne Grinovero 2023-02-23 10:59:35 +00:00
parent 87bf20f1bb
commit b328b1a3fb
4 changed files with 25 additions and 8 deletions

View File

@ -114,8 +114,8 @@ public class CockroachLegacyDialect extends Dialect {
// Pre-compile and reuse pattern
private static final Pattern CRDB_VERSION_PATTERN = Pattern.compile( "v[\\d]+(\\.[\\d]+)?(\\.[\\d]+)?" );
private static final DatabaseVersion DEFAULT_VERSION = DatabaseVersion.make( 19, 2 );
private final PostgreSQLDriverKind driverKind;
protected static final DatabaseVersion DEFAULT_VERSION = DatabaseVersion.make( 19, 2 );
protected final PostgreSQLDriverKind driverKind;
public CockroachLegacyDialect() {
this( DEFAULT_VERSION );
@ -322,7 +322,10 @@ public class CockroachLegacyDialect extends Dialect {
@Override
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
super.contributeTypes( typeContributions, serviceRegistry );
contributeCockroachTypes( typeContributions, serviceRegistry );
}
protected void contributeCockroachTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
final JdbcTypeRegistry jdbcTypeRegistry = typeContributions.getTypeConfiguration()
.getJdbcTypeRegistry();
jdbcTypeRegistry.addDescriptor( TIMESTAMP_UTC, InstantAsTimestampWithTimeZoneJdbcType.INSTANCE );

View File

@ -156,7 +156,7 @@ public class PostgreSQLLegacyDialect extends Dialect {
private static final PostgreSQLIdentityColumnSupport IDENTITY_COLUMN_SUPPORT = new PostgreSQLIdentityColumnSupport();
private final PostgreSQLDriverKind driverKind;
protected final PostgreSQLDriverKind driverKind;
private final UniqueDelegate uniqueDelegate = new CreateTableUniqueDelegate(this);
public PostgreSQLLegacyDialect() {
@ -1313,8 +1313,11 @@ public class PostgreSQLLegacyDialect extends Dialect {
@Override
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
super.contributeTypes(typeContributions, serviceRegistry);
super.contributeTypes( typeContributions, serviceRegistry );
contributePostgreSQLTypes( typeContributions, serviceRegistry );
}
protected void contributePostgreSQLTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
final JdbcTypeRegistry jdbcTypeRegistry = typeContributions.getTypeConfiguration()
.getJdbcTypeRegistry();
// For discussion of BLOB support in Postgres, as of 8.4, have a peek at

View File

@ -122,9 +122,9 @@ public class CockroachDialect extends Dialect {
// Pre-compile and reuse pattern
private static final Pattern CRDB_VERSION_PATTERN = Pattern.compile( "v[\\d]+(\\.[\\d]+)?(\\.[\\d]+)?" );
private static final DatabaseVersion MINIMUM_VERSION = DatabaseVersion.make( 21, 1 );
protected static final DatabaseVersion MINIMUM_VERSION = DatabaseVersion.make( 21, 1 );
private final PostgreSQLDriverKind driverKind;
protected final PostgreSQLDriverKind driverKind;
public CockroachDialect() {
this( MINIMUM_VERSION );
@ -333,7 +333,10 @@ public class CockroachDialect extends Dialect {
@Override
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
super.contributeTypes( typeContributions, serviceRegistry );
contributeCockroachTypes( typeContributions, serviceRegistry );
}
protected void contributeCockroachTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
final JdbcTypeRegistry jdbcTypeRegistry = typeContributions.getTypeConfiguration()
.getJdbcTypeRegistry();
jdbcTypeRegistry.addDescriptor( TIMESTAMP_UTC, InstantAsTimestampWithTimeZoneJdbcType.INSTANCE );

View File

@ -136,12 +136,12 @@ import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTimestampWithM
* @author Gavin King
*/
public class PostgreSQLDialect extends Dialect {
private final static DatabaseVersion MINIMUM_VERSION = DatabaseVersion.make( 10 );
protected final static DatabaseVersion MINIMUM_VERSION = DatabaseVersion.make( 10 );
private static final PostgreSQLIdentityColumnSupport IDENTITY_COLUMN_SUPPORT = new PostgreSQLIdentityColumnSupport();
private final UniqueDelegate uniqueDelegate = new CreateTableUniqueDelegate(this);
private final PostgreSQLDriverKind driverKind;
protected final PostgreSQLDriverKind driverKind;
private final OptionalTableUpdateStrategy optionalTableUpdateStrategy;
public PostgreSQLDialect() {
@ -1308,7 +1308,15 @@ public class PostgreSQLDialect extends Dialect {
@Override
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
super.contributeTypes(typeContributions, serviceRegistry);
contributePostgreSQLTypes(typeContributions, serviceRegistry);
}
/**
* Allow for extension points to override this only
* @param typeContributions
* @param serviceRegistry
*/
protected void contributePostgreSQLTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
final JdbcTypeRegistry jdbcTypeRegistry = typeContributions.getTypeConfiguration()
.getJdbcTypeRegistry();
// For discussion of BLOB support in Postgres, as of 8.4, have a peek at