Skip to content

Commit

Permalink
fix(sql): Fix bulk store objects JOOQ api to support both MySQL and P…
Browse files Browse the repository at this point in the history
…ostgres (#908)
  • Loading branch information
srekapalli committed Jul 23, 2020
1 parent e1ecc62 commit 613cc2b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ class SqlStorageService(
*insertPairs.keys.map { DSL.field(it) }.toTypedArray()
)
.values(insertPairs.values)
.onDuplicateKeyUpdate()
.onConflict(DSL.field("id", String::class.java))
.doUpdate()
.set(updatePairs.mapKeys { DSL.field(it.key) })
}
).execute()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,36 @@ internal object SqlStorageServiceTests : JUnit5Minutests {
expectThrows<NotFoundException> {
sqlStorageService.loadObject<EntityTags>(ObjectType.ENTITY_TAGS, "id-entitytags001")
}

// Verify we can store more than object
sqlStorageService.storeObjects(
ObjectType.ENTITY_TAGS,
listOf(
EntityTags().apply {
id = "id-entitytags1of1"
lastModified = 100
lastModifiedBy = "anonymous"
entityRef = EntityTags.EntityRef().apply {
entityId = "application001"
}
},
EntityTags().apply {
id = "id-entitytags1of2"
lastModified = 100
lastModifiedBy = "anonymous"
entityRef = EntityTags.EntityRef().apply {
entityId = "application001"
}
}

)
)
// Retrieve tags saved above
entityTags = sqlStorageService.loadObject<EntityTags>(ObjectType.ENTITY_TAGS, "id-entitytags1of1")
expectThat(entityTags.id).isEqualTo("id-entitytags1of1")

entityTags = sqlStorageService.loadObject<EntityTags>(ObjectType.ENTITY_TAGS, "id-entitytags1of2")
expectThat(entityTags.id).isEqualTo("id-entitytags1of2")
}
}
}
Expand Down

0 comments on commit 613cc2b

Please sign in to comment.