Skip to content

Commit

Permalink
Fixed distributed axon scenario (add sequence per table + mapping for…
Browse files Browse the repository at this point in the history
… bytea dialect + set hibernate defaults for preferred_instant_jdbc_type and preferred_uuid_jdbc_type) - WIP
  • Loading branch information
p-wunderlich committed Oct 10, 2023
1 parent bafff6d commit da557bf
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 1 deletion.
3 changes: 2 additions & 1 deletion components/approval/backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

<properties>
<maven.deploy.skip>true</maven.deploy.skip>
<camunda-platform-7-autologin.version>0.0.2</camunda-platform-7-autologin.version>
</properties>

<dependencies>
Expand All @@ -29,7 +30,7 @@
<dependency>
<groupId>io.holunda</groupId>
<artifactId>camunda-platform-7-autologin</artifactId>
<version>0.0.1</version>
<version>${camunda-platform-7-autologin.version}</version>
</dependency>
<dependency>
<groupId>io.holunda.polyflow</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,45 @@
package io.holunda.polyflow.example.infrastructure.jpa

import mu.KLogging
import org.hibernate.boot.model.TypeContributions
import org.hibernate.dialect.PostgreSQLDialect
import org.hibernate.service.ServiceRegistry
import org.hibernate.type.SqlTypes
import org.hibernate.type.descriptor.jdbc.BinaryJdbcType
import org.hibernate.type.descriptor.sql.internal.DdlTypeImpl
import java.sql.Types

class NoToastPostgresSQLDialect : PostgreSQLDialect() {

companion object : KLogging()

override fun registerColumnTypes(typeContributions: TypeContributions, serviceRegistry: ServiceRegistry) {
logger.info { "Register postgres mappings for bytea." }
super.registerColumnTypes(typeContributions, serviceRegistry)
val ddlTypeRegistry = typeContributions.typeConfiguration.ddlTypeRegistry
ddlTypeRegistry.addDescriptor(DdlTypeImpl(Types.BLOB, "bytea", this))
ddlTypeRegistry.addDescriptor(DdlTypeImpl(Types.CLOB, "bytea", this))
ddlTypeRegistry.addDescriptor(DdlTypeImpl(Types.NCLOB, "bytea", this))
}

override fun columnType(sqlTypeCode: Int): String {
return when (sqlTypeCode) {
SqlTypes.BLOB -> "bytea"
else -> super.columnType(sqlTypeCode)
}
}

override fun castType(sqlTypeCode: Int): String {
return when (sqlTypeCode) {
SqlTypes.BLOB -> "bytea"
else -> super.castType(sqlTypeCode)
}
}

override fun contributeTypes(typeContributions: TypeContributions, serviceRegistry: ServiceRegistry) {
super.contributeTypes(typeContributions, serviceRegistry)
val jdbcTypeRegistry = typeContributions.typeConfiguration
.jdbcTypeRegistry
jdbcTypeRegistry.addDescriptor(Types.BLOB, BinaryJdbcType.INSTANCE)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package io.holunda.polyflow.example.infrastructure
import org.hibernate.boot.model.TypeContributions
import org.hibernate.dialect.PostgreSQLDialect
import org.hibernate.service.ServiceRegistry
import org.hibernate.type.SqlTypes
import org.hibernate.type.descriptor.jdbc.BinaryJdbcType
import org.hibernate.type.descriptor.sql.internal.DdlTypeImpl
import java.sql.Types

Expand All @@ -15,4 +17,25 @@ class NoToastPostgresSQLDialect : PostgreSQLDialect() {
ddlTypeRegistry.addDescriptor(DdlTypeImpl(Types.CLOB, "bytea", this))
ddlTypeRegistry.addDescriptor(DdlTypeImpl(Types.NCLOB, "bytea", this))
}

override fun columnType(sqlTypeCode: Int): String {
return when (sqlTypeCode) {
SqlTypes.BLOB -> "bytea"
else -> super.columnType(sqlTypeCode)
}
}

override fun castType(sqlTypeCode: Int): String {
return when (sqlTypeCode) {
SqlTypes.BLOB -> "bytea"
else -> super.castType(sqlTypeCode)
}
}

override fun contributeTypes(typeContributions: TypeContributions, serviceRegistry: ServiceRegistry) {
super.contributeTypes(typeContributions, serviceRegistry)
val jdbcTypeRegistry = typeContributions.typeConfiguration
.jdbcTypeRegistry
jdbcTypeRegistry.addDescriptor(Types.BLOB, BinaryJdbcType.INSTANCE)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ spring:
show-sql: false
open-in-view: false
database-platform: io.holunda.polyflow.example.infrastructure.jpa.NoToastPostgresSQLDialect
properties:
hibernate:
type:
preferred_instant_jdbc_type: TIMESTAMP
preferred_uuid_jdbc_type: BINARY
flyway:
enabled: true
locations: "classpath:db/migrations"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DROP SEQUENCE hibernate_sequence;

CREATE SEQUENCE association_value_entry_seq START WITH 1 INCREMENT BY 50;

CREATE SEQUENCE domain_event_entry_seq START WITH 1 INCREMENT BY 50;
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package io.holunda.polyflow.example.process.infrastructure
import org.hibernate.boot.model.TypeContributions
import org.hibernate.dialect.PostgreSQLDialect
import org.hibernate.service.ServiceRegistry
import org.hibernate.type.SqlTypes
import org.hibernate.type.descriptor.jdbc.BinaryJdbcType
import org.hibernate.type.descriptor.sql.internal.DdlTypeImpl
import java.sql.Types

Expand All @@ -15,4 +17,25 @@ class NoToastPostgresSQLDialect : PostgreSQLDialect() {
ddlTypeRegistry.addDescriptor(DdlTypeImpl(Types.CLOB, "bytea", this))
ddlTypeRegistry.addDescriptor(DdlTypeImpl(Types.NCLOB, "bytea", this))
}

override fun columnType(sqlTypeCode: Int): String {
return when (sqlTypeCode) {
SqlTypes.BLOB -> "bytea"
else -> super.columnType(sqlTypeCode)
}
}

override fun castType(sqlTypeCode: Int): String {
return when (sqlTypeCode) {
SqlTypes.BLOB -> "bytea"
else -> super.castType(sqlTypeCode)
}
}

override fun contributeTypes(typeContributions: TypeContributions, serviceRegistry: ServiceRegistry) {
super.contributeTypes(typeContributions, serviceRegistry)
val jdbcTypeRegistry = typeContributions.typeConfiguration
.jdbcTypeRegistry
jdbcTypeRegistry.addDescriptor(Types.BLOB, BinaryJdbcType.INSTANCE)
}
}

0 comments on commit da557bf

Please sign in to comment.