Skip to content

Commit

Permalink
Remove H2 DB dependency
Browse files Browse the repository at this point in the history
+ We provide a convenience config to spec use of in-memory h2 database as a datasource during initial / trial development.
+ H2 had been a dependency that was resolved @ outdated 1.x version with security vulnerabilities.
+ Remove dependency from hoist-core, replace with updated comment re. need to add back in at app-level using v2.x.
+ Update JDBC URL to workaround `value` as reserved word in H2 v2.x.
  • Loading branch information
amcclain committed Mar 26, 2024
1 parent c5085e8 commit e1c11ff
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ dependencies {

runtimeOnly "org.glassfish.web:el-impl:2.2.1-b05"
runtimeOnly "javax.xml.bind:jaxb-api:2.3.1"
runtimeOnly "com.h2database:h2"

//--------------------
// Hoist Additions
Expand Down
21 changes: 13 additions & 8 deletions src/main/groovy/io/xh/hoist/configuration/RuntimeConfig.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

package io.xh.hoist.configuration

import org.hibernate.dialect.H2Dialect

import static io.xh.hoist.util.InstanceConfigUtils.getInstanceConfig
import static io.xh.hoist.util.Utils.withDelegate

Expand All @@ -18,8 +20,7 @@ import static io.xh.hoist.util.Utils.withDelegate
class RuntimeConfig {

/**
* All apps should call this from runtime.groovy
* to setup necessary default configurations
* All apps should call this from runtime.groovy to setup necessary default configurations
*/
static void defaultConfig(Script script) {
withDelegate(script) {
Expand All @@ -28,26 +29,30 @@ class RuntimeConfig {
}

/**
* Call this from runtime.groovy
* to setup an in memory H2 DB instead of
* a MySQL or SQL Server DB. This H2 DB option
* is intended only for early stages of development,
* before a production ready DB has been set up.
* Call this from runtime.groovy to setup an in memory H2 DB instead of MySQL or SQL Server.
* This option is intended only for early stages of development, before a production-ready
* database has been provisioned. Data is transient, NOT intended for actual deployments!
*
* Note you will need to add a dependency to your app's build.gradle file:
* `runtimeOnly "com.h2database:h2:2.2.224"` (check and use latest/suitable version).
*/
static void h2Config(Script script) {
withDelegate(script) {
dataSource {
pooled = true
jmxExport = true
driverClassName = "org.h2.Driver"
dialect = H2Dialect
username = "sa"
password = ""
}
environments {
development {
dataSource {
dbCreate = "create-drop"
url = "jdbc:h2:mem:devDb;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
// `value` is a reserved word in H2 v2.x but used by Hoist AppConfig.
// We can workaround with NON_KEYWORDS=VALUE in the JDBC URL below.
url = "jdbc:h2:mem:devDb;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE;NON_KEYWORDS=VALUE"
}
}
}
Expand Down

0 comments on commit e1c11ff

Please sign in to comment.