use of fr.lirmm.graphik.graal.api.core.AtomSetException in project graal by graphik-team.
the class AdHocRdbmsStore method atomsByPredicate.
@Override
public CloseableIterator<Atom> atomsByPredicate(Predicate p) throws AtomSetException {
List<Term> terms = new LinkedList<Term>();
for (int i = 0; i < p.getArity(); ++i) {
terms.add(DefaultTermFactory.instance().createVariable("X" + i));
}
Atom atom = DefaultAtomFactory.instance().create(p, terms);
ConjunctiveQuery query = DefaultConjunctiveQueryFactory.instance().create(new LinkedListAtomSet(atom));
SqlHomomorphism solver = SqlHomomorphism.instance();
try {
return new SubstitutionIterator2AtomIterator(atom, solver.execute(query, this));
} catch (HomomorphismException e) {
throw new AtomSetException(e);
}
}
use of fr.lirmm.graphik.graal.api.core.AtomSetException in project graal by graphik-team.
the class AdHocRdbmsStore method testDatabaseSchema.
@Override
protected boolean testDatabaseSchema() throws AtomSetException {
Statement statement = null;
try {
statement = this.createStatement();
ResultSet rs = statement.executeQuery(TEST_SCHEMA_QUERY);
rs.close();
} catch (SQLException e) {
return false;
} catch (AtomSetException e) {
throw new AtomSetException(e.getMessage(), e);
} finally {
if (statement != null) {
try {
statement.close();
this.getConnection().rollback();
} catch (SQLException e) {
throw new AtomSetException(e);
}
}
}
return true;
}
use of fr.lirmm.graphik.graal.api.core.AtomSetException in project graal by graphik-team.
the class AbstractRdbmsConjunctiveQueryTranslator method translate.
@Override
public Iterator<SQLQuery> translate(Rule rangeRestrictedRule) throws AtomSetException {
Collection<SQLQuery> queries = new LinkedList<SQLQuery>();
InMemoryAtomSet body = rangeRestrictedRule.getBody();
CloseableIterator<Atom> it = rangeRestrictedRule.getHead().iterator();
try {
while (it.hasNext()) {
Atom headAtom = it.next();
DBTable table = this.store.createPredicateTableIfNotExist(headAtom.getPredicate());
List<Term> terms = headAtom.getTerms();
ConjunctiveQuery query = DefaultConjunctiveQueryFactory.instance().create(body, terms);
SQLQuery selectQuery = this.translate(query);
if (!selectQuery.hasSchemaError()) {
queries.add(new SQLQuery(store.getDriver().getInsertOrIgnoreQuery(table, selectQuery.toString())));
}
}
} catch (IteratorException e) {
throw new AtomSetException(e);
} catch (SQLException e) {
throw new AtomSetException(e);
}
return queries.iterator();
}
use of fr.lirmm.graphik.graal.api.core.AtomSetException in project graal by graphik-team.
the class AbstractRdbmsConjunctiveQueryTranslator method formatFromColumnType.
@Override
public String formatFromColumnType(DBColumn col, Term term) throws AtomSetException {
switch(col.getType()) {
case Types.BOOLEAN:
case Types.INTEGER:
case Types.BIGINT:
case Types.SMALLINT:
case Types.TINYINT:
case Types.DECIMAL:
case Types.DOUBLE:
if (term instanceof Literal) {
Literal l = (Literal) term;
URI datatype = l.getDatatype();
switch(col.getType()) {
case Types.BOOLEAN:
if (URIUtils.XSD_BOOLEAN.equals(l.getDatatype()) || l.getValue() instanceof Boolean) {
return term.getLabel();
}
throw new AtomSetException("No correspondance between the database field (Boolean) and the Term type (" + datatype.toString() + ")");
case Types.INTEGER:
case Types.BIGINT:
case Types.SMALLINT:
case Types.TINYINT:
if (URIUtils.XSD_INTEGER.equals(l.getDatatype()) || l.getValue() instanceof Integer || l.getValue() instanceof BigInteger) {
return term.getLabel();
}
throw new AtomSetException("No correspondance between the database field (Boolean) and the Term type (" + datatype.toString() + ")");
case Types.DECIMAL:
if (URIUtils.XSD_DECIMAL.equals(l.getDatatype()) || l.getValue() instanceof Float || l.getValue() instanceof BigDecimal) {
return term.getLabel();
}
throw new AtomSetException("No correspondance between the database field (Boolean) and the Term type (" + datatype.toString() + ")");
case Types.DOUBLE:
if (URIUtils.XSD_DOUBLE.equals(l.getDatatype()) || l.getValue() instanceof Double) {
return term.getLabel();
}
throw new AtomSetException("No correspondance between the database field (Boolean) and the Term type (" + datatype.toString() + ")");
}
} else {
throw new AtomSetException("No correspondance between the database field (Boolean) and the Term type.");
}
case Types.VARCHAR:
case Types.NVARCHAR:
case Types.LONGVARCHAR:
case Types.LONGNVARCHAR:
return '\'' + term.getIdentifier().toString() + '\'';
default:
throw new AtomSetException("Column type not supported (see java.sql.Types): " + col.getType());
}
}
use of fr.lirmm.graphik.graal.api.core.AtomSetException in project graal by graphik-team.
the class NaturalRDBMSStore method atomsByPredicate.
@Override
public CloseableIterator<Atom> atomsByPredicate(Predicate p) throws AtomSetException {
if (!this.check(p)) {
return Iterators.<Atom>emptyIterator();
}
List<Term> terms = new LinkedList<Term>();
for (int i = 0; i < p.getArity(); ++i) {
terms.add(DefaultTermFactory.instance().createVariable("X" + i));
}
Atom atom = DefaultAtomFactory.instance().create(p, terms);
ConjunctiveQuery query = DefaultConjunctiveQueryFactory.instance().create(new LinkedListAtomSet(atom));
SqlHomomorphism solver = SqlHomomorphism.instance();
try {
return new SubstitutionIterator2AtomIterator(atom, solver.execute(query, this));
} catch (HomomorphismException e) {
throw new AtomSetException(e);
}
}
Aggregations