use of fr.lirmm.graphik.graal.api.core.AtomSetException in project graal by graphik-team.
the class FullyInstantiatedQueryHomomorphism method execute.
@Override
public CloseableIterator<Substitution> execute(ConjunctiveQuery q, AtomSet a, RulesCompilation rc) throws HomomorphismException {
try {
CloseableIteratorWithoutException<Atom> it = q.getAtomSet().iterator();
boolean contains = true;
while (contains && it.hasNext()) {
Atom atom = it.next();
boolean containsAtom = false;
for (Pair<Atom, Substitution> im : rc.getRewritingOf(atom)) {
containsAtom = a.contains(im.getLeft());
if (containsAtom) {
break;
}
}
contains = containsAtom;
}
if (contains) {
return Iterators.singletonIterator(Substitutions.emptySubstitution());
} else {
return Iterators.emptyIterator();
}
} catch (AtomSetException e) {
throw new HomomorphismException(e);
}
}
use of fr.lirmm.graphik.graal.api.core.AtomSetException in project graal by graphik-team.
the class AtomicQueryHomomorphism method execute.
@Override
public CloseableIterator<Substitution> execute(ConjunctiveQuery q, AtomSet a, RulesCompilation rc) throws HomomorphismException {
try {
List<CloseableIterator<Substitution>> iteratorsList = new LinkedList<CloseableIterator<Substitution>>();
Atom atom = q.getAtomSet().iterator().next();
for (Pair<Atom, Substitution> im : rc.getRewritingOf(atom)) {
iteratorsList.add(new ConverterCloseableIterator<Atom, Substitution>(a.match(im.getLeft()), new Atom2SubstitutionConverter(im.getLeft(), q.getAnswerVariables(), im.getRight())));
}
return new CloseableIteratorAggregator<Substitution>(new CloseableIteratorAdapter<CloseableIterator<Substitution>>(iteratorsList.iterator()));
} catch (AtomSetException e) {
throw new HomomorphismException(e);
}
}
use of fr.lirmm.graphik.graal.api.core.AtomSetException in project graal by graphik-team.
the class AdHocRdbmsStore method clear.
@Override
public void clear() throws AtomSetException {
try {
Statement stat = null;
CloseableIterator<Predicate> it = this.predicatesIterator();
try {
stat = this.createStatement();
while (it.hasNext()) {
Predicate p = it.next();
this.removePredicate(stat, p);
}
stat.execute(String.format(TRUNCATE_TABLE, PREDICATE_TABLE_NAME));
stat.execute(String.format(TRUNCATE_TABLE, TERMS_TABLE));
stat.close();
this.getConnection().commit();
} catch (IteratorException e) {
this.getConnection().rollback();
throw new AtomSetException(e);
} catch (SQLException e) {
this.getConnection().rollback();
throw new AtomSetException(e);
} finally {
if (stat != null)
stat.close();
}
} catch (SQLException e) {
throw new AtomSetException(e);
}
}
use of fr.lirmm.graphik.graal.api.core.AtomSetException in project graal by graphik-team.
the class AdHocRdbmsStore method getPredicateTableIfExist.
@Override
protected DBTable getPredicateTableIfExist(Predicate predicate) throws AtomSetException {
DBTable table = null;
try {
this.getPredicateTableStatement.setString(1, predicate.getIdentifier().toString());
this.getPredicateTableStatement.setInt(2, predicate.getArity());
ResultSet results = this.getPredicateTableStatement.executeQuery();
if (results.next()) {
String predicateTableName = results.getString("predicate_table_name");
table = this.getDriver().getTable(predicateTableName);
}
results.close();
} catch (SQLException e) {
throw new AtomSetException(e);
}
return table;
}
use of fr.lirmm.graphik.graal.api.core.AtomSetException in project graal by graphik-team.
the class AdHocRdbmsStore method add.
// /////////////////////////////////////////////////////////////////////////
// PROTECTED METHODS
// /////////////////////////////////////////////////////////////////////////
/**
* @param statement
* @param atom
* @throws AtomSetException
*/
@Override
protected Statement add(Statement statement, Atom atom) throws AtomSetException {
if (!this.check(atom)) {
// FIXME say why
throw new UnsupportedAtomTypeException("");
}
try {
for (Term t : atom.getTerms()) {
if (this.getTerm(t.getLabel()) == null) {
// FIXME Quick fix for
// VARIABLE and
// CONSTANT with same
// label conflict
this.add(statement, t);
}
}
DBTable table = this.createPredicateTableIfNotExist(atom.getPredicate());
Map<String, String> data = new TreeMap<String, String>();
int i = -1;
for (Term t : atom.getTerms()) {
++i;
data.put("term" + i, '\'' + StringUtils.addSlashes(t.getIdentifier().toString()) + '\'');
}
String query = this.getDriver().getInsertOrIgnoreQuery(table, data);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(atom.toString() + " : " + query.toString());
}
statement.addBatch(query);
} catch (SQLException e) {
throw new AtomSetException(e);
}
return statement;
}
Aggregations