Search in sources :

Example 6 with ConversionException

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));
}
Also used : ConversionException(fr.lirmm.graphik.util.stream.converter.ConversionException) Variable(fr.lirmm.graphik.graal.api.core.Variable) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) Constant(fr.lirmm.graphik.graal.api.core.Constant) DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) Term(fr.lirmm.graphik.graal.api.core.Term) DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) Atom(fr.lirmm.graphik.graal.api.core.Atom) LinkedList(java.util.LinkedList) Predicate(fr.lirmm.graphik.graal.api.core.Predicate) Test(org.junit.Test)

Example 7 with ConversionException

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;
}
Also used : ConversionException(fr.lirmm.graphik.util.stream.converter.ConversionException) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet)

Example 8 with ConversionException

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);
    }
}
Also used : ConversionException(fr.lirmm.graphik.util.stream.converter.ConversionException) DBTable(fr.lirmm.graphik.graal.store.rdbms.util.DBTable) SQLException(java.sql.SQLException) DBColumn(fr.lirmm.graphik.graal.store.rdbms.util.DBColumn)

Example 9 with ConversionException

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);
    }
}
Also used : ConversionException(fr.lirmm.graphik.util.stream.converter.ConversionException) TreeMapSubstitution(fr.lirmm.graphik.graal.core.TreeMapSubstitution) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) SQLException(java.sql.SQLException) AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException) Term(fr.lirmm.graphik.graal.api.core.Term) TreeMapSubstitution(fr.lirmm.graphik.graal.core.TreeMapSubstitution)

Aggregations

ConversionException (fr.lirmm.graphik.util.stream.converter.ConversionException)9 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)7 Term (fr.lirmm.graphik.graal.api.core.Term)7 Atom (fr.lirmm.graphik.graal.api.core.Atom)6 Predicate (fr.lirmm.graphik.graal.api.core.Predicate)6 Variable (fr.lirmm.graphik.graal.api.core.Variable)6 DefaultAtom (fr.lirmm.graphik.graal.core.DefaultAtom)6 LinkedList (java.util.LinkedList)6 Test (org.junit.Test)6 Constant (fr.lirmm.graphik.graal.api.core.Constant)5 SQLException (java.sql.SQLException)3 AtomSetException (fr.lirmm.graphik.graal.api.core.AtomSetException)1 TreeMapSubstitution (fr.lirmm.graphik.graal.core.TreeMapSubstitution)1 DBColumn (fr.lirmm.graphik.graal.store.rdbms.util.DBColumn)1 DBTable (fr.lirmm.graphik.graal.store.rdbms.util.DBTable)1 ResultSet (java.sql.ResultSet)1