Skip to content

Commit

Permalink
Merge pull request #59 from RADAR-base/release-0.9.0
Browse files Browse the repository at this point in the history
Release 0.9.0
  • Loading branch information
blootsvoets authored Jul 13, 2022
2 parents d114455 + 7cc4370 commit 49e6596
Show file tree
Hide file tree
Showing 52 changed files with 257 additions and 195 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/scheduled_snyk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,25 @@ jobs:
env:
REPORT_FILE: test.json
steps:
- uses: actions/checkout@master
- uses: actions/checkout@v3
- uses: snyk/actions/setup@master
with:
snyk-version: v1.931.0

- uses: actions/setup-java@v2
- uses: actions/setup-java@v3
with:
distribution: zulu
distribution: temurin
java-version: 11

- name: Setup Gradle
uses: gradle/gradle-build-action@v2

- name: Run Snyk
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
run: >
snyk test
--configuration-matching='^runtimeClasspath$'
--configuration-matching='^compileClasspath$'
--json-file-output=${{ env.REPORT_FILE }}
--org=radar-base
--sub-project=radar-jersey
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/snyk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ jobs:
security:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions/checkout@v3
- uses: snyk/actions/setup@master
with:
snyk-version: v1.931.0

- uses: actions/setup-java@v2
- uses: actions/setup-java@v3
with:
distribution: zulu
distribution: temurin
java-version: 11

