Guest User

Untitled

a guest
Oct 17th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. public Condition mapFilterToCondition(String tableName, String filters) {
  2. Condition condition = DSL.trueCondition();
  3. String[] filterFields = filters.split(",");
  4. Table<?> table = PUBLIC.getTable(tableName);
  5. Field<?>[] fields = table.fields();
  6. for(String filterField : filterFields) {
  7. String[] filter = filterField.split("=");
  8. for(Field<?> field : fields) {
  9. String fieldName = filter[0].replaceAll("(.)(\p{Upper})", "$1_$2").toLowerCase();
  10. if(field.getName().equals(fieldName)) {
  11. if(field.getType() == String.class) {
  12. condition.and(table.field(field).like(filter[1]));
  13. } else if (Boolean.valueOf(filter[1])) {
  14. condition.and(table.field(field).isTrue());
  15. } else if (!Boolean.valueOf(filter[1])) {
  16. condition.and(table.field(field).isFalse());
  17. }
  18. }
  19. }
  20. }
  21. return condition;
  22. }
  23.  
  24. public List<UserAccount> findAllByFilter(Condition condition, Pageable pageable) {
  25. return dsl.select()
  26. .from(USER_ACCOUNT)
  27. .where(condition)
  28. .limit(pageable.getPageSize())
  29. .offset((int) pageable.getOffset())
  30. .fetchInto(UserAccount.class);
  31. }
Add Comment
Please, Sign In to add comment