net.ttddyy.dsproxy.proxy.ParameterKeyUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of datasource-proxy Show documentation
Show all versions of datasource-proxy Show documentation
Provide a datasource proxy that can inject your own logic into all queries.
package net.ttddyy.dsproxy.proxy;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* @author Tadaya Tsuyukubo
* @since 1.4
*/
public class ParameterKeyUtils {
public static Map filterBy(Map map, ParameterKey.ParameterKeyType type) {
Map result = new LinkedHashMap();
for (Map.Entry entry : map.entrySet()) {
ParameterKey key = entry.getKey();
if (key.getType() == type) {
result.put(key, entry.getValue());
}
}
return result;
}
public static Map toNameMap(Map map) {
Map filtered = filterBy(map, ParameterKey.ParameterKeyType.BY_NAME);
Map result = new LinkedHashMap();
for (Map.Entry entry : filtered.entrySet()) {
result.put(entry.getKey().getName(), entry.getValue());
}
return result;
}
public static Map toIndexMap(Map map) {
Map filtered = filterBy(map, ParameterKey.ParameterKeyType.BY_INDEX);
Map result = new LinkedHashMap();
for (Map.Entry entry : filtered.entrySet()) {
result.put(entry.getKey().getIndex(), entry.getValue());
}
return result;
}
}