Good day smart people. I am currently having trouble attempting to use the JDBI Kotlin SqlObject plugin with a Kotlin interface class.
When setting up the following dao in an .kt interface file
interface DTaskStatusDao {
@Timestamped
@SqlUpdate(ADD_TASK_STATUS_ENTRY)
suspend fun insertTask(@BindKotlin @BindMethods taskStatus: TaskStatus<*>)
}
and using the resulting DAO object as such
val dao = jdbi.onDemand(DTaskStatusDao::class): Void
dao.insertTask(it)
I get the following exception :
DTaskStatusDao.insertTask method is annotated with @SqlUpdate so should return void, boolean, or Number but is returning
Since Kotlin doesn't allow using Java primitives, so I assume that only option is to write the dao interface in .java files only? Or am I missing something else?
I have also attempting using different Kotlin comparable types, i.e. Number, Boolean but all seems to boiled down to a java.Object in the JDBI type resoution.
The problem does not arise using non primitives in SQLQuery annotations. Any applicable feedback is greatly appreciated.
For JDBI's SqlObject library, to utilize Kotlin-style primitives (i.e. Unit, Int, Boolean) as a return type for annotated methods (such as the one mention in the OP) one could expose a target interface as a mixin simply by having it extend the core SqlObject interface.
In the case of the OP's example, the answer would to utilize the following:
interface DTaskStatusDao : SqlObject {
@Timestamped
@SqlUpdate(ADD_TASK_STATUS_ENTRY)
suspend fun insertTask(@BindKotlin @BindMethods taskStatus: TaskStatus<*>)
}
Deeper research into the original JDBI repository reveals a unit test that also exhibits this solution.