Java 努普在约克哪里
我提供了一种方法,允许在查询Java 努普在约克哪里,java,kotlin,jooq,Java,Kotlin,Jooq,我提供了一种方法,允许在查询books表时使用多个过滤选项。查询的第一部分要么搜索所有书籍,要么只搜索当前用户拥有的书籍 val allBookQuery = if(searchParameters.isOnShelf == true) { val context = environment.getContext<AuthorizedContext>() context?.currentUser ?: throw GraphQLException("No Curre
books
表时使用多个过滤选项。查询的第一部分要么搜索所有书籍,要么只搜索当前用户拥有的书籍
val allBookQuery = if(searchParameters.isOnShelf == true) {
val context = environment.getContext<AuthorizedContext>()
context?.currentUser ?: throw GraphQLException("No Current User Authenticated")
val userUUID = UUID.fromString(context.currentUser.uuid)
select.from(BOOKS, USER_BOOKS, USERS)
.where(USERS.UUID.eq(userUUID))
.and(USERS.ID.eq(USER_BOOKS.USER_ID))
.and(USER_BOOKS.BOOK_ID.eq(BOOKS.ID))
.and(BOOKS.IS_ARCHIVED.eq(false))
} else {
select.from(BOOKS).where(true)
}
不幸的是,where(Boolean)
方法已被弃用。因此,虽然现在可以使用,但我想用一个没有被弃用的NOOP操作来替换它。而不是where(true)
尝试where(trueCondition())
(trueCondition()
是DSL
的静态方法)
请注意,
where(trueCondition())
假设您将使用和(Condition)
向allBookQuery
添加额外的谓词,如果使用或(Condition)
,当然是错误的。因此,要独立于此,最好使用where(noCondition())
,因为它不提供SQL。也许您可以使用jOOQ()的“动态SQL”方法?我将把它视为一种长期重构。
val filteredBooksQuery = if (searchParameters.bookIds != null) {
allBookQuery.and(BOOKS.ID.`in`(searchParameters.bookIds))
} else {
allBookQuery
}
val finalQuery = if (searchParameters.isAcademic == true) {
filteredBooksQuery.and(BOOKS.IS_ACADEMIC.eq((true)))
} else {
filteredBooksQuery
}