
main.app.cash.backfila.client.jooq.JooqBackfillModule.kt Maven / Gradle / Ivy
package app.cash.backfila.client.jooq
import app.cash.backfila.client.RealBackfillModule
import app.cash.backfila.client.jooq.internal.JooqBackend
import app.cash.backfila.client.spi.BackfillBackend
import com.google.inject.AbstractModule
import com.google.inject.Binder
import com.google.inject.TypeLiteral
import com.google.inject.multibindings.MapBinder
import com.google.inject.multibindings.Multibinder
import javax.inject.Qualifier
import kotlin.reflect.KClass
import kotlin.reflect.jvm.jvmName
/**
* Installs the [BackfillBackend] for Hibernate backfills. See the java doc for [RealBackfillModule].
*/
class JooqBackfillModule> private constructor(
private val backfillClass: KClass,
) : AbstractModule() {
override fun configure() {
install(JooqBackfillBackendModule)
// Ensures that the backfill class is injectable. If you are failing this check you probably
// want to add an @Inject annotation to your class or check that all of your dependencies are provided.
binder().getProvider(backfillClass.java)
mapBinder(binder()).addBinding(backfillClass.jvmName).toInstance(backfillClass)
}
companion object {
inline fun > create(): JooqBackfillModule = create(T::class)
@JvmStatic
fun > create(backfillClass: KClass): JooqBackfillModule {
return JooqBackfillModule(backfillClass)
}
@JvmStatic
fun > create(backfillClass: Class): JooqBackfillModule {
return JooqBackfillModule(backfillClass.kotlin)
}
}
}
/**
* This is a kotlin object so these dependencies are only installed once.
*/
private object JooqBackfillBackendModule : AbstractModule() {
override fun configure() {
Multibinder.newSetBinder(binder(), BackfillBackend::class.java).addBinding()
.to(JooqBackend::class.java)
}
}
private fun mapBinder(binder: Binder) = MapBinder.newMapBinder(
binder,
object : TypeLiteral() {},
object : TypeLiteral>>() {},
ForJooqBackend::class.java,
)
/** Annotation for specifying dependencies specifically for this Backend. */
@Qualifier annotation class ForJooqBackend
© 2015 - 2025 Weber Informatics LLC | Privacy Policy