DatabaseDialect.ktorg.hibernate.dialect.PostgreSQLDialect) and HSQLDB (org.hibernate.dialect.HSQLDialect). Acts as the single source of truth for database type configuration across the application bootstrap, Flyway migration script resolution, and Hibernate session factory setup.asString: String property via the primary constructor@JvmStatic@JvmStatic annotation on fromString() makes it callable as DatabaseDialect.fromString(...) from Java code, rather than DatabaseDialect.Companion.fromString(...)| Constant | Hibernate Dialect Class | Flyway Vendor | Usage Context |
|---|---|---|---|
PostgreSQL | org.hibernate.dialect.PostgreSQLDialect | postgresql | Production deployments — the recommended production database |
HSQL | org.hibernate.dialect.HSQLDialect | hsqldb | Development/testing, embedded setup — used by the setup wizard for single-user/local installations |
Looks up a dialect by its Hibernate class name. Returns null if no match is found — callers must handle the null case (typically by defaulting to HSQL for development). The method uses a simple if-else chain rather than a lookup map, appropriate for the small number of supported dialects.
Maps a JDBC driver product name to the Flyway vendor directory name. This is critical for Flyway database migration script discovery. Flyway organizes migration scripts in vendor-specific directories:
flyway/{module}/migrate/postgresql/V1.1.0__RELEASE-RemoveMGC.sql
flyway/{module}/migrate/hsqldb/V1.1.0__RELEASE-RemoveMGC.sql
The method checks if the product name contains "hsql" (case-insensitive) and returns "hsqldb" or "postgresql" accordingly. This allows the same migration logic to work across database types — vendor-specific SQL differences (e.g., column type syntax, sequence handling) are isolated in the vendor-specific migration scripts.
The file contains a comment listing previously considered or planned database support:
// Not yet supported: // MYSQL, ORACLE, MS_SQL_SERVER, DB2, INFORMIX, DERBY, UNKOWN;
This reveals the design intent to support multiple databases — a common requirement for enterprise software. The current implementation supports only PostgreSQL (for production) and HSQLDB (for embedded/development), with the architecture ready for extension.
The DatabaseDialect enum is part of a layered database abstraction:
asString property provides the Hibernate dialect class for hibernate.cfg.xml or Spring Boot auto-configurationgetFlywayVendorName() method routes to vendor-specific SQL migration scriptsThis file is one of the earlier Kotlin files in the projectforge-common module (alongside other utility classes). Using Kotlin for this enum provides:
fromString() return type DatabaseDialect? forces callers to handle the null casegetFlywayVendorName() method uses a simple substring match (contains("hsql")) rather than an exact comparison. This could produce false positives if a database product name coincidentally contains "hsql" as a substring. A more robust approach would be to match against an exact list of known product names.init/common (schema creation) and migrate/{vendor} (version-specific migrations). This separation allows the base schema to be database-agnostic while vendor-specific migrations handle differences in SQL syntax or features (such as PostgreSQL vs HSQLDB for sequence handling or the "RemoveMGC" migration visible in the project's flyway directories).868d6abb7 2025 -> 2026 63081666f Source file headers: 2024-> 2025. b6092df09 Copyright 2023 -> 2024 ab45d51fa Copyright 2001-2022 -> 2001-2023. 5f7ef41b8 Copyright 2021 -> 2022 637063dd7 Nothing (source file header fixed) 440d191a2 Setup page: activation of standard plugins. AbstractPlugin: Fix of vendor name for flyway.