org.n3r.eql.impl.DecodeMapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of eql Show documentation
Show all versions of eql Show documentation
a simple wrapper framework for jdbc to seperate sql and java code
package org.n3r.eql.impl;
import com.google.common.collect.Maps;
import lombok.Getter;
import lombok.val;
import org.n3r.eql.map.EqlRowMapper;
import org.n3r.eql.util.Pair;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map;
public class DecodeMapper implements EqlRowMapper {
final Map> def = Maps.newHashMap();
@Getter Map map = Maps.newHashMap();
public DecodeMapper(String... defs) {
for (int i = 0; i + 3 <= defs.length; i += 3) {
def.put(defs[i], Pair.of(defs[i + 1], defs[i + 2]));
}
}
@Override
public Object mapRow(ResultSet rs, int rowNum, boolean isSingleColumn) throws SQLException {
val code = rs.getString(1);
val value = rs.getString(2);
val pair = def.get(code);
map.put(pair._1, code);
map.put(pair._2, value);
return null;
}
}