isEqualTo run before filter ?
pondered opened this issue · 7 comments
employeeId = null
mapper.select(dsl -> dsl
.where(id, isEqualTo(()->employeeId).filter(Objects.nonNull(employeeId))));Does not run when employee is null. but throw exception, Is there any other way.
and
mapper.select(dsl -> dsl
.where(id, isEqualTo(()->dto.getEmployeeId()).filter(Objects.nonNull(dot))));In your first example, the exception thrown is probably NonRenderingWhereClauseException. This exception is thrown because you coded a where clause, but the condition didn't render which in this case will cause all rows to be returned. See this page for details about how to configure this behavior: https://mybatis.org/mybatis-dynamic-sql/docs/configuration.html. You can write your statement like this:
mapper.select(dsl -> dsl.configureStatement(c -> c.setNonRenderingWhereClauseAllowed(true))
.where(id, isEqualTo(employeeId).filter(Objects::nonNull)));In your second example, I assume you get a NullPointerException if dto is null. This because the filter can only be applied to the value in the condition - not the object providing the value. You can use a combination of filter and map to achieve your goal:
mapper.select(dsl -> dsl.configureStatement(c -> c.setNonRenderingWhereClauseAllowed(true))
.where(id, isEqualTo(dto).filter(Objects::nonNull).map(MyDTO::getEmployeeId).filter(Objects::nonNull)));oh tanks
hi, isIn not support this. just like
mapper.select(dsl -> dsl.configureStatement(c -> c.setNonRenderingWhereClauseAllowed(true))
.where(id, isIn(dto).filter(Objects::nonNull).map(Dto::list)));
isIn(dto).filter(Objects::nonNull).map(Dto::list)).filter(Objects::nonNull)
this code return type is IsIn<List<Type>>
but accept IsIn<Type>
just like this issue,but now version code is gone
#239
You can do this:
isInWhenPresent(dto == null ? null : dto.list)lol