-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
101 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
pg-kueue-jdbc/src/main/kotlin/io/github/vooft/kueue/jdbc/ConnectionExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.github.vooft.kueue.jdbc | ||
|
||
import io.github.vooft.kueue.common.withVirtualThreadDispatcher | ||
import org.intellij.lang.annotations.Language | ||
import org.postgresql.core.BaseConnection | ||
|
||
internal suspend fun BaseConnection.execute(@Language("SQL") query: String) = withVirtualThreadDispatcher { | ||
createStatement().use { | ||
it.execute(query) | ||
} | ||
} | ||
|
||
internal suspend fun <T> JdbcKueueConnection.useUnwrapped(block: suspend (BaseConnection) -> T): T = | ||
block(jdbcConnection.unwrap(BaseConnection::class.java)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
pg-kueue-jdbc/src/main/kotlin/io/github/vooft/kueue/jdbc/JdbcKueueEventPersister.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.github.vooft.kueue.jdbc | ||
|
||
import io.github.vooft.kueue.KueueEventPersister | ||
import io.github.vooft.kueue.KueueTopic | ||
import java.time.OffsetDateTime | ||
import java.time.ZoneOffset | ||
import java.util.UUID | ||
|
||
class JdbcKueueEventPersister : KueueEventPersister<JdbcKueueConnection> { | ||
override suspend fun persist(kueueConnection: JdbcKueueConnection, topic: KueueTopic, message: String) { | ||
kueueConnection.useUnwrapped { connection -> | ||
connection.prepareStatement("INSERT INTO kueue_events (id, topic, message, created_at) VALUES (?, ?, ?, ?)").use { | ||
it.setObject(1, UUID.randomUUID()) | ||
it.setString(2, topic.topic) | ||
it.setString(3, message) | ||
it.setObject(4, OffsetDateTime.now(ZoneOffset.UTC)) | ||
|
||
it.execute() | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
pg-kueue-utils/src/testFixtures/resources/database/1_kueue_events.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CREATE TABLE kueue_events ( | ||
id UUID PRIMARY KEY, | ||
topic TEXT NOT NULL, | ||
message TEXT NOT NULL, | ||
created_at TIMESTAMP WITH TIME ZONE NOT NULL | ||
); | ||
|
||
CREATE INDEX kueue_events_topic_created_at_idx ON kueue_events (topic, created_at); |