Unicode columns for SqlServer (#248)

* ENT-1291 Switch liquibase changelogs to use nvarchar instead of varchar

* Configure Hibernate to use nationalised strings

* Configure Hibernate to use nationalised strings

* Change schema so that UUIDs are varchars

* Update schema certificate signing request status is not unicode

* Upper case suffix for audit tables

* nvarchar -> varchar for status in the audit table

* Capitalisation

* Capitalisation

* Force hibernate to use unicode columns on SQL server

* Force hibernate to use unicode columns on SQL server

* Schema change to make PostgreSql happy

* SQL files to initialise the perfcluster db for SQL server and PostgreSql

* Code ordering and extra comment
This commit is contained in:
Christian Sailer
2017-12-21 17:34:21 +00:00
committed by GitHub
parent 2a0eefd351
commit a2344f15fb
27 changed files with 189 additions and 121 deletions

View File

@ -42,13 +42,14 @@ class CordaPersistence(
val dataSource: DataSource,
databaseConfig: DatabaseConfig,
schemas: Set<MappedSchema>,
val jdbcUrl: String,
attributeConverters: Collection<AttributeConverter<*, *>> = emptySet()
) : Closeable {
val defaultIsolationLevel = databaseConfig.transactionIsolationLevel
val hibernateConfig: HibernateConfiguration by lazy {
transaction {
HibernateConfiguration(schemas, databaseConfig, attributeConverters)
HibernateConfiguration(schemas, databaseConfig, attributeConverters, jdbcUrl)
}
}
val entityManagerFactory get() = hibernateConfig.sessionFactoryForRegisteredSchemas

View File

@ -23,7 +23,8 @@ import javax.persistence.AttributeConverter
class HibernateConfiguration(
schemas: Set<MappedSchema>,
private val databaseConfig: DatabaseConfig,
private val attributeConverters: Collection<AttributeConverter<*, *>>
private val attributeConverters: Collection<AttributeConverter<*, *>>,
private val jdbcUrl: String
) {
companion object {
private val logger = contextLogger()
@ -94,6 +95,10 @@ class HibernateConfiguration(
// to avoid OOM when large blobs might get logged.
applyBasicType(CordaMaterializedBlobType, CordaMaterializedBlobType.name)
applyBasicType(CordaWrapperBinaryType, CordaWrapperBinaryType.name)
// When connecting to SqlServer (and only then) do we need to tell hibernate to use
// nationalised (i.e. Unicode) strings by default
val forceUnicodeForSqlServer = jdbcUrl.contains(":sqlserver:", ignoreCase = true);
enableGlobalNationalizedCharacterDataSupport(forceUnicodeForSqlServer)
build()
}