org.vagabond.explanation.generation.prov.SourceProvParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vagabond Show documentation
Show all versions of vagabond Show documentation
Vagabond is a tool for automatic generation of explanations for data exchange errors.
package org.vagabond.explanation.generation.prov;
import static org.vagabond.util.LoggerUtil.logArray;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import org.apache.log4j.Logger;
import org.vagabond.explanation.marker.ITupleMarker;
import org.vagabond.explanation.marker.MarkerFactory;
import org.vagabond.explanation.model.prov.ProvWLRepresentation;
import org.vagabond.util.LogProviderHolder;
import org.vagabond.util.ResultSetUtil;
public class SourceProvParser {
static Logger log = LogProviderHolder.getInstance().getLogger(SourceProvParser.class);
private ResultSet dbResult;
private ProvWLRepresentation allProv;
private List tidAttrPos;
private List relNames;
public SourceProvParser (ResultSet result) throws Exception {
this.dbResult = result;
allProv = new ProvWLRepresentation();
tidAttrPos = new ArrayList ();
relNames = new ArrayList ();
parse();
}
private void parse() throws Exception {
parseSchema();
createTupleAndWLSet();
}
private void parseSchema () throws SQLException {
String[] colNames;
String colName;
String relName;
if (log.isDebugEnabled()) {log.debug("parse schema of result set");};
colNames = ResultSetUtil.getResultColumns(dbResult);
for(int i = 0; i < colNames.length; i++) {
colName = colNames[i];
if (isTidProvAttr(colName)) {
relName = ResultSetUtil.getRelFromProvName(colName);
relNames.add(relName);
tidAttrPos.add(i + 1);
}
}
if (log.isDebugEnabled()) {log.debug("Tid attribute positions" + tidAttrPos.toString());};
logArray(log, colNames, "ColNames");
logArray(log, relNames.toArray(), "RelNames");
allProv.setRelNames(relNames);
}
private void createTupleAndWLSet () throws Exception {
Vector witList;
ITupleMarker tup;
String tid;
while(dbResult.next()) {
witList = new Vector ();
for (int i = 0; i < relNames.size(); i++) {
tid = dbResult.getString(tidAttrPos.get(i));
if (log.isDebugEnabled()) {log.debug("parsed tid <" + tid + ">");};
if (tid != null) {
tup = MarkerFactory.newTupleMarker(relNames.get(i), tid);
if (log.isDebugEnabled()) {log.debug("add tuple marker " + tup);};
witList.add(tup);
allProv.addTupleInProv(tup);
}
else
witList.add(null);
}
if (log.isDebugEnabled()) {log.debug("created witness list " + witList);};
allProv.addWitnessList(witList);
}
}
private boolean isTidProvAttr (String name) {
return ResultSetUtil.isProvAttr(name)
&& ResultSetUtil.getAttrFromProvName(name).equals("tid");
}
public ProvWLRepresentation getAllProv() {
return allProv;
}
}