main.app.cash.backfila.client.misk.hibernate.PrimaryKeyCursorMapper.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of client-misk-hibernate Show documentation
Show all versions of client-misk-hibernate Show documentation
Backfila is a service that manages backfill state, calling into other services to do batched work.
The newest version!
package app.cash.backfila.client.misk.hibernate
import javax.inject.Inject
import okio.ByteString
internal class PrimaryKeyCursorMapper @Inject constructor(
private val primaryKeyAdapters: Map, PrimaryKeyCursorAdapter<*>>,
) {
fun fromByteString(type: Class, cursor: ByteString): Result {
val adapter = adapter(type)
return adapter.fromByteString(cursor)
}
fun toByteString(pkey: PK): ByteString {
val adapter = adapter(pkey::class.java)
return adapter.toByteString(pkey)
}
private fun adapter(type: Class): PrimaryKeyCursorAdapter {
val adapter = primaryKeyAdapters[type] ?: throw IllegalArgumentException(
"Unregistered backfill primary key type: $type." +
" Bind a [PrimaryKeyCursorAdapterModule] or use a different type as your primary key.",
)
@Suppress("UNCHECKED_CAST") // We use runtime checks to guarantee casts are safe.
return adapter as PrimaryKeyCursorAdapter
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy