use of fr.lirmm.graphik.util.stream.converter.ConversionException in project graal by graphik-team.
the class Atom2SubstitutionConverterTest method basic2.
@Test
public void basic2() throws ParseException {
// given
Predicate p = DefaultPredicateFactory.instance().create("p", 3);
Variable x = DefaultTermFactory.instance().createVariable("X");
Variable y = DefaultTermFactory.instance().createVariable("Y");
Variable z = DefaultTermFactory.instance().createVariable("Z");
Atom queryAtom = new DefaultAtom(p, x, y, z);
List<Term> ansList = new LinkedList<>();
ansList.add(x);
ansList.add(z);
// when
Converter<Atom, Substitution> converter = new Atom2SubstitutionConverter(queryAtom, ansList);
Substitution s = null;
try {
s = converter.convert(DlgpParser.parseAtom("p(a,b,c)."));
} catch (ConversionException e) {
fail();
}
// then
Constant a = DefaultTermFactory.instance().createConstant("a");
Constant c = DefaultTermFactory.instance().createConstant("c");
assertEquals(a, s.createImageOf(x));
assertEquals(y, s.createImageOf(y));
assertEquals(c, s.createImageOf(z));
}
use of fr.lirmm.graphik.util.stream.converter.ConversionException in project graal by graphik-team.
the class AbstractRdbmsDriver method getTable.
@Override
public DBTable getTable(String tableName) throws SQLException {
tableName = this.formatIdentifier(tableName);
ResultSet tables = this.getMetaData().getTables(null, null, tableName, TABLE_TYPE);
if (tables.next()) {
try {
return this.converter.convert(tables);
} catch (ConversionException e) {
throw new SQLException(e);
}
}
return null;
}
use of fr.lirmm.graphik.util.stream.converter.ConversionException in project graal by graphik-team.
the class ResultSet2DBTableConverter method convert.
// /////////////////////////////////////////////////////////////////////////
// PUBLIC METHODS
// /////////////////////////////////////////////////////////////////////////
@Override
public DBTable convert(ResultSet result) throws ConversionException {
try {
String tableName = result.getString("TABLE_NAME");
List<DBColumn> cols = this.driver.getColumns(tableName);
if (!this.driver.isCaseSensitive()) {
tableName = tableName.toUpperCase();
}
return new DBTable(tableName, cols);
} catch (SQLException e) {
throw new ConversionException(e);
}
}
use of fr.lirmm.graphik.util.stream.converter.ConversionException in project graal by graphik-team.
the class ResultSet2SubstitutionConverter method convert.
// /////////////////////////////////////////////////////////////////////////
// PUBLIC METHODS
// /////////////////////////////////////////////////////////////////////////
@Override
public Substitution convert(ResultSet result) throws ConversionException {
try {
Substitution substitution = new TreeMapSubstitution();
if (!ans.isEmpty()) {
for (Term t : ans) {
if (t.isVariable()) {
int i = result.findColumn(t.getLabel());
int type = result.getMetaData().getColumnType(i);
String value = result.getString(i);
Term substitut = this.queryTranslator.createTermFromColumnType(type, value);
substitution.put((Variable) t, substitut);
}
}
}
return substitution;
} catch (SQLException e) {
throw new ConversionException(e);
} catch (AtomSetException e) {
throw new ConversionException(e);
}
}
Aggregations