Maybe I make it to difficult and maybe I express myself not always good due that english is not my native language, sorry. One step back:
step 1. I have made an SQL query which is working.
step 2. next, I have put this query in the JOOQ converter, with this result. I call this "query with qoutes", table name, field name, aliases are between quotes etc. But is hard to read.
fun InconsistencyCheck(zaakId: ZaakId): Boolean = usingDSL { context ->
context.select(
`when`(count().gt(0), `val`(true) ).otherwise(`val`(false)) // result of the query true or false, and I'm expecting that this is
) //
returned to the caller function
.from(table(unquotedName("zaak")).`as`(unquotedName("zz")),
table(unquotedName("agenda")).`as`(unquotedName("za")),
table(unquotedName("agenda_item")).`as`(unquotedName("zai"))
)
.where(field(name("zz", "id")).eq(zaakId.value)
.and(field(name("za", "zaak_id")).eq(field(name("zz", "id"))))
.and(field(name("za", "actueel")).eq(inline(true)))
.and(field(name("zai", "agenda_id")).eq(field(name("za", "id"))))
).fetchOne(0, Boolean.class) == true // Although this is Java, it is working and '== true' was suggested by IntelliJ
}
step 3: I try to transform the query of step 2 into a "query without quotes". For me it is the same query technically, it turns into an error on fetchOne.
override fun InconsistencyCheck(zaakId: ZaakId): Boolean = usingDSL { context ->
val ZaakMainAlias = ZAAK.`as`("ZAAK_MAIN")
val AgendaMainAlias = AGENDA.`as`("AGENDA_MAIN")
val AgendaItemMainAlias = AGENDA_ITEM.`as`("AGENDA_ITEM_MAIN")
context.select(
`when`(count().gt(0), `val`(true)).otherwise(`val`(false))
)
.from(ZaakMainAlias
,AgendaMainAlias
,AgendaItemMainAlias
)
.where(ZaakMainAlias.ID.eq(zaakId.value)
.and(AgendaMainAlias.ZAAK_ID.eq(ZaakMainAlias.ID))
.and(AgendaMainAlias.ACTUEEL.eq(inline(true)))
.and(AgendaItemMainAlias.AGENDA_ID.eq(AgendaMainAlias.ID))
).fetchOne(0, Boolean.class) == true // this gives the error.
}
Why is the query of step 2 working and step 3 not, with fetchOne?
And understand now, fetchOne() is returning a Record instead of just returning the Boolean true or false.But the query of step 2 is working!
And I'm asking myself, how do others this, just returning true or false. Thats not a weird idea, is it?
I have also tried the Kotlin Boolean:
.fetchOne(0, Boolean::class.javaPrimitiveType) == true
or
.fetchOne(0, Boolean::class.javaObjectType) == true
This is not given an compiler error, but when run this, it is not working in the way it does in step 2. And it gives an error at run-time.
This my last attempt, otherwise I will leave the query as in step2, which is working, but I would like to understand why the query of step 3 is not working?