I am learning JDBC and I figure it would be fun if I pass Map of values to changes and Map of conditions to update() method.
I have something like:
public void update(Map<String, Serializable> valuesToChange, Map<String, Predicate<T>> mapOfConditions){...}
How can I receive String of predicate test?
Let's say that I have:
predicateMap.put("id", id -> (int) id > 20);
predicateMap.put("last_name", lastName -> lastName == "Jobs");
How to receive conditions in String like:
lastName == "Jobs" or id > 20
I need it as a WHERE condition in SQL Query.
Cheers
What you are asking is close to impossible. It would require that you reverse compile the byte code in the predicate to Java and from there translate the Java to SQL. I can’t believe you will want to take the trouble, also because the gain would be minimal.
It may seem simple in a case where the predicate is id -> id == 20
. However, predicates may be complex. They may involve Java language constructs that have no direct SQL counterpart. They may involve calls to library methods including 3rd party library methods, even to remote services and to code written in other languages than Java. I see no way that you will be able to translate all of that to SQL.