- name: Setup Gradle
Expand All @@ -24,7 +26,6 @@ jobs:
run: >
snyk test
--configuration-matching='^runtimeClasspath$'
--configuration-matching='^compileClasspath$'
--fail-on=upgradable
--org=radar-base
--sub-project=radar-jersey
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repositories {
}
dependencies {
api("org.radarbase:radar-jersey:0.8.3")
api("org.radarbase:radar-jersey:0.9.0")
}
```

Expand Down
18 changes: 11 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ plugins {

allprojects {
group = "org.radarbase"
version = "0.8.3"
version = "0.9.0"
}

subprojects {
Expand Down Expand Up @@ -43,12 +43,16 @@ subprojects {
configurations["dokkaHtmlPlugin"]("org.jetbrains.dokka:kotlin-as-java-plugin:$dokkaVersion")

val jacksonVersion: String by project
configurations["dokkaPlugin"](platform("com.fasterxml.jackson:jackson-bom:$jacksonVersion"))
configurations["dokkaRuntime"](platform("com.fasterxml.jackson:jackson-bom:$jacksonVersion"))

val jsoupVersion: String by project
configurations["dokkaPlugin"]("org.jsoup:jsoup:$jsoupVersion")
configurations["dokkaRuntime"]("org.jsoup:jsoup:$jsoupVersion")
val kotlinVersion: String by project

sequenceOf("dokkaPlugin", "dokkaRuntime")
.map { configurations[it] }
.forEach { conf ->
conf(platform("com.fasterxml.jackson:jackson-bom:$jacksonVersion"))
conf("org.jsoup:jsoup:$jsoupVersion")
conf(platform("org.jetbrains.kotlin:kotlin-bom:$kotlinVersion"))
}

val log4j2Version: String by project
val testRuntimeOnly by configurations
Expand Down Expand Up @@ -208,5 +212,5 @@ nexusPublishing {
}

tasks.wrapper {
gradleVersion = "7.4.1"
gradleVersion = "7.4.2"
}
44 changes: 23 additions & 21 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,36 @@ org.gradle.jvmargs=-Xmx2000m
org.gradle.vfs.watch=true
kotlin.code.style=official

kotlinVersion=1.6.10
dokkaVersion=1.6.10
jsoupVersion=1.14.3
kotlinVersion=1.7.10
dokkaVersion=1.7.0
jsoupVersion=1.15.2

jerseyVersion=3.0.4
grizzlyVersion=3.0.1
okhttpVersion=4.9.3
jerseyVersion=3.0.5
grizzlyVersion=4.0.0
okhttpVersion=4.10.0
junitVersion=5.8.2
hamcrestVersion=2.2
mockitoKotlinVersion=4.0.0

hk2Version=3.0.2
hk2Version=3.0.3
managementPortalVersion=0.8.1
javaJwtVersion=3.19.0
jakartaWsRsVersion=3.0.0
jakartaAnnotationVersion=2.0.0
jacksonVersion=2.13.2.20220324
javaJwtVersion=4.0.0
jakartaWsRsVersion=3.1.0
jakartaAnnotationVersion=2.1.1
jacksonVersion=2.13.3
slf4jVersion=1.7.36
log4j2Version=2.17.2
jakartaXmlBindVersion=3.0.1
jakartaJaxbCoreVersion=3.0.2
jakartaJaxbRuntimeVersion=3.0.2
javaxValidationVersion=2.0.1.Final
log4j2Version=2.18.0
jakartaXmlBindVersion=4.0.0
jakartaJaxbCoreVersion=4.0.0
jakartaJaxbRuntimeVersion=4.0.0
jakartaValidationVersion=3.0.2
hibernateValidatorVersion=7.0.4.Final
glassfishJakartaElVersion=4.0.2
jakartaActivation=2.1.0
swaggerVersion=2.1.13
swaggerVersion=2.2.1
mustacheVersion=0.9.10

hibernateVersion=5.6.7.Final
liquibaseVersion=4.9.0
postgresVersion=42.3.3
h2Version=2.1.210
hibernateVersion=6.1.1.Final
liquibaseVersion=4.13.0
postgresVersion=42.4.0
h2Version=2.1.214
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
8 changes: 6 additions & 2 deletions radar-jersey-hibernate/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ dependencies {
api("org.hibernate:hibernate-core:$hibernateVersion")
runtimeOnly("org.hibernate:hibernate-c3p0:$hibernateVersion")

val javaxValidationVersion: String by project
implementation("javax.validation:validation-api:$javaxValidationVersion")
val jakartaValidationVersion: String by project
runtimeOnly("jakarta.validation:jakarta.validation-api:$jakartaValidationVersion")
val hibernateValidatorVersion: String by project
runtimeOnly("org.hibernate.validator:hibernate-validator:$hibernateValidatorVersion")
val glassfishJakartaElVersion: String by project
runtimeOnly("org.glassfish:jakarta.el:$glassfishJakartaElVersion")

val slf4jVersion: String by project
implementation("org.slf4j:slf4j-api:$slf4jVersion")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
package org.radarbase.jersey.hibernate

import jakarta.inject.Provider
import jakarta.persistence.EntityManager
import jakarta.ws.rs.core.Context
import org.radarbase.jersey.hibernate.RadarEntityManagerFactory.Companion.connection
import org.radarbase.jersey.hibernate.DatabaseInitialization.Companion.useConnection
import org.radarbase.jersey.hibernate.config.DatabaseConfig
import org.radarbase.jersey.service.HealthService
import org.radarbase.jersey.service.HealthService.Metric
import org.radarbase.jersey.util.CacheConfig
import org.radarbase.jersey.util.CachedValue
import java.time.Duration
import javax.persistence.EntityManager

class DatabaseHealthMetrics(
@Context private val entityManager: Provider<EntityManager>,
@Context dbConfig: DatabaseConfig
): Metric(name = "db") {
private val cachedStatus = CachedValue(
CacheConfig(
refreshDuration = Duration.ofSeconds(dbConfig.healthCheckValiditySeconds),
retryDuration = Duration.ofSeconds(dbConfig.healthCheckValiditySeconds),
),
::testConnection)
CacheConfig(
refreshDuration = Duration.ofSeconds(dbConfig.healthCheckValiditySeconds),
retryDuration = Duration.ofSeconds(dbConfig.healthCheckValiditySeconds),
),
::testConnection,
)

override val status: HealthService.Status
get() = cachedStatus.get { it == HealthService.Status.UP }
Expand All @@ -29,7 +30,7 @@ class DatabaseHealthMetrics(
get() = mapOf("status" to status)

private fun testConnection(): HealthService.Status = try {
entityManager.get().connection().close()
entityManager.get().useConnection { connection -> connection.close() }
HealthService.Status.UP
} catch (ex: Throwable) {
HealthService.Status.DOWN
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package org.radarbase.jersey.hibernate

import jakarta.persistence.EntityManager
import jakarta.persistence.EntityManagerFactory
import jakarta.ws.rs.core.Context
import jakarta.ws.rs.ext.Provider
import liquibase.Contexts
import liquibase.Liquibase
import liquibase.database.DatabaseFactory
Expand All @@ -9,14 +13,12 @@ import org.glassfish.jersey.server.monitoring.ApplicationEvent
import org.glassfish.jersey.server.monitoring.ApplicationEventListener
import org.glassfish.jersey.server.monitoring.RequestEvent
import org.glassfish.jersey.server.monitoring.RequestEventListener
import org.radarbase.jersey.hibernate.RadarEntityManagerFactory.Companion.connection
import org.hibernate.HibernateException
import org.hibernate.Session
import org.radarbase.jersey.hibernate.RadarEntityManagerFactoryFactory.Companion.useEntityManager
import org.radarbase.jersey.hibernate.config.DatabaseConfig
import org.slf4j.LoggerFactory
import java.sql.Connection
import javax.persistence.EntityManagerFactory
import jakarta.ws.rs.core.Context
import jakarta.ws.rs.ext.Provider

@Provider
class DatabaseInitialization(
Expand All @@ -27,9 +29,8 @@ class DatabaseInitialization(
override fun onEvent(event: ApplicationEvent) {
if (event.type != ApplicationEvent.Type.INITIALIZATION_APP_FINISHED) return
try {
entityManagerFactory.get().useEntityManager {
// make first connection
it.connection().use { connection ->
entityManagerFactory.get().useEntityManager { em ->
em.useConnection { connection ->
if (dbConfig.liquibase.enable) {
initializeLiquibase(connection)
}
Expand All @@ -56,5 +57,11 @@ class DatabaseInitialization(

companion object {
private val logger = LoggerFactory.getLogger(DatabaseInitialization::class.java)

@Throws(HibernateException::class)
fun EntityManager.useConnection(work: (Connection) -> Unit) {
check(this is Session) { "Cannot use connection of EntityManager that is not a Hibernate Session" }
doWork(work)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.radarbase.jersey.hibernate

import jakarta.inject.Provider
import jakarta.persistence.EntityManager
import jakarta.persistence.EntityTransaction
import org.radarbase.jersey.exception.HttpInternalServerException
import org.radarbase.jersey.hibernate.config.CloseableTransaction
import org.slf4j.LoggerFactory
import jakarta.inject.Provider
import javax.persistence.EntityManager
import javax.persistence.EntityTransaction

open class HibernateRepository(
private val entityManagerProvider: Provider<EntityManager>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package org.radarbase.jersey.hibernate

import jakarta.persistence.EntityManager
import jakarta.persistence.EntityManagerFactory
import jakarta.ws.rs.core.Context
import org.glassfish.jersey.internal.inject.DisposableSupplier
import org.hibernate.internal.SessionImpl
import org.slf4j.LoggerFactory
import java.sql.Connection
import javax.persistence.EntityManager
import javax.persistence.EntityManagerFactory

class RadarEntityManagerFactory(
@Context private val emf: EntityManagerFactory
Expand All @@ -26,7 +24,5 @@ class RadarEntityManagerFactory(

companion object {
private val logger = LoggerFactory.getLogger(RadarEntityManagerFactory::class.java)

fun EntityManager.connection(): Connection = unwrap(SessionImpl::class.java).connection()
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package org.radarbase.jersey.hibernate

import jakarta.persistence.EntityManager
import jakarta.persistence.EntityManagerFactory
import jakarta.ws.rs.core.Context
import org.glassfish.jersey.internal.inject.DisposableSupplier
import org.hibernate.jpa.HibernatePersistenceProvider
import org.radarbase.jersey.hibernate.config.DatabaseConfig
import org.radarbase.jersey.hibernate.config.RadarPersistenceInfo
import org.slf4j.LoggerFactory
import java.util.*
import javax.persistence.EntityManager
import javax.persistence.EntityManagerFactory
import jakarta.ws.rs.core.Context

/**
* Creates EntityManagerFactory using Hibernate. When an [EntityManagerFactory] is created,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.radarbase.jersey.hibernate.config

import jakarta.persistence.EntityTransaction
import java.io.Closeable
import javax.persistence.EntityTransaction

interface CloseableTransaction : Closeable {
val transaction: EntityTransaction
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.radarbase.jersey.hibernate.config

import jakarta.inject.Singleton
import jakarta.persistence.EntityManager
import jakarta.persistence.EntityManagerFactory
import org.glassfish.jersey.internal.inject.AbstractBinder
import org.glassfish.jersey.process.internal.RequestScoped
import org.radarbase.jersey.enhancer.JerseyResourceEnhancer
Expand All @@ -8,9 +11,6 @@ import org.radarbase.jersey.hibernate.DatabaseInitialization
import org.radarbase.jersey.hibernate.RadarEntityManagerFactory
import org.radarbase.jersey.hibernate.RadarEntityManagerFactoryFactory
import org.radarbase.jersey.service.HealthService
import jakarta.inject.Singleton
import javax.persistence.EntityManager
import javax.persistence.EntityManagerFactory

class HibernateResourceEnhancer(
private val databaseConfig: DatabaseConfig
Expand Down
Loading

0 comments on commit 49e6596

Please sign in to comment.