com.cherokeesoft.db.utils.graph.DataJoinLayerGraphNode Maven / Gradle / Ivy
package com.cherokeesoft.db.utils.graph;
import com.cherokeesoft.db.utils.api.Filter;
import com.cherokeesoft.db.utils.graph.type.GraphNode;
import lombok.Getter;
import org.simpleflatmapper.jdbc.JdbcMapperFactory;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Function;
public class DataJoinLayerGraphNode implements GraphNode {
private final @Getter BiFunction, Filter, DataGraph>> function;
private final @Getter String fieldName;
public DataJoinLayerGraphNode(String fieldName, BiFunction, Filter, DataGraph>> function) {
this.fieldName = fieldName;
this.function = function;
}
@Override
public Map extends String, ? extends String> getAlias(DataGraph> parentGraph, Filter filter) {
Map res = new HashMap<>();
Map extends String, ? extends String> alias = function.apply(parentGraph, filter).aliases();
for(String key: alias.keySet()) {
res.put(key, fieldName + '.' + alias.get(key));
}
return res;
}
@Override
public String getAliasName(DataGraph> parentGraph, Filter filter, String field) {
Set> entries = function.apply(parentGraph, filter).aliases().entrySet();
for(Map.Entry entry: entries) {
String key = entry.getKey();
String value = entry.getValue();
if(value.equals(field)) {
return key;
}
}
return null;
}
@Override
public String[] keys(DataGraph> parentGraph, Filter filter) {
return function.apply(parentGraph, filter).keys();
}
@Override
public void discriminate(DataGraph> parentGraph, Filter filter, JdbcMapperFactory jdbcMapperFactory) {
DataGraph> subGraph = function.apply(parentGraph, filter);
if(subGraph != null) {
subGraph.discriminator(jdbcMapperFactory);
}
}
}