GaripTipici
GaripTipici

Reputation: 508

Bind a Map to a SQL Query by Using a Method

I have a query in a seperate file; getInfo.sql file, a part of which is as like below:

SELECT * FROM (VALUES (:key1, :value1), (:key2, :value2))

I need to call it from an abstract method as follows:

@SqlQuery Info getInfo(long customerRegistrationNumber, List<KeyValue> keyValuePairs);

I want to bind these key-value pairs into the query. To convert the list into map I have a method which contains some logic like below:

private Map<String, Object> customMapBinds(List<KeyValue> keyValuePairs) {
    Map<String, Object> binds = new HashMap<>();
    keyValuePairs.forEach(x -> {
        binds.put("key1" + keyValuePairs.key1(), keyValuePairs.value1());
        binds.put("key2" + keyValuePairs.key2(), keyValuePairs.value2() - 9);
    });
    return binds;
}

How can I use the private method to bind parameters into SQL in interface ?

Or is there any other way to apply the logic in the private method ?

Upvotes: 0

Views: 46

Answers (0)

Related Questions