use of fr.lirmm.graphik.graal.api.core.AtomSetException in project graal by graphik-team.
the class AbstractRdbmsStore method addAll.
@Override
public boolean addAll(CloseableIterator<? extends Atom> stream) throws AtomSetException {
try {
int c = 0;
Statement statement = this.createStatement();
while (stream.hasNext()) {
this.add(statement, stream.next());
if (++c % MAX_BATCH_SIZE == 0) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("batch commit, size=" + MAX_BATCH_SIZE);
}
statement.executeBatch();
statement.close();
statement = this.createStatement();
}
}
// if(statement != null) {// && !statement.isClosed()) {
statement.executeBatch();
statement.close();
// }
this.getConnection().commit();
} catch (Exception e) {
throw new AtomSetException(e);
}
return true;
}
use of fr.lirmm.graphik.graal.api.core.AtomSetException in project graal by graphik-team.
the class AbstractRdbmsStore method contains.
@Override
public boolean contains(Atom atom) throws AtomSetException {
if (!this.check(atom)) {
return false;
}
Statement statement = this.createStatement();
SQLQuery query = this.getConjunctiveQueryTranslator().translateContainsQuery(atom);
boolean res = false;
if (!query.hasSchemaError()) {
ResultSet results;
try {
statement = this.createStatement();
results = statement.executeQuery(query.toString());
if (results.next()) {
res = true;
}
results.close();
} catch (SQLException e) {
if (statement != null) {
try {
statement.close();
} catch (SQLException sqlEx) {
}
}
throw new AtomSetException("Error during check contains atom: " + atom, e);
}
}
return res;
}
use of fr.lirmm.graphik.graal.api.core.AtomSetException in project graal by graphik-team.
the class SQLRuleApplier method apply.
// //////////////////////////////////////////////////////////////////////////
// METHODS
// //////////////////////////////////////////////////////////////////////////
@Override
public boolean apply(Rule rule, RdbmsStore store) throws RuleApplicationException {
boolean returnValue = false;
if (rule.getExistentials().isEmpty()) {
Statement statement = null;
try {
statement = store.getDriver().createStatement();
Iterator<SQLQuery> sqlQueries = store.getConjunctiveQueryTranslator().translate(rule);
while (sqlQueries.hasNext()) {
SQLQuery query = sqlQueries.next();
if (!query.hasSchemaError())
statement.addBatch(query.toString());
}
int[] res = statement.executeBatch();
for (int i = 0; i < res.length; ++i) {
if (res[i] > 0) {
returnValue = true;
break;
}
}
} catch (AtomSetException e) {
throw new RuleApplicationException("An error has been occured during rule application.", e);
} catch (SQLException e) {
throw new RuleApplicationException("An error has been occured during rule application.", e);
} finally {
if (statement != null) {
try {
statement.getConnection().commit();
statement.close();
} catch (SQLException e) {
}
}
}
} else {
returnValue = this.fallback.apply(rule, store);
}
return returnValue;
}
use of fr.lirmm.graphik.graal.api.core.AtomSetException in project graal by graphik-team.
the class SccChase method next.
// /////////////////////////////////////////////////////////////////////////
// PUBLIC METHODS
// /////////////////////////////////////////////////////////////////////////
@Override
public void next() throws ChaseException {
++this.level;
tmpAtom = new LinkedList<Atom>();
for (Integer scc : layers[level]) {
Set<Rule> component = this.sccg.getComponent(scc);
GraphOfRuleDependencies subGraph = this.grd.getSubGraph(component);
if (component.size() == 1 && !subGraph.hasCircuit()) {
try {
CloseableIterator<Atom> it = this.getRuleApplier().delegatedApply(component.iterator().next(), atomSet);
while (it.hasNext()) {
tmpAtom.add(it.next());
}
it.close();
} catch (RuleApplicationException e) {
throw new ChaseException("", e);
} catch (IteratorException e) {
throw new ChaseException("", e);
}
} else {
Chase chase = new ChaseWithGRD<T>(subGraph, atomSet, this.getRuleApplier());
chase.execute();
}
}
try {
atomSet.addAll(new CloseableIteratorAdapter<Atom>(tmpAtom.iterator()));
} catch (AtomSetException e) {
throw new ChaseException("", e);
}
}
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) throws HomomorphismException {
try {
CloseableIteratorWithoutException<Atom> it = q.getAtomSet().iterator();
boolean contains = true;
while (contains && it.hasNext()) {
contains = a.contains(it.next());
}
if (contains) {
return Iterators.singletonIterator(Substitutions.emptySubstitution());
} else {
return Iterators.emptyIterator();
}
} catch (AtomSetException e) {
throw new HomomorphismException(e);
}
}
Aggregations