Skip to content

Commit

Permalink
[#1] Updated OSS edition
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaseder committed Jun 1, 2022
1 parent 3eaa063 commit ed5c52a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
4 changes: 4 additions & 0 deletions jOOQ-demo-oss/jOOQ-demo-kotlin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
<groupId>org.jooq</groupId>
<artifactId>jooq-kotlin</artifactId>
</dependency>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq-kotlin-coroutines</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package org.jooq.demo.kotlin

import kotlinx.coroutines.reactive.awaitFirst
import kotlinx.coroutines.reactive.awaitFirstOrNull
import kotlinx.coroutines.reactor.mono
import kotlinx.coroutines.runBlocking
import org.jooq.Configuration
import org.jooq.Records.mapping
import org.jooq.demo.AbstractDemo
import org.jooq.demo.kotlin.db.tables.records.ActorRecord
import org.jooq.demo.kotlin.db.tables.references.ACTOR
import org.jooq.kotlin.coroutines.transactionCoroutineResult
import org.junit.After
import org.junit.Test
import reactor.core.publisher.Flux
Expand Down Expand Up @@ -81,9 +85,32 @@ class Demo13Reactive : AbstractDemo() {
return ctx
.selectFrom(ACTOR)
.where(ACTOR.ACTOR_ID.eq(id))

// Turn any reactive streams Publisher<T> into a suspension result using the
// kotlinx-coroutines-reactive extensions
.awaitFirstOrNull()
}

@Test
fun coroutinesWithTransactions() {
val actor: ActorRecord = runBlocking {
insertActorTransaction()
}

println(actor)
}

suspend fun insertActorTransaction(): ActorRecord {
return ctx.transactionCoroutineResult(::insertActor)
}

suspend fun insertActor(c: Configuration): ActorRecord = c.dsl()
.insertInto(ACTOR)
.columns(ACTOR.ACTOR_ID, ACTOR.FIRST_NAME, ACTOR.LAST_NAME)
.values(201L, "A", "A")
.returning()
.awaitFirst()

@After
override fun teardown() {
cleanup(ACTOR, ACTOR.ACTOR_ID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ public static void beforeClass() throws SQLException {
);

ctx = using(configuration = new DefaultConfiguration()

// You can configure jOOQ with a JDBC and/or an R2DBC Connection and/or DataSource/ConnectionFactory
// If both are provided, then blocking calls will be run on the JDBC Connection or DataSource, whereas
// non-blocking calls are run on the R2DBC Connection or ConnectionFactory. Blocking calls are annotated
// as @org.jetbrains.annotations.Blocking
.set(jdbc)
.set(r2dbc)
.set(POSTGRES)
Expand Down
5 changes: 5 additions & 0 deletions jOOQ-demo-oss/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@
<artifactId>jooq-kotlin</artifactId>
<version>${jooq.version}</version>
</dependency>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq-kotlin-coroutines</artifactId>
<version>${jooq.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
Expand Down

0 comments on commit ed5c52a

Please sign in to comment.