Created a repository via Criteria.
I need the ability to search for a list of values using the LIKE and IGNORE_CASE strings, just like in the POSTGRE ILIKE
method.
I am limited is that I need pagable output of information.
I know that Spring Data JPA has such functionality, but another limitation is Spring Data JDBC.
When I started setting up Criteria, I discovered that .ignoreCase(true) did not work correctly, example: list of values in the database:
qwe
qwer
qwert
qwerty
Qwerty
QwertY
QWERTY
request qwer
response only one QWERTY
spring-data-relational-3.1.0.jar
@Repository
@RequiredArgsConstructor
public class Repository {
private final JdbcAggregateTemplate jdbc;
public Page<Account> getList(@NonNull AccountRequest filter, @NonNull Pageable pageable) {
Criteria criteria = Criteria.empty();
if (StringUtils.isNotBlank(filter.getAccountCode())) {
criteria = criteria.and(ACCOUNT_CODE).like("%" + (filter.getAccountCode() + "%")).ignoreCase(true);
}
Query query = Query.query(criteria).with(pageable);
List<Account> all = IteratorUtils.toList(jdbc.findAll(query, Account.class).iterator());
long count = jdbc.count(Query.query(criteria), domainType);
return new PageImpl<>(all, pageable, count);
}
Expecting 6 occurrences but only getting 1
Is there a way to do manual ignoreCase taking into account paged output, or perhaps the problem was fixed in an update?
UPD: I found a problem related to the generation of sql messages, the second UPPER method for a table field is missing
SELECT "account_dictionary"."id" AS "id",
"account_dictionary"."account_code" AS "account_code"
FROM "account_dictionary"
WHERE "account_dictionary".account_code LIKE UPPER(:account_code)
ORDER BY "account_dictionary".create_date DESC
LIMIT 50
Why doesn't it automatically create a second UPPER like that?
WHERE UPPER("account_dictionary".account_code) LIKE UPPER(:account_code)
RESOLVED: In the criteria you need to specify the column name in camelCase!